mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 03:20:00 +03:00
Renaming isSerialAvailable to uartTotalBytesWaiting. Renaming serialAvailable to softSerialTotalBytesWaiting. Adding serialTotalBytesWaiting to serial API and updating calls to the former methods to use the serial API.
This commit is contained in:
parent
97f54561f0
commit
a6f6a5e28b
8 changed files with 21 additions and 11 deletions
|
@ -931,7 +931,7 @@ void cliProcess(void)
|
||||||
cliPrompt();
|
cliPrompt();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (isUartAvailable((uartPort_t *)core.mainport)) {
|
while (serialTotalBytesWaiting(core.mainport)) {
|
||||||
uint8_t c = uartRead((uartPort_t *)core.mainport);
|
uint8_t c = uartRead((uartPort_t *)core.mainport);
|
||||||
if (c == '\t' || c == '?') {
|
if (c == '\t' || c == '?') {
|
||||||
// do tab completion
|
// do tab completion
|
||||||
|
|
|
@ -28,9 +28,16 @@ typedef struct serialPort {
|
||||||
|
|
||||||
struct serialPortVTable {
|
struct serialPortVTable {
|
||||||
void (*serialWrite)(serialPort_t *instance, uint8_t ch);
|
void (*serialWrite)(serialPort_t *instance, uint8_t ch);
|
||||||
|
uint8_t (*serialTotalBytesWaiting)(serialPort_t *instance);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void serialWrite(serialPort_t *instance, uint8_t ch)
|
static inline void serialWrite(serialPort_t *instance, uint8_t ch)
|
||||||
{
|
{
|
||||||
instance->vTable->serialWrite(instance, ch);
|
instance->vTable->serialWrite(instance, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint8_t serialTotalBytesWaiting(serialPort_t *instance)
|
||||||
|
{
|
||||||
|
return instance->vTable->serialTotalBytesWaiting(instance);
|
||||||
|
}
|
||||||
|
|
|
@ -255,8 +255,9 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t serialAvailable(softSerial_t *softSerial)
|
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
|
||||||
{
|
{
|
||||||
|
softSerial_t *softSerial = (softSerial_t *)instance;
|
||||||
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
|
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,7 @@ static void moveHeadToNextByte(softSerial_t *softSerial)
|
||||||
|
|
||||||
uint8_t serialReadByte(softSerial_t *softSerial)
|
uint8_t serialReadByte(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
if (serialAvailable(softSerial) == 0) {
|
if (softSerialTotalBytesWaiting((serialPort_t*)softSerial) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +300,7 @@ void serialWriteByte(serialPort_t *s, uint8_t ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct serialPortVTable softSerialVTable[] = {
|
const struct serialPortVTable softSerialVTable[] = {
|
||||||
{ serialWriteByte }
|
{ serialWriteByte, softSerialTotalBytesWaiting }
|
||||||
};
|
};
|
||||||
|
|
||||||
void serialPrint(softSerial_t *softSerial, const char *str)
|
void serialPrint(softSerial_t *softSerial, const char *str)
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern const struct serialPortVTable softSerialVTable[];
|
||||||
void setupSoftSerial1(uint32_t baud);
|
void setupSoftSerial1(uint32_t baud);
|
||||||
|
|
||||||
uint8_t serialReadByte(softSerial_t *softSerial);
|
uint8_t serialReadByte(softSerial_t *softSerial);
|
||||||
uint8_t serialAvailable(softSerial_t *softSerial);
|
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance);
|
||||||
|
|
||||||
void softSerialWriteByte(serialPort_t *instance, uint8_t ch);
|
void softSerialWriteByte(serialPort_t *instance, uint8_t ch);
|
||||||
void serialPrint(softSerial_t *softSerial, const char *str);
|
void serialPrint(softSerial_t *softSerial, const char *str);
|
||||||
|
|
|
@ -210,8 +210,10 @@ static void uartStartTxDMA(uartPort_t *s)
|
||||||
DMA_Cmd(s->txDMAChannel, ENABLE);
|
DMA_Cmd(s->txDMAChannel, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isUartAvailable(uartPort_t *s)
|
uint8_t uartTotalBytesWaiting(serialPort_t *instance)
|
||||||
{
|
{
|
||||||
|
uartPort_t *s = (uartPort_t*)instance;
|
||||||
|
// FIXME always returns 1 or 0, not the amount of bytes waiting
|
||||||
if (s->rxDMAChannel)
|
if (s->rxDMAChannel)
|
||||||
return s->rxDMAChannel->CNDTR != s->rxDMAPos;
|
return s->rxDMAChannel->CNDTR != s->rxDMAPos;
|
||||||
else
|
else
|
||||||
|
@ -258,7 +260,7 @@ void uartWrite(serialPort_t *instance, uint8_t ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct serialPortVTable uartVTable[] = {
|
const struct serialPortVTable uartVTable[] = {
|
||||||
{ uartWrite }
|
{ uartWrite, uartTotalBytesWaiting }
|
||||||
};
|
};
|
||||||
|
|
||||||
void uartPrint(uartPort_t *s, const char *str)
|
void uartPrint(uartPort_t *s, const char *str)
|
||||||
|
|
|
@ -30,7 +30,7 @@ extern const struct serialPortVTable uartVTable[];
|
||||||
|
|
||||||
serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode);
|
serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode);
|
||||||
void uartChangeBaud(uartPort_t *s, uint32_t baudRate);
|
void uartChangeBaud(uartPort_t *s, uint32_t baudRate);
|
||||||
bool isUartAvailable(uartPort_t *s);
|
uint8_t uartTotalBytesWaiting(serialPort_t *instance);
|
||||||
bool isUartTransmitEmpty(uartPort_t *s);
|
bool isUartTransmitEmpty(uartPort_t *s);
|
||||||
uint8_t uartRead(uartPort_t *s);
|
uint8_t uartRead(uartPort_t *s);
|
||||||
void uartWrite(serialPort_t *instance, uint8_t ch);
|
void uartWrite(serialPort_t *instance, uint8_t ch);
|
||||||
|
|
|
@ -146,7 +146,7 @@ int main(void)
|
||||||
while (1) {
|
while (1) {
|
||||||
loop();
|
loop();
|
||||||
#ifdef SOFTSERIAL_19200_LOOPBACK
|
#ifdef SOFTSERIAL_19200_LOOPBACK
|
||||||
while (serialAvailable(&softSerialPorts[0])) {
|
while (serialTotalBytesWaiting((serialPort_t *)&softSerialPorts[0])) {
|
||||||
|
|
||||||
uint8_t b = serialReadByte(&softSerialPorts[0]);
|
uint8_t b = serialReadByte(&softSerialPorts[0]);
|
||||||
serialWrite((serialPort_t*)&softSerialPorts[0], b);
|
serialWrite((serialPort_t*)&softSerialPorts[0], b);
|
||||||
|
|
|
@ -678,7 +678,7 @@ void serialCom(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (isUartAvailable((uartPort_t *)core.mainport)) {
|
while (serialTotalBytesWaiting(core.mainport)) {
|
||||||
c = uartRead((uartPort_t *)core.mainport);
|
c = uartRead((uartPort_t *)core.mainport);
|
||||||
|
|
||||||
if (c_state == IDLE) {
|
if (c_state == IDLE) {
|
||||||
|
@ -715,7 +715,7 @@ void serialCom(void)
|
||||||
c_state = IDLE;
|
c_state = IDLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cliMode && !isUartAvailable((uartPort_t *)core.telemport) && feature(FEATURE_TELEMETRY) && f.ARMED) { // The first 2 conditions should never evaluate to true but I'm putting it here anyway - silpstream
|
if (!cliMode && !serialTotalBytesWaiting(core.telemport) && feature(FEATURE_TELEMETRY) && f.ARMED) { // The first 2 conditions should never evaluate to true but I'm putting it here anyway - silpstream
|
||||||
sendTelemetry();
|
sendTelemetry();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue