diff --git a/drivers/spi/spi_transfer.c b/drivers/spi/spi_transfer.c index c21cd30a4c0..74e312e3fe1 100644 --- a/drivers/spi/spi_transfer.c +++ b/drivers/spi/spi_transfer.c @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -48,22 +49,6 @@ #ifdef CONFIG_SPI_EXCHANGE -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -142,9 +127,27 @@ int spi_transfer(FAR struct spi_dev_s *spi, FAR struct spi_sequence_s *seq) } #endif + /* [Re-]select the SPI device in preparation for the transfer */ + + SPI_SELECT(spi, seq->dev, true); + /* Perform the transfer */ SPI_EXCHANGE(spi, trans->txbuffer, trans->rxbuffer, trans->nwords); + + /* Possibly de-select the SPI device after the transfer */ + + if (trans->deselect) + { + SPI_SELECT(spi, seq->dev, false); + } + + /* Perform any requested inter-transfer delay */ + + if (trans->delay > 0) + { + usleep(trans->delay); + } } SPI_SELECT(spi, seq->dev, false); diff --git a/include/nuttx/spi/spi_transfer.h b/include/nuttx/spi/spi_transfer.h index 303dc61e5d8..1af7e0a11a5 100644 --- a/include/nuttx/spi/spi_transfer.h +++ b/include/nuttx/spi/spi_transfer.h @@ -76,12 +76,14 @@ struct spi_trans_s { /* SPI attributes for unique to this transaction */ + bool deselect; /* De-select after transfer */ #ifdef CONFIG_SPI_CMDDATA bool cmd; /* true=command; false=data */ #endif #ifdef CONFIG_SPI_HWFEATURES spi_hwfeatures_t hwfeat; /* Hard features to enable on this transfer */ #endif + uint32_t delay; /* Microsecond delay after transfer */ /* These describe the single data transfer */