Remove old HAL components and refactored GPS-related code (#583)

- Added generic GPS/GNSS support with device detection, configuration, and persistent settings.
- Improved device and module lifecycle management.
- Added flexible filesystem locking support for displays and storage.
- Improved display-idle and keyboard backlight handling.
- Updated architecture, driver, module, testing, and licensing documentation.
- Removed old HAL device and related code.
This commit is contained in:
Ken Van Hoeylandt
2026-07-25 17:20:17 +02:00
committed by GitHub
parent 29e80cfd65
commit 2a2558b29a
173 changed files with 3855 additions and 5445 deletions
+14
View File
@@ -585,6 +585,20 @@ error_t device_get_first_active_by_type(const DeviceType* type, Device** out_dev
return error;
}
bool device_has_active_by_type(const struct DeviceType* type) {
ledger_lock();
bool found = false;
for (auto* device : ledger.devices) {
auto* driver = device->internal->driver;
if (driver != nullptr && driver->device_type == type && device->internal->state.started) {
found = true;
break;
}
}
ledger_unlock();
return found;
}
error_t device_get_first_by_compatible(const char* compatible, Device** out_device) {
ledger_lock();
Device* found = nullptr;
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/keyboard.h>
#include <tactility/error.h>
#include <tactility/device.h>
#define KEYBOARD_DRIVER_API(driver) ((struct KeyboardApi*)driver->api)
@@ -11,6 +12,16 @@ error_t keyboard_read_key(Device* device, KeyboardKeyData* data) {
return KEYBOARD_DRIVER_API(driver)->read_key(device, data);
}
error_t keyboard_get_backlight(Device* device, Device** backlight_device) {
const auto* driver = device_get_driver(device);
if (KEYBOARD_DRIVER_API(driver)->get_backlight == nullptr) {
return ERROR_NOT_SUPPORTED;
}
return KEYBOARD_DRIVER_API(driver)->get_backlight(device, backlight_device);
}
const DeviceType KEYBOARD_TYPE {
.name = "keyboard"
};
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/filesystem/file_mutex.h>
#include <cstring>
#include <string>
#include <vector>
static const FileMutex no_mutex = {
.lock = nullptr,
.try_lock = nullptr,
.unlock = nullptr,
};
struct FileMutexEntry {
std::string path;
FileMutex mutex;
};
static std::vector<FileMutexEntry> mutex_entries;
extern "C" {
void file_mutex_register(const FileMutex* mutex, const char* path) {
// Skip if entry for path exists
for (auto& entry : mutex_entries) {
if (entry.path == path) {
return;
}
}
// Store a copy of the entry
mutex_entries.push_back({
.path = path,
.mutex = *mutex
});
}
void file_mutex_get(FileMutex* mutex, const char* path) {
std::string path_string = path;
for (auto& entry : mutex_entries) {
// Match the mount path itself, or a descendant (e.g. "/sdcard" registered, "/sdcard/config.json" requested).
bool is_match = path_string == entry.path ||
(entry.path == "/" && !path_string.empty() && path_string[0] == '/') ||
(path_string.rfind(entry.path, 0) == 0 && path_string[entry.path.size()] == '/');
if (is_match) {
memcpy(mutex, &entry.mutex, sizeof(FileMutex));
return;
}
}
*mutex = no_mutex;
}
void file_mutex_lock(const FileMutex* mutex) {
if (mutex->lock) {
mutex->lock();
}
}
bool file_mutex_try_lock(const FileMutex* mutex, TickType_t timeout) {
if (mutex->try_lock) {
return mutex->try_lock(timeout);
}
return true;
}
void file_mutex_unlock(const FileMutex* mutex) {
if (mutex->unlock) {
mutex->unlock();
}
}
}
+55 -9
View File
@@ -28,22 +28,39 @@ static ModuleLedger ledger;
extern "C" {
error_t module_construct(Module* module) {
if (module->internal != nullptr) {
LOG_E(TAG, "Module %s was already constructed", module->name);
return ERROR_INVALID_STATE;
}
module->internal = new (std::nothrow) ModuleInternal();
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
return ERROR_NONE;
}
error_t module_destruct(Module* module) {
delete static_cast<ModuleInternal*>(module->internal);
if (module->internal == nullptr) {
LOG_E(TAG, "Module %s was already destructed", module->name);
return ERROR_INVALID_STATE;
}
delete module->internal;
module->internal = nullptr;
return ERROR_NONE;
}
error_t module_add(Module* module) {
mutex_lock(&ledger.mutex);
ledger.modules.push_back(module);
bool exists = false;
for (auto* ledger_module : ledger.modules) {
if (ledger_module == module) {
exists = true;
break;
}
}
if (!exists) {
ledger.modules.push_back(module);
}
mutex_unlock(&ledger.mutex);
return ERROR_NONE;
return exists ? ERROR_INVALID_STATE : ERROR_NONE;
}
error_t module_remove(Module* module) {
@@ -57,8 +74,8 @@ error_t module_start(Module* module) {
LOG_I(TAG, "start %s", module->name);
auto* internal = module->internal;
if (internal == nullptr) return ERROR_INVALID_STATE;
if (internal->started) return ERROR_NONE;
if (internal == nullptr) { return ERROR_INVALID_STATE; }
if (internal->started) { return ERROR_NONE; }
if (module->start != nullptr) {
auto error = module->start();
@@ -90,8 +107,8 @@ error_t module_stop(Module* module) {
LOG_I(TAG, "stop %s", module->name);
auto* internal = module->internal;
if (internal == nullptr) return ERROR_INVALID_STATE;
if (!internal->started) return ERROR_NONE;
if (internal == nullptr) { return ERROR_INVALID_STATE; }
if (!internal->started) { return ERROR_NONE; }
if (module->drivers != nullptr && internal->drivers_ready) {
size_t count = 0;
@@ -117,12 +134,41 @@ error_t module_stop(Module* module) {
error_t module_construct_add_start(Module* module) {
error_t error = module_construct(module);
if (error != ERROR_NONE) return error;
if (error != ERROR_NONE) { return error; }
error = module_add(module);
if (error != ERROR_NONE) return error;
if (error != ERROR_NONE) { return error; }
return module_start(module);
}
error_t module_ensure_started(Module* module) {
if (module->internal == nullptr) {
error_t result = module_construct(module);
if (result != ERROR_NONE) { return result; }
}
if (!module->internal->started) {
error_t result = module_start(module);
if (result != ERROR_NONE) { return result; }
}
return ERROR_NONE;
}
error_t module_ensure_destructed(Module* module) {
if (module->internal != nullptr) {
error_t result;
if (module->internal->started) {
result = module_stop(module);
if (result != ERROR_NONE) { return result; }
}
result = module_destruct(module);
if (result != ERROR_NONE) { return result; }
}
return ERROR_NONE;
}
bool module_resolve_symbol(Module* module, const char* symbol_name, uintptr_t* symbol_address) {
if (!module_is_started(module)) return false;
auto* symbol_ptr = module->symbols;