From 87b89d4e8ef010163b4920aad6de5ddda7e722a8 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Wed, 2 Sep 2026 15:55:22 +0200 Subject: [PATCH 1/4] add i3c support --- .github/workflows/Continuous-integration.yml | 7 +- README.md | 48 +++++--- .../LIS2DUXS12_6D_Orientation_I2C.ino} | 2 +- .../LIS2DUXS12_DataLog_Terminal_I2C.ino} | 2 +- .../LIS2DUXS12_Datalog_Terminal_I3C.ino | 78 +++++++++++++ ...LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino | 103 ++++++++++++++++++ .../LIS2DUXS12_Double_Tap_Detection_I2C.ino} | 2 +- .../LIS2DUXS12_FIFO_Interrupt_I2C.ino} | 2 +- .../LIS2DUXS12_FIFO_Polling_I2C.ino} | 2 +- .../LIS2DUXS12_Free_Fall_Detection_I2C.ino} | 2 +- .../LIS2DUXS12_MLC_I2C.ino} | 2 +- ...s2duxs12_activity_recognition_for_mobile.h | 0 .../LIS2DUXS12_Pedometer_I2C.ino} | 2 +- .../LIS2DUXS12_Qvar_Polling_I2C.ino} | 2 +- .../LIS2DUXS12_Single_Tap_Detection_I2C.ino} | 2 +- .../LIS2DUXS12_Tilt_Detection_I2C.ino} | 2 +- .../LIS2DUXS12_Triple_Tap_Detection_I2C.ino} | 2 +- .../LIS2DUXS12_Wake_Up_Detection_I2C.ino} | 2 +- extras/build_config.json | 26 +++++ extras/codespell-ignore-words-list.txt | 3 +- keywords.txt | 3 +- library.properties | 2 +- src/LIS2DUXS12Sensor.cpp | 56 +++++++++- src/LIS2DUXS12Sensor.h | 56 ++++++++-- 24 files changed, 364 insertions(+), 44 deletions(-) rename examples/{LIS2DUXS12_6D_Orientation/LIS2DUXS12_6D_Orientation.ino => LIS2DUXS12_6D_Orientation_I2C/LIS2DUXS12_6D_Orientation_I2C.ino} (99%) rename examples/{LIS2DUXS12_DataLog_Terminal/LIS2DUXS12_DataLog_Terminal.ino => LIS2DUXS12_DataLog_Terminal_I2C/LIS2DUXS12_DataLog_Terminal_I2C.ino} (96%) create mode 100644 examples/LIS2DUXS12_Datalog_Terminal_I3C/LIS2DUXS12_Datalog_Terminal_I3C.ino create mode 100644 examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino rename examples/{LIS2DUXS12_Double_Tap_Detection/LIS2DUXS12_Double_Tap_Detection.ino => LIS2DUXS12_Double_Tap_Detection_I2C/LIS2DUXS12_Double_Tap_Detection_I2C.ino} (96%) rename examples/{LIS2DUXS12_FIFO_Interrupt/LIS2DUXS12_FIFO_Interrupt.ino => LIS2DUXS12_FIFO_Interrupt_I2C/LIS2DUXS12_FIFO_Interrupt_I2C.ino} (98%) rename examples/{LIS2DUXS12_FIFO_Polling/LIS2DUXS12_FIFO_Polling.ino => LIS2DUXS12_FIFO_Polling_I2C/LIS2DUXS12_FIFO_Polling_I2C.ino} (98%) rename examples/{LIS2DUXS12_Free_Fall_Detection/LIS2DUXS12_Free_Fall_Detection.ino => LIS2DUXS12_Free_Fall_Detection_I2C/LIS2DUXS12_Free_Fall_Detection_I2C.ino} (96%) rename examples/{LIS2DUXS12_MLC/LIS2DUXS12_MLC.ino => LIS2DUXS12_MLC_I2C/LIS2DUXS12_MLC_I2C.ino} (98%) rename examples/{LIS2DUXS12_MLC => LIS2DUXS12_MLC_I2C}/lis2duxs12_activity_recognition_for_mobile.h (100%) rename examples/{LIS2DUXS12_Pedometer/LIS2DUXS12_Pedometer.ino => LIS2DUXS12_Pedometer_I2C/LIS2DUXS12_Pedometer_I2C.ino} (98%) rename examples/{LIS2DUXS12_Qvar_Polling/LIS2DUXS12_Qvar_Polling.ino => LIS2DUXS12_Qvar_Polling_I2C/LIS2DUXS12_Qvar_Polling_I2C.ino} (96%) rename examples/{LIS2DUXS12_Single_Tap_Detection/LIS2DUXS12_Single_Tap_Detection.ino => LIS2DUXS12_Single_Tap_Detection_I2C/LIS2DUXS12_Single_Tap_Detection_I2C.ino} (96%) rename examples/{LIS2DUXS12_Tilt_Detection/LIS2DUXS12_Tilt_Detection.ino => LIS2DUXS12_Tilt_Detection_I2C/LIS2DUXS12_Tilt_Detection_I2C.ino} (97%) rename examples/{LIS2DUXS12_Triple_Tap_Detection/LIS2DUXS12_Triple_Tap_Detection.ino => LIS2DUXS12_Triple_Tap_Detection_I2C/LIS2DUXS12_Triple_Tap_Detection_I2C.ino} (96%) rename examples/{LIS2DUXS12_Wake_Up_Detection/LIS2DUXS12_Wake_Up_Detection.ino => LIS2DUXS12_Wake_Up_Detection_I2C/LIS2DUXS12_Wake_Up_Detection_I2C.ino} (96%) create mode 100644 extras/build_config.json diff --git a/.github/workflows/Continuous-integration.yml b/.github/workflows/Continuous-integration.yml index 9a5223b..9906430 100644 --- a/.github/workflows/Continuous-integration.yml +++ b/.github/workflows/Continuous-integration.yml @@ -59,11 +59,14 @@ 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() run: | cat ${{ steps.compile.outputs.compile-result }} exit 1 + \ No newline at end of file diff --git a/README.md b/README.md index 6d580d0..cc9c6bb 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,24 @@ An instance can be created and enabled when the SPI bus is used following the pr Accelero.begin(); Accelero.Enable_X(); +An instance can be created and enabled when the I3C bus is used with SETDASA (static-to-dynamic address assignment): + LIS2DUXS12Sensor Accelero(&I3C, LIS2DUXS12_I3C_ADD_H); + I3C.resetDynamicAddresses(); + I3C.assignDynamicAddress(Accelero.getStaticAddress(), LIS2DUXS12_DYNAMIC_ADDRESS); + Accelero.begin(LIS2DUXS12_DYNAMIC_ADDRESS); + I3C.setClock(12500000); + Accelero.Enable_X(); + +An instance can be created and enabled when the I3C bus is used with ENTDAA (dynamic address discovery): + + LIS2DUXS12Sensor Accelero(&I3C); + I3C.begin(I3C_SDA, I3C_SCL, 1000000U); + I3C.discover(devices, 8, &found); + // find dynAddr by matching LIS2DUXS12_I3C_PID_H in discovered devices + Accelero.begin(dynAddr); + I3C.setClock(12500000); + Accelero.Enable_X(); + The access to the sensor values is done as explained below: Read accelerometer. @@ -35,31 +53,35 @@ The access to the sensor values is done as explained below: ## Examples -* LIS2DUXS12_DataLog_Terminal: This application shows how to get data from LIS2DUXS12 accelerometer and print them on terminal. +* LIS2DUXS12_DataLog_Terminal_I2C: This application shows how to get data from LIS2DUXS12 accelerometer and print them on terminal over I2C. + +* LIS2DUXS12_Datalog_Terminal_I3C: This application shows how to use LIS2DUXS12 accelerometer over I3C using SETDASA. + +* LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA: This application shows how to discover and use LIS2DUXS12 dynamic address over I3C. -* LIS2DUXS12_6D_Orientation: This application shows how to use LIS2DUXS12 accelerometer to find out the 6D orientation and display data on a hyperterminal. +* LIS2DUXS12_6D_Orientation_I2C: This application shows how to use LIS2DUXS12 accelerometer to find out the 6D orientation and display data on a hyperterminal. -* LIS2DUXS12_Double_Tap_Detection: This application shows how to detect the double tap event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Double_Tap_Detection_I2C: This application shows how to detect the double tap event using the LIS2DUXS12 accelerometer. -* LIS2DUXS12_FIFO_Polling: This application shows how to get accelerometer data from FIFO in pooling mode and print them on terminal. +* LIS2DUXS12_FIFO_Polling_I2C: This application shows how to get accelerometer data from FIFO in pooling mode and print them on terminal. -* LIS2DUXS12_FIFO_Interrupt: This application shows how to get accelerometer data from FIFO using interrupt and print them on terminal. +* LIS2DUXS12_FIFO_Interrupt_I2C: This application shows how to get accelerometer data from FIFO using interrupt and print them on terminal. -* LIS2DUXS12_Free_Fall_Detection: This application shows how to detect the free fall event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Free_Fall_Detection_I2C: This application shows how to detect the free fall event using the LIS2DUXS12 accelerometer. -* LIS2DUXS12_MLC: This application shows how to detect the activity using the LIS2DUXS12 Machine Learning Core. +* LIS2DUXS12_MLC_I2C: This application shows how to detect the activity using the LIS2DUXS12 Machine Learning Core. -* LIS2DUXS12_Pedometer: This application shows how to use LIS2DUXS12 accelerometer to count steps. +* LIS2DUXS12_Pedometer_I2C: This application shows how to use LIS2DUXS12 accelerometer to count steps. -* LIS2DUXS12_Qvar_Polling: This application shows how to use LIS2DUXS12 Qvar features in polling mode. +* LIS2DUXS12_Qvar_Polling_I2C: This application shows how to use LIS2DUXS12 Qvar features in polling mode. -* LIS2DUXS12_Single_Tap_Detection: This application shows how to detect the single tap event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Single_Tap_Detection_I2C: This application shows how to detect the single tap event using the LIS2DUXS12 accelerometer. -* LIS2DUXS12_Tilt_Detection: This application shows how to detect the tilt event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Tilt_Detection_I2C: This application shows how to detect the tilt event using the LIS2DUXS12 accelerometer. -* LIS2DUXS12_Triple_Tap_Detection: This application shows how to detect the triple tap event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Triple_Tap_Detection_I2C: This application shows how to detect the triple tap event using the LIS2DUXS12 accelerometer. -* LIS2DUXS12_Wake_Up_Detection: This application shows how to detect the wake-up event using the LIS2DUXS12 accelerometer. +* LIS2DUXS12_Wake_Up_Detection_I2C: This application shows how to detect the wake-up event using the LIS2DUXS12 accelerometer. ## Documentation diff --git a/examples/LIS2DUXS12_6D_Orientation/LIS2DUXS12_6D_Orientation.ino b/examples/LIS2DUXS12_6D_Orientation_I2C/LIS2DUXS12_6D_Orientation_I2C.ino similarity index 99% rename from examples/LIS2DUXS12_6D_Orientation/LIS2DUXS12_6D_Orientation.ino rename to examples/LIS2DUXS12_6D_Orientation_I2C/LIS2DUXS12_6D_Orientation_I2C.ino index 4d71c81..76aab9f 100644 --- a/examples/LIS2DUXS12_6D_Orientation/LIS2DUXS12_6D_Orientation.ino +++ b/examples/LIS2DUXS12_6D_Orientation_I2C/LIS2DUXS12_6D_Orientation_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_6D_Orientation.ino + @file LIS2DUXS12_6D_Orientation_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 6D Orientation ******************************************************************************* diff --git a/examples/LIS2DUXS12_DataLog_Terminal/LIS2DUXS12_DataLog_Terminal.ino b/examples/LIS2DUXS12_DataLog_Terminal_I2C/LIS2DUXS12_DataLog_Terminal_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_DataLog_Terminal/LIS2DUXS12_DataLog_Terminal.ino rename to examples/LIS2DUXS12_DataLog_Terminal_I2C/LIS2DUXS12_DataLog_Terminal_I2C.ino index 65186d7..5af1504 100644 --- a/examples/LIS2DUXS12_DataLog_Terminal/LIS2DUXS12_DataLog_Terminal.ino +++ b/examples/LIS2DUXS12_DataLog_Terminal_I2C/LIS2DUXS12_DataLog_Terminal_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_DataLog_Terminal.ino + @file LIS2DUXS12_DataLog_Terminal_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 inertial measurement sensor ******************************************************************************* diff --git a/examples/LIS2DUXS12_Datalog_Terminal_I3C/LIS2DUXS12_Datalog_Terminal_I3C.ino b/examples/LIS2DUXS12_Datalog_Terminal_I3C/LIS2DUXS12_Datalog_Terminal_I3C.ino new file mode 100644 index 0000000..91995af --- /dev/null +++ b/examples/LIS2DUXS12_Datalog_Terminal_I3C/LIS2DUXS12_Datalog_Terminal_I3C.ino @@ -0,0 +1,78 @@ +/* + @file LIS2DUXS12_DataLog_Terminal_I3C.ino + @author STMicroelectronics + @brief Example to use the LIS2DUXS12 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 "LIS2DUXS12Sensor.h" + +#define LIS2DUXS12_DYNAMIC_ADDRESS 0x30 + +LIS2DUXS12Sensor sensor(&I3C, LIS2DUXS12_I3C_ADD_H); + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + delay(1000); + + Serial.println("=== LIS2DUXS12 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(), LIS2DUXS12_DYNAMIC_ADDRESS)) { + Serial.println("assignDynamicAddress() failed"); + while (1) {} + } + + if (sensor.begin(LIS2DUXS12_DYNAMIC_ADDRESS) != LIS2DUXS12_STATUS_OK) { + Serial.println("sensor.begin() failed"); + while (1) {} + } + + if (!I3C.setClock(12500000)) { + Serial.println("setClock() failed"); + while (1) {} + } + + if (sensor.Enable_X() != LIS2DUXS12_STATUS_OK) { + Serial.println("sensor.Enable_X() failed"); + while (1) {} + } + + Serial.println("LIS2DUXS12 ready"); +} + +void loop() +{ + int32_t accel[3] = {0}; + + if (sensor.Get_X_Axes(accel) == LIS2DUXS12_STATUS_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]); + } else { + Serial.println("Read failed"); + } + + delay(500); +} diff --git a/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino b/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino new file mode 100644 index 0000000..cf1ab57 --- /dev/null +++ b/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino @@ -0,0 +1,103 @@ +/* + @file LIS2DUXS12_DataLog_Terminal_I3C_ENTDAA.ino + @author STMicroelectronics + @brief Example to use the LIS2DUXS12 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 "LIS2DUXS12Sensor.h" + +LIS2DUXS12Sensor sensor(&I3C); + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + delay(1000); + + Serial.println("=== LIS2DUXS12 DAA ==="); + + 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.isI3CDeviceReady(0x19)) { + Serial.println("isI3CDeviceReady() 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 == LIS2DUXS12_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) != LIS2DUXS12_STATUS_OK) { + Serial.println("sensor.begin() failed"); + while (1) {} + } + + if (!I3C.setClock(12500000)) { + Serial.println("setClock() failed"); + while (1) {} + } + + if (sensor.Enable_X() != LIS2DUXS12_STATUS_OK) { + Serial.println("sensor.Enable_X() failed"); + while (1) {} + } + Serial.println("LIS2DUXS12 ready"); +} + +void loop() +{ + int32_t accel[3] = {0}; + int32_t angrate[3] = {0}; + + if (sensor.Get_X_Axes(accel) == LIS2DUXS12_STATUS_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]); + } else { + Serial.println("Read failed"); + } + + delay(500); +} diff --git a/examples/LIS2DUXS12_Double_Tap_Detection/LIS2DUXS12_Double_Tap_Detection.ino b/examples/LIS2DUXS12_Double_Tap_Detection_I2C/LIS2DUXS12_Double_Tap_Detection_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Double_Tap_Detection/LIS2DUXS12_Double_Tap_Detection.ino rename to examples/LIS2DUXS12_Double_Tap_Detection_I2C/LIS2DUXS12_Double_Tap_Detection_I2C.ino index 77479e7..5d4a73a 100644 --- a/examples/LIS2DUXS12_Double_Tap_Detection/LIS2DUXS12_Double_Tap_Detection.ino +++ b/examples/LIS2DUXS12_Double_Tap_Detection_I2C/LIS2DUXS12_Double_Tap_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Double_Tap_Detection.ino + @file LIS2DUXS12_Double_Tap_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Double Tap Detection ******************************************************************************* diff --git a/examples/LIS2DUXS12_FIFO_Interrupt/LIS2DUXS12_FIFO_Interrupt.ino b/examples/LIS2DUXS12_FIFO_Interrupt_I2C/LIS2DUXS12_FIFO_Interrupt_I2C.ino similarity index 98% rename from examples/LIS2DUXS12_FIFO_Interrupt/LIS2DUXS12_FIFO_Interrupt.ino rename to examples/LIS2DUXS12_FIFO_Interrupt_I2C/LIS2DUXS12_FIFO_Interrupt_I2C.ino index 4616d17..4fe8087 100644 --- a/examples/LIS2DUXS12_FIFO_Interrupt/LIS2DUXS12_FIFO_Interrupt.ino +++ b/examples/LIS2DUXS12_FIFO_Interrupt_I2C/LIS2DUXS12_FIFO_Interrupt_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_FIFO_Interrupt.ino + @file LIS2DUXS12_FIFO_Interrupt_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 library with FIFO status interrupts. ******************************************************************************* diff --git a/examples/LIS2DUXS12_FIFO_Polling/LIS2DUXS12_FIFO_Polling.ino b/examples/LIS2DUXS12_FIFO_Polling_I2C/LIS2DUXS12_FIFO_Polling_I2C.ino similarity index 98% rename from examples/LIS2DUXS12_FIFO_Polling/LIS2DUXS12_FIFO_Polling.ino rename to examples/LIS2DUXS12_FIFO_Polling_I2C/LIS2DUXS12_FIFO_Polling_I2C.ino index d536c14..0d2924e 100644 --- a/examples/LIS2DUXS12_FIFO_Polling/LIS2DUXS12_FIFO_Polling.ino +++ b/examples/LIS2DUXS12_FIFO_Polling_I2C/LIS2DUXS12_FIFO_Polling_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_FIFO_Polling.ino + @file LIS2DUXS12_FIFO_Polling_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 library with FIFO status in polling mode. ******************************************************************************* diff --git a/examples/LIS2DUXS12_Free_Fall_Detection/LIS2DUXS12_Free_Fall_Detection.ino b/examples/LIS2DUXS12_Free_Fall_Detection_I2C/LIS2DUXS12_Free_Fall_Detection_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Free_Fall_Detection/LIS2DUXS12_Free_Fall_Detection.ino rename to examples/LIS2DUXS12_Free_Fall_Detection_I2C/LIS2DUXS12_Free_Fall_Detection_I2C.ino index de1a32f..3c39990 100644 --- a/examples/LIS2DUXS12_Free_Fall_Detection/LIS2DUXS12_Free_Fall_Detection.ino +++ b/examples/LIS2DUXS12_Free_Fall_Detection_I2C/LIS2DUXS12_Free_Fall_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Free_Fall_Detection.ino + @file LIS2DUXS12_Free_Fall_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Free Fall Detection ******************************************************************************* diff --git a/examples/LIS2DUXS12_MLC/LIS2DUXS12_MLC.ino b/examples/LIS2DUXS12_MLC_I2C/LIS2DUXS12_MLC_I2C.ino similarity index 98% rename from examples/LIS2DUXS12_MLC/LIS2DUXS12_MLC.ino rename to examples/LIS2DUXS12_MLC_I2C/LIS2DUXS12_MLC_I2C.ino index d91d649..c3c8fab 100644 --- a/examples/LIS2DUXS12_MLC/LIS2DUXS12_MLC.ino +++ b/examples/LIS2DUXS12_MLC_I2C/LIS2DUXS12_MLC_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_MLC.ino + @file LIS2DUXS12_MLC_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Machine Learning Core ******************************************************************************* diff --git a/examples/LIS2DUXS12_MLC/lis2duxs12_activity_recognition_for_mobile.h b/examples/LIS2DUXS12_MLC_I2C/lis2duxs12_activity_recognition_for_mobile.h similarity index 100% rename from examples/LIS2DUXS12_MLC/lis2duxs12_activity_recognition_for_mobile.h rename to examples/LIS2DUXS12_MLC_I2C/lis2duxs12_activity_recognition_for_mobile.h diff --git a/examples/LIS2DUXS12_Pedometer/LIS2DUXS12_Pedometer.ino b/examples/LIS2DUXS12_Pedometer_I2C/LIS2DUXS12_Pedometer_I2C.ino similarity index 98% rename from examples/LIS2DUXS12_Pedometer/LIS2DUXS12_Pedometer.ino rename to examples/LIS2DUXS12_Pedometer_I2C/LIS2DUXS12_Pedometer_I2C.ino index 6fff05f..b7c5fd2 100644 --- a/examples/LIS2DUXS12_Pedometer/LIS2DUXS12_Pedometer.ino +++ b/examples/LIS2DUXS12_Pedometer_I2C/LIS2DUXS12_Pedometer_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Pedometer.ino + @file LIS2DUXS12_Pedometer_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Pedometer ******************************************************************************* diff --git a/examples/LIS2DUXS12_Qvar_Polling/LIS2DUXS12_Qvar_Polling.ino b/examples/LIS2DUXS12_Qvar_Polling_I2C/LIS2DUXS12_Qvar_Polling_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Qvar_Polling/LIS2DUXS12_Qvar_Polling.ino rename to examples/LIS2DUXS12_Qvar_Polling_I2C/LIS2DUXS12_Qvar_Polling_I2C.ino index 91fa3ea..f8250c1 100644 --- a/examples/LIS2DUXS12_Qvar_Polling/LIS2DUXS12_Qvar_Polling.ino +++ b/examples/LIS2DUXS12_Qvar_Polling_I2C/LIS2DUXS12_Qvar_Polling_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Qvar.ino + @file LIS2DUXS12_Qvar_Polling_I2C.ino @author STMicroelectronics @brief Example to use LIS2DUXS12 Qvar features ******************************************************************************* diff --git a/examples/LIS2DUXS12_Single_Tap_Detection/LIS2DUXS12_Single_Tap_Detection.ino b/examples/LIS2DUXS12_Single_Tap_Detection_I2C/LIS2DUXS12_Single_Tap_Detection_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Single_Tap_Detection/LIS2DUXS12_Single_Tap_Detection.ino rename to examples/LIS2DUXS12_Single_Tap_Detection_I2C/LIS2DUXS12_Single_Tap_Detection_I2C.ino index 6bd0cae..3a6fa22 100644 --- a/examples/LIS2DUXS12_Single_Tap_Detection/LIS2DUXS12_Single_Tap_Detection.ino +++ b/examples/LIS2DUXS12_Single_Tap_Detection_I2C/LIS2DUXS12_Single_Tap_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Single_Tap_Detection.ino + @file LIS2DUXS12_Single_Tap_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Single Tap Detection ******************************************************************************* diff --git a/examples/LIS2DUXS12_Tilt_Detection/LIS2DUXS12_Tilt_Detection.ino b/examples/LIS2DUXS12_Tilt_Detection_I2C/LIS2DUXS12_Tilt_Detection_I2C.ino similarity index 97% rename from examples/LIS2DUXS12_Tilt_Detection/LIS2DUXS12_Tilt_Detection.ino rename to examples/LIS2DUXS12_Tilt_Detection_I2C/LIS2DUXS12_Tilt_Detection_I2C.ino index 5b4bdc7..6211fd2 100644 --- a/examples/LIS2DUXS12_Tilt_Detection/LIS2DUXS12_Tilt_Detection.ino +++ b/examples/LIS2DUXS12_Tilt_Detection_I2C/LIS2DUXS12_Tilt_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Tilt_Detection.ino + @file LIS2DUXS12_Tilt_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Tilt Detection ******************************************************************************* diff --git a/examples/LIS2DUXS12_Triple_Tap_Detection/LIS2DUXS12_Triple_Tap_Detection.ino b/examples/LIS2DUXS12_Triple_Tap_Detection_I2C/LIS2DUXS12_Triple_Tap_Detection_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Triple_Tap_Detection/LIS2DUXS12_Triple_Tap_Detection.ino rename to examples/LIS2DUXS12_Triple_Tap_Detection_I2C/LIS2DUXS12_Triple_Tap_Detection_I2C.ino index 81e5476..28d6903 100644 --- a/examples/LIS2DUXS12_Triple_Tap_Detection/LIS2DUXS12_Triple_Tap_Detection.ino +++ b/examples/LIS2DUXS12_Triple_Tap_Detection_I2C/LIS2DUXS12_Triple_Tap_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Triple_Tap_Detection.ino + @file LIS2DUXS12_Triple_Tap_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 Triple Tap Detection ******************************************************************************* diff --git a/examples/LIS2DUXS12_Wake_Up_Detection/LIS2DUXS12_Wake_Up_Detection.ino b/examples/LIS2DUXS12_Wake_Up_Detection_I2C/LIS2DUXS12_Wake_Up_Detection_I2C.ino similarity index 96% rename from examples/LIS2DUXS12_Wake_Up_Detection/LIS2DUXS12_Wake_Up_Detection.ino rename to examples/LIS2DUXS12_Wake_Up_Detection_I2C/LIS2DUXS12_Wake_Up_Detection_I2C.ino index 7b43313..bdad573 100644 --- a/examples/LIS2DUXS12_Wake_Up_Detection/LIS2DUXS12_Wake_Up_Detection.ino +++ b/examples/LIS2DUXS12_Wake_Up_Detection_I2C/LIS2DUXS12_Wake_Up_Detection_I2C.ino @@ -1,5 +1,5 @@ /* - @file LIS2DUXS12_Wake_Up_Detection.ino + @file LIS2DUXS12_Wake_Up_Detection_I2C.ino @author STMicroelectronics @brief Example to use the LIS2DUXS12 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 8d860cc..f5aeb24 100644 --- a/keywords.txt +++ b/keywords.txt @@ -86,7 +86,8 @@ Get_MLC_Status KEYWORD2 Get_MLC_Output KEYWORD2 Read_Reg KEYWORD2 Write_Reg KEYWORD2 - +getStaticAddress KEYWORD2 +getDynAddress KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### diff --git a/library.properties b/library.properties index 5a2ccfd..5d4c25f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino LIS2DUXS12 -version=1.0.2 +version=1.1.0 author=SRA maintainer=stm32duino sentence=Ultra Low Power 3D accelerometer. diff --git a/src/LIS2DUXS12Sensor.cpp b/src/LIS2DUXS12Sensor.cpp index 30079a0..7f8e89d 100644 --- a/src/LIS2DUXS12Sensor.cpp +++ b/src/LIS2DUXS12Sensor.cpp @@ -1,9 +1,9 @@ /** ****************************************************************************** * @file LIS2DUXS12Sensor.cpp - * @author CLab - * @version V1.0.0 - * @date 15 November 2018 + * @author STMicroelectronics + * @version V1.1.0 + * @date September 2026 * @brief Implementation of an LIS2DUXS12 Inertial Measurement Unit (IMU) 3 axes * sensor. ****************************************************************************** @@ -46,6 +46,7 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address) { dev_spi = NULL; + bus_type = LIS2DUXS12_I2C_BUS; reg_ctx.write_reg = LIS2DUXS12_io_write; reg_ctx.read_reg = LIS2DUXS12_io_read; reg_ctx.handle = (void *)this; @@ -66,9 +67,40 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(SPIClass *spi, int cs_pin, uint32_t spi_speed dev_i2c = NULL; address = 0; X_isInitialized = 0; + bus_type = LIS2DUXS12_SPI_4WIRES_BUS; X_isEnabled = 0; } +#if defined(I3C_SUPPORTED) +LIS2DUXS12Sensor::LIS2DUXS12Sensor(I3CBus *i3c, uint8_t static_addr7) +{ + reg_ctx.write_reg = LIS2DUXS12_io_write; + reg_ctx.read_reg = LIS2DUXS12_io_read; + 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 = LIS2DUXS12_I3C_BUS; + X_isEnabled = 0L; + X_isInitialized = 0U; +} + +uint8_t LIS2DUXS12Sensor::getStaticAddress() const +{ + return i3c_static7; +} + +uint8_t LIS2DUXS12Sensor::getDynAddress() const +{ + return i3c_dyn7; +} +#endif /** * @brief Exit from deep power down in SPI * @param pObj the device pObj @@ -102,8 +134,9 @@ LIS2DUXS12StatusTypeDef LIS2DUXS12Sensor:: ExitDeepPowerDownI2C(void) * @brief Configure the sensor in order to be used * @retval 0 in case of success, an error code otherwise */ -LIS2DUXS12StatusTypeDef LIS2DUXS12Sensor::begin() +LIS2DUXS12StatusTypeDef LIS2DUXS12Sensor::begin(uint8_t new_address) { + uint8_t id = 0; if (dev_spi) { // Configure CS pin pinMode(cs_pin, OUTPUT); @@ -115,6 +148,21 @@ LIS2DUXS12StatusTypeDef LIS2DUXS12Sensor::begin() /* Exit from deep power down only the first time in I2C mode */ ExitDeepPowerDownI2C(); } +#if defined(I3C_SUPPORTED) + if (dev_i3c != nullptr) { + if (new_address < 0x08 || new_address > 0x77) { + return LIS2DUXS12_STATUS_ERROR; + } else { + address = new_address; + i3c_dyn7 = new_address; + } + uint8_t id = 0; + if (ReadID(&id) != LIS2DUXS12_STATUS_OK || id != LIS2DUXS12_ID) { + return LIS2DUXS12_STATUS_ERROR; + } + } +#endif + /* Enable register address automatically incremented during a multiple byte access with a serial interface. Enable BDU. */ if (lis2duxs12_init_set(&(reg_ctx), LIS2DUXS12_SENSOR_ONLY_ON) != LIS2DUXS12_STATUS_OK) { diff --git a/src/LIS2DUXS12Sensor.h b/src/LIS2DUXS12Sensor.h index 6d435cf..c0448f6 100644 --- a/src/LIS2DUXS12Sensor.h +++ b/src/LIS2DUXS12Sensor.h @@ -1,9 +1,9 @@ /** ****************************************************************************** * @file LIS2DUXS12Sensor.h - * @author CLab - * @version V1.0.0 - * @date 15 November 2018 + * @author STMicroelectronics + * @version V1.1.0 + * @date September 2026 * @brief Abstract Class of an LIS2DUXS12 Inertial Measurement Unit (IMU) 3 axes * sensor. ****************************************************************************** @@ -49,6 +49,11 @@ #include "SPI.h" #include "lis2duxs12_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 */ #ifdef ESP32 @@ -62,6 +67,15 @@ #define LIS2DUXS12_SPI_3WIRES_BUS 2U #define LIS2DUXS12_I3C_BUS 3U + +#if defined(I3C_SUPPORTED) + #define LIS2DUXS12_I3C_ADD_L 0x18U + #define LIS2DUXS12_I3C_ADD_H 0x19U + + static const uint64_t LIS2DUXS12_I3C_PID_L = 0x02080047120BULL; + static const uint64_t LIS2DUXS12_I3C_PID_H = 0x02080047920BULL; +#endif + #define LIS2DUXS12_X_SENSITIVITY_FOR_FS_2G 0.061f /**< Sensitivity value for 2g full scale, Low-power1 mode [mg/LSB] */ #define LIS2DUXS12_X_SENSITIVITY_FOR_FS_4G 0.122f /**< Sensitivity value for 4g full scale, Low-power1 mode [mg/LSB] */ #define LIS2DUXS12_X_SENSITIVITY_FOR_FS_8G 0.244f /**< Sensitivity value for 8g full scale, Low-power1 mode [mg/LSB] */ @@ -144,8 +158,14 @@ class LIS2DUXS12Sensor { public: LIS2DUXS12Sensor(TwoWire *i2c, uint8_t address = LIS2DUXS12_I2C_ADD_H); LIS2DUXS12Sensor(SPIClass *spi, int cs_pin, uint32_t spi_speed = 2000000); - - LIS2DUXS12StatusTypeDef begin(); +#if defined(I3C_SUPPORTED) + LIS2DUXS12Sensor(I3CBus *i3c, uint8_t static_addr7 = 0); +#endif +#if defined(I3C_SUPPORTED) + uint8_t getStaticAddress() const; + uint8_t getDynAddress() const; +#endif + LIS2DUXS12StatusTypeDef begin(uint8_t new_address = 0); LIS2DUXS12StatusTypeDef end(); LIS2DUXS12StatusTypeDef Enable_X(void); @@ -277,7 +297,13 @@ class LIS2DUXS12Sensor { return 0; } - +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + if (dev_i3c->readRegBuffer(address, RegisterAddr, pBuffer, NumByteToRead) == 0) { + return 0; + } + } +#endif return 1; } @@ -321,7 +347,13 @@ class LIS2DUXS12Sensor { 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; } @@ -333,12 +365,18 @@ class LIS2DUXS12Sensor { /* 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 uint8_t X_isInitialized; uint8_t X_isEnabled; float X_Last_ODR; From 786590693bb75822f18c04e06dfdcb1d9bcd0632 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Wed, 2 Sep 2026 16:19:09 +0200 Subject: [PATCH 2/4] add i3c null in constructor i2c spi --- src/LIS2DUXS12Sensor.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/LIS2DUXS12Sensor.cpp b/src/LIS2DUXS12Sensor.cpp index 7f8e89d..d61e321 100644 --- a/src/LIS2DUXS12Sensor.cpp +++ b/src/LIS2DUXS12Sensor.cpp @@ -46,12 +46,16 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address) { dev_spi = NULL; + #if defined(I3C_SUPPORTED) + dev_i3c = NULL; + #endif bus_type = LIS2DUXS12_I2C_BUS; reg_ctx.write_reg = LIS2DUXS12_io_write; reg_ctx.read_reg = LIS2DUXS12_io_read; reg_ctx.handle = (void *)this; X_isInitialized = 0; X_isEnabled = 0; + } /** Constructor @@ -65,6 +69,9 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(SPIClass *spi, int cs_pin, uint32_t spi_speed reg_ctx.read_reg = LIS2DUXS12_io_read; reg_ctx.handle = (void *)this; dev_i2c = NULL; + #if defined(I3C_SUPPORTED) + dev_i3c = NULL; + #endif address = 0; X_isInitialized = 0; bus_type = LIS2DUXS12_SPI_4WIRES_BUS; From dcebcc922bee1df89153d349dcf238d2261e7f12 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Wed, 2 Sep 2026 16:23:46 +0200 Subject: [PATCH 3/4] update reference to lsm --- .../LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino b/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino index cf1ab57..e1a1f6a 100644 --- a/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino +++ b/examples/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA/LIS2DUXS12_Datalog_Terminal_I3C_ENTDAA.ino @@ -49,24 +49,24 @@ void setup() while (1) {} } - uint8_t lsmDynAddr = 0U; + uint8_t lisDynAddr = 0U; for (size_t i = 0; i < found; ++i) { Serial.println(devices[i].pid, HEX); if (devices[i].pid == LIS2DUXS12_I3C_PID_H) { - lsmDynAddr = devices[i].dynAddr; - Serial.print("lsmDynAddr="); - Serial.println(lsmDynAddr, HEX); + lisDynAddr = devices[i].dynAddr; + Serial.print("lisDynAddr="); + Serial.println(lisDynAddr, HEX); break; } } - if (lsmDynAddr == 0U) { + if (lisDynAddr == 0U) { Serial.println("Sensor not found"); while (1) {} } - if (sensor.begin(lsmDynAddr) != LIS2DUXS12_STATUS_OK) { + if (sensor.begin(lisDynAddr) != LIS2DUXS12_STATUS_OK) { Serial.println("sensor.begin() failed"); while (1) {} } From 790bb57b84f38b92dcb25145159a8cb21965e0d4 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Wed, 2 Sep 2026 16:32:33 +0200 Subject: [PATCH 4/4] fix astyle issue --- src/LIS2DUXS12Sensor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/LIS2DUXS12Sensor.cpp b/src/LIS2DUXS12Sensor.cpp index d61e321..a208e15 100644 --- a/src/LIS2DUXS12Sensor.cpp +++ b/src/LIS2DUXS12Sensor.cpp @@ -46,16 +46,16 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address) { dev_spi = NULL; - #if defined(I3C_SUPPORTED) +#if defined(I3C_SUPPORTED) dev_i3c = NULL; - #endif +#endif bus_type = LIS2DUXS12_I2C_BUS; reg_ctx.write_reg = LIS2DUXS12_io_write; reg_ctx.read_reg = LIS2DUXS12_io_read; reg_ctx.handle = (void *)this; X_isInitialized = 0; X_isEnabled = 0; - + } /** Constructor @@ -69,9 +69,9 @@ LIS2DUXS12Sensor::LIS2DUXS12Sensor(SPIClass *spi, int cs_pin, uint32_t spi_speed reg_ctx.read_reg = LIS2DUXS12_io_read; reg_ctx.handle = (void *)this; dev_i2c = NULL; - #if defined(I3C_SUPPORTED) +#if defined(I3C_SUPPORTED) dev_i3c = NULL; - #endif +#endif address = 0; X_isInitialized = 0; bus_type = LIS2DUXS12_SPI_4WIRES_BUS;