Skip to content

Commit 1d48054

Browse files
committed
mimxrt10xx: Factor out "transfer_common"
.. and set the "MasterPcsContinuous" flag, which removes some of the gap between bytes of a single SPI transaction
1 parent ffb70a8 commit 1d48054

File tree

1 file changed

+18
-28
lines changed
  • ports/mimxrt10xx/common-hal/busio

1 file changed

+18
-28
lines changed

ports/mimxrt10xx/common-hal/busio/SPI.c

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,21 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
283283
self->has_lock = false;
284284
}
285285

286+
static status_t transfer_common(busio_spi_obj_t *self, lpspi_transfer_t *xfer) {
287+
xfer->configFlags = kLPSPI_MasterPcsContinuous;
288+
289+
status_t status;
290+
int retries = MAX_SPI_BUSY_RETRIES;
291+
do {
292+
status = LPSPI_MasterTransferBlocking(self->spi, xfer);
293+
} while (status == kStatus_LPSPI_Busy && --retries > 0);
294+
295+
if (status != kStatus_Success) {
296+
printf("%s: status %ld\r\n", __func__, status);
297+
}
298+
return status;
299+
}
300+
286301
bool common_hal_busio_spi_write(busio_spi_obj_t *self,
287302
const uint8_t *data, size_t len) {
288303
if (len == 0) {
@@ -295,17 +310,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
295310
lpspi_transfer_t xfer = { 0 };
296311
xfer.txData = (uint8_t *)data;
297312
xfer.dataSize = len;
298-
xfer.configFlags = kLPSPI_MasterPcs0;
299313

300-
status_t status;
301-
int retries = MAX_SPI_BUSY_RETRIES;
302-
do {
303-
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
304-
} while (status == kStatus_LPSPI_Busy && --retries > 0);
305-
306-
if (status != kStatus_Success) {
307-
printf("%s: status %ld\r\n", __func__, status);
308-
}
314+
status_t status = transfer_common(self, &xfer);
309315

310316
return status == kStatus_Success;
311317
}
@@ -325,15 +331,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
325331
xfer.rxData = data;
326332
xfer.dataSize = len;
327333

328-
status_t status;
329-
int retries = MAX_SPI_BUSY_RETRIES;
330-
do {
331-
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
332-
} while (status == kStatus_LPSPI_Busy && --retries > 0);
333-
334-
if (status != kStatus_Success) {
335-
printf("%s: status %ld\r\n", __func__, status);
336-
}
334+
status_t status = transfer_common(self, &xfer);
337335

338336
return status == kStatus_Success;
339337
}
@@ -353,15 +351,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
353351
xfer.rxData = data_in;
354352
xfer.dataSize = len;
355353

356-
status_t status;
357-
int retries = MAX_SPI_BUSY_RETRIES;
358-
do {
359-
status = LPSPI_MasterTransferBlocking(self->spi, &xfer);
360-
} while (status == kStatus_LPSPI_Busy && --retries > 0);
361-
362-
if (status != kStatus_Success) {
363-
printf("%s: status %ld\r\n", __func__, status);
364-
}
354+
status_t status = transfer_common(self, &xfer);
365355

366356
return status == kStatus_Success;
367357
}

0 commit comments

Comments
 (0)