diff options
| author | Jeff Epler <jepler@unpythonic.net> | 2021-03-25 09:03:42 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@unpythonic.net> | 2021-03-26 10:04:35 -0500 |
| commit | 1d48054aeaa2762a752462a058a27afb1daac860 (patch) | |
| tree | b6e2fa858e83fbdcc39ac260aed242126b578f47 | |
| parent | ffb70a87372d01e0f5d9f547d117cb79636cbf5b (diff) | |
mimxrt10xx: Factor out "transfer_common"
.. and set the "MasterPcsContinuous" flag, which removes some of the
gap between bytes of a single SPI transaction
| -rw-r--r-- | ports/mimxrt10xx/common-hal/busio/SPI.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index 13a808618..13cc910d8 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -283,6 +283,21 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { self->has_lock = false; } +static status_t transfer_common(busio_spi_obj_t *self, lpspi_transfer_t *xfer) { + xfer->configFlags = kLPSPI_MasterPcsContinuous; + + status_t status; + int retries = MAX_SPI_BUSY_RETRIES; + do { + status = LPSPI_MasterTransferBlocking(self->spi, xfer); + } while (status == kStatus_LPSPI_Busy && --retries > 0); + + if (status != kStatus_Success) { + printf("%s: status %ld\r\n", __func__, status); + } + return status; +} + bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size_t len) { if (len == 0) { @@ -295,17 +310,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, lpspi_transfer_t xfer = { 0 }; xfer.txData = (uint8_t *)data; xfer.dataSize = len; - xfer.configFlags = kLPSPI_MasterPcs0; - status_t status; - int retries = MAX_SPI_BUSY_RETRIES; - do { - status = LPSPI_MasterTransferBlocking(self->spi, &xfer); - } while (status == kStatus_LPSPI_Busy && --retries > 0); - - if (status != kStatus_Success) { - printf("%s: status %ld\r\n", __func__, status); - } + status_t status = transfer_common(self, &xfer); return status == kStatus_Success; } @@ -325,15 +331,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, xfer.rxData = data; xfer.dataSize = len; - status_t status; - int retries = MAX_SPI_BUSY_RETRIES; - do { - status = LPSPI_MasterTransferBlocking(self->spi, &xfer); - } while (status == kStatus_LPSPI_Busy && --retries > 0); - - if (status != kStatus_Success) { - printf("%s: status %ld\r\n", __func__, status); - } + status_t status = transfer_common(self, &xfer); return status == kStatus_Success; } @@ -353,15 +351,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou xfer.rxData = data_in; xfer.dataSize = len; - status_t status; - int retries = MAX_SPI_BUSY_RETRIES; - do { - status = LPSPI_MasterTransferBlocking(self->spi, &xfer); - } while (status == kStatus_LPSPI_Busy && --retries > 0); - - if (status != kStatus_Success) { - printf("%s: status %ld\r\n", __func__, status); - } + status_t status = transfer_common(self, &xfer); return status == kStatus_Success; } |
