Ken Van Hoeylandt 89f1804184
Async keyboard API and device probing support (#654)
- Implemented async keyboard API. Made it backwards compatible.
- `KeyboardApi::read_key` and `keyboard_read_key()` automatically forward to subscribing pollers.
- Implement `Device::probe` for device hot-plug support.
- Implement probing for Tab5 keyboard
- Updated coding style guide
2026-09-20 17:31:07 +02:00

54 lines
1.7 KiB
C++

#include "devices_common.h"
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/log.h>
constexpr auto* TAG = "Tab5";
// Mirrors device_construct_add_start(), but with a device_set_parent() call inserted between
// construct and add - device_set_parent() asserts on device->internal (only valid after
// construct), and device_construct_add_start() doesn't expose a hook to call it before add().
bool construct_add(Device* device, Device* parent, const char* compatible) {
error_t error = device_construct(device);
if (error != ERROR_NONE) {
LOG_E(TAG, "display_detect: failed to construct %s: %s", device->name, error_to_string(error));
return false;
}
device_set_parent(device, parent);
Driver* driver = driver_find_compatible(compatible);
if (driver == nullptr) {
LOG_E(TAG, "display_detect: no driver registered for %s", compatible);
device_destruct(device);
return false;
}
device_set_driver(device, driver);
error = device_add(device);
if (error != ERROR_NONE) {
LOG_E(TAG, "display_detect: failed to add %s: %s", device->name, error_to_string(error));
device_destruct(device);
return false;
}
return true;
}
bool construct_add_start(Device* device, Device* parent, const char* compatible) {
if (!construct_add(device, parent, compatible)) {
return false;
}
error_t error = device_start(device);
if (error != ERROR_NONE) {
LOG_E(TAG, "display_detect: failed to start %s: %s", device->name, error_to_string(error));
device_remove(device);
device_destruct(device);
return false;
}
return true;
}