From 409147a29184de47c6b3180570616ea93914c260 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 5 Nov 2021 16:39:56 +1100 Subject: [PATCH] AP_RCProtocol: add support for DJI Fast SBUS It's just SBUS... but with increased opportunities for corruption --- libraries/AP_RCProtocol/AP_RCProtocol.cpp | 15 +++++++++++++-- libraries/AP_RCProtocol/AP_RCProtocol.h | 14 ++++++++++++++ libraries/AP_RCProtocol/AP_RCProtocol_SBUS.cpp | 9 ++++++--- libraries/AP_RCProtocol/AP_RCProtocol_SBUS.h | 4 ++-- libraries/AP_RCProtocol/SoftSerial.h | 2 ++ libraries/RC_Channel/RC_Channels_VarInfo.h | 2 +- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.cpp b/libraries/AP_RCProtocol/AP_RCProtocol.cpp index 72ea8dd778..e95d2c526a 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol.cpp @@ -39,12 +39,15 @@ void AP_RCProtocol::init() { backend[AP_RCProtocol::PPM] = new AP_RCProtocol_PPMSum(*this); backend[AP_RCProtocol::IBUS] = new AP_RCProtocol_IBUS(*this); - backend[AP_RCProtocol::SBUS] = new AP_RCProtocol_SBUS(*this, true); + backend[AP_RCProtocol::SBUS] = new AP_RCProtocol_SBUS(*this, true, 100000); +#if AP_RCPROTOCOL_FASTSBUS_ENABLED + backend[AP_RCProtocol::FASTSBUS] = new AP_RCProtocol_SBUS(*this, true, 200000); +#endif backend[AP_RCProtocol::DSM] = new AP_RCProtocol_DSM(*this); backend[AP_RCProtocol::SUMD] = new AP_RCProtocol_SUMD(*this); backend[AP_RCProtocol::SRXL] = new AP_RCProtocol_SRXL(*this); #ifndef IOMCU_FW - backend[AP_RCProtocol::SBUS_NI] = new AP_RCProtocol_SBUS(*this, false); + backend[AP_RCProtocol::SBUS_NI] = new AP_RCProtocol_SBUS(*this, false, 100000); backend[AP_RCProtocol::SRXL2] = new AP_RCProtocol_SRXL2(*this); backend[AP_RCProtocol::CRSF] = new AP_RCProtocol_CRSF(*this); backend[AP_RCProtocol::FPORT2] = new AP_RCProtocol_FPort2(*this, true); @@ -257,6 +260,10 @@ static const AP_RCProtocol::SerialConfig serial_configs[] { { 115200, 0, 1, true }, // SBUS settings, even parity, 2 stop bits: { 100000, 2, 2, true }, +#if AP_RCPROTOCOL_FASTSBUS_ENABLED + // FastSBUS: + { 200000, 2, 2, true }, +#endif // CrossFire: { 416666, 0, 1, false }, }; @@ -389,6 +396,10 @@ const char *AP_RCProtocol::protocol_name_from_protocol(rcprotocol_t protocol) case SBUS: case SBUS_NI: return "SBUS"; +#if AP_RCPROTOCOL_FASTSBUS_ENABLED + case FASTSBUS: + return "FastSBUS"; +#endif case DSM: return "DSM"; case SUMD: diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.h b/libraries/AP_RCProtocol/AP_RCProtocol.h index 2629e01406..55b1960bac 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol.h @@ -21,6 +21,14 @@ #define MAX_RCIN_CHANNELS 18 #define MIN_RCIN_CHANNELS 5 +#ifndef AP_RCPROTOCOL_FASTSBUS_ENABLED + #ifdef IOMCU_FW + #define AP_RCPROTOCOL_FASTSBUS_ENABLED 0 + #else + #define AP_RCPROTOCOL_FASTSBUS_ENABLED 1 + #endif +#endif + class AP_RCProtocol_Backend; class AP_RCProtocol { @@ -42,6 +50,9 @@ public: ST24 = 9, FPORT = 10, FPORT2 = 11, +#if AP_RCPROTOCOL_FASTSBUS_ENABLED + FASTSBUS = 12, +#endif NONE //last enum always is None }; void init(); @@ -64,6 +75,9 @@ public: bool requires_3_frames(enum rcprotocol_t p) { switch (p) { case DSM: +#if AP_RCPROTOCOL_FASTSBUS_ENABLED + case FASTSBUS: +#endif case SBUS: case SBUS_NI: case PPM: diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.cpp index 9def4c3490..1ab64ffc99 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.cpp @@ -76,9 +76,10 @@ #endif // constructor -AP_RCProtocol_SBUS::AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool _inverted) : +AP_RCProtocol_SBUS::AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool _inverted, uint32_t configured_baud) : AP_RCProtocol_Backend(_frontend), - inverted(_inverted) + inverted(_inverted), + ss{configured_baud, SoftSerial::SERIAL_CONFIG_8E2I} {} // decode a full SBUS frame @@ -211,7 +212,9 @@ void AP_RCProtocol_SBUS::_process_byte(uint32_t timestamp_us, uint8_t b) // support byte input void AP_RCProtocol_SBUS::process_byte(uint8_t b, uint32_t baudrate) { - if (baudrate != 100000) { + // note that if we're here we're not actually using SoftSerial, + // but it does record our configured baud rate: + if (baudrate != ss.baud()) { return; } _process_byte(AP_HAL::micros(), b); diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.h b/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.h index 3903fd1071..48923d22a4 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_SBUS.h @@ -22,7 +22,7 @@ class AP_RCProtocol_SBUS : public AP_RCProtocol_Backend { public: - AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool inverted); + AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool inverted, uint32_t configured_baud); void process_pulse(uint32_t width_s0, uint32_t width_s1) override; void process_byte(uint8_t byte, uint32_t baudrate) override; @@ -32,7 +32,7 @@ private: bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_values); bool inverted; - SoftSerial ss{100000, SoftSerial::SERIAL_CONFIG_8E2I}; + SoftSerial ss; uint32_t saved_width; struct { diff --git a/libraries/AP_RCProtocol/SoftSerial.h b/libraries/AP_RCProtocol/SoftSerial.h index 019d9232ea..3904429869 100644 --- a/libraries/AP_RCProtocol/SoftSerial.h +++ b/libraries/AP_RCProtocol/SoftSerial.h @@ -33,6 +33,8 @@ public: return byte_timestamp_us; } + uint32_t baud() const { return baudrate; } + private: const uint32_t baudrate; const uint8_t half_bit; // width of half a bit in microseconds diff --git a/libraries/RC_Channel/RC_Channels_VarInfo.h b/libraries/RC_Channel/RC_Channels_VarInfo.h index e9baf64ae9..80fc8c580a 100644 --- a/libraries/RC_Channel/RC_Channels_VarInfo.h +++ b/libraries/RC_Channel/RC_Channels_VarInfo.h @@ -96,7 +96,7 @@ const AP_Param::GroupInfo RC_Channels::var_info[] = { // @DisplayName: RC protocols enabled // @Description: Bitmask of enabled RC protocols. Allows narrowing the protocol detection to only specific types of RC receivers which can avoid issues with incorrect detection. Set to 1 to enable all protocols. // @User: Advanced - // @Bitmask: 0:All,1:PPM,2:IBUS,3:SBUS,4:SBUS_NI,5:DSM,6:SUMD,7:SRXL,8:SRXL2,9:CRSF,10:ST24,11:FPORT,12:FPORT2 + // @Bitmask: 0:All,1:PPM,2:IBUS,3:SBUS,4:SBUS_NI,5:DSM,6:SUMD,7:SRXL,8:SRXL2,9:CRSF,10:ST24,11:FPORT,12:FPORT2,13:FastSBUS AP_GROUPINFO("_PROTOCOLS", 34, RC_CHANNELS_SUBCLASS, _protocols, 1), AP_GROUPEND