mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 11:29:58 +03:00
Renaming serialRead to softSerialRead. Adding serialRead to serial API and updating calls to uartRead and softSerialRead to use the serial API. Renamed uartPrint to serialPrint which now works on any serialPort implementation.
This commit is contained in:
parent
a6f6a5e28b
commit
2ff881aa69
10 changed files with 45 additions and 35 deletions
1
Makefile
1
Makefile
|
@ -59,6 +59,7 @@ COMMON_SRC = startup_stm32f10x_md_gcc.S \
|
|||
drv_i2c.c \
|
||||
drv_i2c_soft.c \
|
||||
drv_system.c \
|
||||
drv_serial.c \
|
||||
drv_uart.c \
|
||||
printf.c \
|
||||
utils.c \
|
||||
|
|
|
@ -932,7 +932,7 @@ void cliProcess(void)
|
|||
}
|
||||
|
||||
while (serialTotalBytesWaiting(core.mainport)) {
|
||||
uint8_t c = uartRead((uartPort_t *)core.mainport);
|
||||
uint8_t c = serialRead(core.mainport);
|
||||
if (c == '\t' || c == '?') {
|
||||
// do tab completion
|
||||
const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
|
||||
|
|
10
src/drv_serial.c
Normal file
10
src/drv_serial.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "board.h"
|
||||
|
||||
|
||||
void serialPrint(serialPort_t *instance, const char *str)
|
||||
{
|
||||
uint8_t ch;
|
||||
while ((ch = *(str++))) {
|
||||
serialWrite(instance, ch);
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ typedef struct serialPort {
|
|||
struct serialPortVTable {
|
||||
void (*serialWrite)(serialPort_t *instance, uint8_t ch);
|
||||
uint8_t (*serialTotalBytesWaiting)(serialPort_t *instance);
|
||||
|
||||
uint8_t (*serialRead)(serialPort_t *instance);
|
||||
};
|
||||
|
||||
static inline void serialWrite(serialPort_t *instance, uint8_t ch)
|
||||
|
@ -41,3 +41,10 @@ static inline uint8_t serialTotalBytesWaiting(serialPort_t *instance)
|
|||
{
|
||||
return instance->vTable->serialTotalBytesWaiting(instance);
|
||||
}
|
||||
|
||||
static inline uint8_t serialRead(serialPort_t *instance)
|
||||
{
|
||||
return instance->vTable->serialRead(instance);
|
||||
}
|
||||
|
||||
void serialPrint(serialPort_t *instance, const char *str);
|
||||
|
|
|
@ -280,19 +280,19 @@ static void moveHeadToNextByte(softSerial_t *softSerial)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t serialReadByte(softSerial_t *softSerial)
|
||||
uint8_t softSerialReadByte(serialPort_t *instance)
|
||||
{
|
||||
if (softSerialTotalBytesWaiting((serialPort_t*)softSerial) == 0) {
|
||||
if (softSerialTotalBytesWaiting(instance) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char b = softSerial->port.rxBuffer[softSerial->port.rxBufferHead];
|
||||
char b = instance->rxBuffer[instance->rxBufferHead];
|
||||
|
||||
moveHeadToNextByte(softSerial);
|
||||
moveHeadToNextByte((softSerial_t *)instance);
|
||||
return b;
|
||||
}
|
||||
|
||||
void serialWriteByte(serialPort_t *s, uint8_t ch)
|
||||
void softSerialWriteByte(serialPort_t *s, uint8_t ch)
|
||||
{
|
||||
s->txBuffer[s->txBufferHead] = ch;
|
||||
s->txBufferHead = (s->txBufferHead + 1) % s->txBufferSize;
|
||||
|
@ -300,13 +300,9 @@ void serialWriteByte(serialPort_t *s, uint8_t ch)
|
|||
}
|
||||
|
||||
const struct serialPortVTable softSerialVTable[] = {
|
||||
{ serialWriteByte, softSerialTotalBytesWaiting }
|
||||
};
|
||||
|
||||
void serialPrint(softSerial_t *softSerial, const char *str)
|
||||
{
|
||||
uint8_t ch;
|
||||
while ((ch = *(str++))) {
|
||||
serialWrite((serialPort_t *)softSerial, ch);
|
||||
}
|
||||
softSerialWriteByte,
|
||||
softSerialTotalBytesWaiting,
|
||||
softSerialReadByte
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,11 +35,10 @@ extern const struct serialPortVTable softSerialVTable[];
|
|||
|
||||
void setupSoftSerial1(uint32_t baud);
|
||||
|
||||
uint8_t serialReadByte(softSerial_t *softSerial);
|
||||
uint8_t softSerialReadByte(serialPort_t *instance);
|
||||
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance);
|
||||
|
||||
void softSerialWriteByte(serialPort_t *instance, uint8_t ch);
|
||||
void serialPrint(softSerial_t *softSerial, const char *str);
|
||||
|
||||
extern timerHardware_t* serialTimerHardware;
|
||||
extern softSerial_t softSerialPorts[];
|
||||
|
|
|
@ -229,9 +229,10 @@ bool isUartTransmitEmpty(uartPort_t *s)
|
|||
return s->port.txBufferTail == s->port.txBufferHead;
|
||||
}
|
||||
|
||||
uint8_t uartRead(uartPort_t *s)
|
||||
uint8_t uartRead(serialPort_t *instance)
|
||||
{
|
||||
uint8_t ch;
|
||||
uartPort_t *s = (uartPort_t *)instance;
|
||||
|
||||
if (s->rxDMAChannel) {
|
||||
ch = s->port.rxBuffer[s->port.rxBufferSize - s->rxDMAPos];
|
||||
|
@ -260,16 +261,12 @@ void uartWrite(serialPort_t *instance, uint8_t ch)
|
|||
}
|
||||
|
||||
const struct serialPortVTable uartVTable[] = {
|
||||
{ uartWrite, uartTotalBytesWaiting }
|
||||
};
|
||||
|
||||
void uartPrint(uartPort_t *s, const char *str)
|
||||
{
|
||||
uint8_t ch;
|
||||
while ((ch = *(str++))) {
|
||||
uartWrite((serialPort_t *)s, ch);
|
||||
}
|
||||
uartWrite,
|
||||
uartTotalBytesWaiting,
|
||||
uartRead
|
||||
}
|
||||
};
|
||||
|
||||
// Handlers
|
||||
|
||||
|
|
|
@ -32,6 +32,5 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback,
|
|||
void uartChangeBaud(uartPort_t *s, uint32_t baudRate);
|
||||
uint8_t uartTotalBytesWaiting(serialPort_t *instance);
|
||||
bool isUartTransmitEmpty(uartPort_t *s);
|
||||
uint8_t uartRead(uartPort_t *s);
|
||||
uint8_t uartRead(serialPort_t *instance);
|
||||
void uartWrite(serialPort_t *instance, uint8_t ch);
|
||||
void uartPrint(uartPort_t *s, const char *str);
|
||||
|
|
|
@ -132,7 +132,8 @@ int main(void)
|
|||
serialInit(mcfg.serial_baudrate);
|
||||
#ifdef SOFTSERIAL_19200_LOOPBACK
|
||||
setupSoftSerial1(19200);
|
||||
serialPrint(&(softSerialPorts[0]), "LOOPBACK 19200 ENABLED\r\n");
|
||||
serialPort_t* loopbackPort = (serialPort_t*)&(softSerialPorts[0]);
|
||||
serialPrint(loopbackPort, "LOOPBACK 19200 ENABLED\r\n");
|
||||
#endif
|
||||
|
||||
previousTime = micros();
|
||||
|
@ -146,10 +147,10 @@ int main(void)
|
|||
while (1) {
|
||||
loop();
|
||||
#ifdef SOFTSERIAL_19200_LOOPBACK
|
||||
while (serialTotalBytesWaiting((serialPort_t *)&softSerialPorts[0])) {
|
||||
while (serialTotalBytesWaiting(loopbackPort)) {
|
||||
|
||||
uint8_t b = serialReadByte(&softSerialPorts[0]);
|
||||
serialWrite((serialPort_t*)&softSerialPorts[0], b);
|
||||
uint8_t b = serialRead(loopbackPort);
|
||||
serialWrite(loopbackPort, b);
|
||||
//uartWrite(core.mainport, b);
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -679,7 +679,7 @@ void serialCom(void)
|
|||
}
|
||||
|
||||
while (serialTotalBytesWaiting(core.mainport)) {
|
||||
c = uartRead((uartPort_t *)core.mainport);
|
||||
c = serialRead(core.mainport);
|
||||
|
||||
if (c_state == IDLE) {
|
||||
c_state = (c == '$') ? HEADER_START : IDLE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue