You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2018/12/05 14:34:38 UTC

[mynewt-core] 07/08: hw/drivers/lps33thw: Add proper I2C/SPI interface handling

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 3ff35b3dc24d295b8ef62fc3f81f17c3e69680af
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:48:49 2018 +0100

    hw/drivers/lps33thw: Add proper I2C/SPI interface handling
---
 hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h |  3 +++
 hw/drivers/sensors/lps33thw/src/lps33thw.c              | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
index 083d8ac..de17a31 100644
--- a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
+++ b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
@@ -94,6 +94,9 @@ struct lps33thw {
     struct lps33thw_cfg cfg;
     os_time_t last_read_time;
     struct lps33thw_private_driver_data pdd;
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    bool node_is_spi;
+#endif
 };
 
 /**
diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index d4d94f0..eaab21a 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -411,6 +411,12 @@ lps33thw_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
     int rc;
 
 #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    struct lps33thw *dev = (struct lps33thw *)itf->si_dev;
+
+    if (dev->node_is_spi) {
+        reg |= LPS33THW_SPI_READ_CMD_BIT;
+    }
+
     rc = bus_node_simple_write_read_transact(itf->si_dev, &reg, 1, buffer, size);
 #else
     rc = sensor_itf_lock(itf, MYNEWT_VAL(LPS33THW_ITF_LOCK_TMO));
@@ -1128,11 +1134,14 @@ lps33thw_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
                                const struct bus_i2c_node_cfg *i2c_cfg,
                                struct sensor_itf *sensor_itf)
 {
+    struct lps33thw *dev = (struct lps33thw *)node;
     struct bus_node_callbacks cbs = {
         .init = init_node_cb,
     };
     int rc;
 
+    dev->node_is_spi = false;
+
     bus_node_set_callbacks((struct os_dev *)node, &cbs);
 
     rc = bus_i2c_node_create(name, node, i2c_cfg, sensor_itf);
@@ -1145,11 +1154,14 @@ lps33thw_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
                                const struct bus_spi_node_cfg *spi_cfg,
                                struct sensor_itf *sensor_itf)
 {
+    struct lps33thw *dev = (struct lps33thw *)node;
     struct bus_node_callbacks cbs = {
         .init = init_node_cb,
     };
     int rc;
 
+    dev->node_is_spi = true;
+
     bus_node_set_callbacks((struct os_dev *)node, &cbs);
 
     rc = bus_spi_node_create(name, node, spi_cfg, sensor_itf);