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:42 UTC

[mynewt-core] 10/26: hw/sensor: Adjust sensors to work with bus driver

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 95bdd145ac352c28f19a36a4eefd10b5c45d0bbd
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Nov 8 18:08:07 2018 +0100

    hw/sensor: Adjust sensors to work with bus driver
    
    With bus driver enabled sensor interface does not need to manage locks
    and device configuration so let's just remove this part in such case.
    This means we needs all sensors used by sensor interface to be either
    bus-driver-compatible or legacy-compatible depending on what we use.
---
 hw/sensor/include/sensor/sensor.h | 14 ++++++++++++++
 hw/sensor/src/sensor.c            |  6 ++++++
 2 files changed, 20 insertions(+)

diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index bedf034..59d42a9 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -506,6 +506,7 @@ struct sensor_int {
 
 struct sensor_itf {
 
+#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
     /* Sensor interface type */
     uint8_t si_type;
 
@@ -517,6 +518,7 @@ struct sensor_itf {
 
     /* Sensor address */
     uint16_t si_addr;
+#endif
 
     /* Sensor interface low int pin */
     uint8_t si_low_pin;
@@ -524,8 +526,10 @@ struct sensor_itf {
     /* Sensor interface high int pin */
     uint8_t si_high_pin;
 
+#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
     /* Mutex for interface access */
     struct os_mutex *si_lock;
+#endif
 
     /* Sensor interface interrupts pins */
     /* XXX We should probably remove low/high pins and replace it with those
@@ -544,6 +548,16 @@ struct sensor_itf {
 #define SENSOR_GET_ITF(__s) (&((__s)->s_itf))
 
 /*
+ * Return original sensor from sensor interface
+ */
+#define SENSOR_ITF_GET_SENSOR(__itf)    CONTAINER_OF((__itf), struct sensor, s_itf)
+
+/*
+ * Return OS device for original sensor from sensor interface
+ */
+#define SENSOR_ITF_GET_DEVICE(__itf)    SENSOR_GET_DEVICE(SENSOR_ITF_GET_SENSOR((__itf)))
+
+/*
  * Checks if the sensor data is valid and then compares if it is greater than
  * the data that is specified
  */
diff --git a/hw/sensor/src/sensor.c b/hw/sensor/src/sensor.c
index 634fcca..1e9e5da 100644
--- a/hw/sensor/src/sensor.c
+++ b/hw/sensor/src/sensor.c
@@ -868,6 +868,7 @@ sensor_pkg_init(void)
 int
 sensor_itf_lock(struct sensor_itf *si, uint32_t timeout)
 {
+#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
     int rc;
     os_time_t ticks;
 
@@ -886,6 +887,9 @@ sensor_itf_lock(struct sensor_itf *si, uint32_t timeout)
     }
 
     return (rc);
+#else
+    return 0;
+#endif
 }
 
 /**
@@ -898,11 +902,13 @@ sensor_itf_lock(struct sensor_itf *si, uint32_t timeout)
 void
 sensor_itf_unlock(struct sensor_itf *si)
 {
+#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
     if (!si->si_lock) {
         return;
     }
 
     os_mutex_release(si->si_lock);
+#endif
 }