diff --git a/.github/workflows/Continuous-integration.yml b/.github/workflows/Continuous-integration.yml index bfb1db3..5708e70 100644 --- a/.github/workflows/Continuous-integration.yml +++ b/.github/workflows/Continuous-integration.yml @@ -59,8 +59,10 @@ jobs: id: compile uses: stm32duino/actions/compile-examples@main with: - board-pattern: "NUCLEO_L476RG" - + custom-config: "./extras/build_config.json" + board-pattern: "NUCLEO_L476RG|NUCLEO_H503RB|NUCLEO_C562RE" + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} # Use the output from the `Compilation` step - name: Compilation Errors if: failure() diff --git a/README.md b/README.md index 2121a23..74e0b58 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Arduino library to support the LSM6DSV16X 3D accelerometer and 3D gyroscope ## API -This sensor uses I2C or SPI to communicate. +This sensor uses I2C, I3C or SPI to communicate. For I2C it is then required to create a TwoWire interface before accessing to the sensors: TwoWire dev_i2c(I2C_SDA, I2C_SCL); @@ -14,6 +14,10 @@ For SPI it is then required to create a SPI interface before accessing to the se SPIClass dev_spi(SPI_MOSI, SPI_MISO, SPI_SCK); dev_spi.begin(); +For I3C it is then required to create an I3C interface before accessing to the sensors: + + I3C.begin(I3C_SDA, I3C_SCL, 1000000U); + An instance can be created and enabled when the I2C bus is used following the procedure below: LSM6DSV16XSensor AccGyr(&dev_i2c); @@ -28,6 +32,27 @@ An instance can be created and enabled when the SPI bus is used following the pr AccGyr.Enable_X(); AccGyr.Enable_G(); + +An instance can be created and enabled when the I3C bus is used with SETDASA (static-to-dynamic address assignment): + LSM6DSV16XSensor AccGyr(&I3C, LSM6DSV16X_I3C_ADD_H); + I3C.resetDynamicAddresses(); + I3C.assignDynamicAddress(AccGyr.getStaticAddress(), LSM6DSV16X_DYNAMIC_ADDRESS); + AccGyr.begin(LSM6DSV16X_DYNAMIC_ADDRESS); + I3C.setClock(12500000); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + +An instance can be created and enabled when the I3C bus is used with ENTDAA (dynamic address discovery): + + LSM6DSV16XSensor AccGyr(&I3C); + I3C.begin(I3C_SDA, I3C_SCL, 1000000U); + I3C.discover(devices, 8, &found); + // find dynAddr by matching LSM6DSV16X_I3C_PID_H in discovered devices + AccGyr.begin(dynAddr); + I3C.setClock(12500000); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + The access to the sensor values is done as explained below: Read accelerometer and gyroscope. @@ -39,31 +64,35 @@ The access to the sensor values is done as explained below: ## Examples -* LSM6DSV16X_DataLog_Terminal: This application shows how to get data from LSM6DSV16X accelerometer and gyroscope and print them on terminal. +* LSM6DSV16X_DataLog_Terminal_I2C: This application shows how to get data from LSM6DSV16X accelerometer and gyroscope and print them on terminal over I2C. + +* LSM6DSV16X_6D_Orientation_I2C: This application shows how to use LSM6DSV16X accelerometer to find out the 6D orientation and display data on a hyperterminal over I2C. + +* LSM6DSV16X_Datalog_Terminal_I3C: This application shows how to use LSM6DSV16X accelerometer and gyroscope over I3C using SETDASA. -* LSM6DSV16X_6D_Orientation: This application shows how to use LSM6DSV16X accelerometer to find out the 6D orientation and display data on a hyperterminal. +* LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA: This application shows how to discover and use LSM6DSV16X dynamic address over I3C. -* LSM6DSV16X_Double_Tap_Detection: This application shows how to detect the double tap event using the LSM6DSV16X accelerometer. +* LSM6DSV16X_Double_Tap_Detection_I2C: This application shows how to detect the double tap event using the LSM6DSV16X accelerometer over I2C. -* LSM6DSV16X_Free_Fall_Detection: This application shows how to detect the free fall event using the LSM6DSV16X accelerometer. +* LSM6DSV16X_Free_Fall_Detection_I2C: This application shows how to detect the free fall event using the LSM6DSV16X accelerometer over I2C. -* LSM6DSV16X_MLC: This application shows how to detect the activity using the LSM6DSV16X Machine Learning Core. +* LSM6DSV16X_MLC_I2C: This application shows how to detect the activity using the LSM6DSV16X Machine Learning Core over I2C. -* LSM6DSV16X_Pedometer: This application shows how to use LSM6DSV16X accelerometer to count steps. +* LSM6DSV16X_Pedometer_I2C: This application shows how to use LSM6DSV16X accelerometer to count steps over I2C. -* LSM6DSV16X_Qvar_Polling: This application shows how to use LSM6DSV16X Qvar features in polling mode. +* LSM6DSV16X_Qvar_Polling_I2C: This application shows how to use LSM6DSV16X Qvar features in polling mode over I2C. -* LSM6DSV16X_Sensor_Fusion: This application shows how to use LSM6DSV16X Sensor Fusion features for reading quaternions. +* LSM6DSV16X_Sensor_Fusion_I2C: This application shows how to use LSM6DSV16X Sensor Fusion features for reading quaternions over I2C. -* LSM6DSV16X_Single_Tap_Detection: This application shows how to detect the single tap event using the LSM6DSV16X accelerometer. +* LSM6DSV16X_Single_Tap_Detection_I2C: This application shows how to detect the single tap event using the LSM6DSV16X accelerometer over I2C. -* LSM6DSV16X_Tilt_Detection: This application shows how to detect the tilt event using the LSM6DSV16X accelerometer. +* LSM6DSV16X_Tilt_Detection_I2C: This application shows how to detect the tilt event using the LSM6DSV16X accelerometer over I2C. -* LSM6DSV16X_Wake_Up_Detection: This application shows how to detect the wake-up event using the LSM6DSV16X accelerometer. +* LSM6DSV16X_Wake_Up_Detection_I2C: This application shows how to detect the wake-up event using the LSM6DSV16X accelerometer over I2C. -* LSM6DSV16X_FIFO_Polling: This application shows how to get accelerometer and gyroscope data from FIFO in pooling mode and print them on terminal. +* LSM6DSV16X_FIFO_Polling_I2C: This application shows how to get accelerometer and gyroscope data from FIFO in pooling mode and print them on terminal over I2C. -* LSM6DSV16X_FIFO_Interrupt: This application shows how to get accelerometer and gyroscope data from FIFO using interrupt and print them on terminal. +* LSM6DSV16X_FIFO_Interrupt_I2C: This application shows how to get accelerometer and gyroscope data from FIFO using interrupt and print them on terminal over I2C. ## Documentation You can find the source files at diff --git a/examples/LSM6DSV16X_6D_Orientation/LSM6DSV16X_6D_Orientation.ino b/examples/LSM6DSV16X_6D_Orientation_I2C/LSM6DSV16X_6D_Orientation_I2C.ino similarity index 98% rename from examples/LSM6DSV16X_6D_Orientation/LSM6DSV16X_6D_Orientation.ino rename to examples/LSM6DSV16X_6D_Orientation_I2C/LSM6DSV16X_6D_Orientation_I2C.ino index bd70b93..6182767 100644 --- a/examples/LSM6DSV16X_6D_Orientation/LSM6DSV16X_6D_Orientation.ino +++ b/examples/LSM6DSV16X_6D_Orientation_I2C/LSM6DSV16X_6D_Orientation_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_HelloWorld.ino + @file LSM6DSV16X_6D_Orientation_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X 6D Orientation ******************************************************************************* diff --git a/examples/LSM6DSV16X_DataLog_Terminal/LSM6DSV16X_DataLog_Terminal.ino b/examples/LSM6DSV16X_DataLog_Terminal_I2C/LSM6DSV16X_DataLog_Terminal_I2C.ino similarity index 93% rename from examples/LSM6DSV16X_DataLog_Terminal/LSM6DSV16X_DataLog_Terminal.ino rename to examples/LSM6DSV16X_DataLog_Terminal_I2C/LSM6DSV16X_DataLog_Terminal_I2C.ino index a6d1c13..753028b 100644 --- a/examples/LSM6DSV16X_DataLog_Terminal/LSM6DSV16X_DataLog_Terminal.ino +++ b/examples/LSM6DSV16X_DataLog_Terminal_I2C/LSM6DSV16X_DataLog_Terminal_I2C.ino @@ -1,9 +1,9 @@ /* - @file LSM6DSV16X_DataLog_Terminal.ino + @file LSM6DSV16X_DataLog_Terminal_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X inertial measurement sensor ******************************************************************************* - Copyright (c) 2022, STMicroelectronics + Copyright (c) 2026, STMicroelectronics All rights reserved. This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the diff --git a/examples/LSM6DSV16X_Datalog_Terminal_I3C/LSM6DSV16X_Datalog_Terminal_I3C.ino b/examples/LSM6DSV16X_Datalog_Terminal_I3C/LSM6DSV16X_Datalog_Terminal_I3C.ino new file mode 100644 index 0000000..680e05c --- /dev/null +++ b/examples/LSM6DSV16X_Datalog_Terminal_I3C/LSM6DSV16X_Datalog_Terminal_I3C.ino @@ -0,0 +1,92 @@ +/* + @file LSM6DSV16X_DataLog_Terminal_I3C.ino + @author STMicroelectronics + @brief Example to use the LSM6DSV16X sensor with I3C and SETDASA command + ******************************************************************************* + Copyright (c) 2026, STMicroelectronics + All rights reserved. + + This software component is licensed by ST under BSD 3-Clause license, + the "License"; You may not use this file except in compliance with the + License. You may obtain a copy of the License at: + opensource.org/licenses/BSD-3-Clause + + ******************************************************************************* +*/ +#include "LSM6DSV16XSensor.h" + +#define LSM6DSV16X_DYNAMIC_ADDRESS 0x30 + +LSM6DSV16XSensor sensor(&I3C, LSM6DSV16X_I3C_ADD_H); + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + delay(1000); + + Serial.println("=== LSM6DSV16X SETDASA ==="); + + if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) { + Serial.println("begin() failed"); + while (1) {} + } + + if (!I3C.resetDynamicAddresses()) { + Serial.println("resetDynamicAddresses() failed"); + while (1) {} + } + + if (!I3C.assignDynamicAddress(sensor.getStaticAddress(), LSM6DSV16X_DYNAMIC_ADDRESS)) { + Serial.println("assignDynamicAddress() failed"); + while (1) {} + } + + if (sensor.begin(LSM6DSV16X_DYNAMIC_ADDRESS) != LSM6DSV16X_OK) { + Serial.println("sensor.begin() failed"); + while (1) {} + } + + if (!I3C.setClock(12500000)) { + Serial.println("setClock() failed"); + while (1) {} + } + + if (sensor.Enable_X() != LSM6DSV16X_OK) { + Serial.println("sensor.Enable_X() failed"); + while (1) {} + } + + if (sensor.Enable_G() != LSM6DSV16X_OK) { + Serial.println("sensor.Enable_G() failed"); + while (1) {} + } + + Serial.println("LSM6DSV16X ready"); +} + +void loop() +{ + int32_t accel[3] = {0}; + int32_t angrate[3] = {0}; + + if (sensor.Get_X_Axes(accel) == LSM6DSV16X_OK && sensor.Get_G_Axes(angrate) == LSM6DSV16X_OK) { + Serial.print("Accel-X[mg]:"); + Serial.print(accel[0]); + Serial.print(",Accel-Y[mg]:"); + Serial.print(accel[1]); + Serial.print(",Accel-Z[mg]:"); + Serial.println(accel[2]); + + Serial.print("AngRate-X[mdps]:"); + Serial.print(angrate[0]); + Serial.print(",AngRate-Y[mdps]:"); + Serial.print(angrate[1]); + Serial.print(",AngRate-Z[mdps]:"); + Serial.println(angrate[2]); + } else { + Serial.println("Read failed"); + } + + delay(500); +} diff --git a/examples/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA.ino b/examples/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA.ino new file mode 100644 index 0000000..fe50e1f --- /dev/null +++ b/examples/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA/LSM6DSV16X_Datalog_Terminal_I3C_ENTDAA.ino @@ -0,0 +1,111 @@ +/* + @file LSM6DSV16X_DataLog_Terminal_I3C_ENTDAA.ino + @author STMicroelectronics + @brief Example to use the LSM6DSV16X sensor with I3C dynamic address assignment + ******************************************************************************* + Copyright (c) 2026, STMicroelectronics + All rights reserved. + + This software component is licensed by ST under BSD 3-Clause license, + the "License"; You may not use this file except in compliance with the + License. You may obtain a copy of the License at: + opensource.org/licenses/BSD-3-Clause + + ******************************************************************************* +*/ + +#include "LSM6DSV16XSensor.h" + +LSM6DSV16XSensor sensor(&I3C); + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + delay(1000); + + Serial.println("=== LSM6DSV16X DAA ==="); + + if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) { + Serial.println("begin() failed"); + while (1) {} + } + + if (!I3C.resetDynamicAddresses()) { + Serial.println("resetDynamicAddresses() failed"); + while (1) {} + } + + I3CDiscoveredDevice devices[8] = {}; + size_t found = 0; + + if (I3C.discover(devices, 8, &found)) { + Serial.println("discover() failed"); + while (1) {} + } + + uint8_t lsmDynAddr = 0U; + + for (size_t i = 0; i < found; ++i) { + Serial.println(devices[i].pid, HEX); + if (devices[i].pid == LSM6DSV16X_I3C_PID_H) { + lsmDynAddr = devices[i].dynAddr; + Serial.print("lsmDynAddr="); + Serial.println(lsmDynAddr, HEX); + break; + } + } + + if (lsmDynAddr == 0U) { + Serial.println("Sensor not found"); + while (1) {} + } + + if (sensor.begin(lsmDynAddr) != LSM6DSV16X_OK) { + Serial.println("sensor.begin() failed"); + while (1) {} + } + + if (!I3C.setClock(12500000)) { + Serial.println("setClock() failed"); + while (1) {} + } + + if (sensor.Enable_X() != LSM6DSV16X_OK) { + Serial.println("sensor.Enable_X() failed"); + while (1) {} + } + + if (sensor.Enable_G() != LSM6DSV16X_OK) { + Serial.println("sensor.Enable_G() failed"); + while (1) {} + } + + Serial.println("LSM6DSV16X ready"); +} + +void loop() +{ + int32_t accel[3] = {0}; + int32_t angrate[3] = {0}; + + if (sensor.Get_X_Axes(accel) == LSM6DSV16X_OK && sensor.Get_G_Axes(angrate) == LSM6DSV16X_OK) { + Serial.print("Accel-X[mg]:"); + Serial.print(accel[0]); + Serial.print(",Accel-Y[mg]:"); + Serial.print(accel[1]); + Serial.print(",Accel-Z[mg]:"); + Serial.println(accel[2]); + + Serial.print("AngRate-X[mdps]:"); + Serial.print(angrate[0]); + Serial.print(",AngRate-Y[mdps]:"); + Serial.print(angrate[1]); + Serial.print(",AngRate-Z[mdps]:"); + Serial.println(angrate[2]); + } else { + Serial.println("Read failed"); + } + + delay(500); +} diff --git a/examples/LSM6DSV16X_Double_Tap_Detection/LSM6DSV16X_Double_Tap_Detection.ino b/examples/LSM6DSV16X_Double_Tap_Detection_I2C/LSM6DSV16X_Double_Tap_Detection_I2C.ino similarity index 96% rename from examples/LSM6DSV16X_Double_Tap_Detection/LSM6DSV16X_Double_Tap_Detection.ino rename to examples/LSM6DSV16X_Double_Tap_Detection_I2C/LSM6DSV16X_Double_Tap_Detection_I2C.ino index fcadae1..df406df 100644 --- a/examples/LSM6DSV16X_Double_Tap_Detection/LSM6DSV16X_Double_Tap_Detection.ino +++ b/examples/LSM6DSV16X_Double_Tap_Detection_I2C/LSM6DSV16X_Double_Tap_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Double_Tap_Detection.ino + @file LSM6DSV16X_Double_Tap_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Double Tap Detection ******************************************************************************* diff --git a/examples/LSM6DSV16X_FIFO_Interrupt/LSM6DSV16X_FIFO_Interrupt.ino b/examples/LSM6DSV16X_FIFO_Interrupt_I2C/LSM6DSV16X_FIFO_Interrupt_I2C.ino similarity index 99% rename from examples/LSM6DSV16X_FIFO_Interrupt/LSM6DSV16X_FIFO_Interrupt.ino rename to examples/LSM6DSV16X_FIFO_Interrupt_I2C/LSM6DSV16X_FIFO_Interrupt_I2C.ino index 8a30eda..ed2864f 100644 --- a/examples/LSM6DSV16X_FIFO_Interrupt/LSM6DSV16X_FIFO_Interrupt.ino +++ b/examples/LSM6DSV16X_FIFO_Interrupt_I2C/LSM6DSV16X_FIFO_Interrupt_I2C.ino @@ -1,5 +1,5 @@ /* - @file STEVAL_MEMS_FIFO_Interrupt.ino + @file LSM6DSV16X_FIFO_Interrupt_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X library with FIFO status interrupts. ******************************************************************************* diff --git a/examples/LSM6DSV16X_FIFO_Polling/LSM6DSV16X_FIFO_Polling.ino b/examples/LSM6DSV16X_FIFO_Polling_I2C/LSM6DSV16X_FIFO_Polling_I2C.ino similarity index 99% rename from examples/LSM6DSV16X_FIFO_Polling/LSM6DSV16X_FIFO_Polling.ino rename to examples/LSM6DSV16X_FIFO_Polling_I2C/LSM6DSV16X_FIFO_Polling_I2C.ino index d3697d3..f487b6d 100644 --- a/examples/LSM6DSV16X_FIFO_Polling/LSM6DSV16X_FIFO_Polling.ino +++ b/examples/LSM6DSV16X_FIFO_Polling_I2C/LSM6DSV16X_FIFO_Polling_I2C.ino @@ -1,5 +1,5 @@ /* - @file STEVAL_MEMS_FIFO_Interrupt.ino + @file LSM6DSV16X_FIFO_Polling_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X library with FIFO status interrupts. ******************************************************************************* diff --git a/examples/LSM6DSV16X_Free_Fall_Detection/LSM6DSV16X_Free_Fall_Detection.ino b/examples/LSM6DSV16X_Free_Fall_Detection_I2C/LSM6DSV16X_Free_Fall_Detection_I2C.ino similarity index 96% rename from examples/LSM6DSV16X_Free_Fall_Detection/LSM6DSV16X_Free_Fall_Detection.ino rename to examples/LSM6DSV16X_Free_Fall_Detection_I2C/LSM6DSV16X_Free_Fall_Detection_I2C.ino index 7beae01..aa24236 100644 --- a/examples/LSM6DSV16X_Free_Fall_Detection/LSM6DSV16X_Free_Fall_Detection.ino +++ b/examples/LSM6DSV16X_Free_Fall_Detection_I2C/LSM6DSV16X_Free_Fall_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Free_Fall_Detection.ino + @file LSM6DSV16X_Free_Fall_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Free Fall Detection ******************************************************************************* diff --git a/examples/LSM6DSV16X_MLC/LSM6DSV16X_MLC.ino b/examples/LSM6DSV16X_MLC_I2C/LSM6DSV16X_MLC_I2C.ino similarity index 98% rename from examples/LSM6DSV16X_MLC/LSM6DSV16X_MLC.ino rename to examples/LSM6DSV16X_MLC_I2C/LSM6DSV16X_MLC_I2C.ino index 5bc61e8..0e3189d 100644 --- a/examples/LSM6DSV16X_MLC/LSM6DSV16X_MLC.ino +++ b/examples/LSM6DSV16X_MLC_I2C/LSM6DSV16X_MLC_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_MLC.ino + @file LSM6DSV16X_MLC_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Machine Learning Core ******************************************************************************* diff --git a/examples/LSM6DSV16X_MLC/lsm6dsv16x_activity_recognition_for_mobile.h b/examples/LSM6DSV16X_MLC_I2C/lsm6dsv16x_activity_recognition_for_mobile.h similarity index 100% rename from examples/LSM6DSV16X_MLC/lsm6dsv16x_activity_recognition_for_mobile.h rename to examples/LSM6DSV16X_MLC_I2C/lsm6dsv16x_activity_recognition_for_mobile.h diff --git a/examples/LSM6DSV16X_Pedometer/LSM6DSV16X_Pedometer.ino b/examples/LSM6DSV16X_Pedometer_I2C/LSM6DSV16X_Pedometer_I2C.ino similarity index 98% rename from examples/LSM6DSV16X_Pedometer/LSM6DSV16X_Pedometer.ino rename to examples/LSM6DSV16X_Pedometer_I2C/LSM6DSV16X_Pedometer_I2C.ino index b2a4f52..eacd9ba 100644 --- a/examples/LSM6DSV16X_Pedometer/LSM6DSV16X_Pedometer.ino +++ b/examples/LSM6DSV16X_Pedometer_I2C/LSM6DSV16X_Pedometer_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Pedometer.ino + @file LSM6DSV16X_Pedometer_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Pedometer ******************************************************************************* diff --git a/examples/LSM6DSV16X_Qvar_Polling/LSM6DSV16X_Qvar_Polling.ino b/examples/LSM6DSV16X_Qvar_Polling_I2C/LSM6DSV16X_Qvar_Polling_I2C.ino similarity index 96% rename from examples/LSM6DSV16X_Qvar_Polling/LSM6DSV16X_Qvar_Polling.ino rename to examples/LSM6DSV16X_Qvar_Polling_I2C/LSM6DSV16X_Qvar_Polling_I2C.ino index a159242..8ddd208 100644 --- a/examples/LSM6DSV16X_Qvar_Polling/LSM6DSV16X_Qvar_Polling.ino +++ b/examples/LSM6DSV16X_Qvar_Polling_I2C/LSM6DSV16X_Qvar_Polling_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Qvar.ino + @file LSM6DSV16X_Qvar_Polling_I2C.ino @author STMicroelectronics @brief Example to use LSM6DSV16X Qvar features ******************************************************************************* diff --git a/examples/LSM6DSV16X_Sensor_Fusion/LSM6DSV16X_Sensor_Fusion.ino b/examples/LSM6DSV16X_Sensor_Fusion_I2C/LSM6DSV16X_Sensor_Fusion_I2C.ino similarity index 98% rename from examples/LSM6DSV16X_Sensor_Fusion/LSM6DSV16X_Sensor_Fusion.ino rename to examples/LSM6DSV16X_Sensor_Fusion_I2C/LSM6DSV16X_Sensor_Fusion_I2C.ino index c6d7d45..173810e 100644 --- a/examples/LSM6DSV16X_Sensor_Fusion/LSM6DSV16X_Sensor_Fusion.ino +++ b/examples/LSM6DSV16X_Sensor_Fusion_I2C/LSM6DSV16X_Sensor_Fusion_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Sensor_Fusion.ino + @file LSM6DSV16X_Sensor_Fusion_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X library with Sensor Fusion Low Power. ******************************************************************************* diff --git a/examples/LSM6DSV16X_Single_Tap_Detection/LSM6DSV16X_Single_Tap_Detection.ino b/examples/LSM6DSV16X_Single_Tap_Detection_I2C/LSM6DSV16X_Single_Tap_Detection_I2C.ino similarity index 96% rename from examples/LSM6DSV16X_Single_Tap_Detection/LSM6DSV16X_Single_Tap_Detection.ino rename to examples/LSM6DSV16X_Single_Tap_Detection_I2C/LSM6DSV16X_Single_Tap_Detection_I2C.ino index 2039f25..7ffd66f 100644 --- a/examples/LSM6DSV16X_Single_Tap_Detection/LSM6DSV16X_Single_Tap_Detection.ino +++ b/examples/LSM6DSV16X_Single_Tap_Detection_I2C/LSM6DSV16X_Single_Tap_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Single_Tap_Detection.ino + @file LSM6DSV16X_Single_Tap_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Single Tap Detection ******************************************************************************* diff --git a/examples/LSM6DSV16X_Tilt_Detection/LSM6DSV16X_Tilt_Detection.ino b/examples/LSM6DSV16X_Tilt_Detection_I2C/LSM6DSV16X_Tilt_Detection_I2C.ino similarity index 97% rename from examples/LSM6DSV16X_Tilt_Detection/LSM6DSV16X_Tilt_Detection.ino rename to examples/LSM6DSV16X_Tilt_Detection_I2C/LSM6DSV16X_Tilt_Detection_I2C.ino index 9bbdd6b..7df3a96 100644 --- a/examples/LSM6DSV16X_Tilt_Detection/LSM6DSV16X_Tilt_Detection.ino +++ b/examples/LSM6DSV16X_Tilt_Detection_I2C/LSM6DSV16X_Tilt_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Tilt_Detection.ino + @file LSM6DSV16X_Tilt_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Tilt Detection ******************************************************************************* diff --git a/examples/LSM6DSV16X_Wake_Up_Detection/LSM6DSV16X_Wake_Up_Detection.ino b/examples/LSM6DSV16X_Wake_Up_Detection_I2C/LSM6DSV16X_Wake_Up_Detection_I2C.ino similarity index 96% rename from examples/LSM6DSV16X_Wake_Up_Detection/LSM6DSV16X_Wake_Up_Detection.ino rename to examples/LSM6DSV16X_Wake_Up_Detection_I2C/LSM6DSV16X_Wake_Up_Detection_I2C.ino index 23ea7c9..cf77fc3 100644 --- a/examples/LSM6DSV16X_Wake_Up_Detection/LSM6DSV16X_Wake_Up_Detection.ino +++ b/examples/LSM6DSV16X_Wake_Up_Detection_I2C/LSM6DSV16X_Wake_Up_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LSM6DSV16X_Wake_Up_Detection.ino + @file LSM6DSV16X_Wake_Up_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LSM6DSV16X Wake Up Detection ******************************************************************************* diff --git a/extras/build_config.json b/extras/build_config.json new file mode 100644 index 0000000..ca99740 --- /dev/null +++ b/extras/build_config.json @@ -0,0 +1,26 @@ +{ + "cores": [ + { + "maintainer": "STMicroelectronics", + "architecture": "stm32", + "boards": [ + ], + "sketches": [ + { + "pattern": "[^I][^3][^C]", + "applicable": true, + "boards": [ + "NUCLEO_L476RG", + "NUCLEO_H503RB", + "NUCLEO_C562RE" + ] + }, + { + "pattern": "I3C", + "applicable": true, + "boards": [ "NUCLEO_H503RB","NUCLEO_C562RE"] + } + ] + } + ] +} diff --git a/extras/codespell-ignore-words-list.txt b/extras/codespell-ignore-words-list.txt index 146ac38..8a7e8a9 100644 --- a/extras/codespell-ignore-words-list.txt +++ b/extras/codespell-ignore-words-list.txt @@ -1 +1,2 @@ -ois \ No newline at end of file +ois +daa \ No newline at end of file diff --git a/keywords.txt b/keywords.txt index 738d01f..a7e7aaf 100644 --- a/keywords.txt +++ b/keywords.txt @@ -19,6 +19,8 @@ LSM6DSV16X_GYRO_Operating_Mode_t KEYWORD1 begin KEYWORD2 end KEYWORD2 ReadID KEYWORD2 +getStaticAddress KEYWORD2 +getDynAddress KEYWORD2 Enable_X KEYWORD2 Disable_X KEYWORD2 Get_X_Sensitivity KEYWORD2 @@ -139,6 +141,14 @@ LSM6DSV16X_OK LITERAL1 LSM6DSV16X_ERROR LITERAL1 LSM6DSV16X_INT1_PIN LITERAL1 LSM6DSV16X_INT2_PIN LITERAL1 +LSM6DSV16X_I2C_BUS LITERAL1 +LSM6DSV16X_SPI_4WIRES_BUS LITERAL1 +LSM6DSV16X_SPI_3WIRES_BUS LITERAL1 +LSM6DSV16X_I3C_BUS LITERAL1 +LSM6DSV16X_I3C_ADD_L LITERAL1 +LSM6DSV16X_I3C_ADD_H LITERAL1 +LSM6DSV16X_I3C_PID_L LITERAL1 +LSM6DSV16X_I3C_PID_H LITERAL1 LSM6DSV16X_ACC_SENSITIVITY_FS_2G LITERAL1 LSM6DSV16X_ACC_SENSITIVITY_FS_4G LITERAL1 LSM6DSV16X_ACC_SENSITIVITY_FS_8G LITERAL1 diff --git a/library.properties b/library.properties index 8565b48..8c98ed8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino LSM6DSV16X -version=2.0.3 +version=2.1.0 author=SRA maintainer=stm32duino sentence=Ultra Low Power inertial measurement unit. diff --git a/src/LSM6DSV16XSensor.cpp b/src/LSM6DSV16XSensor.cpp index bc3fcc3..b568a76 100644 --- a/src/LSM6DSV16XSensor.cpp +++ b/src/LSM6DSV16XSensor.cpp @@ -2,13 +2,13 @@ ****************************************************************************** * @file LSM6DSV16XSensor.cpp * @author STMicroelectronics - * @version V1.0.0 - * @date July 2022 + * @version V2.1.0 + * @date September 2026 * @brief Implementation of a LSM6DSV16X inertial measurement sensor. ****************************************************************************** * @attention * - *

© COPYRIGHT(c) 2022 STMicroelectronics

+ *

© COPYRIGHT(c) 2026 STMicroelectronics

* * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -53,8 +53,13 @@ LSM6DSV16XSensor::LSM6DSV16XSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c) reg_ctx.mdelay = LSM6DSV16X_sleep; reg_ctx.handle = (void *)this; dev_spi = NULL; +#if defined(I3C_SUPPORTED) + dev_i3c = NULL; +#endif + bus_type = LSM6DSV16X_I2C_BUS; acc_is_enabled = 0L; gyro_is_enabled = 0L; + initialized = 0U; } /** Constructor @@ -69,23 +74,77 @@ LSM6DSV16XSensor::LSM6DSV16XSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed reg_ctx.mdelay = LSM6DSV16X_sleep; reg_ctx.handle = (void *)this; dev_i2c = NULL; +#if defined(I3C_SUPPORTED) + dev_i3c = NULL; +#endif + bus_type = LSM6DSV16X_SPI_4WIRES_BUS; + address = 0U; + acc_is_enabled = 0L; + gyro_is_enabled = 0L; + initialized = 0U; +} + +#if defined(I3C_SUPPORTED) +LSM6DSV16XSensor::LSM6DSV16XSensor(I3CBus *i3c, uint8_t static_addr7) +{ + reg_ctx.write_reg = LSM6DSV16X_io_write; + reg_ctx.read_reg = LSM6DSV16X_io_read; + reg_ctx.mdelay = LSM6DSV16X_sleep; + reg_ctx.handle = (void *)this; + + dev_i2c = NULL; + dev_spi = NULL; + dev_i3c = i3c; + + address = static_addr7; + i3c_static7 = static_addr7; + i3c_dyn7 = 0; + + bus_type = LSM6DSV16X_I3C_BUS; acc_is_enabled = 0L; gyro_is_enabled = 0L; + initialized = 0U; +} + +uint8_t LSM6DSV16XSensor::getStaticAddress() const +{ + return i3c_static7; +} + +uint8_t LSM6DSV16XSensor::getDynAddress() const +{ + return i3c_dyn7; } +#endif /** * @brief Initialize the LSM6DSV16X sensor * @retval 0 in case of success, an error code otherwise */ -LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::begin() +LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::begin(uint8_t new_address) { int32_t fs = 0; + uint8_t id = 0; if (dev_spi) { // Configure CS pin pinMode(cs_pin, OUTPUT); digitalWrite(cs_pin, HIGH); } +#if defined(I3C_SUPPORTED) + if (dev_i3c != nullptr) { + if (new_address < 0x08 || new_address > 0x77) { + return LSM6DSV16X_ERROR; + } else { + address = new_address; + i3c_dyn7 = new_address; + } + uint8_t id = 0; + if (ReadID(&id) != LSM6DSV16X_OK || id != LSM6DSV16X_ID) { + return LSM6DSV16X_ERROR; + } + } +#endif /* Enable register address automatically incremented during a multiple byte access with a serial interface. */ @@ -1374,7 +1433,7 @@ LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::Enable_Wake_Up_Detection(LSM6DSV16X_Se return LSM6DSV16X_ERROR; } - /* Set wake-up durantion */ + /* Set wake-up duration */ if (Set_Wake_Up_Duration(0) != LSM6DSV16X_OK) { return LSM6DSV16X_ERROR; } @@ -1469,7 +1528,7 @@ LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::Disable_Wake_Up_Detection() return LSM6DSV16X_ERROR; } - /* Reset wake-up durantion */ + /* Reset wake-up duration */ if (Set_Wake_Up_Duration(0) != LSM6DSV16X_OK) { return LSM6DSV16X_ERROR; } diff --git a/src/LSM6DSV16XSensor.h b/src/LSM6DSV16XSensor.h index 42127d5..bece2c5 100644 --- a/src/LSM6DSV16XSensor.h +++ b/src/LSM6DSV16XSensor.h @@ -2,13 +2,13 @@ ****************************************************************************** * @file LSM6DSV16XSensor.h * @author STMicroelectronics - * @version V1.0.0 - * @date July 2022 + * @version V2.1.0 + * @date September 2026 * @brief Abstract Class of a LSM6DSV16X inertial measurement sensor. ****************************************************************************** * @attention * - *

© COPYRIGHT(c) 2022 STMicroelectronics

+ *

© COPYRIGHT(c) 2026 STMicroelectronics

* * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -48,6 +48,11 @@ #include "SPI.h" #include "lsm6dsv16x_reg.h" +#if (defined(I3C1_BASE) || defined(I3C2_BASE)) && !defined(I3C_SUPPORTED) + #define I3C_SUPPORTED + #include "I3C.h" +#endif + /* Defines -------------------------------------------------------------------*/ /* For compatibility with ESP32 platforms */ @@ -57,6 +62,19 @@ #endif #endif +#define LSM6DSV16X_I2C_BUS 0U +#define LSM6DSV16X_SPI_4WIRES_BUS 1U +#define LSM6DSV16X_SPI_3WIRES_BUS 2U +#define LSM6DSV16X_I3C_BUS 3U + +#if defined(I3C_SUPPORTED) + #define LSM6DSV16X_I3C_ADD_L 0x6AU + #define LSM6DSV16X_I3C_ADD_H 0x6BU + + static const uint64_t LSM6DSV16X_I3C_PID_L = 0x02080070120BULL; + static const uint64_t LSM6DSV16X_I3C_PID_H = 0x02080070920BULL; +#endif + #define LSM6DSV16X_ACC_SENSITIVITY_FS_2G 0.061f #define LSM6DSV16X_ACC_SENSITIVITY_FS_4G 0.122f #define LSM6DSV16X_ACC_SENSITIVITY_FS_8G 0.244f @@ -146,11 +164,19 @@ class LSM6DSV16XSensor { public: LSM6DSV16XSensor(TwoWire *i2c, uint8_t address = LSM6DSV16X_I2C_ADD_H); LSM6DSV16XSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed = 2000000); +#if defined(I3C_SUPPORTED) + LSM6DSV16XSensor(I3CBus *i3c, uint8_t static_addr7 = 0); +#endif - LSM6DSV16XStatusTypeDef begin(); + LSM6DSV16XStatusTypeDef begin(uint8_t new_address = 0); LSM6DSV16XStatusTypeDef end(); LSM6DSV16XStatusTypeDef ReadID(uint8_t *Id); +#if defined(I3C_SUPPORTED) + uint8_t getStaticAddress() const; + uint8_t getDynAddress() const; +#endif + LSM6DSV16XStatusTypeDef Enable_X(); LSM6DSV16XStatusTypeDef Disable_X(); LSM6DSV16XStatusTypeDef Get_X_Sensitivity(float *Sensitivity); @@ -323,6 +349,14 @@ class LSM6DSV16XSensor { return 0; } +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + if (dev_i3c->readRegBuffer(address, RegisterAddr, pBuffer, NumByteToRead) == 0) { + return 0; + } + } +#endif + return 1; } @@ -367,6 +401,14 @@ class LSM6DSV16XSensor { return 0; } +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + if (dev_i3c->writeRegBuffer(address, RegisterAddr, (uint8_t *)pBuffer, NumByteToWrite) == 0) { + return 0; + } + } +#endif + return 1; } @@ -387,12 +429,22 @@ class LSM6DSV16XSensor { /* Helper classes. */ TwoWire *dev_i2c; SPIClass *dev_spi; +#if defined(I3C_SUPPORTED) + I3CBus *dev_i3c; +#endif + + uint32_t bus_type; /*0 means I2C, 1 means SPI 4-Wires, 2 means SPI-3-Wires, 3 means I3C */ /* Configuration */ uint8_t address; int cs_pin; uint32_t spi_speed; +#if defined(I3C_SUPPORTED) + uint8_t i3c_static7; + uint8_t i3c_dyn7; +#endif + lsm6dsv16x_data_rate_t acc_odr; lsm6dsv16x_data_rate_t gyro_odr; lsm6dsv16x_xl_full_scale_t acc_fs;