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/11/23 16:16:50 UTC

[mynewt-core] 18/26: hw/sensor: Add sensor_node_cfg structure

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 4b54d2062980b245c9b4e2466386aece224c53a6
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Nov 15 22:07:51 2018 +0100

    hw/sensor: Add sensor_node_cfg structure
    
    To create os_dev which is a bus node for sensor device we need to pass
    both node configuration and sensor interface. To make this easier,
    there's now sensor_node_cfg struc provided which contains both data and
    can be passed when creating os_dev.
---
 hw/sensor/include/sensor/sensor.h | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 59d42a9..7df28b4 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -23,6 +23,10 @@
 #include <string.h>
 #include "os/mynewt.h"
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#include "bus/i2c.h"
+#include "bus/spi.h"
+#endif
 #if MYNEWT_VAL(SENSOR_OIC)
 #include "oic/oc_ri.h"
 #endif
@@ -506,7 +510,9 @@ struct sensor_int {
 
 struct sensor_itf {
 
-#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    /* Device configuration is stored in bus node */
+#else
     /* Sensor interface type */
     uint8_t si_type;
 
@@ -526,7 +532,9 @@ struct sensor_itf {
     /* Sensor interface high int pin */
     uint8_t si_high_pin;
 
-#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    /* No need for mutex - locking is done by bus driver */
+#else
     /* Mutex for interface access */
     struct os_mutex *si_lock;
 #endif
@@ -537,6 +545,16 @@ struct sensor_itf {
     struct sensor_int si_ints[MYNEWT_VAL(SENSOR_MAX_INTERRUPTS_PINS)];
 };
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+struct sensor_node_cfg {
+    struct sensor_itf itf;
+    union {
+        struct bus_i2c_node_cfg i2c_node_cfg;
+        struct bus_spi_node_cfg spi_node_cfg;
+    };
+};
+#endif
+
 /*
  * Return the OS device structure corresponding to this sensor
  */