From 1d48054aeaa2762a752462a058a27afb1daac860 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 25 Mar 2021 09:03:42 -0500 Subject: [PATCH] mimxrt10xx: Factor out "transfer_common" .. and set the "MasterPcsContinuous" flag, which removes some of the gap between bytes of a single SPI transaction --- ports/mimxrt10xx/common-hal/busio/SPI.c | 46 ++++++++++--------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index 13a8086182..13cc910d88 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; }