From 63c551ce130d623f3c6d62f34214ca0156a28e92 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 15 Jul 2022 21:53:41 +1000 Subject: [PATCH] AP_RPM: add and use AP_RPM_ENABLED ... and backend-specific equivalents --- libraries/AP_RPM/AP_RPM.cpp | 25 +++++++++++------ libraries/AP_RPM/AP_RPM.h | 18 +++++++++++- libraries/AP_RPM/AP_RPM_config.h | 38 ++++++++++++++++++++++++++ libraries/AP_RPM/RPM_Backend.cpp | 7 ++++- libraries/AP_RPM/RPM_Backend.h | 4 +++ libraries/AP_RPM/RPM_EFI.cpp | 10 +++---- libraries/AP_RPM/RPM_EFI.h | 6 +++- libraries/AP_RPM/RPM_ESC_Telem.cpp | 4 +++ libraries/AP_RPM/RPM_ESC_Telem.h | 4 +++ libraries/AP_RPM/RPM_Generator.cpp | 4 +-- libraries/AP_RPM/RPM_Generator.h | 5 ++-- libraries/AP_RPM/RPM_HarmonicNotch.cpp | 16 +++++------ libraries/AP_RPM/RPM_HarmonicNotch.h | 4 +++ libraries/AP_RPM/RPM_Pin.cpp | 7 ++++- libraries/AP_RPM/RPM_Pin.h | 5 ++++ 15 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 libraries/AP_RPM/AP_RPM_config.h diff --git a/libraries/AP_RPM/AP_RPM.cpp b/libraries/AP_RPM/AP_RPM.cpp index 9134e1afcb..6a12285acf 100644 --- a/libraries/AP_RPM/AP_RPM.cpp +++ b/libraries/AP_RPM/AP_RPM.cpp @@ -14,6 +14,9 @@ */ #include "AP_RPM.h" + +#if AP_RPM_ENABLED + #include "RPM_Pin.h" #include "RPM_SITL.h" #include "RPM_EFI.h" @@ -66,36 +69,40 @@ void AP_RPM::init(void) for (uint8_t i=0; i #include #include @@ -37,13 +41,23 @@ public: // RPM driver types enum RPM_Type { RPM_TYPE_NONE = 0, +#if AP_RPM_PIN_ENABLED RPM_TYPE_PWM = 1, RPM_TYPE_PIN = 2, +#endif +#if AP_RPM_EFI_ENABLED RPM_TYPE_EFI = 3, +#endif +#if AP_RPM_HARMONICNOTCH_ENABLED RPM_TYPE_HNTCH = 4, +#endif +#if AP_RPM_ESC_TELEM_ENABLED RPM_TYPE_ESC_TELEM = 5, +#endif +#if AP_RPM_GENERATOR_ENABLED RPM_TYPE_GENERATOR = 6, -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL +#endif +#if AP_RPM_SIM_ENABLED RPM_TYPE_SITL = 10, #endif }; @@ -110,3 +124,5 @@ private: namespace AP { AP_RPM *rpm(); }; + +#endif // AP_RPM_ENABLED diff --git a/libraries/AP_RPM/AP_RPM_config.h b/libraries/AP_RPM/AP_RPM_config.h new file mode 100644 index 0000000000..b7f92d99a5 --- /dev/null +++ b/libraries/AP_RPM/AP_RPM_config.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include +#include + +#ifndef AP_RPM_ENABLED +#define AP_RPM_ENABLED 1 +#endif + +#ifndef AP_RPM_BACKEND_DEFAULT_ENABLED +#define AP_RPM_BACKEND_DEFAULT_ENABLED AP_RPM_ENABLED +#endif + +#ifndef AP_RPM_EFI_ENABLED +#define AP_RPM_EFI_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED && HAL_EFI_ENABLED +#endif + +#ifndef AP_RPM_ESC_TELEM_ENABLED +#define AP_RPM_ESC_TELEM_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_RPM_HARMONICNOTCH_ENABLED +#define AP_RPM_HARMONICNOTCH_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_RPM_PIN_ENABLED +#define AP_RPM_PIN_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_RPM_SIM_ENABLED +#define AP_RPM_SIM_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED && AP_SIM_ENABLED +#endif + +#ifndef AP_RPM_GENERATOR_ENABLED +#define AP_RPM_GENERATOR_ENABLED AP_RPM_BACKEND_DEFAULT_ENABLED && HAL_GENERATOR_ENABLED +#endif diff --git a/libraries/AP_RPM/RPM_Backend.cpp b/libraries/AP_RPM/RPM_Backend.cpp index 9bc03b5596..a22e44102c 100644 --- a/libraries/AP_RPM/RPM_Backend.cpp +++ b/libraries/AP_RPM/RPM_Backend.cpp @@ -13,10 +13,13 @@ along with this program. If not, see . */ +#include "RPM_Backend.h" + +#if AP_RPM_ENABLED + #include #include #include "AP_RPM.h" -#include "RPM_Backend.h" /* base class constructor. @@ -27,3 +30,5 @@ AP_RPM_Backend::AP_RPM_Backend(AP_RPM &_ap_rpm, uint8_t instance, AP_RPM::RPM_St { state.instance = instance; } + +#endif // AP_RPM_ENABLED diff --git a/libraries/AP_RPM/RPM_Backend.h b/libraries/AP_RPM/RPM_Backend.h index c0a4c8cbcc..7c2726c7ed 100644 --- a/libraries/AP_RPM/RPM_Backend.h +++ b/libraries/AP_RPM/RPM_Backend.h @@ -16,6 +16,8 @@ #include "AP_RPM.h" +#if AP_RPM_ENABLED + class AP_RPM_Backend { public: @@ -41,3 +43,5 @@ protected: AP_RPM &ap_rpm; AP_RPM::RPM_State &state; }; + +#endif // AP_RPM_ENABLED diff --git a/libraries/AP_RPM/RPM_EFI.cpp b/libraries/AP_RPM/RPM_EFI.cpp index fcf04cb808..bca16706fc 100644 --- a/libraries/AP_RPM/RPM_EFI.cpp +++ b/libraries/AP_RPM/RPM_EFI.cpp @@ -17,12 +17,10 @@ #include "RPM_EFI.h" -#if HAL_EFI_ENABLED -extern const AP_HAL::HAL& hal; +#if AP_RPM_EFI_ENABLED + +#include -/* - open the sensor in constructor -*/ AP_RPM_EFI::AP_RPM_EFI(AP_RPM &_ap_rpm, uint8_t _instance, AP_RPM::RPM_State &_state) : AP_RPM_Backend(_ap_rpm, _instance, _state) { @@ -41,4 +39,4 @@ void AP_RPM_EFI::update(void) state.last_reading_ms = AP_HAL::millis(); } -#endif // HAL_EFI_ENABLED +#endif // AP_RPM_EFI_ENABLED diff --git a/libraries/AP_RPM/RPM_EFI.h b/libraries/AP_RPM/RPM_EFI.h index b30fbfda3c..a676b1bb67 100644 --- a/libraries/AP_RPM/RPM_EFI.h +++ b/libraries/AP_RPM/RPM_EFI.h @@ -15,8 +15,10 @@ #pragma once #include "AP_RPM.h" + +#if AP_RPM_EFI_ENABLED + #include "RPM_Backend.h" -#include class AP_RPM_EFI : public AP_RPM_Backend { @@ -30,3 +32,5 @@ public: private: uint8_t instance; }; + +#endif diff --git a/libraries/AP_RPM/RPM_ESC_Telem.cpp b/libraries/AP_RPM/RPM_ESC_Telem.cpp index 03885df3f4..3c4dbd2bd3 100644 --- a/libraries/AP_RPM/RPM_ESC_Telem.cpp +++ b/libraries/AP_RPM/RPM_ESC_Telem.cpp @@ -18,6 +18,8 @@ #include "RPM_ESC_Telem.h" +#if AP_RPM_ESC_TELEM_ENABLED + extern const AP_HAL::HAL& hal; /* @@ -40,3 +42,5 @@ void AP_RPM_ESC_Telem::update(void) state.last_reading_ms = AP_HAL::millis(); #endif } + +#endif // AP_RPM_ESC_TELEM_ENABLED diff --git a/libraries/AP_RPM/RPM_ESC_Telem.h b/libraries/AP_RPM/RPM_ESC_Telem.h index 3f0a846dab..df127fb600 100644 --- a/libraries/AP_RPM/RPM_ESC_Telem.h +++ b/libraries/AP_RPM/RPM_ESC_Telem.h @@ -17,6 +17,8 @@ #include "AP_RPM.h" #include "RPM_Backend.h" +#if AP_RPM_ESC_TELEM_ENABLED + class AP_RPM_ESC_Telem : public AP_RPM_Backend { public: @@ -28,3 +30,5 @@ public: private: uint8_t instance; }; + +#endif // AP_RPM_ESC_TELEM_ENABLED diff --git a/libraries/AP_RPM/RPM_Generator.cpp b/libraries/AP_RPM/RPM_Generator.cpp index 50e2d3627d..81b087f20f 100644 --- a/libraries/AP_RPM/RPM_Generator.cpp +++ b/libraries/AP_RPM/RPM_Generator.cpp @@ -17,7 +17,7 @@ #include "RPM_Generator.h" -#if HAL_GENERATOR_ENABLED +#if AP_RPM_GENERATOR_ENABLED extern const AP_HAL::HAL& hal; void AP_RPM_Generator::update(void) @@ -35,4 +35,4 @@ void AP_RPM_Generator::update(void) } } -#endif // HAL_GENERATOR_ENABLED +#endif // AP_RPM_GENERATOR_ENABLED diff --git a/libraries/AP_RPM/RPM_Generator.h b/libraries/AP_RPM/RPM_Generator.h index 82e8e0ff8d..627fc8ae9c 100644 --- a/libraries/AP_RPM/RPM_Generator.h +++ b/libraries/AP_RPM/RPM_Generator.h @@ -18,7 +18,7 @@ #include "RPM_Backend.h" #include -#if HAL_GENERATOR_ENABLED +#if AP_RPM_GENERATOR_ENABLED class AP_RPM_Generator : public AP_RPM_Backend { @@ -30,5 +30,4 @@ public: void update(void) override; }; -#endif // HAL_GENERATOR_ENABLED - +#endif // AP_RPM_GENERATOR_ENABLED diff --git a/libraries/AP_RPM/RPM_HarmonicNotch.cpp b/libraries/AP_RPM/RPM_HarmonicNotch.cpp index 6846355f03..144a30bcb6 100644 --- a/libraries/AP_RPM/RPM_HarmonicNotch.cpp +++ b/libraries/AP_RPM/RPM_HarmonicNotch.cpp @@ -13,16 +13,13 @@ along with this program. If not, see . */ +#include "RPM_HarmonicNotch.h" + +#if AP_RPM_HARMONICNOTCH_ENABLED + #include #include -#include "RPM_HarmonicNotch.h" - -extern const AP_HAL::HAL& hal; - -/* - open the sensor in constructor -*/ AP_RPM_HarmonicNotch::AP_RPM_HarmonicNotch(AP_RPM &_ap_rpm, uint8_t _instance, AP_RPM::RPM_State &_state) : AP_RPM_Backend(_ap_rpm, _instance, _state) { @@ -31,8 +28,8 @@ AP_RPM_HarmonicNotch::AP_RPM_HarmonicNotch(AP_RPM &_ap_rpm, uint8_t _instance, A void AP_RPM_HarmonicNotch::update(void) { - AP_InertialSensor& ins = AP::ins(); - for (auto ¬ch : ins.harmonic_notches) { + const AP_InertialSensor& ins = AP::ins(); + for (const auto ¬ch : ins.harmonic_notches) { if (notch.params.enabled() && notch.params.tracking_mode() != HarmonicNotchDynamicMode::Fixed) { state.rate_rpm = notch.calculated_notch_freq_hz[0] * 60; @@ -43,3 +40,4 @@ void AP_RPM_HarmonicNotch::update(void) } } +#endif // AP_RPM_HARMONICNOTCH_ENABLED diff --git a/libraries/AP_RPM/RPM_HarmonicNotch.h b/libraries/AP_RPM/RPM_HarmonicNotch.h index 4817d441a4..78d9a3081f 100644 --- a/libraries/AP_RPM/RPM_HarmonicNotch.h +++ b/libraries/AP_RPM/RPM_HarmonicNotch.h @@ -17,6 +17,8 @@ #include "AP_RPM.h" #include "RPM_Backend.h" +#if AP_RPM_HARMONICNOTCH_ENABLED + class AP_RPM_HarmonicNotch : public AP_RPM_Backend { public: @@ -29,3 +31,5 @@ public: private: uint8_t instance; }; + +#endif // AP_RPM_HARMONICNOTCH_ENABLED diff --git a/libraries/AP_RPM/RPM_Pin.cpp b/libraries/AP_RPM/RPM_Pin.cpp index 7336070990..83a0039a71 100644 --- a/libraries/AP_RPM/RPM_Pin.cpp +++ b/libraries/AP_RPM/RPM_Pin.cpp @@ -13,9 +13,12 @@ along with this program. If not, see . */ -#include #include "RPM_Pin.h" +#if AP_RPM_PIN_ENABLED + +#include + #include #include @@ -111,3 +114,5 @@ void AP_RPM_Pin::update(void) state.rate_rpm = 0; } } + +#endif // AP_RPM_PIN_ENABLED diff --git a/libraries/AP_RPM/RPM_Pin.h b/libraries/AP_RPM/RPM_Pin.h index 0bc069c681..e196eddc21 100644 --- a/libraries/AP_RPM/RPM_Pin.h +++ b/libraries/AP_RPM/RPM_Pin.h @@ -17,6 +17,9 @@ #include "AP_RPM.h" #include "RPM_Backend.h" + +#if AP_RPM_PIN_ENABLED + #include #include @@ -46,3 +49,5 @@ private: uint32_t timestamp); }; + +#endif // AP_RPM_PIN_ENABLED