Kernel improvements (#468)

* **New Features**
  * Plugin-style modules for platforms and devices with start/stop lifecycle and a runtime-consumable device tree array.

* **Refactor**
  * Consolidated initialization into a kernel/module startup flow.
  * Generated devicetree artifacts moved to the build Generated directory.

* **Changes**
  * Removed legacy no-op registration hooks and I2C lock/unlock wrappers.
  * Driver ownership and private state moved to explicit module/owner model.
  * Added ERROR_NOT_ALLOWED error code.
This commit is contained in:
Ken Van Hoeylandt 2026-01-31 09:18:02 +01:00 committed by GitHub
parent d62314f41f
commit c9185740d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
119 changed files with 1639 additions and 440 deletions

View File

@ -135,7 +135,7 @@ def write_device_init(file, device: Device, bindings: list[Binding], verbose: bo
identifier = get_device_identifier_safe(device)
device_variable = identifier
# Write device struct
file.write(f"\tif (device_construct_add_start(&{device_variable}, \"{compatible_property.value}\") != ERROR_NONE) return ERROR_RESOURCE;\n")
file.write("\t{ " f"&{device_variable}, \"{compatible_property.value}\"" " },\n")
# Write children
for child_device in device.devices:
write_device_init(file, child_device, bindings, verbose)
@ -145,8 +145,6 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
file.write(dedent('''\
// Default headers
#include <tactility/device.h>
#include <tactility/error.h>
#include <tactility/log.h>
// DTS headers
'''))
@ -161,14 +159,14 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
if type(item) is Device:
write_device_structs(file, item, None, bindings, verbose)
# Init function body start
file.write("error_t devices_builtin_init() {\n")
file.write("struct CompatibleDevice devicetree_devices[] = {\n")
# Init function body logic
for item in items:
if type(item) is Device:
write_device_init(file, item, bindings, verbose)
file.write("\treturn ERROR_NONE;\n")
# Init function body end
file.write("}\n")
file.write("\t{ NULL, NULL },\n")
file.write("};\n")
def generate_devicetree_h(filename: str):
with open(filename, "w") as file:
@ -180,7 +178,7 @@ def generate_devicetree_h(filename: str):
extern "C" {
#endif
extern error_t devices_builtin_init();
extern struct CompatibleDevice devicetree_devices[];
#ifdef __cplusplus
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "BigTreeTech Panda Touch / K Touch",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "LilyGO T-Deck",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,10 +0,0 @@
#include <tactility/driver.h>
extern "C" {
extern void register_device_drivers() {
extern Driver tlora_pager_driver;
driver_construct(&tlora_pager_driver);
}
}

View File

@ -1,10 +0,0 @@
#include <tactility/driver.h>
extern "C" {
extern void register_device_drivers() {
extern Driver tlora_pager_driver;
driver_construct(&tlora_pager_driver);
}
}

View File

@ -6,6 +6,8 @@
extern "C" {
extern struct Module device_module;
static int start(Device* device) {
return 0;
}
@ -21,7 +23,8 @@ Driver tlora_pager_driver = {
.stopDevice = stop,
.api = nullptr,
.deviceType = nullptr,
.internal = { 0 }
.owner = &device_module,
.driver_private = nullptr
};
}

View File

@ -0,0 +1,30 @@
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver tlora_pager_driver;
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
* there is no guarantee that the previously constructed drivers can be destroyed */
check(driver_construct(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}
static error_t stop() {
/* We crash when destruct fails, because if a single driver fails to destruct,
* there is no guarantee that the previously destroyed drivers can be recovered */
check(driver_destruct(&tlora_pager_driver) == ERROR_NONE);
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "LilyGO T-Lora Pager",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

View File

@ -1,7 +0,0 @@
extern "C" {
extern void register_device_drivers() {
/* NO-OP */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
// Empty for now
return ERROR_NONE;
}
static error_t stop() {
// Empty for now
return ERROR_NONE;
}
/** @warning The variable name must be exactly "device_module" */
struct Module device_module = {
.name = "Module",
.start = start,
.stop = stop
};
}

1
Firmware/.gitignore vendored
View File

@ -1 +0,0 @@
Generated/

View File

@ -14,16 +14,23 @@ endif ()
set(DEVICETREE_LOCATION "${CMAKE_SOURCE_DIR}/Devices/${TACTILITY_DEVICE_ID}")
set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/Generated")
# Ensure the directory is built in the correct CMake build phase
# If the check is not done, then another directory is created in the root of the build folder.
if (DEFINED CMAKE_CURRENT_BINARY_DIR)
file(MAKE_DIRECTORY "${GENERATED_DIR}")
endif ()
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
SRCS ${SOURCE_FILES} "${GENERATED_DIR}/devicetree.c"
REQUIRES Tactility TactilityC TactilityKernel PlatformEsp32 ${TACTILITY_DEVICE_PROJECT}
)
else ()
add_executable(FirmwareSim ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
add_executable(FirmwareSim ${SOURCE_FILES} "${GENERATED_DIR}/devicetree.c")
target_link_libraries(FirmwareSim PRIVATE
Tactility
TactilityCore
@ -38,22 +45,22 @@ else ()
add_definitions(-D_Nonnull=)
endif ()
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/Firmware/Generated")
# Generate devicetree code and attach to Firmware component
add_custom_target(AlwaysRun
COMMAND ${CMAKE_COMMAND} -E rm -f "${GENERATED_DIR}/devicetree.c"
)
add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
"${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.h"
OUTPUT "${GENERATED_DIR}/devicetree.c"
"${GENERATED_DIR}/devicetree.h"
COMMAND pip install lark pyyaml
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
"${DEVICETREE_LOCATION}" "Firmware/Generated"
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS "${DEVICETREE_LOCATION}/devicetree.yaml" # Optional: trigger rebuild if source changes
DEPENDS AlwaysRun "${DEVICETREE_LOCATION}/devicetree.yaml" # AlwaysRun ensures it always gets built
COMMENT "Generating devicetree source files..."
)
add_custom_target(Generated DEPENDS "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
set_source_files_properties("${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c" PROPERTIES GENERATED TRUE)
set_source_files_properties("${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.h" PROPERTIES GENERATED TRUE)
add_custom_target(Generated DEPENDS "${GENERATED_DIR}/devicetree.c")
set_source_files_properties("${GENERATED_DIR}/devicetree.c" PROPERTIES GENERATED TRUE)
set_source_files_properties("${GENERATED_DIR}/devicetree.h" PROPERTIES GENERATED TRUE)
# Update target for generated code
target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
target_include_directories(${COMPONENT_LIB} PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated")
target_sources(${COMPONENT_LIB} PRIVATE "${GENERATED_DIR}/devicetree.c")
target_include_directories(${COMPONENT_LIB} PRIVATE "${GENERATED_DIR}")

View File

@ -3,6 +3,11 @@
#include <tactility/driver.h>
#include <devicetree.h>
// From the relevant platform
extern struct Module platform_module;
// From the relevant device
extern struct Module device_module;
#ifdef ESP_PLATFORM
#include <tt_init.h>
#else
@ -14,10 +19,6 @@ extern const tt::hal::Configuration hardwareConfiguration;
extern "C" {
extern void register_kernel_drivers();
extern void register_platform_drivers();
extern void register_device_drivers();
void app_main() {
static const tt::Configuration config = {
/**
@ -31,12 +32,7 @@ void app_main() {
tt_init_tactility_c(); // ELF bindings for side-loading on ESP32
#endif
register_kernel_drivers();
register_platform_drivers();
register_device_drivers();
devices_builtin_init();
tt::run(config);
tt::run(config, &platform_module, &device_module, devicetree_devices);
}
} // extern

View File

@ -18,8 +18,6 @@ struct Esp32I2cConfig {
};
error_t esp32_i2c_get_port(struct Device* device, i2c_port_t* port);
void esp32_i2c_lock(struct Device* device);
void esp32_i2c_unlock(struct Device* device);
#ifdef __cplusplus
}

View File

@ -107,6 +107,8 @@ const static GpioControllerApi esp32_gpio_api = {
.get_options = get_options
};
extern struct Module platform_module;
Driver esp32_gpio_driver = {
.name = "esp32_gpio",
.compatible = (const char*[]) { "espressif,esp32-gpio", nullptr },
@ -114,7 +116,8 @@ Driver esp32_gpio_driver = {
.stopDevice = stop,
.api = (void*)&esp32_gpio_api,
.deviceType = nullptr,
.internal = { 0 }
.owner = &platform_module,
.driver_private = nullptr
};
} // extern "C"

View File

@ -150,14 +150,6 @@ error_t esp32_i2c_get_port(struct Device* device, i2c_port_t* port) {
return ERROR_NONE;
}
void esp32_i2c_lock(struct Device* device) {
mutex_lock(&GET_DATA(device)->mutex);
}
void esp32_i2c_unlock(struct Device* device) {
mutex_unlock(&GET_DATA(device)->mutex);
}
static error_t start(Device* device) {
ESP_LOGI(TAG, "start %s", device->name);
auto dts_config = GET_CONFIG(device);
@ -214,6 +206,8 @@ const static I2cControllerApi esp32_i2c_api = {
.write_register = write_register
};
extern struct Module platform_module;
Driver esp32_i2c_driver = {
.name = "esp32_i2c",
.compatible = (const char*[]) { "espressif,esp32-i2c", nullptr },
@ -221,7 +215,8 @@ Driver esp32_i2c_driver = {
.stopDevice = stop,
.api = (void*)&esp32_i2c_api,
.deviceType = &I2C_CONTROLLER_TYPE,
.internal = { 0 }
.owner = &platform_module,
.driver_private = nullptr
};
} // extern "C"

View File

@ -1,13 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/driver.h>
extern "C" {
extern void register_platform_drivers() {
extern Driver esp32_gpio_driver;
driver_construct(&esp32_gpio_driver);
extern Driver esp32_i2c_driver;
driver_construct(&esp32_i2c_driver);
}
}

View File

@ -0,0 +1,33 @@
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver esp32_gpio_driver;
extern Driver esp32_i2c_driver;
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
* there is no guarantee that the previously constructed drivers can be destroyed */
check(driver_construct(&esp32_gpio_driver) == ERROR_NONE);
check(driver_construct(&esp32_i2c_driver) == ERROR_NONE);
return ERROR_NONE;
}
static error_t stop() {
/* We crash when destruct fails, because if a single driver fails to destruct,
* there is no guarantee that the previously destroyed drivers can be recovered */
check(driver_destruct(&esp32_gpio_driver) == ERROR_NONE);
check(driver_destruct(&esp32_i2c_driver) == ERROR_NONE);
return ERROR_NONE;
}
// The name must be exactly "platform_module"
struct Module platform_module = {
.name = "ESP32 Platform",
.start = start,
.stop = stop
};
}

View File

@ -1,10 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/driver.h>
extern "C" {
extern void register_platform_drivers() {
/* Placeholder */
}
}

View File

@ -0,0 +1,22 @@
#include <tactility/module.h>
extern "C" {
static error_t start() {
/* NO-OP for now */
return ERROR_NONE;
}
static error_t stop() {
/* NO-OP for now */
return ERROR_NONE;
}
// The name must be exactly "platform_module"
struct Module platform_module = {
.name = "POSIX Platform",
.start = start,
.stop = stop
};
}

Some files were not shown because too many files have changed in this diff Show More