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:
Armando Visconti 2019-09-19 15:15:11 +02:00 committed by Maureen Helm
parent d0a382b44a
commit 58d5d237b4
3 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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");

View file

@ -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 */