From 0ce9ced1ae5c782c4563951d1a7cf270fc95b305 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 17:58:40 +1300 Subject: [PATCH 01/31] refactor(sketch layer): Remove redundant constructors These were being called twice, resulting in unnecessary bloat. --- src/CRSFforArduino.cpp | 45 +++++++++++++++--------------------------- src/CRSFforArduino.hpp | 1 - 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index 65eede1c..7e96912b 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -36,9 +36,6 @@ namespace sketchLayer */ CRSFforArduino::CRSFforArduino() { -#if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - _serialReceiver = new SerialReceiver(); -#endif } /** @@ -49,13 +46,6 @@ namespace sketchLayer */ CRSFforArduino::CRSFforArduino(HardwareSerial *serialPort) { -#if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - _serialReceiver = new SerialReceiver(serialPort); -#else - // Prevent compiler warnings - (void)rxPin; - (void)txPin; -#endif } /** @@ -64,9 +54,6 @@ namespace sketchLayer */ CRSFforArduino::~CRSFforArduino() { -#if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - delete _serialReceiver; -#endif } /** @@ -77,7 +64,7 @@ namespace sketchLayer bool CRSFforArduino::begin() { #if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - return _serialReceiver->begin(); + return this->SerialReceiver::begin(); #else // Return false if RC is disabled return false; @@ -91,7 +78,7 @@ namespace sketchLayer void CRSFforArduino::end() { #if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - _serialReceiver->end(); + this->SerialReceiver::end(); #endif } @@ -103,11 +90,11 @@ namespace sketchLayer void CRSFforArduino::update() { #if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 - _serialReceiver->processFrames(); + this->SerialReceiver::processFrames(); #endif #if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 - _serialReceiver->handleFlightMode(); + this->SerialReceiver::handleFlightMode(); #endif } @@ -121,7 +108,7 @@ namespace sketchLayer [[deprecated("Use RC channel callback instead")]] uint16_t CRSFforArduino::readRcChannel(uint8_t channel, bool raw) { #if CRSF_RC_ENABLED > 0 - return _serialReceiver->readRcChannel(channel - 1, raw); + return this->SerialReceiver::readRcChannel(channel - 1, raw); #else // Prevent compiler warnings (void)channel; @@ -141,7 +128,7 @@ namespace sketchLayer [[deprecated("Use RC channel callback instead")]] uint16_t CRSFforArduino::getChannel(uint8_t channel) { #if CRSF_RC_ENABLED > 0 - return _serialReceiver->getChannel(channel - 1); + return this->SerialReceiver::getChannel(channel - 1); #else // Prevent compiler warnings (void)channel; @@ -160,7 +147,7 @@ namespace sketchLayer uint16_t CRSFforArduino::rcToUs(uint16_t rc) { #if CRSF_RC_ENABLED > 0 - return _serialReceiver->rcToUs(rc); + return this->SerialReceiver::rcToUs(rc); #else // Prevent compiler warnings (void)rc; @@ -173,7 +160,7 @@ namespace sketchLayer void CRSFforArduino::setRcChannelsCallback(void (*callback)(serialReceiverLayer::rcChannels_t *rcChannels)) { #if CRSF_RC_ENABLED > 0 - _serialReceiver->setRcChannelsCallback(callback); + this->SerialReceiver::setRcChannelsCallback(callback); #else // Prevent compiler warnings (void)callback; @@ -183,7 +170,7 @@ namespace sketchLayer void CRSFforArduino::setLinkStatisticsCallback(void (*callback)(serialReceiverLayer::link_statistics_t linkStatistics)) { #if CRSF_LINK_STATISTICS_ENABLED > 0 - _serialReceiver->setLinkStatisticsCallback(callback); + this->SerialReceiver::setLinkStatisticsCallback(callback); #else // Prevent compiler warnings (void)callback; @@ -202,7 +189,7 @@ namespace sketchLayer bool CRSFforArduino::setFlightMode(serialReceiverLayer::flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) { #if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 - return _serialReceiver->setFlightMode(flightMode, channel - 1, _serialReceiver->usToRc(min), _serialReceiver->usToRc(max)); + return this->SerialReceiver::setFlightMode(flightMode, channel - 1, this->SerialReceiver::usToRc(min), this->SerialReceiver::usToRc(max)); #else // Prevent compiler warnings (void)flightMode; @@ -223,7 +210,7 @@ namespace sketchLayer void CRSFforArduino::setFlightModeCallback(void (*callback)(serialReceiverLayer::flightModeId_t flightMode)) { #if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 - _serialReceiver->setFlightModeCallback(callback); + this->SerialReceiver::setFlightModeCallback(callback); #else // Prevent compiler warnings (void)callback; @@ -240,7 +227,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteAttitude(int16_t roll, int16_t pitch, int16_t yaw) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_ATTITUDE_ENABLED > 0 - _serialReceiver->telemetryWriteAttitude(roll, pitch, yaw); + this->SerialReceiver::telemetryWriteAttitude(roll, pitch, yaw); #else // Prevent compiler warnings (void)roll; @@ -258,7 +245,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteBaroAltitude(uint16_t altitude, int16_t vario) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_BAROALTITUDE_ENABLED > 0 - _serialReceiver->telemetryWriteBaroAltitude(altitude, vario); + this->SerialReceiver::telemetryWriteBaroAltitude(altitude, vario); #else // Prevent compiler warnings (void)altitude; @@ -277,7 +264,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteBattery(float voltage, float current, uint32_t fuel, uint8_t percent) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_BATTERY_ENABLED > 0 - _serialReceiver->telemetryWriteBattery(voltage, current, fuel, percent); + this->SerialReceiver::telemetryWriteBattery(voltage, current, fuel, percent); #else // Prevent compiler warnings (void)voltage; @@ -295,7 +282,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteFlightMode(serialReceiverLayer::flightModeId_t flightMode) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 - _serialReceiver->telemetryWriteFlightMode(flightMode); + this->SerialReceiver::telemetryWriteFlightMode(flightMode); #else // Prevent compiler warnings (void)flightMode; @@ -330,7 +317,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteGPS(float latitude, float longitude, float altitude, float speed, float groundCourse, uint8_t satellites) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_GPS_ENABLED > 0 - _serialReceiver->telemetryWriteGPS(latitude, longitude, altitude, speed, groundCourse, satellites); + this->SerialReceiver::telemetryWriteGPS(latitude, longitude, altitude, speed, groundCourse, satellites); #else // Prevent compiler warnings (void)latitude; diff --git a/src/CRSFforArduino.hpp b/src/CRSFforArduino.hpp index 7243507f..d85d4fb4 100644 --- a/src/CRSFforArduino.hpp +++ b/src/CRSFforArduino.hpp @@ -64,7 +64,6 @@ namespace sketchLayer void telemetryWriteGPS(float latitude, float longitude, float altitude, float speed, float groundCourse, uint8_t satellites); private: - SerialReceiver *_serialReceiver; }; } // namespace sketchLayer From 37bf237c1059df4bce32070219e70d9a558a86d5 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:04:32 +1300 Subject: [PATCH 02/31] build(platformio): Exclude `cfa_code_test.cpp` from source filter --- targets/common.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/targets/common.ini b/targets/common.ini index 70029288..c84cb21b 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -33,6 +33,7 @@ platform = teensy@4.18.0 [env] framework = arduino build_src_filter = + -<../examples/platformio/cfa_code_test.cpp> +<../examples/platformio/main.cpp> +<*/*/*.cpp> +<*.cpp> From 62aea7feee66a3674d15f6b5beb028847dc41f85 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:12:59 +1300 Subject: [PATCH 03/31] build(platformio): Override default build source fiter when Development Mode is enabled --- platformio.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platformio.ini b/platformio.ini index 992cb147..69acff6d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -27,5 +27,9 @@ test_dir = ; [env:development] ; board = adafruit_metro_m4 +; build_src_filter = +; +<../examples/platformio/cfa_code_test.cpp> +; +<*/*/*.cpp> +; +<*.cpp> ; build_type = debug ; extends = env_common_samd51 From a67b8d0c3ef6da27b14a545151742953418c6314 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:20:04 +1300 Subject: [PATCH 04/31] chore(serial receiver interface): Remove commented out code --- src/SerialReceiver/SerialReceiver.cpp | 11 ----------- src/SerialReceiver/SerialReceiver.hpp | 6 +----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 2bf1bac2..42eb29be 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -92,7 +92,6 @@ namespace serialReceiverLayer // Debug. CRSF_DEBUG_SERIAL_PORT.print("[Serial Receiver | INFO]: Initialising... "); #endif - // _uart->enterCriticalSection(); #if CRSF_RC_ENABLED > 0 && CRSF_RC_INITIALISE_CHANNELS > 0 // Initialize the RC Channels. @@ -140,7 +139,6 @@ namespace serialReceiverLayer { delete ct; ct = nullptr; - // _uart->exitCriticalSection(); #if CRSF_DEBUG_ENABLED > 0 // Debug. @@ -158,8 +156,6 @@ namespace serialReceiverLayer // Check that the CRSF Protocol was initialized successfully. if (crsf == nullptr) { - // _uart->exitCriticalSection(); - #if CRSF_DEBUG_ENABLED > 0 // Debug. CRSF_DEBUG_SERIAL_PORT.println("\n[Serial Receiver | FATAL ERROR]: CRSF Protocol could not be initialized."); @@ -178,8 +174,6 @@ namespace serialReceiverLayer // Check that the telemetry was initialised successfully. if (telemetry == nullptr) { - // _uart->exitCriticalSection(); - #if CRSF_DEBUG_ENABLED > 0 // Debug. CRSF_DEBUG_SERIAL_PORT.println("\n[Serial Receiver | FATAL ERROR]: Telemetry could not be initialized."); @@ -190,8 +184,6 @@ namespace serialReceiverLayer telemetry->begin(); #endif - // _uart->exitCriticalSection(); - // Clear the UART buffer. _uart->flush(); while (_uart->available() > 0) @@ -214,9 +206,7 @@ namespace serialReceiverLayer _uart->read(); } - // _uart->enterCriticalSection(); _uart->end(); - // _uart->clearUART(); // Check if the CRSF Protocol was initialized. if (crsf != nullptr) @@ -233,7 +223,6 @@ namespace serialReceiverLayer delete telemetry; } #endif - // _uart->exitCriticalSection(); } #if CRSF_RC_ENABLED > 0 || CRSF_TELEMETRY_ENABLED > 0 || CRSF_LINK_STATISTICS_ENABLED > 0 diff --git a/src/SerialReceiver/SerialReceiver.hpp b/src/SerialReceiver/SerialReceiver.hpp index bac51812..3a6b78ce 100644 --- a/src/SerialReceiver/SerialReceiver.hpp +++ b/src/SerialReceiver/SerialReceiver.hpp @@ -54,13 +54,9 @@ namespace serialReceiverLayer uint16_t value[crsfProtocol::RC_CHANNEL_COUNT]; } rcChannels_t; - // Function pointer for RC Channels Callback + /* Function pointers for callbacks. */ typedef void (*rcChannelsCallback_t)(rcChannels_t *); - - // Function pointer for Flight Mode Callback typedef void (*flightModeCallback_t)(flightModeId_t); - - // Function pointer for Link Statistics Callback typedef void (*linkStatisticsCallback_t)(link_statistics_t); class SerialReceiver From 82bcb5aca0472a7eb8152beed389a04025657af2 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:31:08 +1300 Subject: [PATCH 05/31] refactor(serial receiver interface): Remove unnecessary null checks in `SerialReceiver::begin()` A hardware fault is triggered when there is insufficient memory available anyway. --- src/SerialReceiver/SerialReceiver.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 42eb29be..2cc74269 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -82,6 +82,7 @@ namespace serialReceiverLayer _rcChannels = nullptr; #if CRSF_FLIGHTMODES_ENABLED > 0 delete[] _flightModes; + _flightModes = nullptr; #endif #endif } @@ -152,17 +153,6 @@ namespace serialReceiverLayer // Initialize the CRSF Protocol. crsf = new CRSF(); - - // Check that the CRSF Protocol was initialized successfully. - if (crsf == nullptr) - { -#if CRSF_DEBUG_ENABLED > 0 - // Debug. - CRSF_DEBUG_SERIAL_PORT.println("\n[Serial Receiver | FATAL ERROR]: CRSF Protocol could not be initialized."); -#endif - return false; - } - crsf->begin(); crsf->setFrameTime(BAUD_RATE, 10); _uart->begin(BAUD_RATE); @@ -170,17 +160,6 @@ namespace serialReceiverLayer #if CRSF_TELEMETRY_ENABLED > 0 // Initialise telemetry. telemetry = new Telemetry(); - - // Check that the telemetry was initialised successfully. - if (telemetry == nullptr) - { -#if CRSF_DEBUG_ENABLED > 0 - // Debug. - CRSF_DEBUG_SERIAL_PORT.println("\n[Serial Receiver | FATAL ERROR]: Telemetry could not be initialized."); -#endif - return false; - } - telemetry->begin(); #endif @@ -213,6 +192,7 @@ namespace serialReceiverLayer { crsf->end(); delete crsf; + crsf = nullptr; } #if CRSF_TELEMETRY_ENABLED > 0 @@ -221,6 +201,7 @@ namespace serialReceiverLayer { telemetry->end(); delete telemetry; + telemetry = nullptr; } #endif } From a0b2e7eb1e2b7e5ad681d820fb4b42badbe3f944 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:45:06 +1300 Subject: [PATCH 06/31] style(serial receiver interface): Clean up comments and correctly annotate code --- src/SerialReceiver/SerialReceiver.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 2cc74269..a3431be1 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -90,14 +90,13 @@ namespace serialReceiverLayer bool SerialReceiver::begin() { #if CRSF_DEBUG_ENABLED > 0 - // Debug. CRSF_DEBUG_SERIAL_PORT.print("[Serial Receiver | INFO]: Initialising... "); #endif #if CRSF_RC_ENABLED > 0 && CRSF_RC_INITIALISE_CHANNELS > 0 - // Initialize the RC Channels. - // Arm is set to 178 (1000us) to prevent the FC from arming. - // Throttle is set to 172 (988us) to prevent the ESCs from arming. All other channels are set to 992 (1500us). + /* Initialize the RC Channels. + Arm is set to 178 (1000us) to prevent the FC from arming. + Throttle is set to 172 (988us) to prevent the ESCs from arming. All other channels are set to 992 (1500us). */ for (size_t i = 0; i < RC_CHANNEL_COUNT; i++) { #if CRSF_RC_INITIALISE_ARMCHANNEL > 0 && CRSF_RC_INITIALISE_THROTTLECHANNEL > 0 @@ -135,6 +134,8 @@ namespace serialReceiverLayer } #endif + /* Check if the target development board is + compatible with the CRSF Protocol, and return false if it isn't. */ CompatibilityTable *ct = new CompatibilityTable(); if (!ct->isDevboardCompatible(ct->getDevboardName())) { @@ -142,7 +143,6 @@ namespace serialReceiverLayer ct = nullptr; #if CRSF_DEBUG_ENABLED > 0 - // Debug. CRSF_DEBUG_SERIAL_PORT.println("\r\n[Serial Receiver | FATAL ERROR]: Devboard is not compatible with CRSF Protocol."); #endif return false; @@ -151,19 +151,18 @@ namespace serialReceiverLayer delete ct; ct = nullptr; - // Initialize the CRSF Protocol. + /* Initialise the CRSF Protocol and Telemetry. */ crsf = new CRSF(); crsf->begin(); crsf->setFrameTime(BAUD_RATE, 10); _uart->begin(BAUD_RATE); #if CRSF_TELEMETRY_ENABLED > 0 - // Initialise telemetry. telemetry = new Telemetry(); telemetry->begin(); #endif - // Clear the UART buffer. + /* Clear the UART buffers, and return true. */ _uart->flush(); while (_uart->available() > 0) { @@ -171,7 +170,6 @@ namespace serialReceiverLayer } #if CRSF_DEBUG_ENABLED > 0 - // Debug. CRSF_DEBUG_SERIAL_PORT.println("Done."); #endif return true; @@ -179,6 +177,7 @@ namespace serialReceiverLayer void SerialReceiver::end() { + /* Clear the UART buffers. */ _uart->flush(); while (_uart->available() > 0) { @@ -187,7 +186,8 @@ namespace serialReceiverLayer _uart->end(); - // Check if the CRSF Protocol was initialized. + /* Tear-down and destroy the + CRSF Protocol if it was initialised. */ if (crsf != nullptr) { crsf->end(); @@ -196,7 +196,8 @@ namespace serialReceiverLayer } #if CRSF_TELEMETRY_ENABLED > 0 - // Check if telemetry was initialized. + /* Tear-down and destroy the + Telemetry if it was initialised. */ if (telemetry != nullptr) { telemetry->end(); @@ -216,7 +217,6 @@ namespace serialReceiverLayer flushRemainingFrames(); #if CRSF_LINK_STATISTICS_ENABLED > 0 - // Handle link statistics. crsf->getLinkStatistics(&_linkStatistics); if (_linkStatisticsCallback != nullptr) { @@ -225,7 +225,6 @@ namespace serialReceiverLayer #endif #if CRSF_TELEMETRY_ENABLED > 0 - // Check if it is time to send telemetry. if (telemetry->update()) { telemetry->sendTelemetryData(_uart); @@ -235,7 +234,6 @@ namespace serialReceiverLayer } #if CRSF_RC_ENABLED > 0 - // Update the RC Channels. crsf->getFailSafe(&_rcChannels->failsafe); crsf->getRcChannels(_rcChannels->value); if (_rcChannelsCallback != nullptr) From 90354d8db72e25e173c6436c3a061863968fd94f Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:56:50 +1300 Subject: [PATCH 07/31] perf(serial receiver interface): Only process RC Channels and call the RC Channels Callback if a frame has been received Polling for RC channels when none have been received is unnecessary --- src/SerialReceiver/SerialReceiver.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index a3431be1..a8d25b4b 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -230,17 +230,17 @@ namespace serialReceiverLayer telemetry->sendTelemetryData(_uart); } #endif - } - } #if CRSF_RC_ENABLED > 0 - crsf->getFailSafe(&_rcChannels->failsafe); - crsf->getRcChannels(_rcChannels->value); - if (_rcChannelsCallback != nullptr) - { - _rcChannelsCallback(_rcChannels); - } + crsf->getFailSafe(&_rcChannels->failsafe); + crsf->getRcChannels(_rcChannels->value); + if (_rcChannelsCallback != nullptr) + { + _rcChannelsCallback(_rcChannels); + } #endif + } + } } #endif From 372cec52ddc4274295aa9c7d3a612e054eb5b993 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 18:59:52 +1300 Subject: [PATCH 08/31] chore(crsf): Remove commented out code --- src/SerialReceiver/CRSF/CRSF.cpp | 23 +---------------------- src/SerialReceiver/CRSF/CRSF.hpp | 2 -- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/SerialReceiver/CRSF/CRSF.cpp b/src/SerialReceiver/CRSF/CRSF.cpp index 54555f23..3156fdf6 100644 --- a/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/SerialReceiver/CRSF/CRSF.cpp @@ -48,24 +48,14 @@ namespace serialReceiverLayer frameCount = 0; timePerFrame = 0; - // #ifdef USE_DMA - // memset_dma(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // memset_dma(rcChannelsFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // #else memset(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); memset(rcChannelsFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // #endif } void CRSF::end() { - // #ifdef USE_DMA - // memset_dma(rcChannelsFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // memset_dma(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // #else memset(rcChannelsFrame.raw, 0, CRSF_FRAME_SIZE_MAX); memset(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // #endif timePerFrame = 0; frameCount = 0; @@ -120,15 +110,7 @@ namespace serialReceiverLayer case crsfProtocol::CRSF_FRAMETYPE_RC_CHANNELS_PACKED: if (rxFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) { - // #ifdef USE_DMA - // #ifdef __SAMD51__ - // memcpy(&rcChannelsFrame, &rxFrame, CRSF_FRAME_SIZE_MAX); // ◄ This is a workaround for the crash on SAMD51. - // #else - // memcpy_dma(&rcChannelsFrame, &rxFrame, CRSF_FRAME_SIZE_MAX); // ◄ This is the line that causes the crash on SAMD51. - // #endif - // #else memcpy(&rcChannelsFrame, &rxFrame, CRSF_FRAME_SIZE_MAX); - // #endif rcFrameReceived = true; } break; @@ -149,11 +131,8 @@ namespace serialReceiverLayer #endif } } - // #ifdef USE_DMA - // memset_dma(&rxFrame, 0, CRSF_FRAME_SIZE_MAX); // ◄ This line works fine on both SAMD21 and SAMD51. - // #else + memset(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); - // #endif framePosition = 0; return true; diff --git a/src/SerialReceiver/CRSF/CRSF.hpp b/src/SerialReceiver/CRSF/CRSF.hpp index 69b90e3d..cec3d7c5 100644 --- a/src/SerialReceiver/CRSF/CRSF.hpp +++ b/src/SerialReceiver/CRSF/CRSF.hpp @@ -31,7 +31,6 @@ namespace serialReceiverLayer { - // #if CRSF_LINK_STATISTICS_ENABLED > 0 typedef struct link_statistics_s { int16_t rssi = 0; @@ -51,7 +50,6 @@ namespace serialReceiverLayer 250, // 250 mW 50 // 50 mW }; - // #endif class CRSF { From 756ff7d45544bb9496b550fbb974d785b297697e Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 21:18:37 +1300 Subject: [PATCH 09/31] fix(flight modes): Resolve compilation error in `SerialReceiver::handleFlightMode()` --- src/SerialReceiver/SerialReceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index a8d25b4b..8231c67f 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -336,7 +336,7 @@ namespace serialReceiverLayer { for (size_t i = 0; i < (size_t)FLIGHT_MODE_COUNT; i++) { - if (_rcChannels[_flightModes[i].channel] >= _flightModes[i].min && _rcChannels[_flightModes[i].channel] <= _flightModes[i].max) + if (_rcChannels->value[_flightModes[i].channel] >= _flightModes[i].min && _rcChannels->value[_flightModes[i].channel] <= _flightModes[i].max) { _flightModeCallback((flightModeId_t)i); break; From b59e28786d9a94a6732b9a9deb675770b9c43aa0 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 13 Feb 2024 21:21:25 +1300 Subject: [PATCH 10/31] fix(crsf): Memory leak on `GenericCRC` object --- src/SerialReceiver/CRSF/CRSF.cpp | 1 + src/SerialReceiver/CRSF/CRSF.hpp | 2 +- src/SerialReceiver/Telemetry/Telemetry.cpp | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SerialReceiver/CRSF/CRSF.cpp b/src/SerialReceiver/CRSF/CRSF.cpp index 3156fdf6..d0316ecf 100644 --- a/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/SerialReceiver/CRSF/CRSF.cpp @@ -40,6 +40,7 @@ namespace serialReceiverLayer CRSF::~CRSF() { delete crc8; + crc8 = nullptr; } void CRSF::begin() diff --git a/src/SerialReceiver/CRSF/CRSF.hpp b/src/SerialReceiver/CRSF/CRSF.hpp index cec3d7c5..df44c51d 100644 --- a/src/SerialReceiver/CRSF/CRSF.hpp +++ b/src/SerialReceiver/CRSF/CRSF.hpp @@ -71,7 +71,7 @@ namespace serialReceiverLayer crsfProtocol::frame_t rxFrame; crsfProtocol::frame_t rcChannelsFrame; link_statistics_t linkStatistics; - genericCrc::GenericCRC *crc8; + genericCrc::GenericCRC *crc8 = nullptr; uint8_t calculateFrameCRC(); }; } // namespace serialReceiverLayer diff --git a/src/SerialReceiver/Telemetry/Telemetry.cpp b/src/SerialReceiver/Telemetry/Telemetry.cpp index 753883a2..e01ffb1b 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.cpp +++ b/src/SerialReceiver/Telemetry/Telemetry.cpp @@ -39,8 +39,7 @@ namespace serialReceiverLayer #define RAD PI / 180.0F #endif - Telemetry::Telemetry() : - GenericCRC(), SerialBuffer(CRSF_FRAME_SIZE_MAX) + Telemetry::Telemetry() : SerialBuffer(CRSF_FRAME_SIZE_MAX) { _telemetryFrameScheduleCount = 0; memset(_telemetryFrameSchedule, 0, sizeof(_telemetryFrameSchedule)); From 3541b81b77ef1623063f2738d939349a905df969 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 16 Feb 2024 09:22:09 +1300 Subject: [PATCH 11/31] chore(serial receiver interface): Remove commented out code --- src/SerialReceiver/SerialReceiver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 8231c67f..21ae25ae 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -397,7 +397,6 @@ namespace serialReceiverLayer break; } - // Serial.println(flightModeStr); telemetry->setFlightModeData(flightModeStr, (bool)(flightModeId == FLIGHT_MODE_DISARMED ? true : false)); } #endif From 50520a070455137068fcac8cbc76726e4755c8bd Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 16 Feb 2024 09:25:58 +1300 Subject: [PATCH 12/31] chore(compatibility table): Remove commented out code --- src/hal/CompatibilityTable/CompatibilityTable.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/hal/CompatibilityTable/CompatibilityTable.cpp b/src/hal/CompatibilityTable/CompatibilityTable.cpp index c0aabbb3..6ba0b42b 100644 --- a/src/hal/CompatibilityTable/CompatibilityTable.cpp +++ b/src/hal/CompatibilityTable/CompatibilityTable.cpp @@ -36,8 +36,6 @@ namespace hal */ CompatibilityTable::CompatibilityTable() { -// TEMPORARILY DISABLED: Arduino IDE must be 1.7.0 or greater -// #if ARDUINO >= 10700 // Arduino ESP32 Architecture #if defined(ARDUINO_ARCH_ESP32) @@ -566,10 +564,6 @@ as two separate boards. To prevent a false negative, check for both boards. */ #error "Unsupported architecture. CRSF for Arduino only supports the ESP32, SAMD, and Teensy architectures." device.type.devboard = DEVBOARD_IS_INCOMPATIBLE; #endif // ARDUINO_ARCH_SAMD - - // #else - // #error "This library requires Arduino IDE 1.7.0 or greater. Please update your IDE." - // #endif // ARDUINO >= 10700 } CompatibilityTable::~CompatibilityTable() From 1bafe0a1b5091ee3b5b2d5aaf6fe49287aa910dd Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 16 Feb 2024 09:29:45 +1300 Subject: [PATCH 13/31] chore(generic stream buffer): Remove commented out code --- src/SerialReceiver/SerialBuffer/SerialBuffer.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp index f7f4805d..96952b05 100644 --- a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp +++ b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp @@ -51,11 +51,7 @@ namespace genericStreamBuffer { bufferIndex = 0; bufferLength = 0; - // #ifdef USE_DMA - // memset_dma(buffer, 0, bufferSizeMax); - // #else memset(buffer, 0, bufferSizeMax); - // #endif } // Write signed integers in little endian From 9faa9da4ccd4329e2449c60439f3c6581bff6932 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 16 Feb 2024 09:31:35 +1300 Subject: [PATCH 14/31] chore(telemetry): Remove commented out code --- src/SerialReceiver/Telemetry/Telemetry.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/SerialReceiver/Telemetry/Telemetry.hpp b/src/SerialReceiver/Telemetry/Telemetry.hpp index a93f799f..ecdbab76 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.hpp +++ b/src/SerialReceiver/Telemetry/Telemetry.hpp @@ -50,7 +50,6 @@ namespace serialReceiverLayer void setBatteryData(float voltage, float current, uint32_t capacity, uint8_t percent); void setFlightModeData(const char *flightMode, bool armed = false); void setGPSData(float latitude, float longitude, float altitude, float speed, float course, uint8_t satellites); - // void setVarioData(float vario); void sendTelemetryData(HardwareSerial *db); @@ -67,8 +66,6 @@ namespace serialReceiverLayer void _appendBatterySensorData(); void _appendFlightModeData(); void _appendGPSData(); - // void _appendHeartbeatData(); - // void _appendVarioData(); void _finaliseFrame(); }; } // namespace serialReceiverLayer From d72bb0018d80b35a8f8064e320725ef9653257a7 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 16 Feb 2024 09:36:44 +1300 Subject: [PATCH 15/31] refactor(generic crc): Add compiler errors for non-implemented `CRC_OPTIMISATION_HARDWARE` Hardware-accelerated CRC is not yet implemented. --- src/SerialReceiver/CRC/CRC.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SerialReceiver/CRC/CRC.cpp b/src/SerialReceiver/CRC/CRC.cpp index b9ff3ce4..d15fff4c 100644 --- a/src/SerialReceiver/CRC/CRC.cpp +++ b/src/SerialReceiver/CRC/CRC.cpp @@ -105,6 +105,7 @@ namespace genericCrc } return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_HARDWARE) +#error "CRC_OPTIMISATION_LEVEL is set to CRC_OPTIMISATION_HARDWARE, but no hardware implementation is available." #endif } @@ -132,6 +133,7 @@ namespace genericCrc } return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_HARDWARE) +#error "CRC_OPTIMISATION_LEVEL is set to CRC_OPTIMISATION_HARDWARE, but no hardware implementation is available." #endif } } // namespace genericCrc From 80638567ba31b404f9f144324be846fa9e34fb3d Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 18 Feb 2024 09:13:40 +1300 Subject: [PATCH 16/31] chore(library): Bump version date to `2024-2-18` --- examples/flight_modes/flight_modes.ino | 2 +- examples/link_stats/link_stats.ino | 2 +- examples/platformio/main.cpp | 2 +- examples/rc_channels/rc_channels.ino | 2 +- examples/telemetry/telemetry.ino | 2 +- src/CFA_Config.hpp | 2 +- src/CRSFforArduino.cpp | 2 +- src/CRSFforArduino.hpp | 2 +- src/SerialReceiver/CRC/CRC.cpp | 2 +- src/SerialReceiver/CRC/CRC.hpp | 2 +- src/SerialReceiver/CRSF/CRSF.cpp | 2 +- src/SerialReceiver/CRSF/CRSF.hpp | 2 +- src/SerialReceiver/CRSF/CRSFProtocol.hpp | 2 +- src/SerialReceiver/SerialBuffer/SerialBuffer.cpp | 2 +- src/SerialReceiver/SerialBuffer/SerialBuffer.hpp | 2 +- src/SerialReceiver/SerialReceiver.cpp | 2 +- src/SerialReceiver/SerialReceiver.hpp | 2 +- src/SerialReceiver/Telemetry/Telemetry.cpp | 2 +- src/SerialReceiver/Telemetry/Telemetry.hpp | 2 +- src/hal/CompatibilityTable/CompatibilityTable.cpp | 2 +- src/hal/CompatibilityTable/CompatibilityTable.hpp | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/flight_modes/flight_modes.ino b/examples/flight_modes/flight_modes.ino index 43c0cfde..e3b374dc 100644 --- a/examples/flight_modes/flight_modes.ino +++ b/examples/flight_modes/flight_modes.ino @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief Example of how to read flight modes from a receiver. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/examples/link_stats/link_stats.ino b/examples/link_stats/link_stats.ino index 9725ddd4..4a06d2f6 100644 --- a/examples/link_stats/link_stats.ino +++ b/examples/link_stats/link_stats.ino @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief Example of how to read link statistics from a receiver. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/examples/platformio/main.cpp b/examples/platformio/main.cpp index d5270d38..2a6f0b09 100644 --- a/examples/platformio/main.cpp +++ b/examples/platformio/main.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This is the main development file for CRSF for Arduino. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/examples/rc_channels/rc_channels.ino b/examples/rc_channels/rc_channels.ino index 8ade3ff5..1fdd655d 100644 --- a/examples/rc_channels/rc_channels.ino +++ b/examples/rc_channels/rc_channels.ino @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief Example of how to read rc channels from a receiver. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/examples/telemetry/telemetry.ino b/examples/telemetry/telemetry.ino index 34e58f10..54d6faba 100644 --- a/examples/telemetry/telemetry.ino +++ b/examples/telemetry/telemetry.ino @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief Example of how to send telemetry back to your RC handset using CRSF for Arduino. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/CFA_Config.hpp b/src/CFA_Config.hpp index b3d3d581..43feab00 100644 --- a/src/CFA_Config.hpp +++ b/src/CFA_Config.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This is the configuration file for CRSF for Arduino. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index 7e96912b..971a6652 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -4,7 +4,7 @@ * @brief This is the Sketch Layer, which is a simplified API for CRSF for Arduino. * It is intended to be used by the user in their sketches. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/CRSFforArduino.hpp b/src/CRSFforArduino.hpp index d85d4fb4..22b1643d 100644 --- a/src/CRSFforArduino.hpp +++ b/src/CRSFforArduino.hpp @@ -4,7 +4,7 @@ * @brief This is the Sketch Layer, which is a simplified API for CRSF for Arduino. * It is intended to be used by the user in their sketches. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/CRC/CRC.cpp b/src/SerialReceiver/CRC/CRC.cpp index d15fff4c..03ac12fe 100644 --- a/src/SerialReceiver/CRC/CRC.cpp +++ b/src/SerialReceiver/CRC/CRC.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief A generic CRC8 implementation for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/CRC/CRC.hpp b/src/SerialReceiver/CRC/CRC.hpp index 91930194..973de4a9 100644 --- a/src/SerialReceiver/CRC/CRC.hpp +++ b/src/SerialReceiver/CRC/CRC.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief A generic CRC8 implementation for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/CRSF/CRSF.cpp b/src/SerialReceiver/CRSF/CRSF.cpp index d0316ecf..05fabcbc 100644 --- a/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/SerialReceiver/CRSF/CRSF.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This decodes CRSF frames from a serial port. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/CRSF/CRSF.hpp b/src/SerialReceiver/CRSF/CRSF.hpp index df44c51d..a1ea63f0 100644 --- a/src/SerialReceiver/CRSF/CRSF.hpp +++ b/src/SerialReceiver/CRSF/CRSF.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This decodes CRSF frames from a serial port. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/CRSF/CRSFProtocol.hpp b/src/SerialReceiver/CRSF/CRSFProtocol.hpp index 4e774cc8..bee5707a 100644 --- a/src/SerialReceiver/CRSF/CRSFProtocol.hpp +++ b/src/SerialReceiver/CRSF/CRSFProtocol.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This file contains enums and structs for the CRSF protocol. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp index 96952b05..b258dc04 100644 --- a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp +++ b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief A generic serial buffer for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp b/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp index d39ac802..5c004191 100644 --- a/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp +++ b/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief A generic serial buffer for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 21ae25ae..9cf4142f 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief The Serial Receiver layer for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/SerialReceiver.hpp b/src/SerialReceiver/SerialReceiver.hpp index 3a6b78ce..0464ddec 100644 --- a/src/SerialReceiver/SerialReceiver.hpp +++ b/src/SerialReceiver/SerialReceiver.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief The Serial Receiver layer for the CRSF for Arduino library. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/Telemetry/Telemetry.cpp b/src/SerialReceiver/Telemetry/Telemetry.cpp index e01ffb1b..4635bcfe 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.cpp +++ b/src/SerialReceiver/Telemetry/Telemetry.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This encodes data into CRSF telemetry frames for transmission to the RC handset. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/SerialReceiver/Telemetry/Telemetry.hpp b/src/SerialReceiver/Telemetry/Telemetry.hpp index ecdbab76..fdcf33ad 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.hpp +++ b/src/SerialReceiver/Telemetry/Telemetry.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief This encodes data into CRSF telemetry frames for transmission to the RC handset. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/hal/CompatibilityTable/CompatibilityTable.cpp b/src/hal/CompatibilityTable/CompatibilityTable.cpp index 6ba0b42b..c3b88042 100644 --- a/src/hal/CompatibilityTable/CompatibilityTable.cpp +++ b/src/hal/CompatibilityTable/CompatibilityTable.cpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief The Compatibility Table determines if the target development board is compatible with CRSF for Arduino. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * diff --git a/src/hal/CompatibilityTable/CompatibilityTable.hpp b/src/hal/CompatibilityTable/CompatibilityTable.hpp index d23d1f59..0585413a 100644 --- a/src/hal/CompatibilityTable/CompatibilityTable.hpp +++ b/src/hal/CompatibilityTable/CompatibilityTable.hpp @@ -3,7 +3,7 @@ * @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com) * @brief The Compatibility Table determines if the target development board is compatible with CRSF for Arduino. * @version 1.0.0 - * @date 2024-2-14 + * @date 2024-2-18 * * @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved. * From 42e8c1da198c6c68ec656192df9e25a954649628 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 18 Feb 2024 09:16:04 +1300 Subject: [PATCH 17/31] chore(github): Add missing `*.hpp` line tag to `.gitattributes` --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 7e87b8e2..ca31fcaf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ *.c text eol=lf *.cpp text eol=lf *.h text eol=lf +*.hpp text eol=lf *.ini text eol=lf *.ino text eol=lf *.json text eol=lf From 8a5f33472d0b6c6270e033a4052df43f739ca402 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 18 Feb 2024 09:57:54 +1300 Subject: [PATCH 18/31] fix(telemetry): Incorrect code format --- src/SerialReceiver/Telemetry/Telemetry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SerialReceiver/Telemetry/Telemetry.cpp b/src/SerialReceiver/Telemetry/Telemetry.cpp index 4635bcfe..0e032c24 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.cpp +++ b/src/SerialReceiver/Telemetry/Telemetry.cpp @@ -39,7 +39,8 @@ namespace serialReceiverLayer #define RAD PI / 180.0F #endif - Telemetry::Telemetry() : SerialBuffer(CRSF_FRAME_SIZE_MAX) + Telemetry::Telemetry() : + SerialBuffer(CRSF_FRAME_SIZE_MAX) { _telemetryFrameScheduleCount = 0; memset(_telemetryFrameSchedule, 0, sizeof(_telemetryFrameSchedule)); From 3650fb416dbe5b49ceda6bd2dab07f68ecbc3934 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 18 Feb 2024 10:31:20 +1300 Subject: [PATCH 19/31] ci(arduino): Disable testing on "supported platforms" until Adafruit fixes their fault detection issue This whittles the Arduino CI back to merely checking for correct code format. --- .github/workflows/arduinoide_build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arduinoide_build.yml b/.github/workflows/arduinoide_build.yml index f4ba281d..d8f59837 100644 --- a/.github/workflows/arduinoide_build.yml +++ b/.github/workflows/arduinoide_build.yml @@ -22,5 +22,6 @@ jobs: - name: Check for correct code formatting with clang-format run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . - - name: Test the code on supported platforms - run: python3 ci/build_platform.py metro_m4 + # Disabled until Adafruit fixes their fault detection issue. + # - name: Test the code on supported platforms + # run: python3 ci/build_platform.py metro_m4 From 64ceb03c86f21c1f3fee8fcf58c0ead9a06cf1d7 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 18 Feb 2024 11:46:13 +1300 Subject: [PATCH 20/31] refactor(serial receiver interface): Bring `disarmed` parameter in `telemetryWriteFlightMode()` up to the Sketch Layer This is the first of two parts to re-factoring the Flight Modes telemetry function. --- src/CRSFforArduino.cpp | 7 ++++--- src/CRSFforArduino.hpp | 2 +- src/SerialReceiver/SerialReceiver.cpp | 17 +++++++++++------ src/SerialReceiver/SerialReceiver.hpp | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index 971a6652..edccdeab 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -279,13 +279,14 @@ namespace sketchLayer * * @param flightMode The Flight Mode to send. */ - void CRSFforArduino::telemetryWriteFlightMode(serialReceiverLayer::flightModeId_t flightMode) + void CRSFforArduino::telemetryWriteFlightMode(serialReceiverLayer::flightModeId_t flightMode, bool disarmed) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 - this->SerialReceiver::telemetryWriteFlightMode(flightMode); + this->SerialReceiver::telemetryWriteFlightMode(flightMode, disarmed); #else // Prevent compiler warnings (void)flightMode; + (void)disarmed; #endif } @@ -297,7 +298,7 @@ namespace sketchLayer void CRSFforArduino::telemetryWriteCustomFlightMode(const char *flightMode, bool armed) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 - _serialReceiver->telemetryWriteCustomFlightMode(flightMode, armed); + this->SerialReceiver::telemetryWriteCustomFlightMode(flightMode, armed); #else // Prevent compiler warnings (void)flightMode; diff --git a/src/CRSFforArduino.hpp b/src/CRSFforArduino.hpp index 22b1643d..c59b032e 100644 --- a/src/CRSFforArduino.hpp +++ b/src/CRSFforArduino.hpp @@ -59,7 +59,7 @@ namespace sketchLayer void telemetryWriteAttitude(int16_t roll, int16_t pitch, int16_t yaw); void telemetryWriteBaroAltitude(uint16_t altitude, int16_t vario); void telemetryWriteBattery(float voltage, float current, uint32_t fuel, uint8_t percent); - void telemetryWriteFlightMode(serialReceiverLayer::flightModeId_t flightMode); + void telemetryWriteFlightMode(serialReceiverLayer::flightModeId_t flightMode, bool disarmed = false); void telemetryWriteCustomFlightMode(const char *flightMode, bool armed = false); void telemetryWriteGPS(float latitude, float longitude, float altitude, float speed, float groundCourse, uint8_t satellites); diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 9cf4142f..9807a9f7 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -370,10 +370,12 @@ namespace serialReceiverLayer #endif #if CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 - void SerialReceiver::telemetryWriteFlightMode(flightModeId_t flightModeId) + void SerialReceiver::telemetryWriteFlightMode(flightModeId_t flightMode, bool disarmed) { - switch (flightModeId) + if (flightMode != FLIGHT_MODE_DISARMED) { + switch (flightMode) + { case FLIGHT_MODE_FAILSAFE: flightModeStr = "!FS!"; break; @@ -395,14 +397,17 @@ namespace serialReceiverLayer default: flightModeStr = "ACRO"; break; + } + } + else + { + disarmed = true; } - telemetry->setFlightModeData(flightModeStr, (bool)(flightModeId == FLIGHT_MODE_DISARMED ? true : false)); + telemetry->setFlightModeData(flightModeStr, disarmed); } -#endif -#if CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 - void SerialReceiver::telemetryWriteCustomFlightMode(const char *flightModeStr, bool armed = true) + void SerialReceiver::telemetryWriteCustomFlightMode(const char *flightModeStr, bool armed) { telemetry->setFlightModeData(flightModeStr, armed); } diff --git a/src/SerialReceiver/SerialReceiver.hpp b/src/SerialReceiver/SerialReceiver.hpp index 0464ddec..3b059a2c 100644 --- a/src/SerialReceiver/SerialReceiver.hpp +++ b/src/SerialReceiver/SerialReceiver.hpp @@ -95,7 +95,7 @@ namespace serialReceiverLayer void telemetryWriteAttitude(int16_t roll, int16_t pitch, int16_t yaw); void telemetryWriteBaroAltitude(uint16_t altitude, int16_t vario); void telemetryWriteBattery(float voltage, float current, uint32_t fuel, uint8_t percent); - void telemetryWriteFlightMode(flightModeId_t flightMode); + void telemetryWriteFlightMode(flightModeId_t flightMode, bool disarmed = false); void telemetryWriteCustomFlightMode(const char *flightMode, bool armed = true); void telemetryWriteGPS(float latitude, float longitude, float altitude, float speed, float groundCourse, uint8_t satellites); #endif From 8a0c3e5128b9acecb9a14e9580e6ac4b7b82cafe Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 20:08:25 +1300 Subject: [PATCH 21/31] chore(sketch layer): Deprecate `CRSFforArduino::setFlightMode(serialReceiverLayer::flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max)` --- src/CRSFforArduino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index edccdeab..11f3e753 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -186,7 +186,7 @@ namespace sketchLayer * @param max The maximum RC value for the Flight Mode to be active. * @return true if the Flight Mode was assigned successfully. */ - bool CRSFforArduino::setFlightMode(serialReceiverLayer::flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) + [[deprecated("This function must pass in the name of the Flight Mode as well as its ID.")]] bool CRSFforArduino::setFlightMode(serialReceiverLayer::flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) { #if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 return this->SerialReceiver::setFlightMode(flightMode, channel - 1, this->SerialReceiver::usToRc(min), this->SerialReceiver::usToRc(max)); From bc1055f6aa3176e3427e5e375e4262488f1922cb Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 20:09:31 +1300 Subject: [PATCH 22/31] chore(sketch layer): Deprecate `CRSFforArduino::telemetryWriteCustomFlightMode(const char *flightMode, bool armed)` --- src/CRSFforArduino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index 11f3e753..8be102fd 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -295,7 +295,7 @@ namespace sketchLayer * * @param flightMode The Flight Mode string to send. */ - void CRSFforArduino::telemetryWriteCustomFlightMode(const char *flightMode, bool armed) + [[deprecated("This is nos handled automatically with telemetryWriteFlightMode()")]] void CRSFforArduino::telemetryWriteCustomFlightMode(const char *flightMode, bool armed) { #if CRSF_TELEMETRY_ENABLED > 0 && CRSF_TELEMETRY_FLIGHTMODE_ENABLED > 0 this->SerialReceiver::telemetryWriteCustomFlightMode(flightMode, armed); From 573bcd0478c7bdd59f0e5d30c99f1206f6e7336b Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 20:10:55 +1300 Subject: [PATCH 23/31] chore(serial receiver interface): Deprecate `SerialReceiver::setFlightMode(flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max)` --- src/SerialReceiver/SerialReceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 9807a9f7..b0a606da 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -310,7 +310,7 @@ namespace serialReceiverLayer } #if CRSF_FLIGHTMODES_ENABLED > 0 - bool SerialReceiver::setFlightMode(flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) + [[deprecated]] bool SerialReceiver::setFlightMode(flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) { if (flightMode < FLIGHT_MODE_COUNT && channel <= 15) { From a8291975e8947b5b12cee835564432ba7f34214c Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 20:12:01 +1300 Subject: [PATCH 24/31] chore(serial receiver interface): Deprecate `SerialReceiver::telemetryWriteCustomFlightMode(const char *flightModeStr, bool armed)` --- src/SerialReceiver/SerialReceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index b0a606da..bd1b359f 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -407,7 +407,7 @@ namespace serialReceiverLayer telemetry->setFlightModeData(flightModeStr, disarmed); } - void SerialReceiver::telemetryWriteCustomFlightMode(const char *flightModeStr, bool armed) + [[deprecated]] void SerialReceiver::telemetryWriteCustomFlightMode(const char *flightModeStr, bool armed) { telemetry->setFlightModeData(flightModeStr, armed); } From 9c55d8b14ed712e67a1791fa6a5536467f35833f Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 20:17:55 +1300 Subject: [PATCH 25/31] refactor(library): Flesh out custom Flight Modes API and integrate with existing Flight Modes API --- src/CFA_Config.hpp | 6 ++++ src/CRSFforArduino.cpp | 27 +++++++++++++++++ src/CRSFforArduino.hpp | 1 + src/SerialReceiver/SerialReceiver.cpp | 43 +++++++++++++++++++++++++++ src/SerialReceiver/SerialReceiver.hpp | 13 ++++++++ 5 files changed, 90 insertions(+) diff --git a/src/CFA_Config.hpp b/src/CFA_Config.hpp index 43feab00..4d25729b 100644 --- a/src/CFA_Config.hpp +++ b/src/CFA_Config.hpp @@ -77,6 +77,12 @@ Pro Tip: You can combine the Flight Mode API with the Telemetry API to send flig information back to your controller. */ #define CRSF_FLIGHTMODES_ENABLED 0 +/* Custom Flight Modes +Enables or disables the Custom Flight Modes. +When enabled, this allows you to implement flight modes with custom names +and assign them to a switch on your controller. */ +#define CRSF_CUSTOM_FLIGHT_MODES_ENABLED 0 + /* Telemetry Options - TELEMETRY_ENABLED: Enables or disables the Telemetry API. - TELEMETRY_ATTITUDE_ENABLED: Enables or disables attitude telemetry output. diff --git a/src/CRSFforArduino.cpp b/src/CRSFforArduino.cpp index 8be102fd..b966ea3f 100644 --- a/src/CRSFforArduino.cpp +++ b/src/CRSFforArduino.cpp @@ -177,6 +177,33 @@ namespace sketchLayer #endif } + /** + * @brief Assigns a Flight Mode to the specified channel. + * + * @param flightModeId The ID of the Flight Mode to assign. + * @param flightModeName The name of the Flight Mode to assign. + * @param channel The channel to assign the Flight Mode to. + * @param min The minimum RC value for the Flight Mode to be active. + * @param max The maximum RC value for the Flight Mode to be active. + * @return true if the Flight Mode was assigned successfully. + */ + bool CRSFforArduino::setFlightMode(serialReceiverLayer::flightModeId_t flightModeId, const char *flightModeName, uint8_t channel, uint16_t min, uint16_t max) + { +#if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 + return this->SerialReceiver::setFlightMode(flightModeId, flightModeName, channel - 1, this->SerialReceiver::usToRc(min), this->SerialReceiver::usToRc(max)); +#else + // Prevent compiler warnings + (void)flightModeId; + (void)flightModeName; + (void)channel; + (void)min; + (void)max; + + // Return false if RC is disabled + return false; +#endif + } + /** * @brief Assigns a Flight Mode to the specified channel. * diff --git a/src/CRSFforArduino.hpp b/src/CRSFforArduino.hpp index c59b032e..1b6d35b0 100644 --- a/src/CRSFforArduino.hpp +++ b/src/CRSFforArduino.hpp @@ -52,6 +52,7 @@ namespace sketchLayer void setLinkStatisticsCallback(void (*callback)(serialReceiverLayer::link_statistics_t linkStatistics)); // Flight mode functions. + bool setFlightMode(serialReceiverLayer::flightModeId_t flightModeId, const char *flightModeName, uint8_t channel, uint16_t min, uint16_t max); bool setFlightMode(serialReceiverLayer::flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max); void setFlightModeCallback(void (*callback)(serialReceiverLayer::flightModeId_t flightMode)); diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index bd1b359f..5224c9b6 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -310,6 +310,27 @@ namespace serialReceiverLayer } #if CRSF_FLIGHTMODES_ENABLED > 0 + bool SerialReceiver::setFlightMode(flightModeId_t flightModeId, const char *flightModeName, uint8_t channel, uint16_t min, uint16_t max) + { + if (flightModeId < FLIGHT_MODE_COUNT && flightModeName != nullptr && channel <= 15) + { + if (strlen(flightModeName) > 16) + { + return false; + } + + _flightModes[flightModeId].name = flightModeName; + _flightModes[flightModeId].channel = channel; + _flightModes[flightModeId].min = min; + _flightModes[flightModeId].max = max; + return true; + } + else + { + return false; + } + } + [[deprecated]] bool SerialReceiver::setFlightMode(flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max) { if (flightMode < FLIGHT_MODE_COUNT && channel <= 15) @@ -394,6 +415,28 @@ namespace serialReceiverLayer case FLIGHT_MODE_AIRMODE: flightModeStr = "AIR"; break; + +#if CRSF_CUSTOM_FLIGHT_MODES_ENABLED > 0 + /* All 8 custom flight modes are handled here. */ + case CUSTOM_FLIGHT_MODE1: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE2: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE3: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE4: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE5: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE6: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE7: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE8: + flightModeStr = _flightModes[flightMode].name; + break; +#endif + default: flightModeStr = "ACRO"; break; diff --git a/src/SerialReceiver/SerialReceiver.hpp b/src/SerialReceiver/SerialReceiver.hpp index 3b059a2c..ab604c1f 100644 --- a/src/SerialReceiver/SerialReceiver.hpp +++ b/src/SerialReceiver/SerialReceiver.hpp @@ -44,6 +44,17 @@ namespace serialReceiverLayer FLIGHT_MODE_ANGLE, FLIGHT_MODE_HORIZON, FLIGHT_MODE_AIRMODE, + +#if CRSF_CUSTOM_FLIGHT_MODES_ENABLED > 0 + CUSTOM_FLIGHT_MODE1, + CUSTOM_FLIGHT_MODE2, + CUSTOM_FLIGHT_MODE3, + CUSTOM_FLIGHT_MODE4, + CUSTOM_FLIGHT_MODE5, + CUSTOM_FLIGHT_MODE6, + CUSTOM_FLIGHT_MODE7, + CUSTOM_FLIGHT_MODE8, +#endif FLIGHT_MODE_COUNT } flightModeId_t; @@ -85,6 +96,7 @@ namespace serialReceiverLayer uint16_t readRcChannel(uint8_t channel, bool raw = false); #if CRSF_FLIGHTMODES_ENABLED > 0 + bool setFlightMode(flightModeId_t flightModeId, const char *flightModeName, uint8_t channel, uint16_t min, uint16_t max); bool setFlightMode(flightModeId_t flightMode, uint8_t channel, uint16_t min, uint16_t max); void setFlightModeCallback(flightModeCallback_t callback); void handleFlightMode(); @@ -125,6 +137,7 @@ namespace serialReceiverLayer #if CRSF_RC_ENABLED > 0 && CRSF_FLIGHTMODES_ENABLED > 0 typedef struct flightMode_s { + const char *name = nullptr; uint8_t channel = 0; uint16_t min = 0; uint16_t max = 0; From 96e4faaf6dc862031e562e2aa1ec47c0adf8bc69 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Tue, 20 Feb 2024 21:19:12 +1300 Subject: [PATCH 26/31] chore(serial receiver interface): Resolve incorrect format --- src/SerialReceiver/SerialReceiver.cpp | 78 +++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/SerialReceiver/SerialReceiver.cpp b/src/SerialReceiver/SerialReceiver.cpp index 5224c9b6..bc721e12 100644 --- a/src/SerialReceiver/SerialReceiver.cpp +++ b/src/SerialReceiver/SerialReceiver.cpp @@ -397,49 +397,49 @@ namespace serialReceiverLayer { switch (flightMode) { - case FLIGHT_MODE_FAILSAFE: - flightModeStr = "!FS!"; - break; - case FLIGHT_MODE_GPS_RESCUE: - flightModeStr = "RTH"; - break; - case FLIGHT_MODE_PASSTHROUGH: - flightModeStr = "MANU"; - break; - case FLIGHT_MODE_ANGLE: - flightModeStr = "STAB"; - break; - case FLIGHT_MODE_HORIZON: - flightModeStr = "HOR"; - break; - case FLIGHT_MODE_AIRMODE: - flightModeStr = "AIR"; - break; + case FLIGHT_MODE_FAILSAFE: + flightModeStr = "!FS!"; + break; + case FLIGHT_MODE_GPS_RESCUE: + flightModeStr = "RTH"; + break; + case FLIGHT_MODE_PASSTHROUGH: + flightModeStr = "MANU"; + break; + case FLIGHT_MODE_ANGLE: + flightModeStr = "STAB"; + break; + case FLIGHT_MODE_HORIZON: + flightModeStr = "HOR"; + break; + case FLIGHT_MODE_AIRMODE: + flightModeStr = "AIR"; + break; #if CRSF_CUSTOM_FLIGHT_MODES_ENABLED > 0 - /* All 8 custom flight modes are handled here. */ - case CUSTOM_FLIGHT_MODE1: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE2: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE3: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE4: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE5: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE6: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE7: - [[fallthrough]]; - case CUSTOM_FLIGHT_MODE8: - flightModeStr = _flightModes[flightMode].name; - break; + /* All 8 custom flight modes are handled here. */ + case CUSTOM_FLIGHT_MODE1: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE2: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE3: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE4: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE5: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE6: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE7: + [[fallthrough]]; + case CUSTOM_FLIGHT_MODE8: + flightModeStr = _flightModes[flightMode].name; + break; #endif - default: - flightModeStr = "ACRO"; - break; + default: + flightModeStr = "ACRO"; + break; } } else From 4cec1131257973f459af30ce3d3960d71ac5cb6a Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Wed, 21 Feb 2024 09:28:16 +1300 Subject: [PATCH 27/31] style(generic crc): Remove CoPilot prompts and clean-up code --- src/SerialReceiver/CRC/CRC.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/SerialReceiver/CRC/CRC.cpp b/src/SerialReceiver/CRC/CRC.cpp index 03ac12fe..3bef8705 100644 --- a/src/SerialReceiver/CRC/CRC.cpp +++ b/src/SerialReceiver/CRC/CRC.cpp @@ -32,10 +32,8 @@ namespace genericCrc GenericCRC::GenericCRC() { #if (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SPEED) - // Allocate memory for the CRC8 DVB S2 table. crc_8_dvb_s2_table = (uint8_t *)malloc(256 * sizeof(uint8_t)); - // Generate the CRC8 DVB S2 table. for (uint16_t i = 0; i < 256; i++) { uint8_t crc = i; @@ -50,6 +48,7 @@ namespace genericCrc crc <<= 1; } } + crc_8_dvb_s2_table[i] = crc & 0xff; } #endif @@ -58,7 +57,6 @@ namespace genericCrc GenericCRC::~GenericCRC() { #if (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SPEED) - // Free the memory allocated for the CRC8 DVB S2 table. free(crc_8_dvb_s2_table); #endif } @@ -85,24 +83,22 @@ namespace genericCrc uint8_t GenericCRC::calculate(uint8_t start, uint8_t *data, uint8_t length) { #if (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SPEED) - // start is the first byte of the data to be GenericCRC'd. - // data is a pointer to the data to be GenericCRC'd. - - // Calculate the CRC8 DVB S2 value. uint8_t crc = crc_8_dvb_s2_table[0 ^ start]; + for (uint8_t i = 0; i < length; i++) { crc = crc_8_dvb_s2_table[crc ^ data[i]]; } - // Return the CRC8 DVB S2 value. return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SIZE) uint8_t crc = crc_8_dvb_s2(0, start); + for (uint8_t i = 0; i < length; i++) { crc = crc_8_dvb_s2(crc, data[i]); } + return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_HARDWARE) #error "CRC_OPTIMISATION_LEVEL is set to CRC_OPTIMISATION_HARDWARE, but no hardware implementation is available." @@ -113,24 +109,22 @@ namespace genericCrc { (void)start; #if (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SPEED) - // start is the first byte of the data to be GenericCRC'd. - // data is a pointer to the data to be GenericCRC'd. - - // Calculate the CRC8 DVB S2 value. uint8_t crc = crc_8_dvb_s2_table[0 ^ data[offset]]; + for (uint8_t i = offset + 1; i < length; i++) { crc = crc_8_dvb_s2_table[crc ^ data[i]]; } - // Return the CRC8 DVB S2 value. return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_SIZE) uint8_t crc = crc_8_dvb_s2(0, data[offset]); + for (uint8_t i = offset + 1; i < length; i++) { crc = crc_8_dvb_s2(crc, data[i]); } + return crc; #elif (CRC_OPTIMISATION_LEVEL == CRC_OPTIMISATION_HARDWARE) #error "CRC_OPTIMISATION_LEVEL is set to CRC_OPTIMISATION_HARDWARE, but no hardware implementation is available." From b6f6c0f24ad2196458ad2a2140fd5ced2bb5a77d Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Wed, 21 Feb 2024 09:46:29 +1300 Subject: [PATCH 28/31] style(crsf): Remove CoPilot promps and annotate blocks of code. --- src/SerialReceiver/CRSF/CRSF.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SerialReceiver/CRSF/CRSF.cpp b/src/SerialReceiver/CRSF/CRSF.cpp index 05fabcbc..40d2d74c 100644 --- a/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/SerialReceiver/CRSF/CRSF.cpp @@ -65,6 +65,7 @@ namespace serialReceiverLayer void CRSF::setFrameTime(uint32_t baudRate, uint8_t packetCount) { + /* Calculate the time per frame based on the baud rate and packet count. */ timePerFrame = ((1000000 * packetCount) / (baudRate / (CRSF_FRAME_SIZE_MAX - 1))); } @@ -74,34 +75,34 @@ namespace serialReceiverLayer static uint32_t frameStartTime = 0; const uint32_t currentTime = micros(); - // Reset the frame position if the frame time has elapsed. + /* Reset the frame position if the frame time has expired. */ if (currentTime - frameStartTime > timePerFrame) { framePosition = 0; - // This compensates for micros() overflow. if (currentTime < frameStartTime) { frameStartTime = currentTime; } } - // Reset the frame start time if the frame position is 0. if (framePosition == 0) { frameStartTime = currentTime; } - // Assume the full frame lenthg is 5 bytes until the frame length byte is received. + /* Assume the full frame lenthg is 5 bytes until the frame length byte is received. */ const int fullFrameLength = framePosition < 3 ? 5 : min(rxFrame.frame.frameLength + CRSF_FRAME_LENGTH_ADDRESS + CRSF_FRAME_LENGTH_FRAMELENGTH, (int)CRSF_FRAME_SIZE_MAX); if (framePosition < fullFrameLength) { + /* Store the received byte in the frame buffer. */ rxFrame.raw[framePosition] = rxByte; framePosition++; if (framePosition >= fullFrameLength) { + /* Frame is complete, calculate the CRC and check if it is valid. */ const uint8_t crc = calculateFrameCRC(); if (crc == rxFrame.raw[fullFrameLength - 1]) @@ -122,7 +123,6 @@ namespace serialReceiverLayer { const crsf_payload_link_statistics_t *linkStatisticsPayload = (const crsf_payload_link_statistics_t *)&rxFrame.frame.payload; - /* Decode the link statistics. */ linkStatistics.rssi = (linkStatisticsPayload->active_antenna ? linkStatisticsPayload->uplink_rssi_2 : linkStatisticsPayload->uplink_rssi_1); linkStatistics.lqi = linkStatisticsPayload->uplink_link_quality; linkStatistics.snr = linkStatisticsPayload->uplink_snr; @@ -133,9 +133,9 @@ namespace serialReceiverLayer } } + /* Clear the frame buffer and reset the frame position. */ memset(rxFrame.raw, 0, CRSF_FRAME_SIZE_MAX); framePosition = 0; - return true; } } @@ -145,6 +145,7 @@ namespace serialReceiverLayer void CRSF::getFailSafe(bool *failSafe) { + /* Set the failsafe flag based on the link statistics thresholds. */ if (linkStatistics.lqi <= CRSF_FAILSAFE_LQI_THRESHOLD || linkStatistics.rssi >= CRSF_FAILSAFE_RSSI_THRESHOLD) { *failSafe = true; @@ -157,12 +158,12 @@ namespace serialReceiverLayer void CRSF::getRcChannels(uint16_t *rcChannels) { + /* Decode RC frames if one has been received. */ if (rcFrameReceived) { rcFrameReceived = false; if (rcChannelsFrame.frame.type == CRSF_FRAMETYPE_RC_CHANNELS_PACKED) { - // Unpack RC Channels. const rcChannelsPacked_t *rcChannelsPacked = (rcChannelsPacked_t *)&rcChannelsFrame.frame.payload; rcChannels[RC_CHANNEL_ROLL] = rcChannelsPacked->channel0; @@ -188,7 +189,6 @@ namespace serialReceiverLayer void CRSF::getLinkStatistics(link_statistics_t *linkStats) { #if CRSF_LINK_STATISTICS_ENABLED > 0 - /* Copy the link statistics into the output structure. */ memcpy(linkStats, &linkStatistics, sizeof(link_statistics_t)); #else #endif From 10693071459a3162753ca2ea8535b84c765f5250 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Wed, 21 Feb 2024 09:48:37 +1300 Subject: [PATCH 29/31] style(serial receiver interface): Remove CoPilot prompts. --- src/SerialReceiver/SerialBuffer/SerialBuffer.cpp | 10 ---------- src/SerialReceiver/SerialBuffer/SerialBuffer.hpp | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp index b258dc04..5596bfb6 100644 --- a/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp +++ b/src/SerialReceiver/SerialBuffer/SerialBuffer.cpp @@ -54,7 +54,6 @@ namespace genericStreamBuffer memset(buffer, 0, bufferSizeMax); } - // Write signed integers in little endian size_t SerialBuffer::write8(int8_t value) { if (bufferIndex + 1 > bufferSizeMax) @@ -98,7 +97,6 @@ namespace genericStreamBuffer return 4; } - // Write unsigned integers in little endian size_t SerialBuffer::writeU8(uint8_t value) { if (bufferIndex + 1 > bufferSizeMax) @@ -142,7 +140,6 @@ namespace genericStreamBuffer return 4; } - // Write signed integers in big endian size_t SerialBuffer::write8BE(int8_t value) { if (bufferIndex + 1 > bufferSizeMax) @@ -186,7 +183,6 @@ namespace genericStreamBuffer return 4; } - // Write unsigned integers in big endian size_t SerialBuffer::writeU8BE(uint8_t value) { if (bufferIndex + 1 > bufferSizeMax) @@ -245,7 +241,6 @@ namespace genericStreamBuffer return 4; } - // Write a string size_t SerialBuffer::writeString(const char *string) { size_t length = strlen(string); @@ -262,25 +257,21 @@ namespace genericStreamBuffer return length; } - // Get the current buffer length size_t SerialBuffer::getLength() { return bufferLength; } - // Get the maximum buffer size size_t SerialBuffer::getMaxSize() { return bufferSizeMax; } - // Get the current buffer index size_t SerialBuffer::getIndex() { return bufferIndex; } - // Get the byte at the specified index uint8_t SerialBuffer::getByte(size_t index) { if (index >= bufferSizeMax) @@ -291,7 +282,6 @@ namespace genericStreamBuffer return buffer[index]; } - // Get the buffer uint8_t *SerialBuffer::getBuffer() { return buffer; diff --git a/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp b/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp index 5c004191..a5ee2b50 100644 --- a/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp +++ b/src/SerialReceiver/SerialBuffer/SerialBuffer.hpp @@ -39,43 +39,33 @@ namespace genericStreamBuffer void reset(); - // Write signed integers in little endian size_t write8(int8_t value); size_t write16(int16_t value); size_t write32(int32_t value); - // Write unsigned integers in little endian size_t writeU8(uint8_t value); size_t writeU16(uint16_t value); size_t writeU32(uint32_t value); - // Write signed integers in big endian size_t write8BE(int8_t value); size_t write16BE(int16_t value); size_t write32BE(int32_t value); - // Write unsigned integers in big endian size_t writeU8BE(uint8_t value); size_t writeU16BE(uint16_t value); size_t writeU24BE(uint32_t value); size_t writeU32BE(uint32_t value); - // Write a string size_t writeString(const char *string); - // Get the current buffer length size_t getLength(); - // Get the maximum buffer size size_t getMaxSize(); - // Get the current buffer index size_t getIndex(); - // Get the byte at the specified index uint8_t getByte(size_t index); - // Get the buffer uint8_t *getBuffer(); private: From fa2abf5f1c05671e4a9b9dd15115b573206817b6 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Wed, 21 Feb 2024 09:50:03 +1300 Subject: [PATCH 30/31] style(telemetry): Remove CoPilot prompts --- src/SerialReceiver/Telemetry/Telemetry.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SerialReceiver/Telemetry/Telemetry.cpp b/src/SerialReceiver/Telemetry/Telemetry.cpp index 0e032c24..6a1db940 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.cpp +++ b/src/SerialReceiver/Telemetry/Telemetry.cpp @@ -234,7 +234,6 @@ namespace serialReceiverLayer int16_t Telemetry::_decidegreeToRadians(int16_t decidegrees) { - /* convert angle in decidegree to radians/10000 with reducing angle to +/-180 degree range */ while (decidegrees > 18000) { decidegrees -= 36000; @@ -284,7 +283,6 @@ namespace serialReceiverLayer void Telemetry::_appendFlightModeData() { - // Return if the length of the flight mode string is greater than the flight mode payload size. size_t length = strlen(_telemetryData.flightMode.flightMode) + 1; if (length > CRSF_FRAME_FLIGHT_MODE_PAYLOAD_SIZE) { From 40934928156daa62a5a6a7c95482f7d50d5d48c2 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Wed, 21 Feb 2024 10:01:35 +1300 Subject: [PATCH 31/31] fix(build/compile/verify): Compiler warning on unused parameters --- src/SerialReceiver/CRSF/CRSF.cpp | 1 + src/SerialReceiver/Telemetry/Telemetry.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/SerialReceiver/CRSF/CRSF.cpp b/src/SerialReceiver/CRSF/CRSF.cpp index 40d2d74c..91cdf342 100644 --- a/src/SerialReceiver/CRSF/CRSF.cpp +++ b/src/SerialReceiver/CRSF/CRSF.cpp @@ -191,6 +191,7 @@ namespace serialReceiverLayer #if CRSF_LINK_STATISTICS_ENABLED > 0 memcpy(linkStats, &linkStatistics, sizeof(link_statistics_t)); #else + (void)linkStats; #endif } diff --git a/src/SerialReceiver/Telemetry/Telemetry.cpp b/src/SerialReceiver/Telemetry/Telemetry.cpp index 6a1db940..e574be93 100644 --- a/src/SerialReceiver/Telemetry/Telemetry.cpp +++ b/src/SerialReceiver/Telemetry/Telemetry.cpp @@ -202,6 +202,7 @@ namespace serialReceiverLayer } #else (void)flightMode; + (void)armed; #endif }