samples/shields: add samples to test x-nucleo-iks4a1 shield
Provide three basic examples to test the x-nucleo-iks4a1 shield: - Test shield in standard mode Acquire sensor data from shield with all MEMS sensors connected to micro-controller - Test shield in HUB1 mode Acquire sensor data from shield with lis2mdl and lps22df connected to LSM6DSV16X sensor hub - Test shield in HUB2 mode Acquire sensor data from shield with lis2mdl and lps22df connected to LSm6DSO16IS sensor hub Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
cc3040aed6
commit
9f1c256e46
|
@ -150,6 +150,21 @@ There are three predefined DT overlays in the board:
|
|||
This overlay describes sensor connections (and matching h/w configuration to be done)
|
||||
as explained in SHUB2 Mode (:ref:`x-nucleo-iks4a1-mode-2`)
|
||||
|
||||
Examples
|
||||
********
|
||||
|
||||
Three samples are provided as examples for ``x-nucleo-iks4a1`` shield, each one associated
|
||||
with one of the overlays described above:
|
||||
|
||||
- :ref:`x-nucleo-iks4a1-std-sample` application, to be used when the shield is configured
|
||||
in Standard Mode (Mode 1)
|
||||
- :ref:`x-nucleo-iks4a1-shub1-sample` application, to be used when the shield is configured
|
||||
in SHUB1 Mode (Mode 3)
|
||||
- :ref:`x-nucleo-iks4a1-shub2-sample` application, to be used when the shield is configured
|
||||
in SHUB2 Mode (Mode 2)
|
||||
|
||||
See also :ref:`shields` for more details.
|
||||
|
||||
.. _X-NUCLEO-IKS4A1 website:
|
||||
http://www.st.com/en/ecosystems/x-nucleo-iks4a1.html
|
||||
|
||||
|
|
14
samples/shields/x_nucleo_iks4a1/sensorhub1/CMakeLists.txt
Normal file
14
samples/shields/x_nucleo_iks4a1/sensorhub1/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2024 STMicroelectronics
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
# This sample is specific to x_nucleo_iks4a1 shield. Enforce -DSHIELD option
|
||||
set(SHIELD x_nucleo_iks4a1_shub1)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(x_nucleo_iks4a1)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
60
samples/shields/x_nucleo_iks4a1/sensorhub1/README.rst
Normal file
60
samples/shields/x_nucleo_iks4a1/sensorhub1/README.rst
Normal file
|
@ -0,0 +1,60 @@
|
|||
.. _x-nucleo-iks4a1-shub1-sample:
|
||||
|
||||
X-NUCLEO-IKS4A1 shield SHUB1 (Mode 3) sample
|
||||
############################################
|
||||
|
||||
Overview
|
||||
********
|
||||
This sample is provided as an example to test the X-NUCLEO-IKS4A1 shield
|
||||
configured in SHUB1 (Mode 3).
|
||||
Please refer to :ref:`x-nucleo-iks4a1-mode-3` for more info on this configuration.
|
||||
|
||||
This sample enables LSM6DSV16X IMU in sensorhub mode with LIS2MDL magnetometer and
|
||||
LPS22DF pressure and temperature sensor.
|
||||
|
||||
Then sensor data are displayed periodically
|
||||
|
||||
- LSM6DSV16X 6-Axis acceleration and angular velocity
|
||||
- LSM6DSV16X (from LIS2MDL) 3-Axis magnetic field intensity
|
||||
- LSM6DSV16X (from LPS22DF) ambient temperature and atmospheric pressure
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This sample communicates over I2C with the X-NUCLEO-IKS4A1 shield
|
||||
stacked on a board with an Arduino connector, e.g. the
|
||||
:ref:`nucleo_f411re_board` board.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample runs with X-NUCLEO-IKS4A1 stacked on any board with a matching
|
||||
Arduino connector. For this example, we use a :ref:`nucleo_f411re_board` board.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/shields/x_nucleo_iks4a1/sensorhub1/
|
||||
:host-os: unix
|
||||
:board: nucleo_f411re
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
X-NUCLEO-IKS01A4 sensor dashboard
|
||||
|
||||
LSM6DSV16X: Accel (m.s-2): x: 0.081, y: -0.177, z: 9.945
|
||||
LSM6DSV16X: GYro (dps): x: 0.001, y: -0.000, z: 0.004
|
||||
LSM6DSV16X: Magn (gauss): x: 0.217, y: 0.015, z: -0.415
|
||||
LSM6DSV16X: Temperature: 19.8 C
|
||||
LSM6DSV16X: Pressure:99.655 kpa
|
||||
16:: lsm6dso16is acc trig 6432
|
||||
|
||||
<updated endlessly every 2 seconds>
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
:ref:`x-nucleo-iks4a1`
|
10
samples/shields/x_nucleo_iks4a1/sensorhub1/prj.conf
Normal file
10
samples/shields/x_nucleo_iks4a1/sensorhub1/prj.conf
Normal file
|
@ -0,0 +1,10 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSV16X_SENSORHUB=y
|
||||
CONFIG_LSM6DSV16X_EXT_LIS2MDL=y
|
||||
CONFIG_LSM6DSV16X_EXT_LPS22DF=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
12
samples/shields/x_nucleo_iks4a1/sensorhub1/sample.yaml
Normal file
12
samples/shields/x_nucleo_iks4a1/sensorhub1/sample.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
sample:
|
||||
name: X-NUCLEO-IKS01A4 sensor shield
|
||||
tests:
|
||||
sample.shields.x_nucleo_iks4a1.sensorhub1:
|
||||
harness: shield
|
||||
tags: shield
|
||||
depends_on: arduino_i2c arduino_gpio
|
||||
platform_exclude:
|
||||
- disco_l475_iot1
|
||||
- lpcxpresso55s16
|
||||
- mimxrt1010_evk
|
||||
- stm32mp157c_dk2
|
190
samples/shields/x_nucleo_iks4a1/sensorhub1/src/main.c
Normal file
190
samples/shields/x_nucleo_iks4a1/sensorhub1/src/main.c
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2019 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
static int lsm6dsv16x_acc_trig_cnt;
|
||||
|
||||
static void lsm6dsv16x_acc_trig_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lsm6dsv16x_acc_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lsm6dsv16x_config(const struct device *lsm6dsv16x)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LSM6DSV16X accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSV16X gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSV16X gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSV16X external magn sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LIS2MDL
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_MAGN_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X ext magn\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LPS22DF
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_PRESS,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X ext pressure\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_HTS221
|
||||
odr_attr.val1 = 12;
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_HUMIDITY,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X ext humidity\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dsv16x, &trig, lsm6dsv16x_acc_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct sensor_value lsm6dsv16x_xl[3], lsm6dsv16x_gy[3];
|
||||
#ifdef CONFIG_LSM6DSV16X_ENABLE_TEMP
|
||||
struct sensor_value lsm6dsv16x_temp;
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LIS2MDL
|
||||
struct sensor_value lis2mdl_magn[3];
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LPS22DF
|
||||
struct sensor_value lps22df_press;
|
||||
struct sensor_value lps22df_temp;
|
||||
#endif
|
||||
const struct device *const lsm6dsv16x = DEVICE_DT_GET_ONE(st_lsm6dsv16x);
|
||||
int cnt = 1;
|
||||
|
||||
if (!device_is_ready(lsm6dsv16x)) {
|
||||
printk("%s: device not ready.\n", lsm6dsv16x->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lsm6dsv16x_config(lsm6dsv16x);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
#ifndef CONFIG_LSM6DSV16X_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dsv16x) < 0) {
|
||||
printf("LSM6DSV16X Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ, lsm6dsv16x_xl);
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ, lsm6dsv16x_gy);
|
||||
#ifdef CONFIG_LSM6DSV16X_ENABLE_TEMP
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_DIE_TEMP, &lsm6dsv16x_temp);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LIS2MDL
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_MAGN_XYZ, lis2mdl_magn);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LPS22DF
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_AMBIENT_TEMP, &lps22df_temp);
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_PRESS, &lps22df_press);
|
||||
#endif
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
printf("\0033\014");
|
||||
|
||||
printf("X-NUCLEO-IKS01A4 sensor dashboard\n\n");
|
||||
|
||||
printf("LSM6DSV16X: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[0]),
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[1]),
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[2]));
|
||||
|
||||
printf("LSM6DSV16X: Gyro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[0]),
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[1]),
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[2]));
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_ENABLE_TEMP
|
||||
/* temperature */
|
||||
printf("LSM6DSV16X: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lsm6dsv16x_temp));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LIS2MDL
|
||||
printf("LSM6DSV16X: Magn (gauss): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lis2mdl_magn[0]),
|
||||
sensor_value_to_double(&lis2mdl_magn[1]),
|
||||
sensor_value_to_double(&lis2mdl_magn[2]));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_EXT_LPS22DF
|
||||
printf("LSM6DSV16X: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lps22df_temp));
|
||||
|
||||
printf("LSM6DSV16X: Pressure:%.3f kpa\n",
|
||||
sensor_value_to_double(&lps22df_press));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
printk("%d: lsm6dsv16x acc trig %d\n", cnt, lsm6dsv16x_acc_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(K_MSEC(2000));
|
||||
}
|
||||
}
|
14
samples/shields/x_nucleo_iks4a1/sensorhub2/CMakeLists.txt
Normal file
14
samples/shields/x_nucleo_iks4a1/sensorhub2/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2024 STMicroelectronics
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
# This sample is specific to x_nucleo_iks4a1 shield. Enforce -DSHIELD option
|
||||
set(SHIELD x_nucleo_iks4a1_shub2)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(x_nucleo_iks4a1)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
60
samples/shields/x_nucleo_iks4a1/sensorhub2/README.rst
Normal file
60
samples/shields/x_nucleo_iks4a1/sensorhub2/README.rst
Normal file
|
@ -0,0 +1,60 @@
|
|||
.. _x-nucleo-iks4a1-shub2-sample:
|
||||
|
||||
X-NUCLEO-IKS4A1: shield SHUB2 (Mode 2) sample
|
||||
#############################################
|
||||
|
||||
Overview
|
||||
********
|
||||
This sample is provided as an example to test the X-NUCLEO-IKS4A1 shield
|
||||
configured in Sensor Hub mode (Mode 2).
|
||||
Please refer to :ref:`x-nucleo-iks4a1-mode-2` for more info on this configuration.
|
||||
|
||||
This sample enables LSM6DSO16IS IMU in sensorhub mode with LIS2MDL magnetometer and
|
||||
LPS22DF pressure and temperature sensor.
|
||||
|
||||
Then sensor data are displayed periodically
|
||||
|
||||
- LSM6DSO16IS 6-Axis acceleration and angular velocity
|
||||
- LSM6DSO16IS (from LIS2MDL) 3-Axis magnetic field intensity
|
||||
- LSM6DSO16IS (from LPS22DF) ambient temperature and atmospheric pressure
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This sample communicates over I2C with the X-NUCLEO-IKS4A1 shield
|
||||
stacked on a board with an Arduino connector, e.g. the
|
||||
:ref:`nucleo_f411re_board` board.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample runs with X-NUCLEO-IKS4A1 stacked on any board with a matching
|
||||
Arduino connector. For this example, we use a :ref:`nucleo_f411re_board` board.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/shields/x_nucleo_iks4a1/sensorhub2/
|
||||
:host-os: unix
|
||||
:board: nucleo_f411re
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
X-NUCLEO-IKS01A4 sensor dashboard
|
||||
|
||||
LSM6DSO16IS: Accel (m.s-2): x: 0.081, y: -0.177, z: 9.945
|
||||
LSM6DSO16IS: GYro (dps): x: 0.001, y: -0.000, z: 0.004
|
||||
LSM6DSO16IS: Magn (gauss): x: 0.217, y: 0.015, z: -0.415
|
||||
LSM6DSO16IS: Temperature: 20.8 C
|
||||
LSM6DSO16IS: Pressure:99.756 kpa
|
||||
736:: lsm6dso16is acc trig 314944
|
||||
|
||||
<updated endlessly every 2 seconds>
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
:ref:`x-nucleo-iks4a1`
|
11
samples/shields/x_nucleo_iks4a1/sensorhub2/prj.conf
Normal file
11
samples/shields/x_nucleo_iks4a1/sensorhub2/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_LSM6DSO16IS_ENABLE_TEMP=n
|
||||
CONFIG_LSM6DSO16IS_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO16IS_SENSORHUB=y
|
||||
CONFIG_LSM6DSO16IS_EXT_LIS2MDL=y
|
||||
CONFIG_LSM6DSO16IS_EXT_LPS22DF=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
13
samples/shields/x_nucleo_iks4a1/sensorhub2/sample.yaml
Normal file
13
samples/shields/x_nucleo_iks4a1/sensorhub2/sample.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
sample:
|
||||
name: X-NUCLEO-IKS01A4 sensor shield
|
||||
tests:
|
||||
sample.shields.x_nucleo_iks4a1.sensorhub2:
|
||||
harness: shield
|
||||
tags: shield
|
||||
depends_on: arduino_i2c arduino_gpio
|
||||
platform_exclude:
|
||||
- disco_l475_iot1
|
||||
- lpcxpresso55s16
|
||||
- pan1781_evb
|
||||
- pan1782_evb
|
||||
- stm32mp157c_dk2
|
190
samples/shields/x_nucleo_iks4a1/sensorhub2/src/main.c
Normal file
190
samples/shields/x_nucleo_iks4a1/sensorhub2/src/main.c
Normal file
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2024 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
static int lsm6dso16is_acc_trig_cnt;
|
||||
|
||||
static void lsm6dso16is_acc_trig_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lsm6dso16is_acc_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lsm6dso16is_config(const struct device *lsm6dso16is)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr;
|
||||
|
||||
/* set LSM6DSO16IS accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSO16IS accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO16IS gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSO16IS gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO16IS external magn sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LIS2MDL
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_MAGN_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS ext magn\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LPS22DF
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_PRESS,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS ext pressure\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_HTS221
|
||||
odr_attr.val1 = 12;
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_HUMIDITY,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS ext humidity\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dso16is, &trig, lsm6dso16is_acc_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct sensor_value lsm6dso16is_xl[3], lsm6dso16is_gy[3];
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
struct sensor_value lsm6dso16is_temp;
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LIS2MDL
|
||||
struct sensor_value lis2mdl_magn[3];
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LPS22DF
|
||||
struct sensor_value lps22df_press;
|
||||
struct sensor_value lps22df_temp;
|
||||
#endif
|
||||
const struct device *const lsm6dso16is = DEVICE_DT_GET_ONE(st_lsm6dso16is);
|
||||
int cnt = 1;
|
||||
|
||||
if (!device_is_ready(lsm6dso16is)) {
|
||||
printk("%s: device not ready.\n", lsm6dso16is->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lsm6dso16is_config(lsm6dso16is);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
#ifndef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dso16is) < 0) {
|
||||
printf("LSM6DSO16IS Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ, lsm6dso16is_xl);
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ, lsm6dso16is_gy);
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_DIE_TEMP, &lsm6dso16is_temp);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LIS2MDL
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_MAGN_XYZ, lis2mdl_magn);
|
||||
#endif
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LPS22DF
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_AMBIENT_TEMP, &lps22df_temp);
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_PRESS, &lps22df_press);
|
||||
#endif
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
printf("\0033\014");
|
||||
|
||||
printf("X-NUCLEO-IKS01A4 sensor dashboard\n\n");
|
||||
|
||||
printf("LSM6DSO16IS: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dso16is_xl[0]),
|
||||
sensor_value_to_double(&lsm6dso16is_xl[1]),
|
||||
sensor_value_to_double(&lsm6dso16is_xl[2]));
|
||||
|
||||
printf("LSM6DSO16IS: Gyro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dso16is_gy[0]),
|
||||
sensor_value_to_double(&lsm6dso16is_gy[1]),
|
||||
sensor_value_to_double(&lsm6dso16is_gy[2]));
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
/* temperature */
|
||||
printf("LSM6DSO16IS: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lsm6dso16is_temp));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LIS2MDL
|
||||
printf("LSM6DSO16IS: Magn (gauss): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lis2mdl_magn[0]),
|
||||
sensor_value_to_double(&lis2mdl_magn[1]),
|
||||
sensor_value_to_double(&lis2mdl_magn[2]));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_EXT_LPS22DF
|
||||
printf("LSM6DSO16IS: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lps22df_temp));
|
||||
|
||||
printf("LSM6DSO16IS: Pressure:%.3f kpa\n",
|
||||
sensor_value_to_double(&lps22df_press));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
printk("%d: lsm6dso16is acc trig %d\n", cnt, lsm6dso16is_acc_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(K_MSEC(2000));
|
||||
}
|
||||
}
|
14
samples/shields/x_nucleo_iks4a1/standard/CMakeLists.txt
Normal file
14
samples/shields/x_nucleo_iks4a1/standard/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2024 STMicroelectronics
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
# This sample is specific to x_nucleo_iks4a1 shield. Enforce -DSHIELD option
|
||||
set(SHIELD x_nucleo_iks4a1)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(x_nucleo_iks4a1)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
66
samples/shields/x_nucleo_iks4a1/standard/README.rst
Normal file
66
samples/shields/x_nucleo_iks4a1/standard/README.rst
Normal file
|
@ -0,0 +1,66 @@
|
|||
.. _x-nucleo-iks4a1-std-sample:
|
||||
|
||||
X-NUCLEO-IKS4A1 shield Standard (Mode 1) sample
|
||||
###############################################
|
||||
|
||||
Overview
|
||||
********
|
||||
This sample is provided as an example to test the X-NUCLEO-IKS4A1 shield
|
||||
configured in Standard mode (Mode 1).
|
||||
Please refer to :ref:`x-nucleo-iks4a1-mode-1` for more info on this configuration.
|
||||
|
||||
This sample enables the following four sensors of a X-NUCLEO-IKS4A1 shield, and then
|
||||
periodically reads and displays data from the shield sensors:
|
||||
|
||||
- LSM6DSV16X 6-Axis acceleration and angular velocity
|
||||
- LSM6DSO16IS 6-Axis acceleration and angular velocity
|
||||
- LPS22DF ambient temperature and atmospheric pressure
|
||||
- LIS2MDL 3-Axis magnetic field intensity
|
||||
|
||||
Requirements
|
||||
************
|
||||
|
||||
This sample communicates over I2C with the X-NUCLEO-IKS4A1 shield
|
||||
stacked on a board with an Arduino connector, e.g. the
|
||||
:ref:`nucleo_f411re_board` board.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample runs with X-NUCLEO-IKS4A1 stacked on any board with a matching
|
||||
Arduino connector. For this example, we use a :ref:`nucleo_f411re_board` board.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/shields/x_nucleo_iks4a1/standard/
|
||||
:host-os: unix
|
||||
:board: nucleo_f411re
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
X-NUCLEO-IKS4A1 sensor dashboard
|
||||
|
||||
LIS2MDL: Magn (gauss): x: -0.364, y: -0.523, z: -0.399
|
||||
LIS2MDL: Temperature: 22.4 C
|
||||
LSM6DSO16IS: Accel (m.s-2): x: -0.167, y: -0.249, z: 9.954
|
||||
LSM6DSO16IS: GYro (dps): x: 0.047, y: -0.052, z: -0.042
|
||||
LSM6DSO16IS: Temperature: 25.8 C
|
||||
LSM6DSV16X: Accel (m.s-2): x: 0.005, y: 0.053, z: 9.930
|
||||
LSM6DSV16X: GYro (dps): x: -0.000, y: 0.000, z: 0.005
|
||||
LPS22DF: Temperature: 25.2 C
|
||||
LPS22DF: Pressure:98.121 kpa
|
||||
10:: lis2mdl trig 1839
|
||||
10:: lsm6dso16is acc trig 3892
|
||||
10:: lsm6dsv16x acc trig 4412
|
||||
10:: lps22df trig 174
|
||||
|
||||
<updated endlessly every 2 seconds>
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
:ref:`x-nucleo-iks4a1`
|
11
samples/shields/x_nucleo_iks4a1/standard/prj.conf
Normal file
11
samples/shields/x_nucleo_iks4a1/standard/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_LOG_LEVEL_DBG=y
|
||||
CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LPS2XDF_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO16IS_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_LSM6DSO16IS_ENABLE_TEMP=y
|
||||
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
16
samples/shields/x_nucleo_iks4a1/standard/sample.yaml
Normal file
16
samples/shields/x_nucleo_iks4a1/standard/sample.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
sample:
|
||||
name: X-NUCLEO-IKS01A4 sensor shield
|
||||
common:
|
||||
min_ram: 16
|
||||
tests:
|
||||
sample.shields.x_nucleo_iks4a1.standard:
|
||||
harness: shield
|
||||
tags: shield
|
||||
depends_on: arduino_i2c arduino_gpio
|
||||
platform_exclude:
|
||||
- disco_l475_iot1
|
||||
- lpcxpresso55s16
|
||||
- mimxrt1010_evk
|
||||
- pan1781_evb
|
||||
- pan1782_evb
|
||||
- stm32mp157c_dk2
|
358
samples/shields/x_nucleo_iks4a1/standard/src/main.c
Normal file
358
samples/shields/x_nucleo_iks4a1/standard/src/main.c
Normal file
|
@ -0,0 +1,358 @@
|
|||
/*
|
||||
* Copyright (c) 2024 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <stdio.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
#ifdef CONFIG_LPS2XDF_TRIGGER
|
||||
static int lps22df_trig_cnt;
|
||||
|
||||
static void lps22df_trigger_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lps22df_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LIS2MDL_TRIGGER
|
||||
static int lis2mdl_trig_cnt;
|
||||
|
||||
static void lis2mdl_trigger_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lis2mdl_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
static int lsm6dso16is_acc_trig_cnt;
|
||||
|
||||
static void lsm6dso16is_acc_trig_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lsm6dso16is_acc_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
static int lsm6dsv16x_acc_trig_cnt;
|
||||
|
||||
static void lsm6dsv16x_acc_trig_handler(const struct device *dev,
|
||||
const struct sensor_trigger *trig)
|
||||
{
|
||||
sensor_sample_fetch_chan(dev, SENSOR_CHAN_ALL);
|
||||
lsm6dsv16x_acc_trig_cnt++;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void lis2mdl_config(const struct device *lis2mdl)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
|
||||
/* set LIS2MDL sampling frequency to 100 Hz */
|
||||
odr_attr.val1 = 100;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lis2mdl, SENSOR_CHAN_ALL,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LIS2MDL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS2MDL_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_MAGN_XYZ;
|
||||
sensor_trigger_set(lis2mdl, &trig, lis2mdl_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsm6dso16is_config(const struct device *lsm6dso16is)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr, mode_attr;
|
||||
|
||||
mode_attr.val1 = 0; /* HP */
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_CONFIGURATION, &mode_attr) < 0) {
|
||||
printk("Cannot set mode for LSM6DSO16IS accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO16IS accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSO16IS accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSO16IS gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSO16IS gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSO16IS gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dso16is, &trig, lsm6dso16is_acc_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsm6dsv16x_config(const struct device *lsm6dsv16x)
|
||||
{
|
||||
struct sensor_value odr_attr, fs_attr, mode_attr;
|
||||
|
||||
mode_attr.val1 = 0; /* HP */
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_CONFIGURATION, &mode_attr) < 0) {
|
||||
printk("Cannot set mode for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSV16X accel sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_g_to_ms2(16, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSV16X accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* set LSM6DSV16X gyro sampling frequency to 208 Hz */
|
||||
odr_attr.val1 = 208;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LSM6DSV16X gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_degrees_to_rad(250, &fs_attr);
|
||||
|
||||
if (sensor_attr_set(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ,
|
||||
SENSOR_ATTR_FULL_SCALE, &fs_attr) < 0) {
|
||||
printk("Cannot set full scale for LSM6DSV16X gyro\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ACCEL_XYZ;
|
||||
sensor_trigger_set(lsm6dsv16x, &trig, lsm6dsv16x_acc_trig_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lps22df_config(const struct device *lps22df)
|
||||
{
|
||||
struct sensor_value odr_attr;
|
||||
|
||||
/* set LPS22DF accel sampling frequency to 10 Hz */
|
||||
odr_attr.val1 = 10;
|
||||
odr_attr.val2 = 0;
|
||||
|
||||
if (sensor_attr_set(lps22df, SENSOR_CHAN_ALL,
|
||||
SENSOR_ATTR_SAMPLING_FREQUENCY, &odr_attr) < 0) {
|
||||
printk("Cannot set sampling frequency for LPS22DF accel\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LPS2XDF_TRIGGER
|
||||
struct sensor_trigger trig;
|
||||
|
||||
trig.type = SENSOR_TRIG_DATA_READY;
|
||||
trig.chan = SENSOR_CHAN_ALL;
|
||||
sensor_trigger_set(lps22df, &trig, lps22df_trigger_handler);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct sensor_value lis2mdl_magn[3], lis2mdl_temp, lps22df_press, lps22df_temp;
|
||||
struct sensor_value lsm6dso16is_xl[3], lsm6dso16is_gy[3];
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
struct sensor_value lsm6dso16is_temp;
|
||||
#endif
|
||||
struct sensor_value lsm6dsv16x_xl[3], lsm6dsv16x_gy[3];
|
||||
const struct device *const lis2mdl = DEVICE_DT_GET_ONE(st_lis2mdl);
|
||||
const struct device *const lsm6dso16is = DEVICE_DT_GET_ONE(st_lsm6dso16is);
|
||||
const struct device *const lsm6dsv16x = DEVICE_DT_GET_ONE(st_lsm6dsv16x);
|
||||
const struct device *const lps22df = DEVICE_DT_GET_ONE(st_lps22df);
|
||||
int cnt = 1;
|
||||
|
||||
if (!device_is_ready(lsm6dso16is)) {
|
||||
printk("%s: device not ready.\n", lsm6dso16is->name);
|
||||
return 0;
|
||||
}
|
||||
if (!device_is_ready(lsm6dsv16x)) {
|
||||
printk("%s: device not ready.\n", lsm6dsv16x->name);
|
||||
return 0;
|
||||
}
|
||||
if (!device_is_ready(lis2mdl)) {
|
||||
printk("%s: device not ready.\n", lis2mdl->name);
|
||||
return 0;
|
||||
}
|
||||
if (!device_is_ready(lps22df)) {
|
||||
printk("%s: device not ready.\n", lps22df->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lis2mdl_config(lis2mdl);
|
||||
lsm6dso16is_config(lsm6dso16is);
|
||||
lsm6dsv16x_config(lsm6dsv16x);
|
||||
lps22df_config(lps22df);
|
||||
|
||||
while (1) {
|
||||
/* Get sensor samples */
|
||||
|
||||
#ifndef CONFIG_LIS2MDL_TRIGGER
|
||||
if (sensor_sample_fetch(lis2mdl) < 0) {
|
||||
printf("LIS2MDL Magn Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dso16is) < 0) {
|
||||
printf("LSM6DSO16IS Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LSM6DSV16X_TRIGGER
|
||||
if (sensor_sample_fetch(lsm6dsv16x) < 0) {
|
||||
printf("LSM6DSV16X Sensor sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_LPS2XDF_TRIGGER
|
||||
if (sensor_sample_fetch(lps22df) < 0) {
|
||||
printf("LPS22DF pressure sample update error\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get sensor data */
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_XYZ, lis2mdl_magn);
|
||||
sensor_channel_get(lis2mdl, SENSOR_CHAN_DIE_TEMP, &lis2mdl_temp);
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ, lsm6dso16is_xl);
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_GYRO_XYZ, lsm6dso16is_gy);
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
sensor_channel_get(lsm6dso16is, SENSOR_CHAN_DIE_TEMP, &lsm6dso16is_temp);
|
||||
#endif
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_ACCEL_XYZ, lsm6dsv16x_xl);
|
||||
sensor_channel_get(lsm6dsv16x, SENSOR_CHAN_GYRO_XYZ, lsm6dsv16x_gy);
|
||||
|
||||
sensor_channel_get(lps22df, SENSOR_CHAN_PRESS, &lps22df_press);
|
||||
sensor_channel_get(lps22df, SENSOR_CHAN_AMBIENT_TEMP, &lps22df_temp);
|
||||
|
||||
/* Display sensor data */
|
||||
|
||||
/* Erase previous */
|
||||
printf("\0033\014");
|
||||
|
||||
printf("X-NUCLEO-IKS4A1 sensor dashboard\n\n");
|
||||
|
||||
/* lis2mdl */
|
||||
printf("LIS2MDL: Magn (gauss): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lis2mdl_magn[0]),
|
||||
sensor_value_to_double(&lis2mdl_magn[1]),
|
||||
sensor_value_to_double(&lis2mdl_magn[2]));
|
||||
|
||||
printf("LIS2MDL: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lis2mdl_temp));
|
||||
|
||||
printf("LSM6DSO16IS: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dso16is_xl[0]),
|
||||
sensor_value_to_double(&lsm6dso16is_xl[1]),
|
||||
sensor_value_to_double(&lsm6dso16is_xl[2]));
|
||||
|
||||
printf("LSM6DSO16IS: Gyro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dso16is_gy[0]),
|
||||
sensor_value_to_double(&lsm6dso16is_gy[1]),
|
||||
sensor_value_to_double(&lsm6dso16is_gy[2]));
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_ENABLE_TEMP
|
||||
/* temperature */
|
||||
printf("LSM6DSO16IS: Temperature: %.1f C\n",
|
||||
sensor_value_to_double(&lsm6dso16is_temp));
|
||||
#endif
|
||||
|
||||
printf("LSM6DSV16X: Accel (m.s-2): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[0]),
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[1]),
|
||||
sensor_value_to_double(&lsm6dsv16x_xl[2]));
|
||||
|
||||
printf("LSM6DSV16X: GYro (dps): x: %.3f, y: %.3f, z: %.3f\n",
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[0]),
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[1]),
|
||||
sensor_value_to_double(&lsm6dsv16x_gy[2]));
|
||||
|
||||
printf("LPS22DF: Temperature: %.1f C\n", sensor_value_to_double(&lps22df_temp));
|
||||
printf("LPS22DF: Pressure:%.3f kpa\n", sensor_value_to_double(&lps22df_press));
|
||||
|
||||
#if defined(CONFIG_LIS2MDL_TRIGGER)
|
||||
printk("%d: lis2mdl trig %d\n", cnt, lis2mdl_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSO16IS_TRIGGER
|
||||
printk("%d: lsm6dso16is acc trig %d\n", cnt, lsm6dso16is_acc_trig_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LSM6DSV16X_TRIGGER
|
||||
printk("%d: lsm6dsv16x acc trig %d\n", cnt, lsm6dsv16x_acc_trig_cnt);
|
||||
#endif
|
||||
#ifdef CONFIG_LPS2XDF_TRIGGER
|
||||
printk("%d: lps22df trig %d\n", cnt, lps22df_trig_cnt);
|
||||
#endif
|
||||
|
||||
cnt++;
|
||||
k_sleep(K_MSEC(2000));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue