mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Added support for fast sbus2 protocol (used by newer receivers). Untested, thanks Cesco
This commit is contained in:
parent
af13325f9e
commit
96dcfe9174
4 changed files with 539 additions and 535 deletions
1050
obj/baseflight.hex
1050
obj/baseflight.hex
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
typedef enum portMode_t {
|
||||
MODE_RX = 1,
|
||||
MODE_TX = 2,
|
||||
MODE_RXTX = MODE_RX | MODE_TX
|
||||
MODE_RX = 1 << 0,
|
||||
MODE_TX = 1 << 1,
|
||||
MODE_RXTX = MODE_RX | MODE_TX,
|
||||
MODE_SBUS = 1 << 2,
|
||||
} portMode_t;
|
||||
|
||||
typedef struct serialPort {
|
||||
|
|
|
@ -120,8 +120,13 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback,
|
|||
|
||||
USART_InitStructure.USART_BaudRate = baudRate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
if (mode & MODE_SBUS) {
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_2;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_Even;
|
||||
} else {
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
}
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = 0;
|
||||
if (mode & MODE_RX)
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#define SBUS_MAX_CHANNEL 8
|
||||
#define SBUS_FRAME_SIZE 25
|
||||
#define SBUS_SYNCBYTE 0x0F
|
||||
#define SBUS_ENDBYTE 0x00
|
||||
#define SBUS_OFFSET 988
|
||||
|
||||
static bool sbusFrameDone = false;
|
||||
|
@ -23,7 +22,7 @@ void sbusInit(rcReadRawDataPtr *callback)
|
|||
int b;
|
||||
for (b = 0; b < SBUS_MAX_CHANNEL; b ++)
|
||||
sbusChannelData[b] = 2 * (mcfg.midrc - SBUS_OFFSET);
|
||||
core.rcvrport = uartOpen(USART2, sbusDataReceive, 100000, MODE_RX);
|
||||
core.rcvrport = uartOpen(USART2, sbusDataReceive, 100000, MODE_RX | MODE_SBUS);
|
||||
if (callback)
|
||||
*callback = sbusReadRawRC;
|
||||
core.numRCChannels = SBUS_MAX_CHANNEL;
|
||||
|
@ -61,7 +60,7 @@ static void sbusDataReceive(uint16_t c)
|
|||
static uint8_t sbusFramePosition;
|
||||
|
||||
sbusTime = micros();
|
||||
if ((sbusTime - sbusTimeLast) > 4000)
|
||||
if ((sbusTime - sbusTimeLast) > 2500) // sbus2 fast timing
|
||||
sbusFramePosition = 0;
|
||||
sbusTimeLast = sbusTime;
|
||||
|
||||
|
@ -73,7 +72,6 @@ static void sbusDataReceive(uint16_t c)
|
|||
sbus.in[sbusFramePosition - 1] = (uint8_t)c;
|
||||
|
||||
if (sbusFramePosition == SBUS_FRAME_SIZE - 1) {
|
||||
if (sbus.in[sbusFramePosition - 1] == SBUS_ENDBYTE)
|
||||
sbusFrameDone = true;
|
||||
sbusFramePosition = 0;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue