6
6
*/
7
7
8
8
#include "bmp581.h"
9
+ #include "bmp581_bus.h"
9
10
10
11
#include <math.h>
11
12
@@ -60,14 +61,13 @@ static int set_power_mode(enum bmp5_powermode powermode, const struct device *de
60
61
* Device should be set to standby before transitioning to forced mode or normal
61
62
* mode or continuous mode.
62
63
*/
63
-
64
- ret = i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , & odr );
64
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & odr , 1 );
65
65
if (ret == BMP5_OK ) {
66
66
/* Setting deep_dis = 1(BMP5_DEEP_DISABLED) disables the deep standby mode
67
67
*/
68
68
odr = BMP5_SET_BITSLICE (odr , BMP5_DEEP_DISABLE , BMP5_DEEP_DISABLED );
69
69
odr = BMP5_SET_BITS_POS_0 (odr , BMP5_POWERMODE , BMP5_POWERMODE_STANDBY );
70
- ret = i2c_reg_write_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , odr );
70
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & odr , 1 );
71
71
72
72
if (ret != BMP5_OK ) {
73
73
LOG_DBG ("Failed to set power mode to BMP5_POWERMODE_STANDBY." );
@@ -92,7 +92,7 @@ static int set_power_mode(enum bmp5_powermode powermode, const struct device *de
92
92
case BMP5_POWERMODE_CONTINUOUS :
93
93
odr = BMP5_SET_BITSLICE (odr , BMP5_DEEP_DISABLE , BMP5_DEEP_DISABLED );
94
94
odr = BMP5_SET_BITS_POS_0 (odr , BMP5_POWERMODE , powermode );
95
- ret = i2c_reg_write_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , odr );
95
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & odr , 1 );
96
96
break ;
97
97
default :
98
98
/* invalid power mode */
@@ -116,7 +116,7 @@ static int get_power_mode(enum bmp5_powermode *powermode, const struct device *d
116
116
uint8_t reg = 0 ;
117
117
uint8_t raw_power_mode = 0 ;
118
118
119
- ret = i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , & reg );
119
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & reg , 1 );
120
120
if (ret != BMP5_OK ) {
121
121
LOG_DBG ("Failed to read odr config to get power mode!" );
122
122
return ret ;
@@ -195,7 +195,7 @@ static int get_interrupt_status(uint8_t *int_status, const struct device *dev)
195
195
196
196
conf = (const struct bmp581_config * )dev -> config ;
197
197
198
- return i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_INT_STATUS , int_status );
198
+ return bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_INT_STATUS , int_status , 1 );
199
199
}
200
200
201
201
static int get_nvm_status (uint8_t * nvm_status , const struct device * dev )
@@ -208,7 +208,7 @@ static int get_nvm_status(uint8_t *nvm_status, const struct device *dev)
208
208
209
209
conf = (const struct bmp581_config * )dev -> config ;
210
210
211
- return i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_STATUS , nvm_status );
211
+ return bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_STATUS , nvm_status , 1 );
212
212
}
213
213
214
214
static int validate_chip_id (struct bmp581_data * drv )
@@ -251,7 +251,7 @@ static int get_osr_odr_press_config(struct bmp581_osr_odr_press_config *osr_odr_
251
251
conf = (const struct bmp581_config * )dev -> config ;
252
252
253
253
/* Get OSR and ODR configuration in burst read */
254
- rslt = i2c_burst_read_dt (& conf -> i2c , BMP5_REG_OSR_CONFIG , reg_data , 2 );
254
+ rslt = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_OSR_CONFIG , reg_data , 2 );
255
255
256
256
if (rslt == BMP5_OK ) {
257
257
osr_odr_press_cfg -> osr_t = BMP5_GET_BITS_POS_0 (reg_data [0 ], BMP5_TEMP_OSR );
@@ -275,7 +275,7 @@ static int set_osr_odr_press_config(const struct bmp581_osr_odr_press_config *os
275
275
reg_data [1 ] = BMP5_SET_BITSLICE (reg_data [1 ], BMP5_POWERMODE , osr_odr_press_cfg -> power_mode );
276
276
reg_data [1 ] = BMP5_SET_BITSLICE (reg_data [1 ], BMP5_ODR , osr_odr_press_cfg -> odr );
277
277
278
- return i2c_burst_write_dt (& cfg -> i2c , BMP5_REG_OSR_CONFIG , reg_data , sizeof (reg_data ));
278
+ return bmp581_reg_write_rtio (& cfg -> bus , BMP5_REG_OSR_CONFIG , reg_data , sizeof (reg_data ));
279
279
}
280
280
281
281
static int set_iir_filters_config (const struct bmp581_osr_odr_press_config * osr_odr_press_cfg ,
@@ -287,7 +287,7 @@ static int set_iir_filters_config(const struct bmp581_osr_odr_press_config *osr_
287
287
reg_data = BMP5_SET_BITSLICE (reg_data , BMP5_SET_IIR_TEMP , osr_odr_press_cfg -> iir_t );
288
288
reg_data = BMP5_SET_BITSLICE (reg_data , BMP5_SET_IIR_PRESS , osr_odr_press_cfg -> iir_p );
289
289
290
- return i2c_burst_write_dt (& cfg -> i2c , BMP5_REG_DSP_IIR , & reg_data , 1 );
290
+ return bmp581_reg_write_rtio (& cfg -> bus , BMP5_REG_DSP_IIR , & reg_data , 1 );
291
291
}
292
292
293
293
static int set_osr_config (const struct sensor_value * osr , enum sensor_channel chan ,
@@ -305,7 +305,7 @@ static int set_osr_config(const struct sensor_value *osr, enum sensor_channel ch
305
305
uint8_t press_en = osr -> val2 != 0 ; /* if it is not 0 then pressure is enabled */
306
306
uint8_t osr_val = 0 ;
307
307
308
- ret = i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_OSR_CONFIG , & osr_val );
308
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_OSR_CONFIG , & osr_val , 1 );
309
309
if (ret == BMP5_OK ) {
310
310
switch (chan ) {
311
311
case SENSOR_CHAN_ALL :
@@ -326,7 +326,7 @@ static int set_osr_config(const struct sensor_value *osr, enum sensor_channel ch
326
326
}
327
327
328
328
if (ret == BMP5_OK ) {
329
- ret = i2c_reg_write_byte_dt (& conf -> i2c , BMP5_REG_OSR_CONFIG , osr_val );
329
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_OSR_CONFIG , & osr_val , 1 );
330
330
get_osr_odr_press_config (& drv -> osr_odr_press_config , dev );
331
331
}
332
332
}
@@ -345,12 +345,12 @@ static int set_odr_config(const struct sensor_value *odr, const struct device *d
345
345
int ret = 0 ;
346
346
uint8_t odr_val = 0 ;
347
347
348
- ret = i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , & odr_val );
348
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & odr_val , 1 );
349
349
if (ret != BMP5_OK ) {
350
350
return ret ;
351
351
}
352
352
odr_val = BMP5_SET_BITSLICE (odr_val , BMP5_ODR , odr -> val1 );
353
- ret = i2c_reg_write_byte_dt (& conf -> i2c , BMP5_REG_ODR_CONFIG , odr_val );
353
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_ODR_CONFIG , & odr_val , 1 );
354
354
get_osr_odr_press_config (& drv -> osr_odr_press_config , dev );
355
355
356
356
return ret ;
@@ -367,7 +367,7 @@ static int soft_reset(const struct device *dev)
367
367
return - EINVAL ;
368
368
}
369
369
370
- ret = i2c_reg_write_byte_dt (& conf -> i2c , BMP5_REG_CMD , reset_cmd );
370
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_CMD , & reset_cmd , 1 );
371
371
372
372
if (ret == BMP5_OK ) {
373
373
k_usleep (BMP5_DELAY_US_SOFT_RESET );
@@ -401,7 +401,7 @@ static int bmp581_sample_fetch(const struct device *dev, enum sensor_channel cha
401
401
uint8_t data [6 ];
402
402
int ret = 0 ;
403
403
404
- ret = i2c_burst_read_dt (& conf -> i2c , BMP5_REG_TEMP_DATA_XLSB , data , 6 );
404
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_TEMP_DATA_XLSB , data , 6 );
405
405
if (ret == BMP5_OK ) {
406
406
/* convert raw sensor data to sensor_value. Shift the decimal part by 1 decimal
407
407
* place to compensate for the conversion in sensor_value_to_double()
@@ -473,7 +473,7 @@ static int set_iir_config(const struct sensor_value *iir, const struct device *d
473
473
/* update IIR config */
474
474
uint8_t dsp_config [2 ];
475
475
476
- ret = i2c_burst_read_dt (& conf -> i2c , BMP5_REG_DSP_CONFIG , dsp_config , 2 );
476
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_DSP_CONFIG , dsp_config , 2 );
477
477
if (ret != BMP5_OK ) {
478
478
LOG_DBG ("Failed to read dsp config register." );
479
479
return ret ;
@@ -487,7 +487,7 @@ static int set_iir_config(const struct sensor_value *iir, const struct device *d
487
487
dsp_config [1 ] = BMP5_SET_BITSLICE (dsp_config [1 ], BMP5_SET_IIR_PRESS , iir -> val2 );
488
488
489
489
/* Set IIR configuration */
490
- ret = i2c_burst_write_dt (& conf -> i2c , BMP5_REG_DSP_CONFIG , dsp_config , 2 );
490
+ ret = bmp581_reg_write_rtio (& conf -> bus , BMP5_REG_DSP_CONFIG , dsp_config , 2 );
491
491
492
492
if (ret != BMP5_OK ) {
493
493
LOG_DBG ("Failed to configure IIR filter." );
@@ -550,7 +550,7 @@ static int bmp581_init(const struct device *dev)
550
550
551
551
soft_reset (dev );
552
552
553
- ret = i2c_reg_read_byte_dt (& conf -> i2c , BMP5_REG_CHIP_ID , & drv -> chip_id );
553
+ ret = bmp581_reg_read_rtio (& conf -> bus , BMP5_REG_CHIP_ID , & drv -> chip_id , 1 );
554
554
if (ret != BMP5_OK ) {
555
555
return ret ;
556
556
}
@@ -592,12 +592,11 @@ static DEVICE_API(sensor, bmp581_driver_api) = {
592
592
.attr_set = bmp581_attr_set ,
593
593
};
594
594
595
- #define BMP581_CONFIG (i ) \
596
- static const struct bmp581_config bmp581_config_##i = { \
597
- .i2c = I2C_DT_SPEC_INST_GET(i), \
598
- }
599
-
600
595
#define BMP581_INIT (i ) \
596
+ \
597
+ RTIO_DEFINE(bmp581_rtio_ctx_##i, 8, 8); \
598
+ I2C_DT_IODEV_DEFINE(bmp581_bus_##i, DT_DRV_INST(i)); \
599
+ \
601
600
static struct bmp581_data bmp581_data_##i = { \
602
601
.osr_odr_press_config = { \
603
602
.press_en = 1, \
@@ -609,7 +608,14 @@ static DEVICE_API(sensor, bmp581_driver_api) = {
609
608
.power_mode = DT_INST_PROP(i, power_mode), \
610
609
}, \
611
610
}; \
612
- BMP581_CONFIG(i); \
611
+ \
612
+ static const struct bmp581_config bmp581_config_##i = { \
613
+ .bus.rtio = { \
614
+ .ctx = &bmp581_rtio_ctx_##i, \
615
+ .iodev = &bmp581_bus_##i, \
616
+ .type = BMP581_BUS_TYPE_I2C, \
617
+ }, \
618
+ }; \
613
619
\
614
620
SENSOR_DEVICE_DT_INST_DEFINE(i, bmp581_init, NULL, &bmp581_data_##i, &bmp581_config_##i, \
615
621
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \
0 commit comments