diff --git a/hw/bsp/dwm1001/pkg.yml b/hw/bsp/dwm1001/pkg.yml index d7512f8..9d4502f 100644 --- a/hw/bsp/dwm1001/pkg.yml +++ b/hw/bsp/dwm1001/pkg.yml @@ -45,3 +45,9 @@ pkg.deps.CIR_ENABLED: pkg.deps.BLE_LP_CLOCK: - "@apache-mynewt-nimble/nimble/drivers/nrf52" + +pkg.deps.LIS2DH12_ONB: + - "@apache-mynewt-core/hw/drivers/sensors/lis2dh12" + +pkg.init: + config_lis2dh12_sensor: 'MYNEWT_VAL(DWM1001_DEV_SYSINIT_STAGE_LIS2DH12)' diff --git a/hw/bsp/dwm1001/src/hal_bsp.c b/hw/bsp/dwm1001/src/hal_bsp.c index b166db8..aa1f6bc 100644 --- a/hw/bsp/dwm1001/src/hal_bsp.c +++ b/hw/bsp/dwm1001/src/hal_bsp.c @@ -42,6 +42,31 @@ #include "os/os_dev.h" #include "bsp/bsp.h" +#if MYNEWT_VAL(LIS2DH12_ONB) +#include "lis2dh12/lis2dh12.h" +static struct lis2dh12 lis2dh12; +#endif + +#if MYNEWT_VAL(LIS2DH12_ONB) +static struct sensor_itf i2c_0_itf_lis = { + .si_type = SENSOR_ITF_I2C, + .si_num = 0, + .si_addr = 0x19, + .si_ints = { + { /* TODO: determine correct values */ + .host_pin = 25, + .device_pin = 0, + .active = true + }, + { /* TODO: determine correct values */ + .host_pin = 25, + .device_pin = 0, + .active = true + } + } +}; +#endif + #if MYNEWT_VAL(SPI_0_MASTER) struct dpl_sem g_spi0_sem; @@ -129,6 +154,33 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri) return cfg_pri; } +int +config_lis2dh12_sensor(void) +{ +#if MYNEWT_VAL(LIS2DH12_ONB) + int rc; + struct os_dev *dev; + struct lis2dh12_cfg cfg; + + dev = (struct os_dev *) os_dev_open("lis2dh12_0", OS_TIMEOUT_NEVER, NULL); + assert(dev != NULL); + + + memset(&cfg, 0, sizeof(cfg)); + + cfg.lc_s_mask = SENSOR_TYPE_ACCELEROMETER; + cfg.lc_rate = LIS2DH12_DATA_RATE_HN_1344HZ_L_5376HZ; + cfg.lc_fs = LIS2DH12_FS_2G; + cfg.lc_pull_up_disc = 1; + + rc = lis2dh12_config((struct lis2dh12 *)dev, &cfg); + SYSINIT_PANIC_ASSERT(rc == 0); + + os_dev_close(dev); +#endif + return 0; +} + void hal_bsp_init(void) @@ -143,6 +195,13 @@ hal_bsp_init(void) /* Create all available nRF52832 peripherals */ nrf52_periph_create(); +#if MYNEWT_VAL(LIS2DH12_ONB) + rc = os_dev_create((struct os_dev *) &lis2dh12, "lis2dh12_0", + OS_DEV_INIT_PRIMARY, 0, lis2dh12_init, + (void *)&i2c_0_itf_lis); + assert(rc == 0); +#endif + #if MYNEWT_VAL(SPI_0_MASTER) rc = dpl_sem_init(&g_spi0_sem, 0x1); assert(rc == 0); diff --git a/hw/bsp/dwm1001/syscfg.yml b/hw/bsp/dwm1001/syscfg.yml index f5e33de..3e636ca 100644 --- a/hw/bsp/dwm1001/syscfg.yml +++ b/hw/bsp/dwm1001/syscfg.yml @@ -58,6 +58,14 @@ syscfg.defs: DW1000_DEVICE_0_RX_ANT_DLY: description: 'RX_ANT_DLY' value: 0x4042 + LIS2DH12_ONB: + description: 'Enable DWM1001 onboard LIS2DH12 sensor' + value: 0 + + DWM1001_DEV_SYSINIT_STAGE_LIS2DH12: + description: > + Sysinit stage for the DWM1001-dev; initializes the LIS2DH12 sensor. + value: 400 syscfg.vals: MCU_TARGET: nRF52832