You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2019/03/14 22:08:39 UTC

[mynewt-core] branch sensor_reset_api created (now 69f7e76)

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

vipulrahane pushed a change to branch sensor_reset_api
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


      at 69f7e76  hw/sensors: Add API for doing sensor_reset()

This branch includes the following new commits:

     new 69f7e76  hw/sensors: Add API for doing sensor_reset()

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[mynewt-core] 01/01: hw/sensors: Add API for doing sensor_reset()

Posted by vi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 69f7e761d20002aa3ad05a86c7135549f39d9218
Author: Vipul Rahane <vr...@gmail.com>
AuthorDate: Thu Mar 14 15:07:12 2019 -0700

    hw/sensors: Add API for doing sensor_reset()
    
    - Add optional API for doing sensor_reset()
    - Use the API for LPS33HW and LPS33THW
---
 .../sensors/lps33hw/include/lps33hw/lps33hw.h      |  4 ++--
 hw/drivers/sensors/lps33hw/src/lps33hw.c           |  9 ++++++--
 .../sensors/lps33thw/include/lps33thw/lps33thw.h   |  4 ++--
 hw/drivers/sensors/lps33thw/src/lps33thw.c         |  9 ++++++--
 hw/sensor/include/sensor/sensor.h                  | 19 +++++++++++++++
 hw/sensor/src/sensor.c                             | 27 ++++++++++++++++++++++
 6 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
index cc3e102..9c42eae 100644
--- a/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
+++ b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
@@ -126,11 +126,11 @@ int lps33hw_set_lpf(struct sensor_itf *itf,
 /**
  * Software reset.
  *
- * @param The interface object associated with the lps33hw.
+ * @param Ptr to the sensor
  *
  * @return 0 on success, non-zero error on failure.
  */
-int lps33hw_reset(struct sensor_itf *itf);
+int lps33hw_reset(struct sensor *sensor);
 
 /*
  * Get pressure.
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw.c b/hw/drivers/sensors/lps33hw/src/lps33hw.c
index c7585f0..a2d9e9b 100644
--- a/hw/drivers/sensors/lps33hw/src/lps33hw.c
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw.c
@@ -99,7 +99,8 @@ static const struct sensor_driver g_lps33hw_sensor_driver = {
     .sd_set_trigger_thresh        = lps33hw_sensor_set_trigger_thresh,
     .sd_handle_interrupt          = lps33hw_sensor_handle_interrupt,
     .sd_clear_low_trigger_thresh  = lps33hw_sensor_clear_low_thresh,
-    .sd_clear_high_trigger_thresh = lps33hw_sensor_clear_high_thresh
+    .sd_clear_high_trigger_thresh = lps33hw_sensor_clear_high_thresh,
+    .sd_reset                     = lps33hw_reset
 };
 
 /*
@@ -534,8 +535,12 @@ lps33hw_set_lpf(struct sensor_itf *itf, enum lps33hw_low_pass_config lpf)
 }
 
 int
-lps33hw_reset(struct sensor_itf *itf)
+lps33hw_reset(struct sensor *sensor)
 {
+    struct sensor_itf *itf;
+
+    itf = SENSOR_GET_ITF(sensor);
+
     return lps33hw_set_reg(itf, LPS33HW_CTRL_REG2, 0x04);
 }
 
diff --git a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
index 89f1a5a..b4a7c1c 100644
--- a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
+++ b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
@@ -127,11 +127,11 @@ int lps33thw_set_lpf(struct sensor_itf *itf,
 /**
  * Software reset.
  *
- * @param The interface object associated with the lps33thw.
+ * @param Ptr to the sensor
  *
  * @return 0 on success, non-zero error on failure.
  */
-int lps33thw_reset(struct sensor_itf *itf);
+int lps33thw_reset(struct sensor *sensor);
 
 /*
  * Get pressure.
diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index e800a3a..52adc68 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -99,7 +99,8 @@ static const struct sensor_driver g_lps33thw_sensor_driver = {
     .sd_set_trigger_thresh        = lps33thw_sensor_set_trigger_thresh,
     .sd_handle_interrupt          = lps33thw_sensor_handle_interrupt,
     .sd_clear_low_trigger_thresh  = lps33thw_sensor_clear_low_thresh,
-    .sd_clear_high_trigger_thresh = lps33thw_sensor_clear_high_thresh
+    .sd_clear_high_trigger_thresh = lps33thw_sensor_clear_high_thresh,
+    .sd_reset                     = lps33thw_reset
 };
 
 /*
@@ -538,8 +539,12 @@ lps33thw_set_lpf(struct sensor_itf *itf, enum lps33thw_low_pass_config lpf)
 }
 
 int
-lps33thw_reset(struct sensor_itf *itf)
+lps33thw_reset(struct sensor *sensor)
 {
+    struct sensor_itf *itf;
+     
+    itf = SENSOR_GET_ITF(sensor);
+
     return lps33thw_set_reg(itf, LPS33THW_CTRL_REG2, 0x04);
 }
 
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 8828756..26c64ae 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -484,6 +484,16 @@ typedef int (*sensor_unset_notification_t)(struct sensor *,
  */
 typedef int (*sensor_handle_interrupt_t)(struct sensor *sensor);
 
+/**
+ * Reset Sensor function Ptr
+ *
+ * @param Ptr to the sensor
+ *
+ * @return 0 on success, non-zero on failure
+ */
+typedef int (*sensor_reset_t)(struct sensor *);
+
+
 struct sensor_driver {
     sensor_read_func_t sd_read;
     sensor_get_config_func_t sd_get_config;
@@ -494,6 +504,7 @@ struct sensor_driver {
     sensor_set_notification_t sd_set_notification;
     sensor_unset_notification_t sd_unset_notification;
     sensor_handle_interrupt_t sd_handle_interrupt;
+    sensor_reset_t sd_reset;
 };
 
 struct sensor_timestamp {
@@ -1097,6 +1108,14 @@ sensor_mgr_put_interrupt_evt(struct sensor *sensor);
 void
 sensor_mgr_put_read_evt(void *arg);
 
+/**
+ * Resets the sensor
+ *
+ * @param Ptr to sensor
+ */
+int
+sensor_reset(struct sensor *sensor);
+
 #if MYNEWT_VAL(SENSOR_CLI)
 /**
  * Convinience API to convert floats to strings,
diff --git a/hw/sensor/src/sensor.c b/hw/sensor/src/sensor.c
index 53b531a..19714b8 100644
--- a/hw/sensor/src/sensor.c
+++ b/hw/sensor/src/sensor.c
@@ -2202,3 +2202,30 @@ err:
     return (rc);
 }
 
+/**
+ * Reset sensor
+ *
+ * @param Ptr to the sensor
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+sensor_reset(struct sensor *sensor)
+{
+    int rc;
+
+    if (!sensor->s_funcs->sd_reset) {
+        rc = SYS_EINVAL;
+        return rc;
+    }
+
+    rc = sensor_lock(sensor);
+    if (rc) {
+        return rc;
+    }
+
+    rc = sensor->s_funcs->sd_reset(sensor);
+
+    sensor_unlock(sensor);
+    return rc;
+}