From 2c00813aab9df9d53fc35befba0be36cb980756c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 3 May 2023 23:08:00 +1000 Subject: [PATCH] AP_RCProtocol: add and use AP_RCPROTOCOL_ENABLED --- libraries/AP_RCProtocol/AP_RCProtocol.cpp | 13 +++++++++++- libraries/AP_RCProtocol/AP_RCProtocol.h | 21 +++++++++++++------ .../AP_RCProtocol/AP_RCProtocol_Backend.cpp | 6 ++++++ .../AP_RCProtocol/AP_RCProtocol_Backend.h | 5 +++++ libraries/AP_RCProtocol/AP_RCProtocol_DSM.cpp | 8 ++++++- libraries/AP_RCProtocol/AP_RCProtocol_DSM.h | 9 +++++++- .../AP_RCProtocol/AP_RCProtocol_IBUS.cpp | 6 ++++++ libraries/AP_RCProtocol/AP_RCProtocol_IBUS.h | 9 +++++++- .../AP_RCProtocol/AP_RCProtocol_PPMSum.cpp | 4 ++++ .../AP_RCProtocol/AP_RCProtocol_PPMSum.h | 8 ++++++- .../AP_RCProtocol/AP_RCProtocol_ST24.cpp | 6 ++++++ libraries/AP_RCProtocol/AP_RCProtocol_ST24.h | 8 ++++++- .../AP_RCProtocol/AP_RCProtocol_SUMD.cpp | 7 +++++++ libraries/AP_RCProtocol/AP_RCProtocol_SUMD.h | 8 ++++++- .../AP_RCProtocol/AP_RCProtocol_config.h | 6 +++++- 15 files changed, 110 insertions(+), 14 deletions(-) diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.cpp b/libraries/AP_RCProtocol/AP_RCProtocol.cpp index 5dc8a1212d..236a94f9d3 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol.cpp @@ -15,8 +15,12 @@ * Code by Andrew Tridgell and Siddharth Bharat Purohit */ -#include +#include "AP_RCProtocol_config.h" + #include "AP_RCProtocol.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol_PPMSum.h" #include "AP_RCProtocol_DSM.h" #include "AP_RCProtocol_IBUS.h" @@ -31,6 +35,8 @@ #include #include +#include + extern const AP_HAL::HAL& hal; void AP_RCProtocol::init() @@ -405,6 +411,8 @@ void AP_RCProtocol::start_bind(void) } } +#endif // AP_RCPROTOCOL_ENABLED + /* return protocol name */ @@ -459,6 +467,7 @@ const char *AP_RCProtocol::protocol_name_from_protocol(rcprotocol_t protocol) return nullptr; } +#if AP_RCPROTOCOL_ENABLED /* return protocol name */ @@ -493,3 +502,5 @@ namespace AP { return rcprot; } }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol.h b/libraries/AP_RCProtocol/AP_RCProtocol.h index 59cd5ec891..90c8667627 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol.h @@ -28,9 +28,6 @@ class AP_RCProtocol_Backend; class AP_RCProtocol { public: - AP_RCProtocol() {} - ~AP_RCProtocol(); - friend class AP_RCProtocol_Backend; enum rcprotocol_t { PPM = 0, @@ -64,6 +61,16 @@ public: #endif NONE //last enum always is None }; + + // return protocol name as a string + static const char *protocol_name_from_protocol(rcprotocol_t protocol); + +#if AP_RCPROTOCOL_ENABLED + + AP_RCProtocol() {} + ~AP_RCProtocol(); + friend class AP_RCProtocol_Backend; + void init(); bool valid_serial_prot() const { @@ -134,9 +141,6 @@ public: int16_t get_RSSI(void) const; int16_t get_rx_link_quality(void) const; - // return protocol name as a string - static const char *protocol_name_from_protocol(rcprotocol_t protocol); - // return protocol name as a string const char *protocol_name(void) const; @@ -196,10 +200,15 @@ private: // allowed RC protocols mask (first bit means "all") uint32_t rc_protocols_mask; + +#endif // AP_RCPROTCOL_ENABLED + }; +#if AP_RCPROTOCOL_ENABLED namespace AP { AP_RCProtocol &RC(); }; #include "AP_RCProtocol_Backend.h" +#endif // AP_RCProtocol_enabled diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_Backend.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_Backend.cpp index 73dc5f1aae..de6cca8f5f 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_Backend.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_Backend.cpp @@ -15,6 +15,10 @@ * Code by Andrew Tridgell and Siddharth Bharat Purohit */ +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol.h" #include #include @@ -207,3 +211,5 @@ void AP_RCProtocol_Backend::log_data(AP_RCProtocol::rcprotocol_t prot, uint32_t } #endif // HAL_LOGGING_ENABLED } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_Backend.h b/libraries/AP_RCProtocol/AP_RCProtocol_Backend.h index d50360b3c7..474a3ab20c 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_Backend.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_Backend.h @@ -18,6 +18,9 @@ #pragma once #include "AP_RCProtocol.h" + +#if AP_RCPROTOCOL_ENABLED + #include #include @@ -131,3 +134,5 @@ private: int16_t rssi = -1; int16_t rx_link_quality = -1; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_DSM.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_DSM.cpp index 5d31ed4649..6258f4069c 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_DSM.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_DSM.cpp @@ -17,7 +17,11 @@ /* with thanks to PX4 dsm.c for DSM decoding approach */ -#include + +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol_DSM.h" #include @@ -534,3 +538,5 @@ void AP_RCProtocol_DSM::process_byte(uint8_t b, uint32_t baudrate) } _process_byte(AP_HAL::millis(), b); } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_DSM.h b/libraries/AP_RCProtocol/AP_RCProtocol_DSM.h index 66197ef95a..65a3e266c1 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_DSM.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_DSM.h @@ -17,7 +17,12 @@ #pragma once -#include "AP_RCProtocol.h" +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + +#include "AP_RCProtocol_Backend.h" + #include "SoftSerial.h" #define AP_DSM_MAX_CHANNELS 12 @@ -77,3 +82,5 @@ private: SoftSerial ss{115200, SoftSerial::SERIAL_CONFIG_8N1}; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.cpp index 55ac7c0be3..aa415ae326 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.cpp @@ -14,6 +14,10 @@ * */ +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol_IBUS.h" // constructor @@ -105,3 +109,5 @@ void AP_RCProtocol_IBUS::process_byte(uint8_t b, uint32_t baudrate) } _process_byte(AP_HAL::micros(), b); } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.h b/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.h index 7725d374ab..199654f830 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_IBUS.h @@ -16,10 +16,15 @@ #pragma once +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #define IBUS_FRAME_SIZE 32 #define IBUS_INPUT_CHANNELS 14 -#include "AP_RCProtocol.h" +#include "AP_RCProtocol_Backend.h" + #include "SoftSerial.h" class AP_RCProtocol_IBUS : public AP_RCProtocol_Backend @@ -40,3 +45,5 @@ private: uint32_t last_byte_us; } byte_input; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.cpp index 1915d32276..5df42ae5a8 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.cpp @@ -17,6 +17,8 @@ #include "AP_RCProtocol_PPMSum.h" +#if AP_RCPROTOCOL_ENABLED + /* process a PPM-sum pulse of the given width */ @@ -63,3 +65,5 @@ void AP_RCProtocol_PPMSum::process_pulse(uint32_t width_s0, uint32_t width_s1) ppm_state._channel_counter = -1; } } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.h b/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.h index 815f189fd9..74aa78d371 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_PPMSum.h @@ -16,7 +16,11 @@ */ #pragma once -#include "AP_RCProtocol.h" +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + +#include "AP_RCProtocol_Backend.h" class AP_RCProtocol_PPMSum : public AP_RCProtocol_Backend { public: @@ -29,3 +33,5 @@ private: uint16_t _pulse_capt[MAX_RCIN_CHANNELS]; } ppm_state; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_ST24.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_ST24.cpp index c020e4e6ff..534b6ac78f 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_ST24.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_ST24.cpp @@ -42,6 +42,10 @@ * * @author Marco Bauer */ +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol_ST24.h" // #define SUMD_DEBUG @@ -233,3 +237,5 @@ void AP_RCProtocol_ST24::process_byte(uint8_t byte, uint32_t baudrate) } _process_byte(byte); } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_ST24.h b/libraries/AP_RCProtocol/AP_RCProtocol_ST24.h index 1c0c937049..993d42dc79 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_ST24.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_ST24.h @@ -17,7 +17,11 @@ #pragma once -#include "AP_RCProtocol.h" +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + +#include "AP_RCProtocol_Backend.h" #include "SoftSerial.h" #define ST24_DATA_LEN_MAX 64 @@ -149,3 +153,5 @@ private: SoftSerial ss{115200, SoftSerial::SERIAL_CONFIG_8N1}; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.cpp b/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.cpp index fa57571d2b..a6b76e2d19 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.cpp +++ b/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.cpp @@ -42,7 +42,12 @@ * * @author Marco Bauer */ +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + #include "AP_RCProtocol_SUMD.h" + #include #define SUMD_HEADER_LENGTH 3 @@ -332,3 +337,5 @@ void AP_RCProtocol_SUMD::process_byte(uint8_t byte, uint32_t baudrate) } _process_byte(AP_HAL::micros(), byte); } + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.h b/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.h index 2d9a4e90fa..da321d74cd 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_SUMD.h @@ -17,7 +17,11 @@ #pragma once -#include "AP_RCProtocol.h" +#include "AP_RCProtocol_config.h" + +#if AP_RCPROTOCOL_ENABLED + +#include "AP_RCProtocol_Backend.h" #include "SoftSerial.h" #define SUMD_MAX_CHANNELS 32 @@ -68,3 +72,5 @@ private: SoftSerial ss{115200, SoftSerial::SERIAL_CONFIG_8N1}; }; + +#endif // AP_RCPROTOCOL_ENABLED diff --git a/libraries/AP_RCProtocol/AP_RCProtocol_config.h b/libraries/AP_RCProtocol/AP_RCProtocol_config.h index 6d8442c5a5..ab9ba7dcda 100644 --- a/libraries/AP_RCProtocol/AP_RCProtocol_config.h +++ b/libraries/AP_RCProtocol/AP_RCProtocol_config.h @@ -3,8 +3,12 @@ #include #include +#ifndef AP_RCPROTOCOL_ENABLED +#define AP_RCPROTOCOL_ENABLED 1 +#endif + #ifndef AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED -#define AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED 1 +#define AP_RCPROTOCOL_BACKEND_DEFAULT_ENABLED AP_RCPROTOCOL_ENABLED #endif #ifndef AP_RCPROTOCOL_CRSF_ENABLED