1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 14:55:21 +03:00

Added support for fast sbus2 protocol (used by newer receivers). Untested, thanks Cesco

This commit is contained in:
dongie 2014-02-19 16:36:10 +09:00
parent af13325f9e
commit 96dcfe9174
4 changed files with 539 additions and 535 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,10 @@
#pragma once #pragma once
typedef enum portMode_t { typedef enum portMode_t {
MODE_RX = 1, MODE_RX = 1 << 0,
MODE_TX = 2, MODE_TX = 1 << 1,
MODE_RXTX = MODE_RX | MODE_TX MODE_RXTX = MODE_RX | MODE_TX,
MODE_SBUS = 1 << 2,
} portMode_t; } portMode_t;
typedef struct serialPort { typedef struct serialPort {

View file

@ -120,8 +120,13 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback,
USART_InitStructure.USART_BaudRate = baudRate; USART_InitStructure.USART_BaudRate = baudRate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b; 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_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_Parity = USART_Parity_No;
}
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = 0; USART_InitStructure.USART_Mode = 0;
if (mode & MODE_RX) if (mode & MODE_RX)

View file

@ -6,7 +6,6 @@
#define SBUS_MAX_CHANNEL 8 #define SBUS_MAX_CHANNEL 8
#define SBUS_FRAME_SIZE 25 #define SBUS_FRAME_SIZE 25
#define SBUS_SYNCBYTE 0x0F #define SBUS_SYNCBYTE 0x0F
#define SBUS_ENDBYTE 0x00
#define SBUS_OFFSET 988 #define SBUS_OFFSET 988
static bool sbusFrameDone = false; static bool sbusFrameDone = false;
@ -23,7 +22,7 @@ void sbusInit(rcReadRawDataPtr *callback)
int b; int b;
for (b = 0; b < SBUS_MAX_CHANNEL; b ++) for (b = 0; b < SBUS_MAX_CHANNEL; b ++)
sbusChannelData[b] = 2 * (mcfg.midrc - SBUS_OFFSET); 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) if (callback)
*callback = sbusReadRawRC; *callback = sbusReadRawRC;
core.numRCChannels = SBUS_MAX_CHANNEL; core.numRCChannels = SBUS_MAX_CHANNEL;
@ -61,7 +60,7 @@ static void sbusDataReceive(uint16_t c)
static uint8_t sbusFramePosition; static uint8_t sbusFramePosition;
sbusTime = micros(); sbusTime = micros();
if ((sbusTime - sbusTimeLast) > 4000) if ((sbusTime - sbusTimeLast) > 2500) // sbus2 fast timing
sbusFramePosition = 0; sbusFramePosition = 0;
sbusTimeLast = sbusTime; sbusTimeLast = sbusTime;
@ -73,7 +72,6 @@ static void sbusDataReceive(uint16_t c)
sbus.in[sbusFramePosition - 1] = (uint8_t)c; sbus.in[sbusFramePosition - 1] = (uint8_t)c;
if (sbusFramePosition == SBUS_FRAME_SIZE - 1) { if (sbusFramePosition == SBUS_FRAME_SIZE - 1) {
if (sbus.in[sbusFramePosition - 1] == SBUS_ENDBYTE)
sbusFrameDone = true; sbusFrameDone = true;
sbusFramePosition = 0; sbusFramePosition = 0;
} else { } else {