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/03 12:42:12 UTC
[mynewt-core] 01/15: hw/sensor: Refactor sensor_itf 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 476a89bf95513c6ae3db327875b32c8cecefe5c9
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Nov 23 17:21:38 2018 +0100
hw/sensor: Refactor sensor_itf with bus driver
Initial idea of retrieving os_dev from sensor_itf when using bus driver
seems to be a bad idea since as it turns out there is some exsising
code which uses "loose" sensor_itf structures to access sensors.
To fix this, let's have os_dev pointer as a part of sensor_itf. It
should be initialized to point to os_dev structure for sensor and then
it can be used as usual.
---
hw/sensor/include/sensor/sensor.h | 31 ++++---------------------------
1 file changed, 4 insertions(+), 27 deletions(-)
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 7df28b4..4f5c6da 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -512,6 +512,7 @@ struct sensor_itf {
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
/* Device configuration is stored in bus node */
+ struct os_dev *si_dev;
#else
/* Sensor interface type */
uint8_t si_type;
@@ -524,6 +525,9 @@ struct sensor_itf {
/* Sensor address */
uint16_t si_addr;
+
+ /* Mutex for interface access */
+ struct os_mutex *si_lock;
#endif
/* Sensor interface low int pin */
@@ -532,29 +536,12 @@ struct sensor_itf {
/* Sensor interface high int pin */
uint8_t si_high_pin;
-#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
-
/* Sensor interface interrupts pins */
/* XXX We should probably remove low/high pins and replace it with those
*/
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
*/
@@ -566,16 +553,6 @@ struct sensor_node_cfg {
#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
*/