Skip to content

Commit d55eb70

Browse files
committed
spi_tranfer: factorize common code to simplify maintenance
1 parent 9c83128 commit d55eb70

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

libraries/SPI/src/utility/spi_com.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -407,33 +407,22 @@ spi_status_e spi_transfer(spi_t *obj, uint8_t *tx_buffer, uint8_t *rx_buffer,
407407
return Timeout > 0U ? SPI_ERROR : SPI_TIMEOUT;
408408
}
409409
tickstart = HAL_GetTick();
410-
if (skipReceive) {
411-
while (size--) {
412-
while (!LL_SPI_IsActiveFlag_TXE(_SPI))
413-
;
414-
LL_SPI_TransmitData8(_SPI, *tx_buffer++);
415-
416-
if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) {
417-
ret = SPI_TIMEOUT;
418-
break;
419-
}
420-
}
421-
} else {
422-
while (size--) {
423-
while (!LL_SPI_IsActiveFlag_TXE(_SPI))
424-
;
425-
LL_SPI_TransmitData8(_SPI, *tx_buffer++);
410+
while (size--) {
411+
while (!LL_SPI_IsActiveFlag_TXE(_SPI))
412+
;
413+
LL_SPI_TransmitData8(_SPI, *tx_buffer++);
426414

415+
if (!skipReceive) {
427416
while (!LL_SPI_IsActiveFlag_RXNE(_SPI))
428417
;
429418
*rx_buffer++ = LL_SPI_ReceiveData8(_SPI);
430-
431-
if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) {
432-
ret = SPI_TIMEOUT;
433-
break;
434-
}
419+
}
420+
if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) {
421+
ret = SPI_TIMEOUT;
422+
break;
435423
}
436424
}
425+
437426
return ret;
438427
}
439428

0 commit comments

Comments
 (0)