drivers: spi_oc_simple: initialize all cs gpios during init
In case when we have multiple devices connected to the one SPI interface the initial state of CS gpios after MCU reset is floating and it might be low that prevents us from communicating between particular devices. Fix that by initializing all provided cs gpios and setting them as inactive. Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
This commit is contained in:
parent
99daca9bba
commit
225f0b3825
1 changed files with 8 additions and 4 deletions
|
@ -78,10 +78,6 @@ static int spi_oc_simple_configure(const struct spi_oc_simple_cfg *info,
|
|||
|
||||
spi->ctx.config = config;
|
||||
|
||||
if (config->cs) {
|
||||
spi_context_cs_configure(&spi->ctx);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -185,11 +181,18 @@ static struct spi_driver_api spi_oc_simple_api = {
|
|||
|
||||
int spi_oc_simple_init(const struct device *dev)
|
||||
{
|
||||
int err;
|
||||
const struct spi_oc_simple_cfg *info = dev->config;
|
||||
struct spi_oc_simple_data *data = dev->data;
|
||||
|
||||
/* Clear chip selects */
|
||||
sys_write8(0, SPI_OC_SIMPLE_SPSS(info));
|
||||
|
||||
err = spi_context_cs_configure_all(&data->ctx);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Make sure the context is unlocked */
|
||||
spi_context_unlock_unconditionally(&SPI_OC_SIMPLE_DATA(dev)->ctx);
|
||||
|
||||
|
@ -212,6 +215,7 @@ int spi_oc_simple_init(const struct device *dev)
|
|||
static struct spi_oc_simple_data spi_oc_simple_data_##inst = { \
|
||||
SPI_CONTEXT_INIT_LOCK(spi_oc_simple_data_##inst, ctx), \
|
||||
SPI_CONTEXT_INIT_SYNC(spi_oc_simple_data_##inst, ctx), \
|
||||
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx) \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue