2026-08-09 16:17:42 +02:00

46 lines
1.3 KiB
C++

// SPDX-License-Identifier: Apache-2.0
#include <tactility/device.h>
#include <tactility/drivers/keyboard.h>
#include <tactility/error.h>
#define KEYBOARD_DRIVER_API(driver) ((struct KeyboardApi*)driver->api)
extern "C" {
error_t keyboard_read_key(Device* device, KeyboardKeyData* data) {
const auto* driver = device_get_driver(device);
// Default the modifier fields here rather than in each driver: only drivers whose hardware can
// report modifiers set them, and the rest would otherwise leave whatever the caller's stack held.
data->ctrl = false;
data->alt = false;
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);
}
bool keyboard_is_present(Device* device) {
const auto* driver = device_get_driver(device);
if (KEYBOARD_DRIVER_API(driver)->is_present == nullptr) {
return true;
}
return KEYBOARD_DRIVER_API(driver)->is_present(device);
}
const DeviceType KEYBOARD_TYPE {
.name = "keyboard"
};
}