mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 07:15:18 +03:00
Update serial.c
This commit is contained in:
parent
df2ba31c1d
commit
7b7ee481db
1 changed files with 56 additions and 1 deletions
|
@ -36,6 +36,9 @@
|
||||||
#include "drivers/serial_uart.h"
|
#include "drivers/serial_uart.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "drivers/gpio.h"
|
||||||
|
#include "drivers/light_led.h"
|
||||||
|
|
||||||
#if defined(USE_VCP)
|
#if defined(USE_VCP)
|
||||||
#include "drivers/serial_usb_vcp.h"
|
#include "drivers/serial_usb_vcp.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -92,7 +95,7 @@ baudRate_e lookupBaudRateIndex(uint32_t baudRate)
|
||||||
return BAUD_AUTO;
|
return BAUD_AUTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static serialPortUsage_t *findSerialPortUsageByIdentifier(serialPortIdentifier_e identifier)
|
serialPortUsage_t *findSerialPortUsageByIdentifier(serialPortIdentifier_e identifier)
|
||||||
{
|
{
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||||
|
@ -421,3 +424,55 @@ void evaluateOtherData(serialPort_t *serialPort, uint8_t receivedChar)
|
||||||
systemResetToBootloader();
|
systemResetToBootloader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GPS) || ! defined(SKIP_SERIAL_PASSTHROUGH)
|
||||||
|
// Default data consumer for serialPassThrough.
|
||||||
|
static void nopConsumer(uint8_t data)
|
||||||
|
{
|
||||||
|
UNUSED(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
A high-level serial passthrough implementation. Used by cli to start an
|
||||||
|
arbitrary serial passthrough "proxy". Optional callbacks can be given to allow
|
||||||
|
for specialized data processing.
|
||||||
|
*/
|
||||||
|
void serialPassthrough(serialPort_t *left, serialPort_t *right, serialConsumer
|
||||||
|
*leftC, serialConsumer *rightC)
|
||||||
|
{
|
||||||
|
waitForSerialPortToFinishTransmitting(left);
|
||||||
|
waitForSerialPortToFinishTransmitting(right);
|
||||||
|
|
||||||
|
if (!leftC)
|
||||||
|
leftC = &nopConsumer;
|
||||||
|
if (!rightC)
|
||||||
|
rightC = &nopConsumer;
|
||||||
|
|
||||||
|
LED0_OFF;
|
||||||
|
LED1_OFF;
|
||||||
|
|
||||||
|
// Either port might be open in a mode other than MODE_RXTX. We rely on
|
||||||
|
// serialRxBytesWaiting() to do the right thing for a TX only port. No
|
||||||
|
// special handling is necessary OR performed.
|
||||||
|
while(1) {
|
||||||
|
// TODO: maintain a timestamp of last data received. Use this to
|
||||||
|
// implement a guard interval and check for `+++` as an escape sequence
|
||||||
|
// to return to CLI command mode.
|
||||||
|
// https://en.wikipedia.org/wiki/Escape_sequence#Modem_control
|
||||||
|
if (serialRxBytesWaiting(left)) {
|
||||||
|
LED0_ON;
|
||||||
|
uint8_t c = serialRead(left);
|
||||||
|
serialWrite(right, c);
|
||||||
|
leftC(c);
|
||||||
|
LED0_OFF;
|
||||||
|
}
|
||||||
|
if (serialRxBytesWaiting(right)) {
|
||||||
|
LED0_ON;
|
||||||
|
uint8_t c = serialRead(right);
|
||||||
|
serialWrite(left, c);
|
||||||
|
rightC(c);
|
||||||
|
LED0_OFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue