mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
Currently port usage is hard-coded to the default port layout, cli commands are coming in a future commit. This decouples all code from the global 'serialPorts' structure which has been removed. Any code that needs to use a serial port can use findOpenSerialPort() and openSerialPort() and maintain it's own reference to the port. Ports can switch between functions. e.g. by default cli/msp/telemetry/gps passthrough all use USART1. Each port maintains it's current function. see begin/endSerialPortFunction. There are only certain combinations of serial port functions that are supported, these are listed in serialPortFunctionScenario_e. This commit also adds a few 'static' keywords to variables that should have been. There a a few other minor fixes and tweaks to various bits of code that this uncovered too.
61 lines
1.9 KiB
C
61 lines
1.9 KiB
C
#pragma once
|
|
|
|
|
|
typedef enum {
|
|
SERIAL_NOT_INVERTED = 0,
|
|
SERIAL_INVERTED
|
|
} serialInversion_e;
|
|
|
|
typedef enum portMode_t {
|
|
MODE_RX = 1 << 0,
|
|
MODE_TX = 1 << 1,
|
|
MODE_RXTX = MODE_RX | MODE_TX,
|
|
MODE_SBUS = 1 << 2,
|
|
} portMode_t;
|
|
|
|
typedef void (* serialReceiveCallbackPtr)(uint16_t data); // used by serial drivers to return frames to app
|
|
|
|
typedef struct serialPort {
|
|
|
|
const struct serialPortVTable *vTable;
|
|
uint8_t identifier;
|
|
portMode_t mode;
|
|
serialInversion_e inversion;
|
|
uint32_t baudRate;
|
|
|
|
uint32_t rxBufferSize;
|
|
uint32_t txBufferSize;
|
|
volatile uint8_t *rxBuffer;
|
|
volatile uint8_t *txBuffer;
|
|
uint32_t rxBufferHead;
|
|
uint32_t rxBufferTail;
|
|
uint32_t txBufferHead;
|
|
uint32_t txBufferTail;
|
|
|
|
// FIXME rename member to rxCallback
|
|
serialReceiveCallbackPtr callback;
|
|
} serialPort_t;
|
|
|
|
struct serialPortVTable {
|
|
void (*serialWrite)(serialPort_t *instance, uint8_t ch);
|
|
|
|
uint8_t (*serialTotalBytesWaiting)(serialPort_t *instance);
|
|
|
|
uint8_t (*serialRead)(serialPort_t *instance);
|
|
|
|
// Specified baud rate may not be allowed by an implementation, use serialGetBaudRate to determine actual baud rate in use.
|
|
void (*serialSetBaudRate)(serialPort_t *instance, uint32_t baudRate);
|
|
|
|
bool (*isSerialTransmitBufferEmpty)(serialPort_t *instance);
|
|
|
|
void (*setMode)(serialPort_t *instance, portMode_t mode);
|
|
};
|
|
|
|
inline void serialWrite(serialPort_t *instance, uint8_t ch);
|
|
inline uint8_t serialTotalBytesWaiting(serialPort_t *instance);
|
|
inline uint8_t serialRead(serialPort_t *instance);
|
|
inline void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate);
|
|
void serialSetMode(serialPort_t *instance, portMode_t mode);
|
|
inline bool isSerialTransmitBufferEmpty(serialPort_t *instance);
|
|
void serialPrint(serialPort_t *instance, const char *str);
|
|
uint32_t serialGetBaudRate(serialPort_t *instance);
|