From d55eb703823cccf8c4f98e85d517a332b0922c84 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Thu, 6 Feb 2020 11:53:42 +0100 Subject: [PATCH] spi_tranfer: factorize common code to simplify maintenance --- libraries/SPI/src/utility/spi_com.c | 31 ++++++++++------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/libraries/SPI/src/utility/spi_com.c b/libraries/SPI/src/utility/spi_com.c index 1ce808d86f..fdca96bad0 100644 --- a/libraries/SPI/src/utility/spi_com.c +++ b/libraries/SPI/src/utility/spi_com.c @@ -407,33 +407,22 @@ spi_status_e spi_transfer(spi_t *obj, uint8_t *tx_buffer, uint8_t *rx_buffer, return Timeout > 0U ? SPI_ERROR : SPI_TIMEOUT; } tickstart = HAL_GetTick(); - if (skipReceive) { - while (size--) { - while (!LL_SPI_IsActiveFlag_TXE(_SPI)) - ; - LL_SPI_TransmitData8(_SPI, *tx_buffer++); - - if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) { - ret = SPI_TIMEOUT; - break; - } - } - } else { - while (size--) { - while (!LL_SPI_IsActiveFlag_TXE(_SPI)) - ; - LL_SPI_TransmitData8(_SPI, *tx_buffer++); + while (size--) { + while (!LL_SPI_IsActiveFlag_TXE(_SPI)) + ; + LL_SPI_TransmitData8(_SPI, *tx_buffer++); + if (!skipReceive) { while (!LL_SPI_IsActiveFlag_RXNE(_SPI)) ; *rx_buffer++ = LL_SPI_ReceiveData8(_SPI); - - if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) { - ret = SPI_TIMEOUT; - break; - } + } + if ((Timeout != HAL_MAX_DELAY) && (HAL_GetTick() - tickstart >= Timeout)) { + ret = SPI_TIMEOUT; + break; } } + return ret; }