mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
Refactor struct Module
This commit is contained in:
parent
626d0d9776
commit
1de6f52604
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "btt-panda-touch",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s024c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s028r",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s028rv3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s032c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-4848s040c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-8048s043c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-e32r28t",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "cyd-e32r32p",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-advance-35",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-advance-50",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-28",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-35",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-50",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "generic-esp32",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "generic-esp32c6",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "generic-esp32p4",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "generic-esp32s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "guition-jc1060p470ciwy",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "guition-jc2432w328c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "guition-jc3248w535c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "guition-jc8048w550c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "heltec-wifi-lora-32-v3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdeck",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdisplay-s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdisplay",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdongle-s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -25,7 +25,8 @@ struct Module device_module = {
|
||||
.name = "lilygo-tlora-pager",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-cardputer-adv",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-cardputer",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-core2",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-cores3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-papers3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-stickc-plus",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-stickc-plus2",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "m5stack-tab5",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "simulator",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "unphone",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "waveshare-esp32-s3-geek",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-lcd-13",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-128",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-147",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-43",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@ struct Module device_module = {
|
||||
.name = "wireless-tag-wt32-sc01-plus",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -25,7 +25,8 @@ struct Module hal_device_module = {
|
||||
.name = "hal-device",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -64,5 +64,6 @@ struct Module lvgl_module = {
|
||||
.name = "lvgl",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = (const struct ModuleSymbol*)lvgl_module_symbols
|
||||
.symbols = (const struct ModuleSymbol*)lvgl_module_symbols,
|
||||
.internal = NULL
|
||||
};
|
||||
|
||||
@ -31,7 +31,8 @@ struct Module platform_module = {
|
||||
.name = "platform-esp32",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -18,7 +18,8 @@ struct Module platform_module = {
|
||||
.name = "platform-posix",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -59,9 +59,7 @@ struct Module {
|
||||
*/
|
||||
const struct ModuleSymbol* symbols;
|
||||
|
||||
struct {
|
||||
bool started;
|
||||
} internal;
|
||||
void* internal;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -23,7 +23,8 @@ struct Module root_module = {
|
||||
.name = "kernel",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = (const struct ModuleSymbol*)KERNEL_SYMBOLS
|
||||
.symbols = (const struct ModuleSymbol*)KERNEL_SYMBOLS,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct CompatibleDevice devicetree_devices[]) {
|
||||
|
||||
@ -3,9 +3,14 @@
|
||||
#include <algorithm>
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/module.h>
|
||||
#include <new>
|
||||
|
||||
#define TAG "module"
|
||||
|
||||
struct ModuleInternal {
|
||||
bool started;
|
||||
};
|
||||
|
||||
struct ModuleLedger {
|
||||
std::vector<struct Module*> modules;
|
||||
struct Mutex mutex = { 0 };
|
||||
@ -19,11 +24,14 @@ static ModuleLedger ledger;
|
||||
extern "C" {
|
||||
|
||||
error_t module_construct(struct Module* module) {
|
||||
module->internal.started = false;
|
||||
module->internal = new (std::nothrow) ModuleInternal { .started = false };
|
||||
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_destruct(struct Module* module) {
|
||||
delete static_cast<ModuleInternal*>(module->internal);
|
||||
module->internal = nullptr;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -44,28 +52,30 @@ error_t module_remove(struct Module* module) {
|
||||
error_t module_start(struct Module* module) {
|
||||
LOG_I(TAG, "start %s", module->name);
|
||||
|
||||
if (module->internal.started) return ERROR_NONE;
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
if (internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->start();
|
||||
module->internal.started = (error == ERROR_NONE);
|
||||
internal->started = (error == ERROR_NONE);
|
||||
return error;
|
||||
}
|
||||
|
||||
bool module_is_started(struct Module* module) {
|
||||
return module->internal.started;
|
||||
return static_cast<ModuleInternal*>(module->internal)->started;
|
||||
}
|
||||
|
||||
error_t module_stop(struct Module* module) {
|
||||
LOG_I(TAG, "stop %s", module->name);
|
||||
|
||||
if (!module->internal.started) return ERROR_NONE;
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
if (!internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->stop();
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
|
||||
module->internal.started = false;
|
||||
internal->started = false;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ TEST_CASE("Module construction and destruction") {
|
||||
.start = test_start,
|
||||
.stop = test_stop,
|
||||
.symbols = nullptr,
|
||||
.internal = {.started = false}
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
// Test successful construction
|
||||
@ -40,7 +40,7 @@ TEST_CASE("Module registration") {
|
||||
.start = test_start,
|
||||
.stop = test_stop,
|
||||
.symbols = nullptr,
|
||||
.internal = {.started = false}
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
// module_add should succeed
|
||||
@ -61,7 +61,7 @@ TEST_CASE("Module lifecycle") {
|
||||
.start = test_start,
|
||||
.stop = test_stop,
|
||||
.symbols = nullptr,
|
||||
.internal = {.started = false}
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
// 1. Successful start (no parent required anymore)
|
||||
@ -117,7 +117,7 @@ TEST_CASE("Global symbol resolution") {
|
||||
.start = test_start,
|
||||
.stop = test_stop,
|
||||
.symbols = test_symbols,
|
||||
.internal = {.started = false}
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
uintptr_t addr;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user