mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 06:15:16 +03:00
First cut at polymorphic serial port implementation. Split serialPort_t into uartPort_t and serialPort_t. Calls to uartWrite() can now be replaced with calls to serialWrite(). Replacing calls to serialWriteByte(softSerial_t*, char) with calls to serialWrite(serialPort_t*, char). This completes the proof of concept for polymorphic serial port implementations (uartPort and softSerialPort). 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. 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. Replacing calls to isUartTransmitEmpty with isSoftSerialTransmitBufferEmpty. Replacing remaing calls to uartWrite with serialWrite. Adding isSoftSerialTransmitBufferEmpty to the serial API. Adding serialSet/GetBaudRate to the serial API. Since softSerial does not implement serialSetBaudRate some GPS serial initialisation code has been updated. At this point it is probably possible to switch around all the ports and use a software serial implementation if desired. By Dominic Clifton / https://github.com/hydra/baseflight/ git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@423 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
38 lines
1.1 KiB
C
Executable file
38 lines
1.1 KiB
C
Executable file
#pragma once
|
|
|
|
#define UART_BUFFER_SIZE 64
|
|
|
|
#define UART1_RX_BUFFER_SIZE 256
|
|
#define UART1_TX_BUFFER_SIZE 256
|
|
#define UART2_RX_BUFFER_SIZE 128
|
|
#define UART2_TX_BUFFER_SIZE 64
|
|
#define MAX_SERIAL_PORTS 2
|
|
|
|
|
|
// FIXME this is a uart_t really. Move the generic properties into a separate structure (serialPort_t) and update the code to use it
|
|
typedef struct {
|
|
serialPort_t port;
|
|
|
|
// FIXME these are uart specific and do not belong in here
|
|
DMA_Channel_TypeDef *rxDMAChannel;
|
|
DMA_Channel_TypeDef *txDMAChannel;
|
|
|
|
uint32_t rxDMAIrq;
|
|
uint32_t txDMAIrq;
|
|
|
|
uint32_t rxDMAPos;
|
|
bool txDMAEmpty;
|
|
|
|
USART_TypeDef *USARTx;
|
|
} uartPort_t;
|
|
|
|
extern const struct serialPortVTable uartVTable[];
|
|
|
|
serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode);
|
|
|
|
// serialPort API
|
|
void uartWrite(serialPort_t *instance, uint8_t ch);
|
|
uint8_t uartTotalBytesWaiting(serialPort_t *instance);
|
|
uint8_t uartRead(serialPort_t *instance);
|
|
void uartSetBaudRate(serialPort_t *s, uint32_t baudRate);
|
|
bool isUartTransmitBufferEmpty(serialPort_t *s);
|