@@ -71,6 +71,32 @@ LPS22DFSensor::LPS22DFSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : de
7171 enabled = 0L ;
7272}
7373
74+ LPS22DFSensor::LPS22DFSensor (I3CBus *i3c, uint8_t staticAddr7, uint8_t dynAddr7)
75+ {
76+ reg_ctx.write_reg = LPS22DF_io_write;
77+ reg_ctx.read_reg = LPS22DF_io_read;
78+ reg_ctx.handle = (void *)this ;
79+
80+ dev_i2c = NULL ;
81+ dev_spi = NULL ;
82+ dev_i3c = i3c;
83+
84+ address = (dynAddr7 != 0 ) ? dynAddr7 : staticAddr7;
85+ i3c_static7 = staticAddr7;
86+ i3c_dyn7 = dynAddr7;
87+
88+ enabled = 0U ;
89+ initialized = 0U ;
90+
91+ bus_type = LPS22DF_I3C_BUS ;
92+ }
93+
94+ void LPS22DFSensor::set_address (uint8_t dynAddr7)
95+ {
96+
97+ address = dynAddr7;
98+ }
99+
74100/* *
75101 * @brief Configure the sensor in order to be used
76102 * @retval 0 in case of success, an error code otherwise
@@ -86,21 +112,62 @@ LPS22DFStatusTypeDef LPS22DFSensor::begin()
86112 digitalWrite (cs_pin, HIGH );
87113 }
88114
115+ if (dev_i3c != nullptr ) {
116+ Serial.println (" I3C" );
117+
118+ bool doAutoSetdasa = (i3c_static7 != 0 ) && (i3c_dyn7 != 0 );
119+
120+ if (doAutoSetdasa) {
121+ dev_i3c->setClock (1000000 ); // 1 MHz mixte I3C+I2C
122+
123+ if (dev_i3c->assignDynamicAddress (i3c_static7, i3c_dyn7) != 0 ) {
124+ Serial.println (" I3C: SETDASA failed" );
125+ return LPS22DF_ERROR ;
126+ }
127+
128+ address = i3c_dyn7;
129+
130+ uint8_t id = 0 ;
131+ if (ReadID (&id) != LPS22DF_OK || id != LPS22DF_ID ) {
132+ Serial.print (" I3C: probe failed after SETDASA, id=0x" );
133+ Serial.println (id, HEX );
134+ return LPS22DF_ERROR ;
135+ }
136+
137+ Serial.println (" I3C: dynamic address and WHO_AM_I OK" );
138+ } else {
139+
140+ uint8_t id = 0 ;
141+ if (ReadID (&id) != LPS22DF_OK || id != LPS22DF_ID ) {
142+ Serial.print (" I3C: manual mode: WHO_AM_I failed, id=0x" );
143+ Serial.println (id, HEX );
144+ return LPS22DF_ERROR ;
145+ }
146+ Serial.println (" I3C: manual mode, WHO_AM_I OK at address 0x" );
147+ Serial.println (address, HEX );
148+ }
149+ dev_i3c->setClock (12500000 );
150+ }
151+
89152 /* Set bdu and if_inc recommended for driver usage */
90153 if (lps22df_init_set (®_ctx, LPS22DF_DRV_RDY ) != LPS22DF_OK ) {
91154 return LPS22DF_ERROR ;
92155 }
93156
94157 /* Select bus interface */
95- if (bus_type == LPS22DF_SPI_3WIRES_BUS ) { /* SPI 3-Wires */
158+ if (bus_type == LPS22DF_SPI_3WIRES_BUS ) {
96159 bus_mode.interface = lps22df_bus_mode_t ::LPS22DF_SPI_3W ;
97- } else if (bus_type == LPS22DF_SPI_4WIRES_BUS ) { /* SPI 3-Wires */
160+ } else if (bus_type == LPS22DF_SPI_4WIRES_BUS ) {
98161 bus_mode.interface = lps22df_bus_mode_t ::LPS22DF_SPI_4W ;
162+ } else if (bus_type == LPS22DF_I3C_BUS ) {
163+ bus_mode.interface = lps22df_bus_mode_t ::LPS22DF_INT_PIN_ON_I3C ;
99164 } else {
100165 bus_mode.interface = lps22df_bus_mode_t ::LPS22DF_SEL_BY_HW ;
101166 }
102167
103168 bus_mode.filter = lps22df_bus_mode_t ::LPS22DF_AUTO ;
169+ bus_mode.i3c_ibi_time = lps22df_bus_mode_t ::LPS22DF_IBI_1ms;
170+
104171 if (lps22df_bus_mode_set (®_ctx, &bus_mode) != LPS22DF_OK ) {
105172 return LPS22DF_ERROR ;
106173 }
@@ -501,3 +568,39 @@ int32_t LPS22DF_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16
501568{
502569 return ((LPS22DFSensor *)handle)->IO_Read (pBuffer, ReadAddr, nBytesToRead);
503570}
571+
572+ LPS22DFStatusTypeDef LPS22DFSensor::ConfigureDataReadyOnI3cIbi ()
573+ {
574+ if (dev_i3c == nullptr ) {
575+ return LPS22DF_ERROR ;
576+ }
577+
578+ if (Write_Reg (LPS22DF_IF_CTRL , 0x80 ) != LPS22DF_OK ) {
579+ return LPS22DF_ERROR ;
580+ }
581+
582+ if (Write_Reg (LPS22DF_CTRL_REG4 , 0x30 ) != LPS22DF_OK ) {
583+ return LPS22DF_ERROR ;
584+ }
585+
586+ return LPS22DF_OK ;
587+ }
588+
589+ LPS22DFStatusTypeDef LPS22DFSensor::EnableIbiOnBus (uint8_t targetIndex,
590+ uint32_t timeoutMs,
591+ bool withPayload)
592+ {
593+ if (dev_i3c == nullptr ) {
594+ return LPS22DF_ERROR ;
595+ }
596+
597+ if (dev_i3c->enableIbi (targetIndex, address, withPayload, false , timeoutMs) != 0 ) {
598+ return LPS22DF_ERROR ;
599+ }
600+
601+ if (dev_i3c->enableControllerEvents (HAL_I3C_IT_IBIIE ) != 0 ) {
602+ return LPS22DF_ERROR ;
603+ }
604+
605+ return LPS22DF_OK ;
606+ }
0 commit comments