@@ -283,6 +283,21 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
283
283
self -> has_lock = false;
284
284
}
285
285
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
+
286
301
bool common_hal_busio_spi_write (busio_spi_obj_t * self ,
287
302
const uint8_t * data , size_t len ) {
288
303
if (len == 0 ) {
@@ -295,17 +310,8 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self,
295
310
lpspi_transfer_t xfer = { 0 };
296
311
xfer .txData = (uint8_t * )data ;
297
312
xfer .dataSize = len ;
298
- xfer .configFlags = kLPSPI_MasterPcs0 ;
299
313
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 );
309
315
310
316
return status == kStatus_Success ;
311
317
}
@@ -325,15 +331,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
325
331
xfer .rxData = data ;
326
332
xfer .dataSize = len ;
327
333
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 );
337
335
338
336
return status == kStatus_Success ;
339
337
}
@@ -353,15 +351,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou
353
351
xfer .rxData = data_in ;
354
352
xfer .dataSize = len ;
355
353
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 );
365
355
366
356
return status == kStatus_Success ;
367
357
}
0 commit comments