module_base: remove CRTP template pattern to reduce flash bloat (#26476)

* module_base: claude rewrite to remove CRTP bloat

* module_base: apply to all drivers/modules

* format

* fix build errors

* fix missing syntax

* remove reference to module.h in files that need module_base.h

* remove old ModuleBase<T>

* add module_base.cpp to px4_protected_layers.cmake

* fix IridiumSBD can_stop()

* fix IridiumSBD.cpp

* clang-tidy: downcast static cast

* get_instance() template accessor, revert clang-tidy global

* rename module_base.h to module.h

* revert changes in zenoh/Kconfig.topics
This commit is contained in:
Jacob Dahl
2026-02-19 15:17:17 +13:00
committed by GitHub
parent 657854ae1b
commit ce3e62841f
227 changed files with 1741 additions and 1496 deletions
+11 -2
View File
@@ -40,6 +40,8 @@
#include "pga460.h"
ModuleBase::Descriptor PGA460::desc{task_spawn, custom_command, print_usage};
PGA460::PGA460(const char *port)
{
@@ -751,6 +753,13 @@ int PGA460::take_measurement(const uint8_t mode)
return PX4_OK;
}
int PGA460::run_trampoline(int argc, char *argv[])
{
return ModuleBase::run_trampoline_impl(desc, [](int ac, char *av[]) -> ModuleBase * {
return PGA460::instantiate(ac, av);
}, argc, argv);
}
int PGA460::task_spawn(int argc, char *argv[])
{
px4_main_t entry_point = (px4_main_t)&run_trampoline;
@@ -765,7 +774,7 @@ int PGA460::task_spawn(int argc, char *argv[])
return -errno;
}
_task_id = task_id;
desc.task_id = task_id;
return PX4_OK;
}
@@ -905,5 +914,5 @@ int PGA460::write_register(const uint8_t reg, const uint8_t val)
extern "C" __EXPORT int pga460_main(int argc, char *argv[])
{
return PGA460::main(argc, argv);
return ModuleBase::main(PGA460::desc, argc, argv);
}
+8 -1
View File
@@ -207,10 +207,12 @@
#define P2_THR_15 0x0 //reg addr 0x7E
#define THR_CRC 0x1D //reg addr 0x7F
class PGA460 : public ModuleBase<PGA460>
class PGA460 : public ModuleBase
{
public:
static Descriptor desc;
PGA460(const char *port = PGA460_DEFAULT_PORT);
virtual ~PGA460();
@@ -245,6 +247,11 @@ public:
*/
static int task_spawn(int argc, char *argv[]);
/**
* @see ModuleBase
*/
static int run_trampoline(int argc, char *argv[]);
/**
* @brief Closes the serial port.
* @return Returns 0 if success or ERRNO.
+3 -1
View File
@@ -67,9 +67,11 @@ static constexpr uint32_t HXSRX0X_CONVERSION_INTERVAL{50_ms};
// Maximum time to wait for a conversion to complete.
static constexpr uint32_t HXSRX0X_CONVERSION_TIMEOUT{30_ms};
class SRF05 : public ModuleBase<SRF05>, public px4::ScheduledWorkItem
class SRF05 : public ModuleBase, public px4::ScheduledWorkItem
{
public:
static Descriptor desc;
SRF05(const uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
virtual ~SRF05() override;
+8 -6
View File
@@ -46,6 +46,8 @@
#include <px4_arch/micro_hal.h>
ModuleBase::Descriptor SRF05::desc{task_spawn, custom_command, print_usage};
SRF05::SRF05(const uint8_t rotation) :
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default),
_px4_rangefinder(0 /* no device type for GPIO input */, rotation)
@@ -114,7 +116,7 @@ SRF05::Run()
{
if (should_exit()) {
ScheduleClear();
exit_and_cleanup();
exit_and_cleanup(desc);
return;
}
@@ -195,8 +197,8 @@ int SRF05::task_spawn(int argc, char *argv[])
SRF05 *instance = new SRF05(rotation);
if (instance) {
_object.store(instance);
_task_id = task_id_is_work_queue;
desc.object.store(instance);
desc.task_id = task_id_is_work_queue;
if (instance->init() == PX4_OK) {
return PX4_OK;
@@ -207,8 +209,8 @@ int SRF05::task_spawn(int argc, char *argv[])
}
delete instance;
_object.store(nullptr);
_task_id = -1;
desc.object.store(nullptr);
desc.task_id = -1;
return PX4_ERROR;
}
@@ -251,7 +253,7 @@ SRF05::print_status()
extern "C" __EXPORT int srf05_main(int argc, char *argv[])
{
return SRF05::main(argc, argv);
return ModuleBase::main(SRF05::desc, argc, argv);
}
#else
# error ("GPIO_ULTRASOUND_xxx not defined. Driver not supported.");