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 20:59:59 UTC
[mynewt-core] branch master updated (1992666 -> 74cd2ea)
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 1992666 hw/sensors/bma253: Change data units g to m/s2
new ee582a4 sensors/lis2dh12: Fix interrupt polarity settings
new 74cd2ea sensor_creator: Add lis2dh12
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:
.../sensors/lis2dh12/include/lis2dh12/lis2dh12.h | 3 +-
hw/drivers/sensors/lis2dh12/src/lis2dh12.c | 24 +++---
hw/sensor/creator/pkg.yml | 2 +
hw/sensor/creator/src/sensor_creator.c | 96 ++++++++++++++++++++++
hw/sensor/creator/syscfg.yml | 28 +++++++
5 files changed, 142 insertions(+), 11 deletions(-)
[mynewt-core] 01/02: sensors/lis2dh12: Fix interrupt polarity
settings
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 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) {
[mynewt-core] 02/02: sensor_creator: Add lis2dh12
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 74cd2ea6d078c9b6227bcb7f5889fe73beae244e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Aug 19 14:51:49 2019 +0200
sensor_creator: Add lis2dh12
Sensor creator can now configure lis2dh12 accelerometer.
---
hw/sensor/creator/pkg.yml | 2 +
hw/sensor/creator/src/sensor_creator.c | 96 ++++++++++++++++++++++++++++++++++
hw/sensor/creator/syscfg.yml | 28 ++++++++++
3 files changed, 126 insertions(+)
diff --git a/hw/sensor/creator/pkg.yml b/hw/sensor/creator/pkg.yml
index 2cabce1..93758cf 100644
--- a/hw/sensor/creator/pkg.yml
+++ b/hw/sensor/creator/pkg.yml
@@ -56,6 +56,8 @@ pkg.deps.BMP388_OFB:
- "@apache-mynewt-core/hw/drivers/sensors/bmp388"
pkg.deps.LIS2DW12_OFB:
- "@apache-mynewt-core/hw/drivers/sensors/lis2dw12"
+pkg.deps.LIS2DH12_OFB:
+ - "@apache-mynewt-core/hw/drivers/sensors/lis2dh12"
pkg.deps.LPS33HW_OFB:
- "@apache-mynewt-core/hw/drivers/sensors/lps33hw"
pkg.deps.LPS33THW_OFB:
diff --git a/hw/sensor/creator/src/sensor_creator.c b/hw/sensor/creator/src/sensor_creator.c
index 7848bf7..d0de05a 100644
--- a/hw/sensor/creator/src/sensor_creator.c
+++ b/hw/sensor/creator/src/sensor_creator.c
@@ -89,6 +89,10 @@
#include <lis2dw12/lis2dw12.h>
#endif
+#if MYNEWT_VAL(LIS2DH12_OFB)
+#include <lis2dh12/lis2dh12.h>
+#endif
+
#if MYNEWT_VAL(LIS2DS12_OFB)
#include <lis2ds12/lis2ds12.h>
#endif
@@ -182,6 +186,10 @@ static struct lps33thw lps33thw;
static struct lis2dw12 lis2dw12;
#endif
+#if MYNEWT_VAL(LIS2DH12_OFB)
+static struct lis2dh12 lis2dh12;
+#endif
+
#if MYNEWT_VAL(LIS2DS12_OFB)
static struct lis2ds12 lis2ds12;
#endif
@@ -495,6 +503,48 @@ static struct sensor_itf i2c_0_itf_lis2ds12 = {
};
#endif
+#if MYNEWT_VAL(LIS2DH12_OFB)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#if MYNEWT_VAL(LIS2DH12_OFB_I2C_NUM) >= 0
+static const struct bus_i2c_node_cfg lis2dh12_node_cfg = {
+ .node_cfg = {
+ .bus_name = MYNEWT_VAL(LIS2DH12_OFB_BUS),
+ },
+ .addr = MYNEWT_VAL(LIS2DH12_OFB_ITF_ADDR),
+ .freq = 400,
+};
+#elif MYNEWT_VAL(LIS2DH12_OFB_SPI_NUM) >= 0
+static const struct bus_spi_node_cfg lis2dh12_node_cfg = {
+ .node_cfg = {
+ .bus_name = MYNEWT_VAL(LIS2DH12_OFB_BUS),
+ },
+ .pin_cs = MYNEWT_VAL(LIS2DH12_OFB_CS),
+ .mode = BUS_SPI_MODE_3,
+ .data_order = BUS_SPI_DATA_ORDER_MSB,
+ .freq = 4000,
+};
+#endif
+static struct sensor_itf lis2dh12_itf = {
+ .si_ints = {
+ { MYNEWT_VAL(LIS2DH12_OFB_INT1_PIN_HOST), 1,
+ MYNEWT_VAL(LIS2DH12_OFB_INT_CFG_ACTIVE)},
+ { MYNEWT_VAL(LIS2DH12_OFB_INT2_PIN_HOST), 2,
+ MYNEWT_VAL(LIS2DH12_OFB_INT_CFG_ACTIVE)}}
+};
+#else
+static struct sensor_itf lis2dh12_itf = {
+ .si_type = SENSOR_ITF_I2C,
+ .si_num = MYNEWT_VAL(LIS2DH12_OFB_I2C_NUM),
+ .si_addr = MYNEWT_VAL(LIS2DH12_OFB_ITF_ADDR),
+ .si_ints = {
+ { MYNEWT_VAL(LIS2DH12_OFB_INT1_PIN_HOST), 1,
+ MYNEWT_VAL(LIS2DH12_OFB_INT_CFG_ACTIVE)},
+ { MYNEWT_VAL(LIS2DH12_OFB_INT2_PIN_HOST), 2,
+ MYNEWT_VAL(LIS2DH12_OFB_INT_CFG_ACTIVE)}}
+};
+#endif
+#endif
+
#if MYNEWT_VAL(I2C_0) && MYNEWT_VAL(BME680_OFB)
static struct sensor_itf i2c_0_itf_bme680 = {
.si_type = SENSOR_ITF_I2C,
@@ -1156,6 +1206,35 @@ config_lis2dw12_sensor(void)
#endif
/**
+ * LIS2DH12 Sensor default configuration used by the creator package
+ *
+ * @return 0 on success, non-zero on failure
+ */
+#if MYNEWT_VAL(LIS2DH12_OFB)
+static int
+config_lis2dh12_sensor(void)
+{
+ int rc;
+ struct os_dev *dev;
+ struct lis2dh12_cfg cfg = {0};
+
+ dev = os_dev_open("lis2dh12_0", OS_TIMEOUT_NEVER, NULL);
+ assert(dev != NULL);
+
+ cfg.lc_s_mask = SENSOR_TYPE_ACCELEROMETER;
+ cfg.lc_rate = LIS2DH12_DATA_RATE_HN_1344HZ_L_5376HZ;
+ cfg.lc_fs = LIS2DH12_FS_2G;
+
+ rc = lis2dh12_config((struct lis2dh12 *)dev, &cfg);
+ assert(rc == 0);
+
+ os_dev_close(dev);
+
+ return rc;
+}
+#endif
+
+/**
* LIS2DS12 Sensor default configuration used by the creator package
*
* @return 0 on success, non-zero on failure
@@ -1681,6 +1760,23 @@ sensor_dev_create(void)
assert(rc == 0);
#endif
+#if MYNEWT_VAL(LIS2DH12_OFB)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#if MYNEWT_VAL(BMP388_OFB_I2C_NUM) >= 0
+ rc = lis2dh12_create_i2c_sensor_dev(&lis2dh12.i2c_node, "lis2dh12_0",
+ &lis2dh12_node_cfg, &lis2dh12_itf);
+ assert(rc == 0);
+#endif
+#else
+ rc = os_dev_create((struct os_dev *)&lis2dh12, "lis2dh12_0",
+ OS_DEV_INIT_PRIMARY, 0, lis2dh12_init, &lis2dh12_itf);
+ assert(rc == 0);
+#endif
+
+ rc = config_lis2dh12_sensor();
+ assert(rc == 0);
+#endif
+
#if MYNEWT_VAL(LIS2DS12_OFB)
rc = os_dev_create((struct os_dev *) &lis2ds12, "lis2ds12_0",
OS_DEV_INIT_PRIMARY, 0, lis2ds12_init, (void *)&i2c_0_itf_lis2ds12);
diff --git a/hw/sensor/creator/syscfg.yml b/hw/sensor/creator/syscfg.yml
index c8d0c7d..5813e2e 100644
--- a/hw/sensor/creator/syscfg.yml
+++ b/hw/sensor/creator/syscfg.yml
@@ -140,6 +140,34 @@ syscfg.defs:
LIS2DW12_OFB:
description: 'LIS2DW12 is present'
value : 0
+ LIS2DH12_OFB:
+ description: 'LIS2DH12 is present'
+ value : 0
+ LIS2DH12_OFB_I2C_NUM:
+ description: 'I2C interface used for LIS2DH12'
+ value:
+ restrictions:
+ - '(LIS2DH12_OFB == 0) ||
+ ((LIS2DH12_OFB_I2C_NUM == 0) && (I2C_0 == 1)) ||
+ ((LIS2DH12_OFB_I2C_NUM == 1) && (I2C_1 == 1)) ||
+ ((LIS2DH12_OFB_I2C_NUM == 2) && (I2C_2 == 1)) ||
+ ((LIS2DH12_OFB_I2C_NUM == -1))'
+ LIS2DH12_OFB_ITF_ADDR:
+ description: 'I2C address of LIS2DH12 0x18 or 0x19'
+ value: 0x18
+ range: 0x18,0x19
+ LIS2DH12_OFB_INT1_PIN_HOST:
+ description: 'Host pin for LIS2DH12 INT1 pin'
+ value: -1
+ LIS2DH12_OFB_INT2_PIN_HOST:
+ description: 'Host pin for LIS2DH12 INT2 pin'
+ value: -1
+ LIS2DH12_OFB_INT_CFG_ACTIVE:
+ description: 'Set 0 for active-low, 1 for active-high'
+ value: 1
+ LIS2DH12_OFB_BUS:
+ description: 'I2C or SPI interface used for LIS2DH12'
+ value: '"i2c0"'
BMA2XX_OFB:
description: 'A sensor in the BMA2XX family is present'
value : 0