driver/sensor: lis2mdl: handle SPI 4-wires mode selection
The LIS2MDL supports SPI half duplex mode with a single data line by default (3-wire), but it might configured to switch to standard full duplex mode (4-wire). Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
d0a382b44a
commit
58d5d237b4
|
@ -53,4 +53,8 @@ config LIS2MDL_MAG_ODR_RUNTIME
|
|||
bool "Set magnetometer sampling frequency (ODR) at runtime (default: 10 Hz)"
|
||||
default y
|
||||
|
||||
config LIS2MDL_SPI_FULL_DUPLEX
|
||||
bool "Enable SPI 4wire mode (separated MISO and MOSI lines)"
|
||||
depends on SPI
|
||||
|
||||
endif # LIS2MDL
|
||||
|
|
|
@ -310,6 +310,13 @@ static int lis2mdl_init(struct device *dev)
|
|||
|
||||
k_busy_wait(100);
|
||||
|
||||
#if CONFIG_LIS2MDL_SPI_FULL_DUPLEX
|
||||
/* After s/w reset set SPI 4wires again if the case */
|
||||
if (lis2mdl_spi_mode_set(lis2mdl->ctx, LIS2MDL_SPI_4_WIRE) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* enable BDU */
|
||||
if (lis2mdl_block_data_update_set(lis2mdl->ctx, PROPERTY_ENABLE) < 0) {
|
||||
LOG_DBG("setting bdu failed\n");
|
||||
|
|
|
@ -122,6 +122,13 @@ int lis2mdl_spi_init(struct device *dev)
|
|||
cfg->gpio_cs_port, cfg->cs_gpio);
|
||||
#endif
|
||||
|
||||
#if CONFIG_LIS2MDL_SPI_FULL_DUPLEX
|
||||
/* Set SPI 4wires */
|
||||
if (lis2mdl_spi_mode_set(data->ctx, LIS2MDL_SPI_4_WIRE) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* DT_ST_LIS2MDL_BUS_SPI */
|
||||
|
|
Loading…
Reference in a new issue