Call transmit buffer out and receive buffer in
This commit is contained in:
parent
a885184796
commit
a864b869ae
|
@ -206,14 +206,14 @@ bool spiIsBusBusy(SPI_TypeDef *instance)
|
|||
|
||||
}
|
||||
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len)
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *in, const uint8_t *out, int len)
|
||||
{
|
||||
uint16_t spiTimeout = 1000;
|
||||
|
||||
uint8_t b;
|
||||
instance->DR;
|
||||
while (len--) {
|
||||
b = in ? *(in++) : 0xFF;
|
||||
b = out ? *(out++) : 0xFF;
|
||||
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET) {
|
||||
if ((spiTimeout--) == 0)
|
||||
return spiTimeoutUserCallback(instance);
|
||||
|
@ -233,8 +233,8 @@ bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len
|
|||
#else
|
||||
b = SPI_I2S_ReceiveData(instance);
|
||||
#endif
|
||||
if (out)
|
||||
*(out++) = b;
|
||||
if (in)
|
||||
*(in++) = b;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -88,7 +88,7 @@ void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor);
|
|||
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t in);
|
||||
bool spiIsBusBusy(SPI_TypeDef *instance);
|
||||
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len);
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *in, const uint8_t *out, int len);
|
||||
|
||||
uint16_t spiGetErrorCounter(SPI_TypeDef *instance);
|
||||
void spiResetErrorCounter(SPI_TypeDef *instance);
|
||||
|
|
|
@ -261,22 +261,22 @@ bool spiIsBusBusy(SPI_TypeDef *instance)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len)
|
||||
bool spiTransfer(SPI_TypeDef *instance, uint8_t *in, const uint8_t *out, int len)
|
||||
{
|
||||
SPIDevice device = spiDeviceByInstance(instance);
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
if (!out) // Tx only
|
||||
if (!in) // Tx only
|
||||
{
|
||||
status = HAL_SPI_Transmit(&spiDevice[device].hspi, (uint8_t *)in, len, SPI_DEFAULT_TIMEOUT);
|
||||
status = HAL_SPI_Transmit(&spiDevice[device].hspi, (uint8_t *)out, len, SPI_DEFAULT_TIMEOUT);
|
||||
}
|
||||
else if (!in) // Rx only
|
||||
else if (!out) // Rx only
|
||||
{
|
||||
status = HAL_SPI_Receive(&spiDevice[device].hspi, out, len, SPI_DEFAULT_TIMEOUT);
|
||||
status = HAL_SPI_Receive(&spiDevice[device].hspi, in, len, SPI_DEFAULT_TIMEOUT);
|
||||
}
|
||||
else // Tx and Rx
|
||||
{
|
||||
status = HAL_SPI_TransmitReceive(&spiDevice[device].hspi, in, out, len, SPI_DEFAULT_TIMEOUT);
|
||||
status = HAL_SPI_TransmitReceive(&spiDevice[device].hspi, out, in, len, SPI_DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
if ( status != HAL_OK)
|
||||
|
|
Loading…
Reference in New Issue