From 94d54f22bcc15fce0acdf8719c452689a5da4e4b Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Mon, 21 Sep 2026 14:45:41 +0200 Subject: [PATCH 1/3] add i3c support --- .github/workflows/Continuous-integration.yml | 71 +++++++++++++++++ README.md | 21 ++++- .../LPS22HH_DataLog_Terminal_I2C.ino} | 0 .../LPS22HH_Datalog_Terminal_I3C.ino | 78 +++++++++++++++++++ extras/build_config.json | 26 +++++++ extras/codespell-ignore-words-list.txt | 2 + keywords.txt | 7 +- library.properties | 2 +- src/LPS22HHSensor.cpp | 62 +++++++++++++-- src/LPS22HHSensor.h | 53 ++++++++++++- 10 files changed, 310 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/Continuous-integration.yml rename examples/{LPS22HH_DataLog_Terminal/LPS22HH_DataLog_Terminal.ino => LPS22HH_DataLog_Terminal_I2C/LPS22HH_DataLog_Terminal_I2C.ino} (100%) create mode 100644 examples/LPS22HH_Datalog_Terminal_I3C/LPS22HH_Datalog_Terminal_I3C.ino create mode 100644 extras/build_config.json diff --git a/.github/workflows/Continuous-integration.yml b/.github/workflows/Continuous-integration.yml new file mode 100644 index 0000000..cb08b7b --- /dev/null +++ b/.github/workflows/Continuous-integration.yml @@ -0,0 +1,71 @@ +name: LPS22HH Continuous Integration +on: + push: + branches: + - main + paths-ignore: + - '*' + - '**.md' + - '**.txt' + pull_request: + paths-ignore: + - '*' + - '**.md' + - '**.txt' +jobs: + astyle_check: + runs-on: ubuntu-latest + name: AStyle check + steps: + # First of all, clone the repo using the checkout action. + - name: Checkout + uses: actions/checkout@main + + - name: Astyle check + id: Astyle + uses: stm32duino/actions/astyle-check@main + + # Use the output from the `Astyle` step + - name: Astyle Errors + if: failure() + run: | + cat ${{ steps.Astyle.outputs.astyle-result }} + exit 1 + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@main + + # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md + - name: Spell check + uses: codespell-project/actions-codespell@master + with: + check_filenames: true + check_hidden: true + # In the event of a false positive, add the word in all lower case to this file: + ignore_words_file: ./extras/codespell-ignore-words-list.txt + lib_build: + runs-on: ubuntu-latest + name: Library compilation + steps: + + # First of all, clone the repo using the checkout action. + - name: Checkout + uses: actions/checkout@main + + - name: Compilation + id: compile + uses: stm32duino/actions/compile-examples@main + with: + 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 diff --git a/README.md b/README.md index f8f74c4..025c3a3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Arduino library to support the LPS22HH 260-1260 hPa absolute digital output baro ## 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: LPS22HHSensor PressTemp(&dev_i2c); @@ -26,6 +30,15 @@ An instance can be created and enabled when the SPI bus is used following the pr PressTemp.begin(); PressTemp.Enable(); +An instance can be created and enabled when the I3C bus is used with SETDASA (static-to-dynamic address assignment): + + LPS22HHSensor PressTemp(&I3C, LPS22HH_I3C_ADD_H); + I3C.resetDynamicAddresses(); + I3C.assignDynamicAddress(PressTemp.getStaticAddress(), LPS22HH_DYNAMIC_ADDRESS); + PressTemp.begin(LPS22HH_DYNAMIC_ADDRESS); + I3C.setClock(12500000); + PressTemp.Enable(); + The access to the sensor values is done as explained below: Read pressure and temperature. @@ -35,6 +48,12 @@ The access to the sensor values is done as explained below: PressTemp.GetPressure(&pressure); PressTemp.GetTemperature(&temperature); +# Examples + +There are several examples with the LPS22HH library. +* LPS22HH_DataLog_Terminal_I2C: This application shows how to get pressure and temperature data from the LPS22HH sensor over I2C and print them on terminal. +* LPS22HH_Datalog_Terminal_I3C: This application shows how to use the LPS22HH sensor over I3C using SETDASA. + ## Documentation You can find the source files at diff --git a/examples/LPS22HH_DataLog_Terminal/LPS22HH_DataLog_Terminal.ino b/examples/LPS22HH_DataLog_Terminal_I2C/LPS22HH_DataLog_Terminal_I2C.ino similarity index 100% rename from examples/LPS22HH_DataLog_Terminal/LPS22HH_DataLog_Terminal.ino rename to examples/LPS22HH_DataLog_Terminal_I2C/LPS22HH_DataLog_Terminal_I2C.ino diff --git a/examples/LPS22HH_Datalog_Terminal_I3C/LPS22HH_Datalog_Terminal_I3C.ino b/examples/LPS22HH_Datalog_Terminal_I3C/LPS22HH_Datalog_Terminal_I3C.ino new file mode 100644 index 0000000..270d11a --- /dev/null +++ b/examples/LPS22HH_Datalog_Terminal_I3C/LPS22HH_Datalog_Terminal_I3C.ino @@ -0,0 +1,78 @@ +/* + @file LPS22HH_Datalog_Terminal_I3C.ino + @author STMicroelectronics + @brief Example to use the LPS22HH pressure 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 "LPS22HHSensor.h" + +#define LPS22HH_DYNAMIC_ADDRESS 0x30 + +LPS22HHSensor sensor(&I3C, LPS22HH_I3C_ADD_H); + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + delay(1000); + + Serial.println("=== LPS22HH 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(), LPS22HH_DYNAMIC_ADDRESS)) { + Serial.println("assignDynamicAddress() failed"); + while (1) {} + } + + if (sensor.begin(LPS22HH_DYNAMIC_ADDRESS) != LPS22HH_OK) { + Serial.println("sensor.begin() failed"); + while (1) {} + } + + if (!I3C.setClock(12500000)) { + Serial.println("setClock() failed"); + while (1) {} + } + + if (sensor.Enable() != LPS22HH_OK) { + Serial.println("sensor.Enable() failed"); + while (1) {} + } + + Serial.println("LPS22HH ready"); +} + +void loop() +{ + float pressure = 0; + float temperature = 0; + + if (sensor.GetPressure(&pressure) == LPS22HH_OK && sensor.GetTemperature(&temperature) == LPS22HH_OK) { + Serial.print("Pres[hPa]:"); + Serial.print(pressure, 2); + Serial.print(",Temp[C]:"); + Serial.println(temperature, 2); + } else { + Serial.println("Read failed"); + } + + delay(500); +} 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 784f9b3..8a827db 100644 --- a/extras/codespell-ignore-words-list.txt +++ b/extras/codespell-ignore-words-list.txt @@ -1,2 +1,4 @@ +daa +ois pres ths diff --git a/keywords.txt b/keywords.txt index c68f019..abd4df1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -15,6 +15,8 @@ LPS22HHSensor KEYWORD1 begin KEYWORD2 end KEYWORD2 ReadID KEYWORD2 +getStaticAddress KEYWORD2 +getDynAddress KEYWORD2 Enable KEYWORD2 Disable KEYWORD2 GetOutputDataRate KEYWORD2 @@ -43,4 +45,7 @@ Get_One_Shot_Status KEYWORD2 ####################################### LPS22HH_OK LITERAL1 -LPS22HH_ERROR LITERAL1 \ No newline at end of file +LPS22HH_ERROR LITERAL1 +LPS22HH_I3C_BUS LITERAL1 +LPS22HH_I3C_ADD_L LITERAL1 +LPS22HH_I3C_ADD_H LITERAL1 \ No newline at end of file diff --git a/library.properties b/library.properties index 2bf107f..21c7502 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino LPS22HH -version=2.0.4 +version=2.1.0 author=SRA maintainer=stm32duino sentence=Nano pressure sensor. diff --git a/src/LPS22HHSensor.cpp b/src/LPS22HHSensor.cpp index 99cdaed..91d9c8d 100644 --- a/src/LPS22HHSensor.cpp +++ b/src/LPS22HHSensor.cpp @@ -2,8 +2,8 @@ ****************************************************************************** * @file LPS22HHSensor.cpp * @author SRA - * @version V1.0.0 - * @date February 2019 + * @version V2.1.0 + * @date September 2026 * @brief Implementation of a LPS22HH pressure sensor. ****************************************************************************** * @attention @@ -50,6 +50,10 @@ LPS22HHSensor::LPS22HHSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address) { dev_spi = NULL; +#if defined(I3C_SUPPORTED) + dev_i3c = NULL; +#endif + bus_type = LPS22HH_I2C_BUS; reg_ctx.write_reg = LPS22HH_io_write; reg_ctx.read_reg = LPS22HH_io_read; reg_ctx.handle = (void *)this; @@ -67,15 +71,46 @@ LPS22HHSensor::LPS22HHSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : de reg_ctx.read_reg = LPS22HH_io_read; reg_ctx.handle = (void *)this; dev_i2c = NULL; +#if defined(I3C_SUPPORTED) + dev_i3c = NULL; +#endif + bus_type = LPS22HH_SPI_4WIRES_BUS; address = 0; enabled = 0; } +#if defined(I3C_SUPPORTED) +/** Constructor + * @param i3c object of an helper class which handles the I3C peripheral + * @param static_addr7 the I3C static address of the component's instance + */ +LPS22HHSensor::LPS22HHSensor(I3CBus *i3c, uint8_t static_addr7) : dev_i3c(i3c), address(static_addr7), i3c_static7(static_addr7), i3c_dyn7(0) +{ + reg_ctx.write_reg = LPS22HH_io_write; + reg_ctx.read_reg = LPS22HH_io_read; + reg_ctx.handle = (void *)this; + dev_i2c = NULL; + dev_spi = NULL; + bus_type = LPS22HH_I3C_BUS; + enabled = 0; +} + +uint8_t LPS22HHSensor::getStaticAddress() const +{ + return i3c_static7; +} + +uint8_t LPS22HHSensor::getDynAddress() const +{ + return i3c_dyn7; +} +#endif + /** * @brief Configure the sensor in order to be used * @retval 0 in case of success, an error code otherwise */ -LPS22HHStatusTypeDef LPS22HHSensor::begin() +LPS22HHStatusTypeDef LPS22HHSensor::begin(uint8_t new_address) { if (dev_spi) { // Configure CS pin @@ -83,9 +118,24 @@ LPS22HHStatusTypeDef LPS22HHSensor::begin() digitalWrite(cs_pin, HIGH); } - /* Disable MIPI I3C(SM) interface */ - if (lps22hh_i3c_interface_set(®_ctx, LPS22HH_I3C_DISABLE) != LPS22HH_OK) { - return LPS22HH_ERROR; +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + uint8_t id = 0; + if (new_address < 0x08 || new_address > 0x77) { + return LPS22HH_ERROR; + } + address = new_address; + i3c_dyn7 = new_address; + if (ReadID(&id) != LPS22HH_OK || id != LPS22HH_ID) { + return LPS22HH_ERROR; + } + } else +#endif + { + /* Disable MIPI I3C(SM) interface */ + if (lps22hh_i3c_interface_set(®_ctx, LPS22HH_I3C_DISABLE) != LPS22HH_OK) { + return LPS22HH_ERROR; + } } /* Power down the device, set Low Noise Enable (bit 5), clear One Shot (bit 4) */ diff --git a/src/LPS22HHSensor.h b/src/LPS22HHSensor.h index 0fe573d..214090b 100644 --- a/src/LPS22HHSensor.h +++ b/src/LPS22HHSensor.h @@ -2,8 +2,8 @@ ****************************************************************************** * @file LPS22HHSensor.h * @author SRA - * @version V1.0.0 - * @date February 2019 + * @version V2.1.0 + * @date September 2026 * @brief Abstract Class of a LPS22HH pressure sensor. ****************************************************************************** * @attention @@ -48,6 +48,11 @@ #include "SPI.h" #include "lps22hh_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 @@ -56,6 +61,16 @@ #endif #endif +#define LPS22HH_I2C_BUS 0U +#define LPS22HH_SPI_4WIRES_BUS 1U +#define LPS22HH_SPI_3WIRES_BUS 2U +#define LPS22HH_I3C_BUS 3U + +#if defined(I3C_SUPPORTED) + #define LPS22HH_I3C_ADD_L 0x5CU + #define LPS22HH_I3C_ADD_H 0x5DU +#endif + /* Typedefs ------------------------------------------------------------------*/ @@ -74,9 +89,16 @@ class LPS22HHSensor { public: LPS22HHSensor(TwoWire *i2c, uint8_t address = LPS22HH_I2C_ADD_H); LPS22HHSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed = 2000000); - LPS22HHStatusTypeDef begin(); +#if defined(I3C_SUPPORTED) + LPS22HHSensor(I3CBus *i3c, uint8_t static_addr7 = 0); +#endif + LPS22HHStatusTypeDef begin(uint8_t new_address = 0); LPS22HHStatusTypeDef end(); LPS22HHStatusTypeDef ReadID(uint8_t *Id); +#if defined(I3C_SUPPORTED) + uint8_t getStaticAddress() const; + uint8_t getDynAddress() const; +#endif LPS22HHStatusTypeDef Enable(); LPS22HHStatusTypeDef Disable(); LPS22HHStatusTypeDef GetOutputDataRate(float *Odr); @@ -149,6 +171,14 @@ class LPS22HHSensor { return 0; } +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + if (dev_i3c->readRegBuffer(address, RegisterAddr, pBuffer, NumByteToRead) == 0) { + return 0; + } + } +#endif + return 1; } @@ -193,6 +223,14 @@ class LPS22HHSensor { return 0; } +#if defined(I3C_SUPPORTED) + if (dev_i3c) { + if (dev_i3c->writeRegBuffer(address, RegisterAddr, pBuffer, NumByteToWrite) == 0) { + return 0; + } + } +#endif + return 1; } @@ -203,11 +241,20 @@ class LPS22HHSensor { /* 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 lps22hh_odr_t last_odr; uint8_t enabled; From 09f32fc9362eb0620bc02e2e994ea1c1243cebd9 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Mon, 21 Sep 2026 17:03:02 +0200 Subject: [PATCH 2/3] remove old checks --- .github/workflows/astyle.yml | 21 --------------------- .github/workflows/codespell.yml | 26 -------------------------- .github/workflows/compile-examples.yml | 25 ------------------------- 3 files changed, 72 deletions(-) delete mode 100644 .github/workflows/astyle.yml delete mode 100644 .github/workflows/codespell.yml delete mode 100644 .github/workflows/compile-examples.yml diff --git a/.github/workflows/astyle.yml b/.github/workflows/astyle.yml deleted file mode 100644 index d99b5fb..0000000 --- a/.github/workflows/astyle.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Astyle Check - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Astyle check - id: Astyle - uses: stm32duino/actions/astyle-check@main - # Use the output from the `Astyle` step - - name: Astyle Errors - if: failure() - run: | - cat ${{ steps.Astyle.outputs.astyle-result }} - exit 1 diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml deleted file mode 100644 index a914073..0000000 --- a/.github/workflows/codespell.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: codespell - -on: - push: - branches: - - main - pull_request: - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -jobs: - codespell: - name: Check for spelling errors - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@main - - # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md - - name: Spell check - uses: codespell-project/actions-codespell@master - with: - check_filenames: true - check_hidden: true - # In the event of a false positive, add the word in all lower case to this file: - ignore_words_file: ./extras/codespell-ignore-words-list.txt diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml deleted file mode 100644 index ad0275c..0000000 --- a/.github/workflows/compile-examples.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Compile Examples -on: - - push - - pull_request - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - fqbn: - - STMicroelectronics:stm32:Disco:pnum=B_L4S5I_IOT01A - - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG - # - STMicroelectronics:stm32:Disco:pnum=B_U585I_IOT02A - - steps: - - uses: actions/checkout@v2 - - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} - platforms: | - - source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json - name: STMicroelectronics:stm32 From 816424db3748f6ea57bf312764117748d52ef7e1 Mon Sep 17 00:00:00 2001 From: Davide QUARANTIELLO Date: Tue, 22 Sep 2026 14:14:18 +0200 Subject: [PATCH 3/3] add missing keywords --- keywords.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/keywords.txt b/keywords.txt index abd4df1..b78b48b 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,6 +7,7 @@ ####################################### LPS22HHSensor KEYWORD1 +LPS22HHStatusTypeDef KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -46,6 +47,9 @@ Get_One_Shot_Status KEYWORD2 LPS22HH_OK LITERAL1 LPS22HH_ERROR LITERAL1 +LPS22HH_I2C_BUS LITERAL1 +LPS22HH_SPI_4WIRES_BUS LITERAL1 +LPS22HH_SPI_3WIRES_BUS LITERAL1 LPS22HH_I3C_BUS LITERAL1 LPS22HH_I3C_ADD_L LITERAL1 LPS22HH_I3C_ADD_H LITERAL1 \ No newline at end of file