This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 8528cdf59c0d02f803e965b596ea35481bbd6b6f Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> AuthorDate: Wed Jun 12 17:17:49 2019 +0200 sensor/creator: Add BMP280 bus driver support Now sensor creator can creat BPM280 devices for SPI and I2C when bus driver is present. --- hw/sensor/creator/src/sensor_creator.c | 35 ++++++++++++++++++++++++++++++++-- hw/sensor/creator/syscfg.yml | 31 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/hw/sensor/creator/src/sensor_creator.c b/hw/sensor/creator/src/sensor_creator.c index c63fe04..2e26856 100644 --- a/hw/sensor/creator/src/sensor_creator.c +++ b/hw/sensor/creator/src/sensor_creator.c @@ -225,13 +225,35 @@ static struct icp101xx icp10114; *#endif */ -#if MYNEWT_VAL(I2C_0) && MYNEWT_VAL(BMP280_OFB) +#if MYNEWT_VAL(BMP280_OFB) +#if MYNEWT_VAL(BUS_DRIVER_PRESENT) +#if MYNEWT_VAL(BMP280_OFB_I2C_NUM) >= 0 +static const struct bus_i2c_node_cfg bmp280_node_cfg = { + .node_cfg = { + .bus_name = MYNEWT_VAL(BMP280_OFB_BUS), + }, + .addr = MYNEWT_VAL(BMP280_OFB_I2C_ADDR), + .freq = 400, +}; +#endif +#if MYNEWT_VAL(BMP280_OFB_SPI_NUM) >= 0 +struct bus_spi_node_cfg bmp280_node_cfg = { + .node_cfg.bus_name = MYNEWT_VAL(BME280_OFB_SPI_BUS), + .pin_cs = MYNEWT_VAL(BMP280_OFB_CS), + .mode = BUS_SPI_MODE_0, + .data_order = HAL_SPI_MSB_FIRST, + .freq = MYNEWT_VAL(BMP280_OFB_BAUDRATE), +}; +#endif +static struct sensor_itf bmp280_itf; +#elif MYNEWT_VAL(I2C_0) static struct sensor_itf i2c_0_itf_bmp = { .si_type = SENSOR_ITF_I2C, .si_num = 0, .si_addr = BMP280_DFLT_I2C_ADDR }; #endif +#endif #if MYNEWT_VAL(SPI_0_MASTER) && MYNEWT_VAL(BME280_OFB) #if MYNEWT_VAL(BUS_DRIVER_PRESENT) @@ -1545,10 +1567,19 @@ sensor_dev_create(void) #endif #if MYNEWT_VAL(BMP280_OFB) +#if MYNEWT_VAL(BUS_DRIVER_PRESENT) +#if MYNEWT_VAL(BMP280_OFB_I2C_NUM) >= 0 + rc = bmp280_create_i2c_sensor_dev(&bmp280.i2c_node, "bmp280_0", + &bmp280_node_cfg, &bmp280_itf); +#elif MYNEWT_VAL(BMP280_OFB_SPI_NUM) >= 0 + rc = bmp280_create_spi_sensor_dev(&bmp280.spi_node, "bmp280_0", + &bmp280_node_cfg, &bmp280_itf); +#endif +#else rc = os_dev_create((struct os_dev *) &bmp280, "bmp280_0", OS_DEV_INIT_PRIMARY, 0, bmp280_init, (void *)&i2c_0_itf_bmp); assert(rc == 0); - +#endif rc = config_bmp280_sensor(); assert(rc == 0); #endif diff --git a/hw/sensor/creator/syscfg.yml b/hw/sensor/creator/syscfg.yml index 756504d..c8d0c7d 100644 --- a/hw/sensor/creator/syscfg.yml +++ b/hw/sensor/creator/syscfg.yml @@ -67,6 +67,37 @@ syscfg.defs: BMP280_OFB: description: 'BMP280 is present' value : 0 + BMP280_OFB_BUS: + description: 'I2C or SPI interface used for BMP280' + value: '"i2c0"' + BMP280_OFB_I2C_NUM: + description: 'I2C interface used for BMP280' + value: -1 + restrictions: + - '(BMP280_OFB == 0) || + ((BMP280_OFB_I2C_NUM == 0) && (I2C_0 == 1)) || + ((BMP280_OFB_I2C_NUM == 1) && (I2C_1 == 1)) || + ((BMP280_OFB_I2C_NUM == 2) && (I2C_2 == 1)) || + ((BMP280_OFB_I2C_NUM == -1))' + BMP280_OFB_SPI_NUM: + description: 'SPI interface used for ADXL345' + value: -1 + restrictions: + - '(BMP280_OFB == 0) || + ((BMP280_OFB_SPI_NUM == 0) && (SPI_0_MASTER == 1)) || + ((BMP280_OFB_SPI_NUM == 1) && (SPI_1_MASTER == 1)) || + ((BMP280_OFB_SPI_NUM == 2) && (SPI_2_MASTER == 1)) || + ((BMP280_OFB_SPI_NUM == -1))' + BMP280_OFB_BAUDRATE: + description: 'BMP280 SPI speed' + value: 4000 + BMP280_OFB_I2C_ADDR: + description: 'I2C address of BMP280 0x76 or 0x77' + value: 0x77 + range: 0x76,0x77 + BMP280_OFB_CS: + description: 'SPI CS pin for BMP280' + value: TCS34725_OFB: description: 'TCS34725 is present' value : 0