TactilityKernel improvements (#464)
* **New Features** * Thread API with lifecycle, priority, affinity and state monitoring * Timer subsystem: one-shot/periodic timers, reset, pending callbacks, expiry queries * Expanded I²C: register-level ops, bulk writes, presence checks, ESP32 integration and new config properties * GPIO controller: pin level and options APIs * Error utilities: new error code, error-to-string, timeout helper and common macros * Device construction helpers (construct+start) * **Tests** * New unit tests for thread and timer behavior * **Documentation** * Expanded coding style guide (files/folders, C conventions)
This commit is contained in:
committed by
GitHub
parent
f6ddb14ec1
commit
71f8369377
@@ -146,6 +146,7 @@ failed_ledger_lookup:
|
||||
}
|
||||
|
||||
error_t device_start(Device* device) {
|
||||
LOG_I(TAG, "start %s", device->name);
|
||||
if (!device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
@@ -166,6 +167,7 @@ error_t device_start(Device* device) {
|
||||
}
|
||||
|
||||
error_t device_stop(struct Device* device) {
|
||||
LOG_I(TAG, "stop %s", device->name);
|
||||
if (!device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
@@ -183,6 +185,56 @@ error_t device_stop(struct Device* device) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t device_construct_add(struct Device* device, const char* compatible) {
|
||||
struct Driver* driver = driver_find_compatible(compatible);
|
||||
if (driver == nullptr) {
|
||||
LOG_E(TAG, "Can't find driver '%s' for device '%s'", compatible, device->name);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
error_t error = device_construct(device);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to construct device %s: %s", device->name, error_to_string(error));
|
||||
goto on_construct_error;
|
||||
}
|
||||
|
||||
device_set_driver(device, driver);
|
||||
|
||||
error = device_add(device);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to add device %s: %s", device->name, error_to_string(error));
|
||||
goto on_add_error;
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
on_add_error:
|
||||
device_destruct(device);
|
||||
on_construct_error:
|
||||
return error;
|
||||
}
|
||||
|
||||
error_t device_construct_add_start(struct Device* device, const char* compatible) {
|
||||
error_t error = device_construct_add(device, compatible);
|
||||
if (error != ERROR_NONE) {
|
||||
goto on_construct_add_error;
|
||||
}
|
||||
|
||||
error = device_start(device);
|
||||
if (error != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to start device %s: %s", device->name, error_to_string(error));
|
||||
goto on_start_error;
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
on_start_error:
|
||||
device_remove(device);
|
||||
device_destruct(device);
|
||||
on_construct_add_error:
|
||||
return error;
|
||||
}
|
||||
|
||||
void device_set_parent(Device* device, Device* parent) {
|
||||
assert(!device->internal.state.started);
|
||||
device->parent = parent;
|
||||
|
||||
Reference in New Issue
Block a user