mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 17:55:30 +03:00
Call transmit buffer out and receive buffer in
This commit is contained in:
parent
a885184796
commit
a864b869ae
3 changed files with 11 additions and 11 deletions
|
@ -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;
|
uint16_t spiTimeout = 1000;
|
||||||
|
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
instance->DR;
|
instance->DR;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
b = in ? *(in++) : 0xFF;
|
b = out ? *(out++) : 0xFF;
|
||||||
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET) {
|
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET) {
|
||||||
if ((spiTimeout--) == 0)
|
if ((spiTimeout--) == 0)
|
||||||
return spiTimeoutUserCallback(instance);
|
return spiTimeoutUserCallback(instance);
|
||||||
|
@ -233,8 +233,8 @@ bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len
|
||||||
#else
|
#else
|
||||||
b = SPI_I2S_ReceiveData(instance);
|
b = SPI_I2S_ReceiveData(instance);
|
||||||
#endif
|
#endif
|
||||||
if (out)
|
if (in)
|
||||||
*(out++) = b;
|
*(in++) = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -88,7 +88,7 @@ void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor);
|
||||||
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t in);
|
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t in);
|
||||||
bool spiIsBusBusy(SPI_TypeDef *instance);
|
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);
|
uint16_t spiGetErrorCounter(SPI_TypeDef *instance);
|
||||||
void spiResetErrorCounter(SPI_TypeDef *instance);
|
void spiResetErrorCounter(SPI_TypeDef *instance);
|
||||||
|
|
|
@ -261,22 +261,22 @@ bool spiIsBusBusy(SPI_TypeDef *instance)
|
||||||
return false;
|
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);
|
SPIDevice device = spiDeviceByInstance(instance);
|
||||||
HAL_StatusTypeDef status;
|
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
|
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)
|
if ( status != HAL_OK)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue