Introduce TIMEOUT_1_BYTE

This makes the code more explicit about what is last parameter of
HAL_SPI_Transmit/HAL_SPI_Receive functions.
pull/4975/head
Laurent MEUNIER 2017-09-04 11:16:49 +02:00
parent 8c99bf3b62
commit b01cc966b0
1 changed files with 6 additions and 3 deletions

View File

@ -63,6 +63,9 @@
# define DEBUG_PRINTF(...) {}
#endif
/* Consider 10ms as the default timeout for sending/receving 1 byte */
#define TIMEOUT_1_BYTE 10
void init_spi(spi_t *obj)
{
struct spi_s *spiobj = SPI_S(obj);
@ -367,7 +370,7 @@ int spi_master_write(spi_t *obj, int value)
SPI_HandleTypeDef *handle = &(spiobj->handle);
if (handle->Init.Direction == SPI_DIRECTION_1LINE) {
return HAL_SPI_Transmit(handle, (uint8_t*)&value, 1, 10);
return HAL_SPI_Transmit(handle, (uint8_t*)&value, 1, TIMEOUT_1_BYTE);
}
#if defined(LL_SPI_RX_FIFO_TH_HALF)
@ -422,13 +425,13 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
} else {
/* In case of 1 WIRE only, first handle TX, then Rx */
if (tx_length != 0) {
if (HAL_OK != HAL_SPI_Transmit(handle, (uint8_t*)tx_buffer, tx_length, tx_length*10)) {
if (HAL_OK != HAL_SPI_Transmit(handle, (uint8_t*)tx_buffer, tx_length, tx_length*TIMEOUT_1_BYTE)) {
/* report an error */
total = 0;
}
}
if (rx_length != 0) {
if (HAL_OK != HAL_SPI_Receive(handle, (uint8_t*)rx_buffer, rx_length, rx_length*10)) {
if (HAL_OK != HAL_SPI_Receive(handle, (uint8_t*)rx_buffer, rx_length, rx_length*TIMEOUT_1_BYTE)) {
/* report an error */
total = 0;
}