You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/11/19 21:24:22 UTC

[mynewt-core] 01/04: sensors/bme280: Update CLI to bus driver

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 4f1ef774a0d8dbb0e49afa88c45a2044ceee49a5
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Nov 18 14:16:41 2019 +0100

    sensors/bme280: Update CLI to bus driver
    
    bme280_shell.c was not updated to work with bus driver.
---
 hw/drivers/sensors/bme280/src/bme280_shell.c | 50 ++++++++++++++++++++++++++++
 hw/drivers/sensors/bme280/syscfg.yml         |  8 ++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/hw/drivers/sensors/bme280/src/bme280_shell.c b/hw/drivers/sensors/bme280/src/bme280_shell.c
index 76e513d..5c702e6 100644
--- a/hw/drivers/sensors/bme280/src/bme280_shell.c
+++ b/hw/drivers/sensors/bme280/src/bme280_shell.c
@@ -28,6 +28,7 @@
 #include "bme280/bme280.h"
 #include "bme280_priv.h"
 #include "parse/parse.h"
+#include "bsp/bsp.h"
 
 static int bme280_shell_cmd(int argc, char **argv);
 
@@ -36,11 +37,15 @@ static struct shell_cmd bme280_shell_cmd_struct = {
     .sc_cmd_func = bme280_shell_cmd
 };
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static struct sensor_itf g_sensor_itf;
+#else
 static struct sensor_itf g_sensor_itf = {
     .si_type = MYNEWT_VAL(BME280_SHELL_ITF_TYPE),
     .si_num = MYNEWT_VAL(BME280_SHELL_ITF_NUM),
     .si_cs_pin = MYNEWT_VAL(BME280_SHELL_CSPIN)
 };
+#endif
 
 static int
 bme280_shell_err_too_many_args(char *cmd_name)
@@ -396,11 +401,56 @@ bme280_shell_cmd(int argc, char **argv)
     return bme280_shell_err_unknown_arg(argv[1]);
 }
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+
+struct bme280 bme280_raw;
+#if MYNEWT_VAL(BME280_SHELL_ITF_TYPE) == SENSOR_ITF_I2C
+
+static const struct bus_i2c_node_cfg bme280_raw_cfg = {
+    .node_cfg = {
+        .bus_name = MYNEWT_VAL(BME280_SHELL_ITF_BUS),
+    },
+    .addr = MYNEWT_VAL(BME280_SHELL_ITF_ADDR),
+    .freq = 400,
+};
+#elif MYNEWT_VAL(BME280_SHELL_ITF_TYPE) == SENSOR_ITF_SPI
+
+static const struct bus_spi_node_cfg bme280_raw_cfg = {
+    .node_cfg = {
+        .bus_name = MYNEWT_VAL(BME280_SHELL_ITF_BUS),
+    },
+    .pin_cs = MYNEWT_VAL(BME280_SHELL_CSPIN),
+    .data_order = BUS_SPI_DATA_ORDER_MSB,
+    .mode = BUS_SPI_MODE_0,
+    .freq = 4000,
+};
+#endif
+
+#endif
+
 int
 bme280_shell_init(void)
 {
     int rc;
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    struct os_dev *dev = NULL;
+
+    g_sensor_itf.si_dev = (struct os_dev *)&bme280_raw;
+#if MYNEWT_VAL(BME280_SHELL_ITF_TYPE) == SENSOR_ITF_I2C
+    rc = bus_i2c_node_create("bme280_raw", &bme280_raw.i2c_node,
+                             &bme280_raw_cfg, &g_sensor_itf);
+#elif MYNEWT_VAL(BME280_SHELL_ITF_TYPE) == SENSOR_ITF_SPI
+    rc = bus_spi_node_create("bme280_raw", &bme280_raw.spi_node,
+                             &bme280_raw_cfg, &g_sensor_itf);
+#endif
+    if (rc == 0) {
+        dev = os_dev_open("bme280_raw", 0, NULL);
+    }
+    if (rc != 0 || dev == NULL) {
+        console_printf("Failed to create bme280_raw device\n");
+    }
+#endif
     rc = shell_cmd_register(&bme280_shell_cmd_struct);
     SYSINIT_PANIC_ASSERT(rc == 0);
 
diff --git a/hw/drivers/sensors/bme280/syscfg.yml b/hw/drivers/sensors/bme280/syscfg.yml
index ebfa9b0..85116ea 100644
--- a/hw/drivers/sensors/bme280/syscfg.yml
+++ b/hw/drivers/sensors/bme280/syscfg.yml
@@ -25,11 +25,17 @@ syscfg.defs:
         description: 'Shell interface number for the BME280'
         value: 0
     BME280_SHELL_ITF_TYPE:
-        description: 'Shell interface type for the BME280'
+        description: 'Shell interface type for the BME280 (0 - SPI, 1 - I2C)'
         value: 0
+    BME280_SHELL_ITF_BUS:
+        description: 'Shell interface bus for the BME280 when bus driver is used'
+        value: '"spi0"'
     BME280_SHELL_CSPIN:
         description: 'CS pin for BME280'
         value : 3
+    BME280_SHELL_ITF_ADDR:
+        description: 'Slave address for BME280 (0x76 or 0x77)'
+        value : 0x77
     BME280_CLI:
         description: 'Enable shell support for the BME280'
         value: 0