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/08/19 21:00:00 UTC

[mynewt-core] 01/02: sensors/lis2dh12: Fix interrupt polarity settings

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 ee582a4f7e1c6374e6b5f637aabf19e60ff2afb4
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Aug 19 14:19:28 2019 +0200

    sensors/lis2dh12: Fix interrupt polarity settings
    
    Some code from lis2dw12 was used to setup interrupt pin
    push-pull/open-drain configuration.
    lis2dw12 does not have this functionality.
    What it has is interrupt active level that was setup instead,
    just function name and comment were misleading.
    
    Code leaves non-intuitive values for level 0 - active high
    1 - active low just to maintain compatibility with code
    that already uses this.
    
    Additionally code inside init_intpin was taking value for hal_gpio_irq_init
    directly from sensor_itf filed. This pattern is not used in others
    drivers. While it could be left this was relaying on
    correct value setup by the user, existing BSPs ruuvi_tab_b
    and thingy do not initialized this filed at all.
    That results in hal_gpio_irq_init being called with 0 which
    corresponds to HAL_GPIO_TRIG_NONE which causes failure.
---
 .../sensors/lis2dh12/include/lis2dh12/lis2dh12.h   |  3 ++-
 hw/drivers/sensors/lis2dh12/src/lis2dh12.c         | 24 +++++++++++++---------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h b/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
index 9a3705f..98c6716 100644
--- a/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
+++ b/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
@@ -216,7 +216,8 @@ struct lis2dh12_cfg {
     uint8_t latch_int2    : 1;
     uint8_t d4d_int1      : 1;
     uint8_t d4d_int2      : 1;
-    uint8_t int_pp_od     : 1;
+    /* Interrupt polarity 0 - active high */
+    uint8_t int_pol       : 1;
 
     /* Power mode */
     uint8_t power_mode;
diff --git a/hw/drivers/sensors/lis2dh12/src/lis2dh12.c b/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
index 30b9552..98740db 100644
--- a/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
+++ b/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
@@ -1132,7 +1132,11 @@ init_intpin(struct lis2dh12 *lis2dh12, int int_num, hal_gpio_irq_handler_t handl
 
     pin = lis2dh12->sensor.s_itf.si_ints[int_num].host_pin;
     if (pin >= 0) {
-        trig = lis2dh12->sensor.s_itf.si_ints[int_num].active;
+        if (lis2dh12->sensor.s_itf.si_ints[int_num].active) {
+            trig = HAL_GPIO_TRIG_RISING;
+        } else {
+            trig = HAL_GPIO_TRIG_FALLING;
+        }
 
         rc = hal_gpio_irq_init(pin,
                                handler,
@@ -1387,15 +1391,15 @@ err:
 }
 
 /**
- * Sets the interrupt push-pull/open-drain selection
+ * Sets the interrupt signal activation level for both pins
  *
  * @param The sensor interface
- * @param interrupt setting (0 = push-pull, 1 = open-drain)
+ * @param interrupt pin polarity (0 = active high, 1 = active low)
  *
  * @return 0 on success, non-zero on failure
  */
 int
-lis2dh12_set_int_pp_od(struct sensor_itf *itf, uint8_t mode)
+lis2dh12_set_int_polarity(struct sensor_itf *itf, uint8_t mode)
 {
     int rc;
     uint8_t reg;
@@ -1412,15 +1416,15 @@ lis2dh12_set_int_pp_od(struct sensor_itf *itf, uint8_t mode)
 }
 
 /**
- * Gets the interrupt push-pull/open-drain selection
+ * Gets the interrupt activation level
  *
  * @param The sensor interface
- * @param ptr to store setting (0 = push-pull, 1 = open-drain)
+ * @param ptr to store setting
  *
  * @return 0 on success, non-zero on failure
  */
 int
-lis2dh12_get_int_pp_od(struct sensor_itf *itf, uint8_t *mode)
+lis2dh12_get_int_polarity(struct sensor_itf *itf, uint8_t *int_pol)
 {
     int rc;
     uint8_t reg;
@@ -1430,7 +1434,7 @@ lis2dh12_get_int_pp_od(struct sensor_itf *itf, uint8_t *mode)
         return rc;
     }
 
-    *mode = (reg & LIS2DH12_CTRL_REG6_INT_POLARITY) ? 1 : 0;
+    *int_pol = (reg & LIS2DH12_CTRL_REG6_INT_POLARITY) ? 1 : 0;
 
     return 0;
 }
@@ -3054,11 +3058,11 @@ lis2dh12_config(struct lis2dh12 *lis2dh12, struct lis2dh12_cfg *cfg)
         goto err;
     }
 
-    rc = lis2dh12_set_int_pp_od(itf, cfg->int_pp_od);
+    rc = lis2dh12_set_int_polarity(itf, cfg->int_pol);
     if (rc) {
         goto err;
     }
-    lis2dh12->cfg.int_pp_od = cfg->int_pp_od;
+    lis2dh12->cfg.int_pol = cfg->int_pol;
 
     rc = lis2dh12_pull_up_disc(itf, cfg->lc_pull_up_disc);
     if (rc) {