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 2018/09/07 22:28:50 UTC

[mynewt-core] branch master updated: hw/sensors: lis2dw12: Lis2dw12 breakup orientation notification events (#1386)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 86ddf74  hw/sensors: lis2dw12: Lis2dw12 breakup orientation notification events (#1386)
86ddf74 is described below

commit 86ddf7405d7ce69845f2803d391c5cfd312bba62
Author: Vipul Rahane <vr...@gmail.com>
AuthorDate: Fri Sep 7 15:28:48 2018 -0700

    hw/sensors: lis2dw12: Lis2dw12 breakup orientation notification events (#1386)
    
    Add sensor event X_L, X_H, Y_L, Y_H, Z_L and Z_H
    
    Old X events were restrictive since we did not get the direction out of them
    Maintain backwards compatibility for lis2ds12 by keeping old X events
---
 hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 245 ++++++++++++-----------------
 hw/sensor/include/sensor/sensor.h          |  12 ++
 2 files changed, 114 insertions(+), 143 deletions(-)

diff --git a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
index 52a801e..cd85c76 100644
--- a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
+++ b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
@@ -84,23 +84,42 @@ const struct lis2dw12_notif_cfg dflt_notif_cfg[] = {
       .int_cfg   = LIS2DW12_INT1_CFG_6D
     },
     {
-      .event     = SENSOR_EVENT_TYPE_ORIENT_X_CHANGE,
+      .event     = SENSOR_EVENT_TYPE_ORIENT_X_L_CHANGE,
       .int_num   = 0,
-      .notif_src = LIS2DW12_SIXD_SRC_XL|LIS2DW12_SIXD_SRC_XH,
+      .notif_src = LIS2DW12_SIXD_SRC_XL,
       .int_cfg   = LIS2DW12_INT1_CFG_6D
     },
     {
-      .event     = SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE,
+      .event     = SENSOR_EVENT_TYPE_ORIENT_Y_L_CHANGE,
       .int_num   = 0,
-      .notif_src = LIS2DW12_SIXD_SRC_YL|LIS2DW12_SIXD_SRC_YH,
+      .notif_src = LIS2DW12_SIXD_SRC_YL,
       .int_cfg   = LIS2DW12_INT1_CFG_6D
     },
     {
-      .event     = SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE,
+      .event     = SENSOR_EVENT_TYPE_ORIENT_Z_L_CHANGE,
       .int_num   = 0,
-      .notif_src = LIS2DW12_SIXD_SRC_ZL|LIS2DW12_SIXD_SRC_ZH,
+      .notif_src = LIS2DW12_SIXD_SRC_ZL,
+      .int_cfg   = LIS2DW12_INT1_CFG_6D
+    },
+    {
+      .event     = SENSOR_EVENT_TYPE_ORIENT_X_H_CHANGE,
+      .int_num   = 0,
+      .notif_src = LIS2DW12_SIXD_SRC_XH,
+      .int_cfg   = LIS2DW12_INT1_CFG_6D
+    },
+    {
+      .event     = SENSOR_EVENT_TYPE_ORIENT_Y_H_CHANGE,
+      .int_num   = 0,
+      .notif_src = LIS2DW12_SIXD_SRC_YH,
+      .int_cfg   = LIS2DW12_INT1_CFG_6D
+    },
+    {
+      .event     = SENSOR_EVENT_TYPE_ORIENT_Z_H_CHANGE,
+      .int_num   = 0,
+      .notif_src = LIS2DW12_SIXD_SRC_ZH,
       .int_cfg   = LIS2DW12_INT1_CFG_6D
     }
+
 };
 
 static struct hal_spi_settings spi_lis2dw12_settings = {
@@ -122,9 +141,12 @@ STATS_SECT_START(lis2dw12_stat_section)
     STATS_SECT_ENTRY(wakeup_notify)
     STATS_SECT_ENTRY(sleep_chg_notify)
     STATS_SECT_ENTRY(orient_chg_notify)
-    STATS_SECT_ENTRY(orient_chg_x_notify)
-    STATS_SECT_ENTRY(orient_chg_y_notify)
-    STATS_SECT_ENTRY(orient_chg_z_notify)
+    STATS_SECT_ENTRY(orient_chg_x_l_notify)
+    STATS_SECT_ENTRY(orient_chg_y_l_notify)
+    STATS_SECT_ENTRY(orient_chg_z_l_notify)
+    STATS_SECT_ENTRY(orient_chg_x_h_notify)
+    STATS_SECT_ENTRY(orient_chg_y_h_notify)
+    STATS_SECT_ENTRY(orient_chg_z_h_notify)
 #endif
 STATS_SECT_END
 
@@ -140,9 +162,12 @@ STATS_NAME_START(lis2dw12_stat_section)
     STATS_NAME(lis2dw12_stat_section, wakeup_notify)
     STATS_NAME(lis2dw12_stat_section, sleep_chg_notify)
     STATS_NAME(lis2dw12_stat_section, orient_chg_notify)
-    STATS_NAME(lis2dw12_stat_section, orient_chg_x_notify)
-    STATS_NAME(lis2dw12_stat_section, orient_chg_y_notify)
-    STATS_NAME(lis2dw12_stat_section, orient_chg_z_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_x_l_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_y_l_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_z_l_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_x_h_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_y_h_notify)
+    STATS_NAME(lis2dw12_stat_section, orient_chg_z_h_notify)
 #endif
 STATS_NAME_END(lis2dw12_stat_section)
 
@@ -2790,14 +2815,23 @@ lis2dw12_inc_notif_stats(sensor_event_type_t event)
         case SENSOR_EVENT_TYPE_ORIENT_CHANGE:
             STATS_INC(g_lis2dw12stats, orient_chg_notify);
             break;
-        case SENSOR_EVENT_TYPE_ORIENT_X_CHANGE:
-            STATS_INC(g_lis2dw12stats, orient_chg_x_notify);
+        case SENSOR_EVENT_TYPE_ORIENT_X_L_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_x_l_notify);
+            break;
+        case SENSOR_EVENT_TYPE_ORIENT_Y_L_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_y_l_notify);
+            break;
+        case SENSOR_EVENT_TYPE_ORIENT_Z_L_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_z_l_notify);
             break;
-        case SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE:
-            STATS_INC(g_lis2dw12stats, orient_chg_y_notify);
+        case SENSOR_EVENT_TYPE_ORIENT_X_H_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_x_h_notify);
             break;
-        case SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE:
-            STATS_INC(g_lis2dw12stats, orient_chg_z_notify);
+        case SENSOR_EVENT_TYPE_ORIENT_Y_H_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_y_h_notify);
+            break;
+        case SENSOR_EVENT_TYPE_ORIENT_Z_H_CHANGE:
+            STATS_INC(g_lis2dw12stats, orient_chg_z_h_notify);
             break;
         case SENSOR_EVENT_TYPE_SLEEP_CHANGE:
             STATS_INC(g_lis2dw12stats, sleep_chg_notify);
@@ -2808,6 +2842,8 @@ lis2dw12_inc_notif_stats(sensor_event_type_t event)
         case SENSOR_EVENT_TYPE_FREE_FALL:
             STATS_INC(g_lis2dw12stats, free_fall_notify);
             break;
+        default:
+            break;
     }
 #endif
 
@@ -2815,6 +2851,25 @@ lis2dw12_inc_notif_stats(sensor_event_type_t event)
 }
 
 static int
+lis2dw12_notify(struct lis2dw12 *lis2dw12, uint8_t src,
+                    sensor_event_type_t event_type)
+{
+    struct lis2dw12_notif_cfg *notif_cfg;
+
+    notif_cfg = lis2dw12_find_notif_cfg_by_event(event_type, &lis2dw12->cfg);
+    if (!notif_cfg) {
+        return SYS_EINVAL;
+    }
+
+    if (src & notif_cfg->notif_src) {
+        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx, event_type);
+        lis2dw12_inc_notif_stats(event_type);
+    }
+
+    return 0;
+}
+
+static int
 lis2dw12_sensor_handle_interrupt(struct sensor *sensor)
 {
     struct lis2dw12 *lis2dw12;
@@ -2822,7 +2877,6 @@ lis2dw12_sensor_handle_interrupt(struct sensor *sensor)
     uint8_t int_src;
     uint8_t int_status;
     uint8_t sixd_src;
-    struct lis2dw12_notif_cfg *notif_cfg;
     int rc;
 
     lis2dw12 = (struct lis2dw12 *)SENSOR_GET_DEVICE(sensor);
@@ -2839,19 +2893,10 @@ lis2dw12_sensor_handle_interrupt(struct sensor *sensor)
             return rc;
         }
 
-        notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_SLEEP,
-                                                     &lis2dw12->cfg);
-        if (!notif_cfg) {
-            rc = SYS_EINVAL;
+        rc = lis2dw12_notify(lis2dw12, int_status, SENSOR_EVENT_TYPE_SLEEP);
+        if (rc) {
             goto err;
         }
-
-        if (int_status & notif_cfg->notif_src) {
-            /* Sleep state detected */
-            sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                      SENSOR_EVENT_TYPE_SLEEP);
-            lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_SLEEP);
-        }
     }
 
     rc = lis2dw12_get_sixd_src(itf, &sixd_src);
@@ -2860,80 +2905,39 @@ lis2dw12_sensor_handle_interrupt(struct sensor *sensor)
         goto err;
     }
 
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_ORIENT_CHANGE,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_CHANGE);
+    if (rc) {
         goto err;
     }
 
-    if (sixd_src & notif_cfg->notif_src) {
-
-        /* Orientation change detected, can be a combination of ZH, ZL, YH,
-         * YL, XH and XL
-         */
-
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_ORIENT_CHANGE);
-
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_ORIENT_CHANGE);
-    }
-
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_ORIENT_X_CHANGE,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_X_L_CHANGE);
+    if (rc) {
         goto err;
     }
 
-    if (sixd_src & notif_cfg->notif_src) {
-
-        /* Orientation change detected, can be a combination of ZH, ZL, YH,
-         * YL, XH and XL
-         */
-
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_ORIENT_X_CHANGE);
-
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_ORIENT_X_CHANGE);
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_Y_L_CHANGE);
+    if (rc) {
+        goto err;
     }
 
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_Z_L_CHANGE);
+    if (rc) {
         goto err;
     }
 
-    if (sixd_src & notif_cfg->notif_src) {
-
-        /* Orientation change detected, can be a combination of ZH, ZL, YH,
-         * YL, XH and XL
-         */
-
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE);
-
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE);
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_X_H_CHANGE);
+    if (rc) {
+        goto err;
     }
 
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_Y_H_CHANGE);
+    if (rc) {
         goto err;
     }
 
-    if (sixd_src & notif_cfg->notif_src) {
-
-        /* Orientation change detected, can be a combination of ZH, ZL, YH,
-         * YL, XH and XL
-         */
-
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE);
-
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE);
+    rc = lis2dw12_notify(lis2dw12, sixd_src, SENSOR_EVENT_TYPE_ORIENT_Z_H_CHANGE);
+    if (rc) {
+        goto err;
     }
 
     rc = lis2dw12_clear_int(itf, &int_src);
@@ -2942,76 +2946,31 @@ lis2dw12_sensor_handle_interrupt(struct sensor *sensor)
         return rc;
     }
 
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_SINGLE_TAP,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, int_src, SENSOR_EVENT_TYPE_SINGLE_TAP);
+    if (rc) {
         goto err;
     }
 
-    if (int_src & notif_cfg->notif_src) {
-        /* Single tap is detected */
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_SINGLE_TAP);
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_SINGLE_TAP);
-    }
-
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_DOUBLE_TAP,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, int_src, SENSOR_EVENT_TYPE_DOUBLE_TAP);
+    if (rc) {
         goto err;
     }
 
-    if (int_src & notif_cfg->notif_src) {
-        /* Double tap is detected */
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_DOUBLE_TAP);
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_DOUBLE_TAP);
-    }
-
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_FREE_FALL,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, int_src, SENSOR_EVENT_TYPE_FREE_FALL);
+    if (rc) {
         goto err;
     }
 
-    if (int_src & notif_cfg->notif_src) {
-        /* Freefall is detected */
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_FREE_FALL);
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_FREE_FALL);
-    }
-
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_WAKEUP,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, int_src, SENSOR_EVENT_TYPE_WAKEUP);
+    if (rc) {
         goto err;
     }
 
-    if (int_src & notif_cfg->notif_src) {
-        /* Wake up is detected */
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_WAKEUP);
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_WAKEUP);
-    }
-
-    notif_cfg = lis2dw12_find_notif_cfg_by_event(SENSOR_EVENT_TYPE_SLEEP_CHANGE,
-                                                 &lis2dw12->cfg);
-    if (!notif_cfg) {
-        rc = SYS_EINVAL;
+    rc = lis2dw12_notify(lis2dw12, int_src, SENSOR_EVENT_TYPE_SLEEP_CHANGE);
+    if (rc) {
         goto err;
     }
 
-    if (int_src & notif_cfg->notif_src) {
-        /* Sleep change detected, either wakeup or sleep */
-        sensor_mgr_put_notify_evt(&lis2dw12->pdd.notify_ctx,
-                                  SENSOR_EVENT_TYPE_SLEEP_CHANGE);
-        lis2dw12_inc_notif_stats(SENSOR_EVENT_TYPE_SLEEP_CHANGE);
-    }
-
     return 0;
 err:
     return rc;
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 69fd8b4..6884349 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -120,6 +120,18 @@ typedef enum {
     SENSOR_EVENT_TYPE_ORIENT_Y_CHANGE  = (1 << 8),
     /* Orientation Change Event in the Z direction */
     SENSOR_EVENT_TYPE_ORIENT_Z_CHANGE  = (1 << 9),
+    /* Orientation Change Event in the X L direction */
+    SENSOR_EVENT_TYPE_ORIENT_X_L_CHANGE  = (1 << 10),
+    /* Orientation Change Event in the Y L direction */
+    SENSOR_EVENT_TYPE_ORIENT_Y_L_CHANGE  = (1 << 11),
+    /* Orientation Change Event in the Z L direction */
+    SENSOR_EVENT_TYPE_ORIENT_Z_L_CHANGE  = (1 << 12),
+    /* Orientation Change Event in the X H direction */
+    SENSOR_EVENT_TYPE_ORIENT_X_H_CHANGE  = (1 << 13),
+    /* Orientation Change Event in the Y H direction */
+    SENSOR_EVENT_TYPE_ORIENT_Y_H_CHANGE  = (1 << 14),
+    /* Orientation Change Event in the Z H direction */
+    SENSOR_EVENT_TYPE_ORIENT_Z_H_CHANGE  = (1 << 15),
 } sensor_event_type_t;