From 50cc18b52a4541b3dfda34883757fc828ff27f08 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 1 Feb 2024 16:45:16 +1100 Subject: [PATCH] AP_Radio: tidy AP_Radio includes --- libraries/AP_Radio/AP_Radio.cpp | 25 +++++++++++-------------- libraries/AP_Radio/AP_Radio.h | 6 ++++++ libraries/AP_Radio/AP_Radio_backend.cpp | 6 ++++++ libraries/AP_Radio/AP_Radio_backend.h | 6 ++++++ libraries/AP_Radio/AP_Radio_bk2425.cpp | 11 +++++------ libraries/AP_Radio/AP_Radio_bk2425.h | 7 +++++-- libraries/AP_Radio/AP_Radio_cc2500.h | 9 ++++++--- libraries/AP_Radio/AP_Radio_config.h | 23 +++++++++++++++++++++++ libraries/AP_Radio/AP_Radio_cypress.cpp | 9 +++++---- libraries/AP_Radio/AP_Radio_cypress.h | 6 ++++-- libraries/AP_Radio/driver_bk2425.cpp | 8 +++++--- libraries/AP_Radio/driver_bk2425.h | 8 +++++--- 12 files changed, 87 insertions(+), 37 deletions(-) create mode 100644 libraries/AP_Radio/AP_Radio_config.h diff --git a/libraries/AP_Radio/AP_Radio.cpp b/libraries/AP_Radio/AP_Radio.cpp index ae7f805922a8a..5afaa5764b603 100644 --- a/libraries/AP_Radio/AP_Radio.cpp +++ b/libraries/AP_Radio/AP_Radio.cpp @@ -1,6 +1,8 @@ -#include +#include "AP_Radio_config.h" + +#if AP_RADIO_ENABLED -#if HAL_RCINPUT_WITH_AP_RADIO +#include #include "AP_Radio.h" #include "AP_Radio_backend.h" @@ -151,40 +153,36 @@ AP_Radio::AP_Radio(void) bool AP_Radio::init(void) { switch (radio_type) { -#if (not defined AP_RADIO_CYRF6936 || AP_RADIO_CYRF6936) +#if AP_RADIO_CYRF6936_ENABLED case RADIO_TYPE_CYRF6936: driver = new AP_Radio_cypress(*this); break; #endif -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS -#if (not defined AP_RADIO_CC2500 || AP_RADIO_CC2500) +#if AP_RADIO_CC2500_ENABLED case RADIO_TYPE_CC2500: driver = new AP_Radio_cc2500(*this); break; #endif -#endif -#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 -#if (not defined AP_RADIO_BK2425 || AP_RADIO_BK2425) +#if AP_RADIO_BK2425_ENABLED case RADIO_TYPE_BK2425: driver = new AP_Radio_beken(*this); break; #endif -#endif #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 case RADIO_TYPE_AUTO: // auto-detect between cc2500 and beken radios -#if (not defined AP_RADIO_CC2500 || AP_RADIO_CC2500) +#if AP_RADIO_CC2500_ENABLED if (AP_Radio_cc2500::probe()) { driver = new AP_Radio_cc2500(*this); } #endif -#if (not defined AP_RADIO_BK2425 || AP_RADIO_BK2425) +#if AP_RADIO_BK2425_ENABLED if (driver == nullptr) { driver = new AP_Radio_beken(*this); } #endif break; -#endif +#endif // CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 default: break; } @@ -301,5 +299,4 @@ void AP_Radio::change_txmode(void) } } -#endif // HAL_RCINPUT_WITH_AP_RADIO - +#endif // AP_RADIO_ENABLED diff --git a/libraries/AP_Radio/AP_Radio.h b/libraries/AP_Radio/AP_Radio.h index 0095457de26d3..450bcecd4a781 100644 --- a/libraries/AP_Radio/AP_Radio.h +++ b/libraries/AP_Radio/AP_Radio.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Radio_config.h" + +#if AP_RADIO_ENABLED + /* * base class for direct attached radios */ @@ -128,3 +132,5 @@ class AP_Radio static AP_Radio *_singleton; }; + +#endif // AP_RADIO_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_backend.cpp b/libraries/AP_Radio/AP_Radio_backend.cpp index b30a509d972ef..f3dcdaf2de2ef 100644 --- a/libraries/AP_Radio/AP_Radio_backend.cpp +++ b/libraries/AP_Radio/AP_Radio_backend.cpp @@ -16,6 +16,10 @@ * backend class for direct attached radios */ +#include "AP_Radio_config.h" + +#if AP_RADIO_ENABLED + #include #include "AP_Radio_backend.h" @@ -27,3 +31,5 @@ AP_Radio_backend::AP_Radio_backend(AP_Radio &_radio) : AP_Radio_backend::~AP_Radio_backend(void) { } + +#endif // AP_RADIO_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_backend.h b/libraries/AP_Radio/AP_Radio_backend.h index a1fd9e168e8de..f360224603aa3 100644 --- a/libraries/AP_Radio/AP_Radio_backend.h +++ b/libraries/AP_Radio/AP_Radio_backend.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_Radio_config.h" + +#if AP_RADIO_ENABLED + /* * backend class for direct attached radios */ @@ -156,3 +160,5 @@ class AP_Radio_backend AP_Radio &radio; }; + +#endif // AP_RADIO_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_bk2425.cpp b/libraries/AP_Radio/AP_Radio_bk2425.cpp index 46c4ca079cabc..2ed5b64f1b710 100644 --- a/libraries/AP_Radio/AP_Radio_bk2425.cpp +++ b/libraries/AP_Radio/AP_Radio_bk2425.cpp @@ -1,3 +1,7 @@ +#include "AP_Radio_config.h" + +#if AP_RADIO_BK2425_ENABLED + /* driver for Beken_2425 radio */ @@ -5,8 +9,6 @@ //#pragma GCC optimize("O0") -#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 - #include #include "AP_Radio_bk2425.h" #include @@ -1421,7 +1423,4 @@ void SyncAdaptive::Miss(uint8_t channel) } } - - -#endif // HAL_RCINPUT_WITH_AP_RADIO - +#endif // AP_RADIO_BK2425_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_bk2425.h b/libraries/AP_Radio/AP_Radio_bk2425.h index 5d35e250d7c3e..4481b70779134 100644 --- a/libraries/AP_Radio/AP_Radio_bk2425.h +++ b/libraries/AP_Radio/AP_Radio_bk2425.h @@ -20,9 +20,12 @@ With thanks to cleanflight and betaflight projects */ +#include "AP_Radio_config.h" + +#if AP_RADIO_BK2425_ENABLED + #include "AP_Radio_backend.h" -#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 #include "hal.h" #include "telem_structure.h" #include "driver_bk2425.h" @@ -258,4 +261,4 @@ class AP_Radio_beken : public AP_Radio_backend uint8_t myDroneId[4]; // CRC of the flight boards UUID, to inform the tx }; -#endif // HAL_RCINPUT_WITH_AP_RADIO +#endif // AP_RADIO_BK2425_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_cc2500.h b/libraries/AP_Radio/AP_Radio_cc2500.h index 1ddc608173ad3..b5eedad3fd36a 100644 --- a/libraries/AP_Radio/AP_Radio_cc2500.h +++ b/libraries/AP_Radio/AP_Radio_cc2500.h @@ -20,8 +20,12 @@ With thanks to cleanflight and betaflight projects */ +#include "AP_Radio_config.h" + +#if AP_RADIO_CC2500_ENABLED + #include "AP_Radio_backend.h" -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS + #include "hal.h" #include "telem_structure.h" #include "driver_cc2500.h" @@ -226,5 +230,4 @@ class AP_Radio_cc2500 : public AP_Radio_backend }; -#endif // CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS - +#endif // AP_RADIO_CC2500_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_config.h b/libraries/AP_Radio/AP_Radio_config.h new file mode 100644 index 0000000000000..92ab9fbd789a2 --- /dev/null +++ b/libraries/AP_Radio/AP_Radio_config.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#ifndef AP_RADIO_ENABLED +#define AP_RADIO_ENABLED HAL_RCINPUT_WITH_AP_RADIO +#endif + +#ifndef AP_RADIO_BACKEND_DEFAULT_ENABLED +#define AP_RADIO_BACKEND_DEFAULT_ENABLED AP_RADIO_ENABLED +#endif + +#ifndef AP_RADIO_CC2500_ENABLED +#define AP_RADIO_CC2500_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_RADIO_CYRF6936_ENABLED +#define AP_RADIO_CYRF6936_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_RADIO_BK2425_ENABLED +#define AP_RADIO_BK2425_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED +#endif diff --git a/libraries/AP_Radio/AP_Radio_cypress.cpp b/libraries/AP_Radio/AP_Radio_cypress.cpp index ff6f99b4b65ef..7d3d2101be0fa 100644 --- a/libraries/AP_Radio/AP_Radio_cypress.cpp +++ b/libraries/AP_Radio/AP_Radio_cypress.cpp @@ -1,6 +1,8 @@ -#include +#include "AP_Radio_config.h" + +#if AP_RADIO_CYRF6936_ENABLED -#if HAL_RCINPUT_WITH_AP_RADIO +#include #include #include "AP_Radio_cypress.h" @@ -1681,5 +1683,4 @@ void AP_Radio_cypress::handle_data_packet(mavlink_channel_t chan, const mavlink_ } } -#endif // HAL_RCINPUT_WITH_AP_RADIO - +#endif // AP_RADIO_CYRF6936_ENABLED diff --git a/libraries/AP_Radio/AP_Radio_cypress.h b/libraries/AP_Radio/AP_Radio_cypress.h index 15c63d528d707..504f9737e9b3c 100644 --- a/libraries/AP_Radio/AP_Radio_cypress.h +++ b/libraries/AP_Radio/AP_Radio_cypress.h @@ -14,7 +14,9 @@ */ #pragma once -#if HAL_RCINPUT_WITH_AP_RADIO +#include "AP_Radio_config.h" + +#if AP_RADIO_CYRF6936_ENABLED /* AP_Radio implementation for Cypress 2.4GHz radio. @@ -279,4 +281,4 @@ class AP_Radio_cypress : public AP_Radio_backend void setup_timeout(uint32_t timeout_ms); }; -#endif +#endif // AP_RADIO_CYRPRESS_ENABLED diff --git a/libraries/AP_Radio/driver_bk2425.cpp b/libraries/AP_Radio/driver_bk2425.cpp index 04452cde2beda..4fb08653c887d 100644 --- a/libraries/AP_Radio/driver_bk2425.cpp +++ b/libraries/AP_Radio/driver_bk2425.cpp @@ -1,11 +1,13 @@ +#include "AP_Radio_config.h" + +#if AP_RADIO_BK2425_ENABLED + // -------------------------------------------------------------------- // low level driver for the beken radio on SPI // -------------------------------------------------------------------- #include "driver_bk2425.h" -#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 - #include #include using namespace ChibiOS; @@ -722,4 +724,4 @@ void Radio_Beken::DumpRegisters(void) SetRBank(0); } -#endif // HAL_RCINPUT_WITH_AP_RADIO +#endif // AP_RADIO_BK2425_ENABLED diff --git a/libraries/AP_Radio/driver_bk2425.h b/libraries/AP_Radio/driver_bk2425.h index 14fbf5a264a14..9352a21ff7530 100644 --- a/libraries/AP_Radio/driver_bk2425.h +++ b/libraries/AP_Radio/driver_bk2425.h @@ -6,9 +6,11 @@ #pragma once -#include +#include "AP_Radio_config.h" + +#if AP_RADIO_BK2425_ENABLED -#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 +#include #define SUPPORT_BK_DEBUG_PINS 0 // 0=UART6 is for GPS, 1=UART6 is debug gpio #define TX_SPEED 250u // Default transmit speed in kilobits per second. @@ -414,4 +416,4 @@ class Radio_Beken BkRadioMode bkMode; }; -#endif +#endif // AP_RADIO_BK2425_ENABLED