Skip to content

Commit 3cc11ce

Browse files
authored
Merge pull request #10271 from MUSTARDTIGERFPV/serialpassthrough-modes
Allow serialpassthrough to set parity & stop bits
2 parents 265cd57 + 81bed95 commit 3cc11ce

File tree

11 files changed

+109
-3
lines changed

11 files changed

+109
-3
lines changed

docs/Cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ While connected to the CLI, all Logical Switches are temporarily disabled (5.1.0
107107
| `save` | Save and reboot |
108108
| `sd_info` | Sdcard info |
109109
| `serial` | Configure serial ports. [Usage](Serial.md) |
110-
| `serialpassthrough` | Passthrough serial data to port, with `<id> <baud> <mode>`, where `id` is the zero based port index, `baud` is a standard baud rate, and mode is `rx`, `tx`, or both (`rxtx`) |
110+
| `serialpassthrough` | Passthrough serial data to port, with `<id> <baud> <mode> <options>`, where `id` is the zero based port index, `baud` is a standard baud rate, mode is `rx`, `tx`, or both (`rxtx`), and options is a short string like `8N1` or `8E2` |
111111
| `servo` | Configure servos |
112112
| `set` | Change setting with name=value or blank or * for list |
113113
| `smix` | Custom servo mixer |

src/main/drivers/serial.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ void serialSetMode(serialPort_t *instance, portMode_t mode)
8686
instance->vTable->setMode(instance, mode);
8787
}
8888

89+
void serialSetOptions(serialPort_t *instance, portOptions_t options)
90+
{
91+
instance->vTable->setOptions(instance, options);
92+
}
93+
8994
void serialWriteBufShim(void *instance, const uint8_t *data, int count)
9095
{
9196
serialWriteBuf((serialPort_t *)instance, data, count);

src/main/drivers/serial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct serialPortVTable {
9595

9696
void (*setMode)(serialPort_t *instance, portMode_t mode);
9797

98+
void (*setOptions)(serialPort_t *instance, portOptions_t options);
99+
98100
void (*writeBuf)(serialPort_t *instance, const void *data, int count);
99101

100102
bool (*isConnected)(const serialPort_t *instance);
@@ -113,6 +115,7 @@ void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count);
113115
uint8_t serialRead(serialPort_t *instance);
114116
void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate);
115117
void serialSetMode(serialPort_t *instance, portMode_t mode);
118+
void serialSetOptions(serialPort_t *instance, portOptions_t options);
116119
bool isSerialTransmitBufferEmpty(const serialPort_t *instance);
117120
void serialPrint(serialPort_t *instance, const char *str);
118121
uint32_t serialGetBaudRate(serialPort_t *instance);

src/main/drivers/serial_softserial.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ void softSerialSetMode(serialPort_t *instance, portMode_t mode)
623623
instance->mode = mode;
624624
}
625625

626+
void softSerialSetOptions(serialPort_t *instance, portOptions_t options)
627+
{
628+
instance->options = options;
629+
}
630+
626631
bool isSoftSerialTransmitBufferEmpty(const serialPort_t *instance)
627632
{
628633
return instance->txBufferHead == instance->txBufferTail;
@@ -636,6 +641,7 @@ static const struct serialPortVTable softSerialVTable = {
636641
.serialSetBaudRate = softSerialSetBaudRate,
637642
.isSerialTransmitBufferEmpty = isSoftSerialTransmitBufferEmpty,
638643
.setMode = softSerialSetMode,
644+
.setOptions = softSerialSetOptions,
639645
.isConnected = NULL,
640646
.writeBuf = NULL,
641647
.beginWrite = NULL,

src/main/drivers/serial_tcp.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ void tcpSetMode(serialPort_t *instance, portMode_t mode)
317317
UNUSED(mode);
318318
}
319319

320+
void tcpSetOptions(serialPort_t *instance, portOptions_t options)
321+
{
322+
UNUSED(instance);
323+
UNUSED(options);
324+
}
325+
320326
static const struct serialPortVTable tcpVTable[] = {
321327
{
322328
.serialWrite = tcpWrite,
@@ -326,6 +332,7 @@ static const struct serialPortVTable tcpVTable[] = {
326332
.serialSetBaudRate = tcpSetBaudRate,
327333
.isSerialTransmitBufferEmpty = isTcpTransmitBufferEmpty,
328334
.setMode = tcpSetMode,
335+
.setOptions = tcpSetOptions,
329336
.isConnected = tcpIsConnected,
330337
.writeBuf = tcpWritBuf,
331338
.beginWrite = NULL,

src/main/drivers/serial_uart.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
175175
uartReconfigure(uartPort);
176176
}
177177

178+
void uartSetOptions(serialPort_t *instance, portOptions_t options)
179+
{
180+
uartPort_t *uartPort = (uartPort_t *)instance;
181+
uartPort->port.options = options;
182+
uartReconfigure(uartPort);
183+
}
184+
178185
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
179186
{
180187
const uartPort_t *s = (const uartPort_t*)instance;
@@ -255,6 +262,7 @@ const struct serialPortVTable uartVTable[] = {
255262
.serialSetBaudRate = uartSetBaudRate,
256263
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
257264
.setMode = uartSetMode,
265+
.setOptions = uartSetOptions,
258266
.isConnected = NULL,
259267
.writeBuf = NULL,
260268
.beginWrite = NULL,

src/main/drivers/serial_uart_hal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
185185
uartReconfigure(uartPort);
186186
}
187187

188+
void uartSetOptions(serialPort_t *instance, portOptions_t options)
189+
{
190+
uartPort_t *uartPort = (uartPort_t *)instance;
191+
uartPort->port.options = options;
192+
uartReconfigure(uartPort);
193+
}
194+
188195
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
189196
{
190197
uartPort_t *s = (uartPort_t*)instance;
@@ -266,6 +273,7 @@ const struct serialPortVTable uartVTable[] = {
266273
.serialSetBaudRate = uartSetBaudRate,
267274
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
268275
.setMode = uartSetMode,
276+
.setOptions = uartSetOptions,
269277
.isConnected = NULL,
270278
.writeBuf = NULL,
271279
.beginWrite = NULL,

src/main/drivers/serial_uart_hal_at32f43x.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
178178
uartReconfigure(uartPort);
179179
}
180180

181+
void uartSetOptions(serialPort_t *instance, portOptions_t options)
182+
{
183+
uartPort_t *uartPort = (uartPort_t *)instance;
184+
uartPort->port.options = options;
185+
uartReconfigure(uartPort);
186+
}
187+
181188
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
182189
{
183190
const uartPort_t *s = (const uartPort_t*)instance;
@@ -260,6 +267,7 @@ const struct serialPortVTable uartVTable[] = {
260267
.serialSetBaudRate = uartSetBaudRate,
261268
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
262269
.setMode = uartSetMode,
270+
.setOptions = uartSetOptions,
263271
.isConnected = NULL,
264272
.writeBuf = NULL,
265273
.beginWrite = NULL,

src/main/drivers/serial_usb_vcp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
6767
// TODO implement
6868
}
6969

70+
static void usbVcpSetOptions(serialPort_t *instance, portOptions_t options)
71+
{
72+
UNUSED(instance);
73+
UNUSED(options);
74+
75+
// TODO implement
76+
}
77+
7078
static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance)
7179
{
7280
UNUSED(instance);
@@ -184,6 +192,7 @@ static const struct serialPortVTable usbVTable[] = {
184192
.serialSetBaudRate = usbVcpSetBaudRate,
185193
.isSerialTransmitBufferEmpty = isUsbVcpTransmitBufferEmpty,
186194
.setMode = usbVcpSetMode,
195+
.setOptions = usbVcpSetOptions,
187196
.isConnected = usbVcpIsConnected,
188197
.writeBuf = usbVcpWriteBuf,
189198
.beginWrite = usbVcpBeginWrite,

src/main/drivers/serial_usb_vcp_at32f43x.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
308308
UNUSED(mode);
309309
}
310310

311+
static void usbVcpSetOptions(serialPort_t *instance, portOptions_t options)
312+
{
313+
UNUSED(instance);
314+
UNUSED(options);
315+
}
316+
311317
static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance)
312318
{
313319
UNUSED(instance);
@@ -434,6 +440,7 @@ static const struct serialPortVTable usbVTable[] = {
434440
.serialSetBaudRate = usbVcpSetBaudRate,
435441
.isSerialTransmitBufferEmpty = isUsbVcpTransmitBufferEmpty,
436442
.setMode = usbVcpSetMode,
443+
.setOptions = usbVcpSetOptions,
437444
.isConnected = usbVcpIsConnected,
438445
.writeBuf = usbVcpWriteBuf,
439446
.beginWrite = usbVcpBeginWrite,

0 commit comments

Comments
 (0)