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

[mynewt-core] branch master updated (8f6ab27 -> 4639374)

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

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


    from 8f6ab27  sys/fault: Stub implementation
     new 9218c05  hw/drivers/lis2dw12: Adjust coding style
     new 4639374  hw/drivers/lis2dw12: Improve self test procedure

The 2 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.


Summary of changes:
 hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 87 +++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 30 deletions(-)


[mynewt-core] 01/02: hw/drivers/lis2dw12: Adjust coding style

Posted by je...@apache.org.
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 9218c05d0712ed13e7a903741e595fe1242dc14c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Dec 13 12:53:49 2018 +0100

    hw/drivers/lis2dw12: Adjust coding style
    
    C++ comments changed to C style.
    White space changes.
    Variable declarations put before code.
    
    No functional changes.
---
 hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 64 ++++++++++++++++--------------
 1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
index c25df42..359455a 100644
--- a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
+++ b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
@@ -2061,9 +2061,13 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
     int32_t scratch[3] = {0,0,0};
     int i;
     uint8_t prev_config[6];
-    *result = 0;
-    uint8_t config[6] = { LIS2DW12_DATA_RATE_50HZ | LIS2DW12_PM_HIGH_PERF, LIS2DW12_CTRL_REG2_IF_ADD_INC | LIS2DW12_CTRL_REG2_BDU, 0x00, 0x00, 0x00, LIS2DW12_FS_4G};
+    uint8_t config[6] = { LIS2DW12_DATA_RATE_50HZ | LIS2DW12_PM_HIGH_PERF,
+                          LIS2DW12_CTRL_REG2_IF_ADD_INC | LIS2DW12_CTRL_REG2_BDU,
+                          0x00, 0x00, 0x00, LIS2DW12_FS_4G};
     uint8_t fs;
+    int16_t diff;
+
+    *result = 0;
 
     rc = lis2dw12_readlen(itf, LIS2DW12_REG_CTRL_REG1, prev_config, 6);
     if (rc) {
@@ -2088,21 +2092,21 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
         return rc;
     }
 
-    //discard
+    /* discard */
     //TODO poll DRDY in STATUS (27h) instead?
-    rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+    rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
     if (rc) {
         return rc;
     }
 
     /* take no st offset reading */
-    for(i=0; i<LIS2DW12_ST_NUM_READINGS; i++) {
+    for (i = 0; i < LIS2DW12_ST_NUM_READINGS; i++) {
 
         // TODO poll DRDY in STATUS (27h) instead?
         /* wait at least 20 ms */
         os_time_delay(OS_TICKS_PER_SEC / 50 + 1);
 
-        rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+        rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
         if (rc) {
             return rc;
         }
@@ -2111,12 +2115,12 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
         scratch[2] += data[2];
     }
 
-    //average
-    no_st[0] = scratch[0]/LIS2DW12_ST_NUM_READINGS;
-    no_st[1] = scratch[1]/LIS2DW12_ST_NUM_READINGS;
-    no_st[2] = scratch[2]/LIS2DW12_ST_NUM_READINGS;
+    /* average */
+    no_st[0] = scratch[0] / LIS2DW12_ST_NUM_READINGS;
+    no_st[1] = scratch[1] / LIS2DW12_ST_NUM_READINGS;
+    no_st[2] = scratch[2] / LIS2DW12_ST_NUM_READINGS;
 
-    //clean scratch
+    /* clean scratch */
     memset(&scratch, 0, sizeof scratch);
 
     /* go into self test mode 1 */
@@ -2128,21 +2132,21 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
     /* wait 200ms */
     os_time_delay(OS_TICKS_PER_SEC / 5 + 1);
 
-    //discard
+    /* discard */
     //TODO poll DRDY in STATUS (27h) instead?
-    rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+    rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
     if (rc) {
         return rc;
     }
 
     /* take positive offset reading */
-    for(i=0; i<LIS2DW12_ST_NUM_READINGS; i++) {
+    for (i = 0; i < LIS2DW12_ST_NUM_READINGS; i++) {
 
         // TODO poll DRDY in STATUS (27h) instead?
         /* wait at least 20 ms */
         os_time_delay(OS_TICKS_PER_SEC / 50 + 1);
 
-        rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+        rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
         if (rc) {
             return rc;
         }
@@ -2151,15 +2155,15 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
         scratch[2] += data[2];
     }
 
-    //average
-    st[0] = scratch[0]/LIS2DW12_ST_NUM_READINGS;
-    st[1] = scratch[1]/LIS2DW12_ST_NUM_READINGS;
-    st[2] = scratch[2]/LIS2DW12_ST_NUM_READINGS;
+    /* average */
+    st[0] = scratch[0] / LIS2DW12_ST_NUM_READINGS;
+    st[1] = scratch[1] / LIS2DW12_ST_NUM_READINGS;
+    st[2] = scratch[2] / LIS2DW12_ST_NUM_READINGS;
 
-    //clean scratch
+    /* clean scratch */
     memset(&scratch, 0, sizeof scratch);
 
-    // |Min(ST_X)| <=|OUTX_AVG_ST - OUTX_AVG_NO_ST| <= |Max(ST_X)|
+    /* |Min(ST_X)| <=|OUTX_AVG_ST - OUTX_AVG_NO_ST| <= |Max(ST_X)| */
     /* compare values to thresholds */
     for (i = 0; i < 3; i++) {
         int16_t diff = abs(st[i] - no_st[i]);
@@ -2177,20 +2181,20 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
     /* wait 200ms */
     os_time_delay(OS_TICKS_PER_SEC / 5 + 1);
 
-    //discard
-    rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+    /* discard */
+    rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
     if (rc) {
         return rc;
     }
 
     /* take negative offset reading */
-    for(i=0; i<LIS2DW12_ST_NUM_READINGS; i++) {
+    for ( i = 0; i < LIS2DW12_ST_NUM_READINGS; i++) {
 
         // TODO poll DRDY in STATUS (27h) instead?
         /* wait at least 20 ms */
         os_time_delay(OS_TICKS_PER_SEC / 50 + 1);
 
-        rc = lis2dw12_get_data(itf, fs, &(data[0]), &(data[1]), &(data[2]));
+        rc = lis2dw12_get_data(itf, fs, &data[0], &data[1], &data[2]);
         if (rc) {
             return rc;
         }
@@ -2199,14 +2203,14 @@ int lis2dw12_run_self_test(struct sensor_itf *itf, int *result)
         scratch[2] += data[2];
     }
 
-    //average
-    st[0] = scratch[0]/LIS2DW12_ST_NUM_READINGS;
-    st[1] = scratch[1]/LIS2DW12_ST_NUM_READINGS;
-    st[2] = scratch[2]/LIS2DW12_ST_NUM_READINGS;
+    /* average */
+    st[0] = scratch[0] / LIS2DW12_ST_NUM_READINGS;
+    st[1] = scratch[1] / LIS2DW12_ST_NUM_READINGS;
+    st[2] = scratch[2] / LIS2DW12_ST_NUM_READINGS;
 
     /* compare values to thresholds */
     for (i = 0; i < 3; i++) {
-        int16_t diff = abs(st[i] - no_st[i]);
+        diff = abs(st[i] - no_st[i]);
         if (diff < LIS2DW12_ST_MIN || diff > LIS2DW12_ST_MAX) {
             *result -= 1;
         }


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

Posted by je...@apache.org.
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]);