You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/01/02 09:48:05 UTC

[mynewt-core] 02/02: hw/drivers/lis2dw12: Improve self test procedure

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

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

commit 4639374ebf1eade941693c9501eb7375b32ba58a
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri Nov 30 16:15:02 2018 +0100

    hw/drivers/lis2dw12: Improve self test procedure
    
    If FIFO was enabled before self test was executed it would fail.
    Failure was due test reading old data from FIFO (data stored there
    before self test was started).
    Now FIFO is turned off before self test is turned on and later
    it is restored to original state.
---
 hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
index 359455a..dd0c71e 100644
--- a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
+++ b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
@@ -2069,6 +2069,21 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
 
     *result = 0;
 
+    uint8_t fifo_ctrl;
+
+    rc = lis2dw12_read8(itf, LIS2DW12_REG_FIFO_CTRL, &fifo_ctrl);
+    if (rc) {
+        return rc;
+    }
+
+    if (fifo_ctrl) {
+        /* Turn off fifo if was on */
+        rc = lis2dw12_write8(itf, LIS2DW12_REG_FIFO_CTRL, 0);
+        if (rc) {
+            return rc;
+        }
+    }
+
     rc = lis2dw12_readlen(itf, LIS2DW12_REG_CTRL_REG1, prev_config, 6);
     if (rc) {
         return rc;
@@ -2208,6 +2223,14 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
     st[1] = scratch[1] / LIS2DW12_ST_NUM_READINGS;
     st[2] = scratch[2] / LIS2DW12_ST_NUM_READINGS;
 
+    /* Restore fifo mode if any */
+    if (fifo_ctrl) {
+        rc = lis2dw12_write8(itf, LIS2DW12_REG_FIFO_CTRL, fifo_ctrl);
+        if (rc) {
+            return rc;
+        }
+    }
+
     /* compare values to thresholds */
     for (i = 0; i < 3; i++) {
         diff = abs(st[i] - no_st[i]);