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/09/04 06:50:30 UTC
[mynewt-core] 03/03: sensor_creator: Add lsm3dso sensor
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 3e2c04d28b4fa47658a56ffaa7f7844e67667c92
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Sep 2 15:10:03 2019 +0200
sensor_creator: Add lsm3dso sensor
Instance of lsm3dso can be created by sensor creator.
---
hw/sensor/creator/pkg.yml | 2 +
hw/sensor/creator/src/sensor_creator.c | 102 +++++++++++++++++++++++++++++++++
hw/sensor/creator/syscfg.yml | 18 ++++++
3 files changed, 122 insertions(+)
diff --git a/hw/sensor/creator/pkg.yml b/hw/sensor/creator/pkg.yml
index 93758cf..f3747ae 100644
--- a/hw/sensor/creator/pkg.yml
+++ b/hw/sensor/creator/pkg.yml
@@ -30,6 +30,8 @@ pkg.deps.DRV2605_OFB:
- "@apache-mynewt-core/hw/drivers/drv2605"
pkg.deps.LSM303DLHC_OFB:
- "@apache-mynewt-core/hw/drivers/sensors/lsm303dlhc"
+pkg.deps.LSM6DSO_OFB:
+ - "@apache-mynewt-core/hw/drivers/sensors/lsm6dso"
pkg.deps.MPU6050_OFB:
- "@apache-mynewt-core/hw/drivers/sensors/mpu6050"
pkg.deps.TSL2561_OFB:
diff --git a/hw/sensor/creator/src/sensor_creator.c b/hw/sensor/creator/src/sensor_creator.c
index 313106b..bb3f35d 100644
--- a/hw/sensor/creator/src/sensor_creator.c
+++ b/hw/sensor/creator/src/sensor_creator.c
@@ -28,6 +28,9 @@
#if MYNEWT_VAL(LSM303DLHC_OFB)
#include <lsm303dlhc/lsm303dlhc.h>
#endif
+#if MYNEWT_VAL(LSM6DSO_OFB)
+#include <lsm6dso/lsm6dso.h>
+#endif
#if MYNEWT_VAL(MPU6050_OFB)
#include <mpu6050/mpu6050.h>
#endif
@@ -122,6 +125,10 @@ static struct drv2605 drv2605;
static struct lsm303dlhc lsm303dlhc;
#endif
+#if MYNEWT_VAL(LSM6DSO_OFB)
+static struct lsm6dso lsm6dso;
+#endif
+
#if MYNEWT_VAL(MPU6050_OFB)
static struct mpu6050 mpu6050;
#endif
@@ -299,6 +306,25 @@ static struct sensor_itf i2c_0_itf_lsm = {
};
#endif
+#if MYNEWT_VAL(LSM6DSO_OFB)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static const struct bus_i2c_node_cfg lsm6dso_node_cfg = {
+ .node_cfg = {
+ .bus_name = MYNEWT_VAL(LSM6DSO_OFB_I2C_BUS),
+ },
+ .addr = MYNEWT_VAL(LSM6DSO_OFB_I2C_ADDR),
+ .freq = 400,
+};
+static struct sensor_itf lsm6dso_i2c_itf;
+#else
+static struct sensor_itf lsm6dso_i2c_itf = {
+ .si_type = SENSOR_ITF_I2C,
+ .si_num = MYNEWT_VAL(LSM6DSO_OFB_I2C_NUM),
+ .si_addr = MYNEWT_VAL(LSM6DSO_OFB_I2C_ADDR)
+};
+#endif
+#endif
+
#if MYNEWT_VAL(MPU6050_OFB)
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
static const struct bus_i2c_node_cfg mpu6050_node_cfg = {
@@ -951,6 +977,68 @@ config_lsm303dlhc_sensor(void)
#endif
/**
+ * LSM6DSO Sensor default configuration used by the creator package
+ *
+ * @return 0 on success, non-zero on failure
+ */
+#if MYNEWT_VAL(LSM6DSO_OFB)
+static int
+config_lsm6dso_sensor(void)
+{
+ int rc;
+ struct os_dev *dev;
+ struct lsm6dso_cfg cfg = {
+ .acc_fs = LSM6DSO_ACCEL_FS_4G_VAL,
+ .acc_rate = LSM6DSO_ACCEL_52HZ_VAL,
+
+ .gyro_fs = LSM6DSO_GYRO_FS_500DPS_VAL,
+ .gyro_rate = LSM6DSO_GYRO_52HZ_VAL,
+
+ .wk = {
+ .hpf_slope = 1, /* High pass filter applied */
+ .wake_up_ths = 15,
+ .wake_up_dur = 3,
+ .sleep_duration = 3,
+ },
+ .fifo = {
+ .mode = LSM6DSO_FIFO_MODE_CONTINUOUS_VAL,
+ .wtm = 10,
+ },
+ .ff = {
+ .freefall_dur = 3,
+ .freefall_ths = 3,
+ },
+ .tap = {
+ .dur = 10,
+ .en_x = 1,
+ .en_y = 1,
+ .en_z = 1,
+ .en_dtap = 1,
+ .quiet = 0,
+ .shock = 0,
+ .tap_prio = 0,
+ .tap_ths = 20
+ },
+ .orientation = {
+ .en_4d = 0,
+ .ths_6d = 0,
+ },
+ .int1_pin_cfg = 0,
+ .int2_pin_cfg = 0,
+ .map_int2_to_int1 = 0,
+ };
+
+ dev = (struct os_dev *)os_dev_open("lsm6dso_0", OS_TIMEOUT_NEVER, NULL);
+ assert(dev != NULL);
+
+ rc = lsm6dso_config((struct lsm6dso *)dev, &cfg);
+
+ os_dev_close(dev);
+ return rc;
+}
+#endif
+
+/**
* MPU6050 Sensor default configuration used by the creator package
*
* @return 0 on success, non-zero on failure
@@ -1662,6 +1750,20 @@ sensor_dev_create(void)
assert(rc == 0);
#endif
+#if MYNEWT_VAL(LSM6DSO_OFB)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ rc = lsm6dso_create_i2c_sensor_dev(&lsm6dso.i2c_node, "lsm6dso_0",
+ &lsm6dso_node_cfg, &lsm6dso_i2c_itf);
+#else
+ rc = os_dev_create((struct os_dev *)&lsm6dso, "lsm6dso_0",
+ OS_DEV_INIT_PRIMARY, 0, lsm6dso_init, (void *)&lsm6dso_i2c_itf);
+#endif
+ assert(rc == 0);
+
+ rc = config_lsm6dso_sensor();
+ assert(rc == 0);
+#endif
+
#if MYNEWT_VAL(MPU6050_OFB)
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
rc = mpu6050_create_i2c_sensor_dev(&mpu6050.i2c_node, "mpu6050_0",
diff --git a/hw/sensor/creator/syscfg.yml b/hw/sensor/creator/syscfg.yml
index ff164af..b5f2f67 100644
--- a/hw/sensor/creator/syscfg.yml
+++ b/hw/sensor/creator/syscfg.yml
@@ -29,6 +29,24 @@ syscfg.defs:
LSM303DLHC_OFB:
description: 'LSM303 is present'
value : 0
+ LSM6DSO_OFB:
+ description: 'LSM6DSO is present'
+ value : 0
+ LSM6DSO_OFB_I2C_NUM:
+ description: 'I2C interface used for LSM6DS0'
+ value: 0
+ restrictions:
+ - '(LSM6DSO_OFB == 0) ||
+ ((LSM6DSO_OFB_I2C_NUM == 0) && (I2C_0 == 1)) ||
+ ((LSM6DSO_OFB_I2C_NUM == 1) && (I2C_1 == 1)) ||
+ ((LSM6DSO_OFB_I2C_NUM == 2) && (I2C_2 == 1))'
+ LSM6DSO_OFB_I2C_BUS:
+ description: 'I2C interface used for LSM6DSO'
+ value : '"i2c0"'
+ LSM6DSO_OFB_I2C_ADDR:
+ description: 'I2C address of LSM6DSO 0x6A or 0x6B'
+ value: 0x6A
+ range: 0x6A,0x6B
MPU6050_OFB:
description: 'MPU6050 is present'
value : 0