Skip to content

Commit 262008a

Browse files
afontaine-invnfabiobaltieri
authored andcommitted
drivers: sensor: icm42670: fix serif type
Fix correct use of serif_type if the driver is compiled with both SPI and I2C enabled by storing it in device config. Signed-off-by: Aurelie Fontaine <aurelie.fontaine@tdk.com>
1 parent 72c02b3 commit 262008a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

drivers/sensor/tdk/icm42670/icm42670.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ static int icm42670_gyro_config(struct icm42670_data *drv_data, enum sensor_attr
438438
static int icm42670_sensor_init(const struct device *dev)
439439
{
440440
struct icm42670_data *data = dev->data;
441+
const struct icm42670_config *config = dev->config;
441442
int err = 0;
442443

443444
/* Initialize serial interface and device */
@@ -446,12 +447,7 @@ static int icm42670_sensor_init(const struct device *dev)
446447
data->serif.write_reg = inv_io_hal_write_reg;
447448
data->serif.max_read = ICM42670_SERIAL_INTERFACE_MAX_READ;
448449
data->serif.max_write = ICM42670_SERIAL_INTERFACE_MAX_WRITE;
449-
#if CONFIG_SPI
450-
data->serif.serif_type = UI_SPI4;
451-
#endif
452-
#if CONFIG_I2C
453-
data->serif.serif_type = UI_I2C;
454-
#endif
450+
data->serif.serif_type = config->serif_type;
455451
err = inv_imu_init(&data->driver, &data->serif, NULL);
456452
if (err < 0) {
457453
LOG_ERR("Init failed: %d", err);
@@ -1053,12 +1049,14 @@ static DEVICE_API(sensor, icm42670_driver_api) = {
10531049
#define ICM42670_CONFIG_SPI(inst) \
10541050
{.bus.spi = SPI_DT_SPEC_INST_GET(inst, ICM42670_SPI_CFG, 0), \
10551051
.bus_io = &icm42670_bus_io_spi, \
1052+
.serif_type = UI_SPI4, \
10561053
ICM42670_CONFIG_COMMON(inst)}
10571054

10581055
/* Initializes the bus members for an instance on an I2C bus. */
10591056
#define ICM42670_CONFIG_I2C(inst) \
10601057
{.bus.i2c = I2C_DT_SPEC_INST_GET(inst), \
10611058
.bus_io = &icm42670_bus_io_i2c, \
1059+
.serif_type = UI_I2C, \
10621060
ICM42670_CONFIG_COMMON(inst)}
10631061

10641062
/*

drivers/sensor/tdk/icm42670/icm42670.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct icm42670_data {
9595
struct icm42670_config {
9696
union icm42670_bus bus;
9797
const struct icm42670_bus_io *bus_io;
98+
uint32_t serif_type;
9899
struct gpio_dt_spec gpio_int;
99100
uint8_t accel_fs;
100101
uint16_t accel_hz;

0 commit comments

Comments
 (0)