New kernel drivers and more (#560)

- Added kernel base drivers for: display, pointer (touch, mouse, etc.), keyboard, adc, power supply and backlight
- Implement new kernel driver modules: `st7789-module` and `gt911-module`
- Implement ESP32 ADC "oneshot" kernel driver
- Implement ESP32  backlight kernel driver with ledc API
- Implemented `battery-sense` driver that allows for voltage measurement and creates a power supply child device
- Updated github actions
- Updated flash scripts
- Fix for esp32 legacy driver conflict with ADC
- Created separate `lilygo-tdeck` and `lilygo-tdeck-plus` devices
- Created `lilygo-module` with LilyGO kernel drivers
- Fix for intermittent errors in build related to code generation of `devicetree.c`
- `lvgl-module` can now map kernel drivers onto LVGL devices
- Created `KernelDisplayApp` as a mirror of `HalDisplayApp` (formerly `DisplayApp`)
- Removed `struct` and `enum` prefix in a lot of kernel driver cpp source files
- `lilygo-tdeck` and `lilygo-tdeck-plus` are now fully relying on kernel drivers and don't use any of the old HAL
This commit is contained in:
Ken Van Hoeylandt
2026-07-12 00:29:12 +02:00
committed by GitHub
parent c4406b24ba
commit 50c0a14a93
149 changed files with 5274 additions and 1266 deletions
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <Tactility/hal/display/DisplayDriver.h>
#include <tactility/device.h>
namespace tt::hal::display {
/** Wraps a TactilityKernel Device of type DISPLAY_TYPE as a DisplayDriver. */
class KernelDisplayDriver final : public DisplayDriver {
::Device* device;
public:
explicit KernelDisplayDriver(::Device* device);
ColorFormat getColorFormat() const override;
uint16_t getPixelWidth() const override;
uint16_t getPixelHeight() const override;
bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) override;
uint8_t getFrameBuffers(void* outBuffers[2]) const override;
};
}
@@ -2,6 +2,7 @@
#include <tactility/hal/Device.h>
#include <cstdint>
#include <string>
namespace tt::hal::power {
@@ -9,8 +10,8 @@ class PowerDevice : public Device {
public:
PowerDevice() = default;
~PowerDevice() override = default;
PowerDevice();
~PowerDevice() override;
Type getType() const override { return Type::Power; }
@@ -46,6 +47,17 @@ public:
virtual bool supportsPowerOff() const { return false; }
virtual void powerOff() { /* NO-OP*/ }
private:
/** Creates the kernel-level power_supply device that exposes this instance to TactilityKernel. */
void createPowerSupplyDevice();
/** Destroys the kernel-level power_supply device created by createPowerSupplyDevice(). */
void destroyPowerSupplyDevice();
std::string kernelDeviceName;
KernelDevice kernelDevice {};
};
}
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <Tactility/hal/touch/TouchDriver.h>
#include <tactility/device.h>
namespace tt::hal::touch {
/** Wraps a TactilityKernel Device of type POINTER_TYPE as a TouchDriver. */
class KernelTouchDriver final : public TouchDriver {
::Device* device;
public:
explicit KernelTouchDriver(::Device* device);
bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* pointCount, uint8_t maxPointCount) override;
};
}
@@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
namespace tt::hal::touch {
class TouchDriver {
+12 -3
View File
@@ -23,7 +23,9 @@
#include <tactility/concurrent/thread.h>
#include <tactility/crypt_module.h>
#include <tactility/drivers/display.h>
#include <tactility/drivers/grove.h>
#include <tactility/drivers/power_supply.h>
#include <tactility/drivers/rtc.h>
#include <tactility/drivers/uart_controller.h>
#include <tactility/filesystem/file_system.h>
@@ -112,6 +114,7 @@ namespace app {
namespace boot { extern const AppManifest manifest; }
namespace development { extern const AppManifest manifest; }
namespace display { extern const AppManifest manifest; }
namespace kerneldisplay { extern const AppManifest manifest; }
namespace files { extern const AppManifest manifest; }
namespace fileselection { extern const AppManifest manifest; }
namespace gpssettings { extern const AppManifest manifest; }
@@ -169,7 +172,11 @@ static void registerInternalApps() {
addAppManifest(app::apphubdetails::manifest);
addAppManifest(app::applist::manifest);
addAppManifest(app::appsettings::manifest);
addAppManifest(app::display::manifest);
if (device_exists_of_type(&DISPLAY_TYPE)) {
addAppManifest(app::kerneldisplay::manifest);
} else if (hal::hasDevice(hal::Device::Type::Display)) {
addAppManifest(app::display::manifest);
}
addAppManifest(app::files::manifest);
addAppManifest(app::fileselection::manifest);
addAppManifest(app::i2cscanner::manifest);
@@ -178,7 +185,9 @@ static void registerInternalApps() {
addAppManifest(app::launcher::manifest);
addAppManifest(app::localesettings::manifest);
addAppManifest(app::notes::manifest);
addAppManifest(app::poweroff::manifest);
if (device_exists_of_type(&POWER_SUPPLY_TYPE)) {
addAppManifest(app::poweroff::manifest);
}
addAppManifest(app::settings::manifest);
addAppManifest(app::selectiondialog::manifest);
addAppManifest(app::setup::manifest);
@@ -222,7 +231,7 @@ static void registerInternalApps() {
addAppManifest(app::gpssettings::manifest);
}
if (hal::hasDevice(hal::Device::Type::Power)) {
if (device_exists_of_type(&POWER_SUPPLY_TYPE)) {
addAppManifest(app::power::manifest);
}
+41 -3
View File
@@ -1,8 +1,10 @@
#include "Tactility/lvgl/Lvgl.h"
#include "tactility/drivers/backlight.h"
#include "tactility/drivers/display.h"
#include <Tactility/SystemEvents.h>
#include <Tactility/CpuAffinity.h>
#include <Tactility/Paths.h>
#include <Tactility/SystemEvents.h>
#include <Tactility/TactilityPrivate.h>
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppPaths.h>
@@ -56,7 +58,7 @@ class BootApp : public App {
getCpuAffinityConfiguration().system
);
static void setupDisplay() {
static void setupHalDisplay() {
const auto hal_display = getHalDisplay();
if (hal_display == nullptr) {
return;
@@ -80,6 +82,41 @@ class BootApp : public App {
}
}
static void setupKernelDisplay() {
auto* display = device_find_first_by_type(&DISPLAY_TYPE);
// Boards not yet migrated to the kernel display driver register a placeholder device (so
// the devicetree node resolves) with a NULL api - nothing for this function to act on.
if (display != nullptr && device_get_driver(display)->api == nullptr) {
display = nullptr;
}
if (display != nullptr) {
Device* backlight;
if (display_get_backlight(display, &backlight) == ERROR_NONE) {
if (!device_is_ready(backlight)) {
if (device_start(backlight) != ERROR_NONE) {
LOG_E(TAG, "Failed to start %s", backlight->name);
}
}
settings::display::DisplaySettings settings;
if (settings::display::load(settings)) {
} else {
settings = settings::display::getDefault();
}
if (backlight_set_brightness(backlight, settings.backlightDuty) == ERROR_NONE) {
LOG_I(TAG, "Backlight for %s set to %d", display->name, settings.backlightDuty);
} else {
LOG_E(TAG, "Failed to set brightness of %s", backlight->name);
}
} else {
LOG_I(TAG, "No backlight for %s", display->name);
}
} else {
LOG_I(TAG, "No kernel display");
}
}
static bool setupUsbBootMode() {
if (!hal::usb::isUsbBootMode()) {
return false;
@@ -124,7 +161,8 @@ class BootApp : public App {
// TODO: Support for multiple displays
LOG_I(TAG, "Setup display");
setupDisplay(); // Set backlight
setupHalDisplay();
setupKernelDisplay();
prepareFileSystems();
#ifdef CONFIG_TT_USER_DATA_LOCATION_SD
+8 -8
View File
@@ -34,7 +34,7 @@ static bool hasCalibratableTouchDevice() {
return false;
}
class DisplayApp final : public App {
class HalDisplayApp final : public App {
settings::display::DisplaySettings displaySettings;
bool displaySettingsUpdated = false;
@@ -44,7 +44,7 @@ class DisplayApp final : public App {
static void onBacklightSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto hal_display = getHalDisplay();
assert(hal_display != nullptr);
@@ -59,7 +59,7 @@ class DisplayApp final : public App {
static void onGammaSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto hal_display = hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
assert(hal_display != nullptr);
if (hal_display->getGammaCurveCount() > 0) {
@@ -71,7 +71,7 @@ class DisplayApp final : public App {
}
static void onOrientationSet(lv_event_t* event) {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
LOG_I(TAG, "Selected %u", (unsigned)selected_index);
@@ -84,7 +84,7 @@ class DisplayApp final : public App {
}
static void onTimeoutSwitch(lv_event_t* event) {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
bool enabled = lv_obj_has_state(sw, LV_STATE_CHECKED);
app->displaySettings.backlightTimeoutEnabled = enabled;
@@ -105,7 +105,7 @@ class DisplayApp final : public App {
}
static void onTimeoutChanged(lv_event_t* event) {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t idx = lv_dropdown_get_selected(dropdown);
// Map dropdown index to ms: 0=15s,1=30s,2=1m,3=2m,4=5m,5=Never
@@ -117,7 +117,7 @@ class DisplayApp final : public App {
}
static void onScreensaverChanged(lv_event_t* event) {
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t idx = lv_dropdown_get_selected(dropdown);
// Validate index bounds before casting to enum
@@ -338,7 +338,7 @@ extern const AppManifest manifest = {
.appName = "Display",
.appIcon = LVGL_ICON_SHARED_DISPLAY_SETTINGS,
.appCategory = Category::Settings,
.createApp = create<DisplayApp>
.createApp = create<HalDisplayApp>
};
} // namespace
@@ -0,0 +1,284 @@
#include <tactility/drivers/display.h>
#include <tactility/error.h>
#include <tactility/lvgl_icon_shared.h>
#include <tactility/device.h>
#include <tactility/drivers/backlight.h>
#include <tactility/log.h>
#include <tactility/lvgl_module.h>
#include <Tactility/Tactility.h>
#ifdef ESP_PLATFORM
#include <Tactility/service/displayidle/DisplayIdleService.h>
#endif
#include <Tactility/app/App.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/settings/DisplaySettings.h>
#include <lvgl.h>
namespace tt::app::kerneldisplay {
constexpr auto* TAG = "KernelDisplay";
static Device* getBacklightDevice() {
Device* display = device_find_first_by_type(&DISPLAY_TYPE);
check(display);
// Boards not yet migrated to the kernel display driver register a placeholder device (so the
// devicetree node resolves) with a NULL api - nothing for display_get_backlight() to act on.
if (device_get_driver(display)->api == nullptr) {
return nullptr;
}
Device* backlight = nullptr;
return display_get_backlight(display, &backlight) == ERROR_NONE ? backlight : nullptr;
}
class KernelDisplayApp final : public App {
settings::display::DisplaySettings displaySettings;
bool displaySettingsUpdated = false;
lv_obj_t* timeoutSwitch = nullptr;
lv_obj_t* timeoutDropdown = nullptr;
lv_obj_t* screensaverDropdown = nullptr;
static void onBacklightSliderEvent(lv_event_t* event) {
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* backlight = getBacklightDevice();
assert(backlight != nullptr);
int32_t slider_value = lv_slider_get_value(slider);
app->displaySettings.backlightDuty = static_cast<uint8_t>(slider_value);
app->displaySettingsUpdated = true;
backlight_set_brightness(backlight, app->displaySettings.backlightDuty);
}
static void onOrientationSet(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
LOG_I(TAG, "Selected %u", (unsigned)selected_index);
auto selected_orientation = static_cast<settings::display::Orientation>(selected_index);
if (selected_orientation != app->displaySettings.orientation) {
app->displaySettings.orientation = selected_orientation;
app->displaySettingsUpdated = true;
lv_display_set_rotation(lv_display_get_default(), settings::display::toLvglDisplayRotation(selected_orientation));
}
}
static void onTimeoutSwitch(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
bool enabled = lv_obj_has_state(sw, LV_STATE_CHECKED);
app->displaySettings.backlightTimeoutEnabled = enabled;
app->displaySettingsUpdated = true;
if (app->timeoutDropdown) {
if (enabled) {
lv_obj_clear_state(app->timeoutDropdown, LV_STATE_DISABLED);
if (app->screensaverDropdown) {
lv_obj_clear_state(app->screensaverDropdown, LV_STATE_DISABLED);
}
} else {
lv_obj_add_state(app->timeoutDropdown, LV_STATE_DISABLED);
if (app->screensaverDropdown) {
lv_obj_add_state(app->screensaverDropdown, LV_STATE_DISABLED);
}
}
}
}
static void onTimeoutChanged(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t idx = lv_dropdown_get_selected(dropdown);
// Map dropdown index to ms: 0=15s,1=30s,2=1m,3=2m,4=5m,5=Never
static const uint32_t values_ms[] = {15000, 30000, 60000, 120000, 300000, 0};
if (idx < (sizeof(values_ms)/sizeof(values_ms[0]))) {
app->displaySettings.backlightTimeoutMs = values_ms[idx];
app->displaySettingsUpdated = true;
}
}
static void onScreensaverChanged(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t idx = lv_dropdown_get_selected(dropdown);
// Validate index bounds before casting to enum
if (idx >= static_cast<uint32_t>(settings::display::ScreensaverType::Count)) {
return;
}
auto selected_type = static_cast<settings::display::ScreensaverType>(idx);
if (selected_type != app->displaySettings.screensaverType) {
app->displaySettings.screensaverType = selected_type;
app->displaySettingsUpdated = true;
}
}
public:
void onShow(AppContext& app, lv_obj_t* parent) override {
displaySettings = settings::display::loadOrGetDefault();
auto ui_density = lvgl_get_ui_density();
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
auto* backlight = getBacklightDevice();
lvgl::toolbar_create(parent, app);
auto* main_wrapper = lv_obj_create(parent);
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_width(main_wrapper, LV_PCT(100));
lv_obj_set_flex_grow(main_wrapper, 1);
// Backlight slider
// Note: no gamma slider here - unlike HalDisplayApp (app/display/Display.cpp), the kernel
// DisplayApi has no gamma curve control yet.
if (backlight != nullptr) {
auto* brightness_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(brightness_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_hor(brightness_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(brightness_wrapper, 0, LV_STATE_DEFAULT);
if (ui_density != LVGL_UI_DENSITY_COMPACT) {
lv_obj_set_style_pad_ver(brightness_wrapper, 4, LV_STATE_DEFAULT);
}
auto* brightness_label = lv_label_create(brightness_wrapper);
lv_label_set_text(brightness_label, "Brightness");
lv_obj_align(brightness_label, LV_ALIGN_LEFT_MID, 0, 0);
auto* brightness_slider = lv_slider_create(brightness_wrapper);
lv_obj_set_width(brightness_slider, LV_PCT(50));
lv_obj_align(brightness_slider, LV_ALIGN_RIGHT_MID, 0, 0);
lv_slider_set_range(brightness_slider, backlight_get_min_brightness(backlight), backlight_get_max_brightness(backlight));
lv_obj_add_event_cb(brightness_slider, onBacklightSliderEvent, LV_EVENT_VALUE_CHANGED, this);
lv_slider_set_value(brightness_slider, displaySettings.backlightDuty, LV_ANIM_OFF);
}
// Orientation
auto* orientation_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(orientation_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(orientation_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(orientation_wrapper, 0, LV_STATE_DEFAULT);
auto* orientation_label = lv_label_create(orientation_wrapper);
lv_label_set_text(orientation_label, "Orientation");
lv_obj_align(orientation_label, LV_ALIGN_LEFT_MID, 0, 0);
auto* orientation_dropdown = lv_dropdown_create(orientation_wrapper);
// Note: order correlates with settings::display::Orientation item order
lv_dropdown_set_options(orientation_dropdown, "Landscape\nPortrait Right\nLandscape Flipped\nPortrait Left");
lv_obj_align(orientation_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(orientation_dropdown, onOrientationSet, LV_EVENT_VALUE_CHANGED, this);
// Set the dropdown to match current orientation enum
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
// Screen timeout
// Note: DisplayIdleService doesn't act on these settings for kernel-driver displays yet
// (it only looks up the deprecated tt::hal::display::DisplayDevice), so these currently
// just get saved without taking effect. Kept for parity/forward-compatibility.
if (backlight != nullptr) {
auto* timeout_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(timeout_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(timeout_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(timeout_wrapper, 0, LV_STATE_DEFAULT);
auto* timeout_label = lv_label_create(timeout_wrapper);
lv_label_set_text(timeout_label, "Auto screen off");
lv_obj_align(timeout_label, LV_ALIGN_LEFT_MID, 0, 0);
timeoutSwitch = lv_switch_create(timeout_wrapper);
if (displaySettings.backlightTimeoutEnabled) {
lv_obj_add_state(timeoutSwitch, LV_STATE_CHECKED);
}
lv_obj_align(timeoutSwitch, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(timeoutSwitch, onTimeoutSwitch, LV_EVENT_VALUE_CHANGED, this);
auto* timeout_select_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(timeout_select_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(timeout_select_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(timeout_select_wrapper, 0, LV_STATE_DEFAULT);
auto* timeout_value_label = lv_label_create(timeout_select_wrapper);
lv_label_set_text(timeout_value_label, "Timeout");
lv_obj_align(timeout_value_label, LV_ALIGN_LEFT_MID, 0, 0);
timeoutDropdown = lv_dropdown_create(timeout_select_wrapper);
lv_dropdown_set_options(timeoutDropdown, "15 seconds\n30 seconds\n1 minute\n2 minutes\n5 minutes\nNever");
lv_obj_align(timeoutDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(timeoutDropdown, onTimeoutChanged, LV_EVENT_VALUE_CHANGED, this);
// Initialize dropdown selection from settings
uint32_t ms = displaySettings.backlightTimeoutMs;
uint32_t idx = 2; // default 1 minute
if (ms == 15000) idx = 0;
else if (ms == 30000)
idx = 1;
else if (ms == 60000)
idx = 2;
else if (ms == 120000)
idx = 3;
else if (ms == 300000)
idx = 4;
else if (ms == 0)
idx = 5;
lv_dropdown_set_selected(timeoutDropdown, idx);
if (!displaySettings.backlightTimeoutEnabled) {
lv_obj_add_state(timeoutDropdown, LV_STATE_DISABLED);
}
// Screensaver type
auto* screensaver_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(screensaver_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(screensaver_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(screensaver_wrapper, 0, LV_STATE_DEFAULT);
auto* screensaver_label = lv_label_create(screensaver_wrapper);
lv_label_set_text(screensaver_label, "Screensaver");
lv_obj_align(screensaver_label, LV_ALIGN_LEFT_MID, 0, 0);
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
// Note: order correlates with settings::display::ScreensaverType enum order
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
if (!displaySettings.backlightTimeoutEnabled) {
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
}
}
// Note: no touch calibration section here - unlike HalDisplayApp, the kernel PointerApi has
// no calibration support yet.
}
void onHide(AppContext& app) override {
if (displaySettingsUpdated) {
// Dispatch it, so file IO doesn't block the UI
const settings::display::DisplaySettings settings_to_save = displaySettings;
getMainDispatcher().dispatch([settings_to_save] {
settings::display::save(settings_to_save);
#ifdef ESP_PLATFORM
// Notify DisplayIdle service to reload settings
auto displayIdle = service::displayidle::findService();
if (displayIdle) {
displayIdle->reloadSettings();
}
#endif
});
}
}
};
extern const AppManifest manifest = {
.appId = "Display",
.appName = "Display",
.appIcon = LVGL_ICON_SHARED_DISPLAY_SETTINGS,
.appCategory = Category::Settings,
.createApp = create<KernelDisplayApp>
};
} // namespace
@@ -5,15 +5,12 @@
#include <Tactility/settings/KeyboardSettings.h>
#include <Tactility/lvgl/Toolbar.h>
#include <tactility/device.h>
#include <tactility/drivers/backlight.h>
#include <tactility/lvgl_icon_shared.h>
#include <lvgl.h>
// Forward declare driver functions
namespace keyboardbacklight {
bool setBrightness(uint8_t brightness);
}
namespace tt::app::keyboardsettings {
constexpr auto* TAG = "KeyboardSettings";
@@ -30,7 +27,11 @@ static uint32_t timeoutMsToIndex(uint32_t ms) {
}
static void applyKeyboardBacklight(bool enabled, uint8_t brightness) {
keyboardbacklight::setBrightness(enabled ? brightness : 0);
// TODO: Get keyboard backlight from (optional) keyboard child device
Device* backlight = device_find_by_name("keyboard_backlight");
if (backlight != nullptr) {
backlight_set_brightness(backlight, enabled ? brightness : 0);
}
}
class KeyboardSettingsApp final : public App {
+5 -4
View File
@@ -4,13 +4,14 @@
#include <Tactility/app/AppPaths.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/app/setup/Setup.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/BootSettings.h>
#include <cstring>
#include <lvgl.h>
#include <tactility/device.h>
#include <tactility/drivers/power_supply.h>
#include <tactility/log.h>
#include <tactility/lvgl_fonts.h>
#include <tactility/lvgl_icon_launcher.h>
@@ -73,9 +74,9 @@ class LauncherApp final : public App {
static bool shouldShowPowerButton() {
bool show_power_button = false;
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&show_power_button](const auto& device) {
if (device->supportsPowerOff()) {
show_power_button = true;
device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) {
if (device_is_ready(device) && power_supply_supports_power_off(device)) {
*static_cast<bool*>(context) = true;
return false; // stop iterating
} else {
return true; // continue iterating
+26 -26
View File
@@ -4,10 +4,10 @@
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/service/loader/Loader.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/Timer.h>
#include <tactility/hal/Device.h>
#include <tactility/device.h>
#include <tactility/drivers/power_supply.h>
#include <tactility/lvgl_icon_shared.h>
#include <lvgl.h>
@@ -34,7 +34,7 @@ class PowerApp : public App {
Timer update_timer = Timer(Timer::Type::Periodic, kernel::millisToTicks(1000),[]() { onTimer(); });
std::shared_ptr<hal::power::PowerDevice> power;
::Device* power = nullptr;
lv_obj_t* enableLabel = nullptr;
lv_obj_t* enableSwitch = nullptr;
@@ -58,8 +58,8 @@ class PowerApp : public App {
if (code == LV_EVENT_VALUE_CHANGED) {
bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED);
if (power->isAllowedToCharge() != is_on) {
power->setAllowedToCharge(is_on);
if (power_supply_is_allowed_to_charge(power) != is_on) {
power_supply_set_allowed_to_charge(power, is_on);
updateUi();
}
}
@@ -76,8 +76,8 @@ class PowerApp : public App {
if (code == LV_EVENT_VALUE_CHANGED) {
bool is_on = lv_obj_has_state(qc_switch, LV_STATE_CHECKED);
if (power->isQuickChargeEnabled() != is_on) {
power->setQuickChargeEnabled(is_on);
if (power_supply_is_quick_charge_enabled(power) != is_on) {
power_supply_set_quick_charge_enabled(power, is_on);
updateUi();
}
}
@@ -94,37 +94,37 @@ class PowerApp : public App {
}
const char* charge_state;
hal::power::PowerDevice::MetricData metric_data;
if (power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, metric_data)) {
charge_state = metric_data.valueAsBool ? "yes" : "no";
PowerSupplyPropertyValue property_value;
if (power_supply_get_property(power, POWER_SUPPLY_PROP_IS_CHARGING, &property_value) == ERROR_NONE) {
charge_state = property_value.int_value ? "yes" : "no";
} else {
charge_state = "N/A";
}
uint8_t charge_level;
int charge_level;
bool charge_level_scaled_set = false;
if (power->getMetric(hal::power::PowerDevice::MetricType::ChargeLevel, metric_data)) {
charge_level = metric_data.valueAsUint8;
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &property_value) == ERROR_NONE) {
charge_level = property_value.int_value;
charge_level_scaled_set = true;
}
bool charging_enabled_set = power->supportsChargeControl();
bool charging_enabled_and_allowed = power->supportsChargeControl() && power->isAllowedToCharge();
bool charging_enabled_set = power_supply_supports_charge_control(power);
bool charging_enabled_and_allowed = charging_enabled_set && power_supply_is_allowed_to_charge(power);
bool quick_charge_set = power->supportsQuickCharge();
bool quick_charge_enabled = power->supportsQuickCharge() && power->isQuickChargeEnabled();
bool quick_charge_set = power_supply_supports_quick_charge(power);
bool quick_charge_enabled = quick_charge_set && power_supply_is_quick_charge_enabled(power);
int32_t current;
int current;
bool current_set = false;
if (power->getMetric(hal::power::PowerDevice::MetricType::Current, metric_data)) {
current = metric_data.valueAsInt32;
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CURRENT, &property_value) == ERROR_NONE) {
current = property_value.int_value;
current_set = true;
}
uint32_t battery_voltage;
int battery_voltage;
bool battery_voltage_set = false;
if (power->getMetric(hal::power::PowerDevice::MetricType::BatteryVoltage, metric_data)) {
battery_voltage = metric_data.valueAsUint32;
if (power_supply_get_property(power, POWER_SUPPLY_PROP_VOLTAGE, &property_value) == ERROR_NONE) {
battery_voltage = property_value.int_value;
battery_voltage_set = true;
}
@@ -151,7 +151,7 @@ class PowerApp : public App {
lv_label_set_text_fmt(chargeStateLabel, "Charging: %s", charge_state);
if (battery_voltage_set) {
lv_label_set_text_fmt(batteryVoltageLabel, "Battery voltage: %lu mV", battery_voltage);
lv_label_set_text_fmt(batteryVoltageLabel, "Battery voltage: %d mV", battery_voltage);
} else {
lv_label_set_text_fmt(batteryVoltageLabel, "Battery voltage: N/A");
}
@@ -163,7 +163,7 @@ class PowerApp : public App {
}
if (current_set) {
lv_label_set_text_fmt(currentLabel, "Current: %ld mA", current);
lv_label_set_text_fmt(currentLabel, "Current: %d mA", current);
} else {
lv_label_set_text_fmt(currentLabel, "Current: N/A");
}
@@ -174,7 +174,7 @@ class PowerApp : public App {
public:
void onCreate(AppContext& app) override {
power = hal::findFirstDevice<hal::power::PowerDevice>(hal::Device::Type::Power);
power = device_find_first_active_by_type(&POWER_SUPPLY_TYPE);
}
void onShow(AppContext& app, lv_obj_t* parent) override {
+5 -4
View File
@@ -1,10 +1,11 @@
#include <Tactility/app/AppContext.h>
#include <Tactility/app/AppRegistration.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/service/loader/Loader.h>
#include <lvgl.h>
#include <tactility/device.h>
#include <tactility/drivers/power_supply.h>
#include <tactility/hal/Device.h>
#include <tactility/lvgl_fonts.h>
#include <tactility/lvgl_icon_shared.h>
@@ -48,15 +49,15 @@ class PowerOffApp final : public App {
}
static void onYesPressed(lv_event_t* /*event*/) {
auto power = hal::findFirstDevice<hal::power::PowerDevice>(hal::Device::Type::Power);
if (power == nullptr || !power->supportsPowerOff()) {
auto* power = device_find_first_active_by_type(&POWER_SUPPLY_TYPE);
if (power == nullptr || !power_supply_supports_power_off(power)) {
return;
}
auto display = hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
showPoweredOffScreenAndWait(display.get());
power->powerOff();
power_supply_power_off(power);
}
static void onNoPressed(lv_event_t* /*event*/) {
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
#include <Tactility/hal/display/KernelDisplayDriver.h>
#include <tactility/drivers/display.h>
#include <algorithm>
#include <cassert>
#include <utility>
namespace tt::hal::display {
static ColorFormat toColorFormat(DisplayColorFormat format) {
switch (format) {
case DISPLAY_COLOR_FORMAT_MONOCHROME:
return ColorFormat::Monochrome;
case DISPLAY_COLOR_FORMAT_BGR565:
return ColorFormat::BGR565;
case DISPLAY_COLOR_FORMAT_BGR565_SWAPPED:
return ColorFormat::BGR565Swapped;
case DISPLAY_COLOR_FORMAT_RGB565:
return ColorFormat::RGB565;
case DISPLAY_COLOR_FORMAT_RGB565_SWAPPED:
return ColorFormat::RGB565Swapped;
case DISPLAY_COLOR_FORMAT_RGB888:
return ColorFormat::RGB888;
default:
std::unreachable();
}
}
KernelDisplayDriver::KernelDisplayDriver(::Device* device) : device(device) {
assert(device_get_type(device) == &DISPLAY_TYPE);
}
ColorFormat KernelDisplayDriver::getColorFormat() const {
return toColorFormat(display_get_color_format(device));
}
uint16_t KernelDisplayDriver::getPixelWidth() const {
return display_get_resolution_x(device);
}
uint16_t KernelDisplayDriver::getPixelHeight() const {
return display_get_resolution_y(device);
}
bool KernelDisplayDriver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) {
return display_draw_bitmap(device, xStart, yStart, xEnd, yEnd, pixelData) == ERROR_NONE;
}
uint8_t KernelDisplayDriver::getFrameBuffers(void* outBuffers[2]) const {
uint8_t count = std::min<uint8_t>(display_get_frame_buffer_count(device), 2);
for (uint8_t i = 0; i < count; i++) {
display_get_frame_buffer(device, i, &outBuffers[i]);
}
return count;
}
}
+172
View File
@@ -0,0 +1,172 @@
// SPDX-License-Identifier: Apache-2.0
#include <Tactility/hal/power/PowerDevice.h>
#include <tactility/check.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/power_supply.h>
#include <format>
namespace tt::hal::power {
#define GET_POWER_DEVICE(device) (static_cast<PowerDevice*>(device_get_driver_data(device)))
static PowerDevice::MetricType toMetricType(PowerSupplyProperty property) {
switch (property) {
case POWER_SUPPLY_PROP_IS_CHARGING:
return PowerDevice::MetricType::IsCharging;
case POWER_SUPPLY_PROP_CURRENT:
return PowerDevice::MetricType::Current;
case POWER_SUPPLY_PROP_VOLTAGE:
return PowerDevice::MetricType::BatteryVoltage;
case POWER_SUPPLY_PROP_CAPACITY:
default:
return PowerDevice::MetricType::ChargeLevel;
}
}
static int toIntValue(PowerDevice::MetricType type, const PowerDevice::MetricData& data) {
switch (type) {
case PowerDevice::MetricType::IsCharging:
return data.valueAsBool ? 1 : 0;
case PowerDevice::MetricType::Current:
return data.valueAsInt32;
case PowerDevice::MetricType::BatteryVoltage:
return static_cast<int>(data.valueAsUint32);
case PowerDevice::MetricType::ChargeLevel:
default:
return data.valueAsUint8;
}
}
static bool apiSupportsProperty(::Device* device, PowerSupplyProperty property) {
return GET_POWER_DEVICE(device)->supportsMetric(toMetricType(property));
}
static error_t apiGetProperty(::Device* device, PowerSupplyProperty property, PowerSupplyPropertyValue* outValue) {
auto* power_device = GET_POWER_DEVICE(device);
auto metric_type = toMetricType(property);
if (!power_device->supportsMetric(metric_type)) {
return ERROR_NOT_SUPPORTED;
}
PowerDevice::MetricData data;
if (!power_device->getMetric(metric_type, data)) {
return ERROR_NOT_FOUND;
}
outValue->int_value = toIntValue(metric_type, data);
return ERROR_NONE;
}
static bool apiSupportsChargeControl(::Device* device) {
return GET_POWER_DEVICE(device)->supportsChargeControl();
}
static bool apiIsAllowedToCharge(::Device* device) {
return GET_POWER_DEVICE(device)->isAllowedToCharge();
}
static error_t apiSetAllowedToCharge(::Device* device, bool allowed) {
auto* power_device = GET_POWER_DEVICE(device);
if (!power_device->supportsChargeControl()) {
return ERROR_NOT_SUPPORTED;
}
power_device->setAllowedToCharge(allowed);
return ERROR_NONE;
}
static bool apiSupportsQuickCharge(::Device* device) {
return GET_POWER_DEVICE(device)->supportsQuickCharge();
}
static bool apiIsQuickChargeEnabled(::Device* device) {
return GET_POWER_DEVICE(device)->isQuickChargeEnabled();
}
static error_t apiSetQuickChargeEnabled(::Device* device, bool enabled) {
auto* power_device = GET_POWER_DEVICE(device);
if (!power_device->supportsQuickCharge()) {
return ERROR_NOT_SUPPORTED;
}
power_device->setQuickChargeEnabled(enabled);
return ERROR_NONE;
}
static bool apiSupportsPowerOff(::Device* device) {
return GET_POWER_DEVICE(device)->supportsPowerOff();
}
static error_t apiPowerOff(::Device* device) {
auto* power_device = GET_POWER_DEVICE(device);
if (!power_device->supportsPowerOff()) {
return ERROR_NOT_SUPPORTED;
}
power_device->powerOff();
return ERROR_NONE;
}
static error_t startDevice(::Device*) { return ERROR_NONE; }
static error_t stopDevice(::Device*) { return ERROR_NONE; }
static PowerSupplyApi powerSupplyApi {
.supports_property = apiSupportsProperty,
.get_property = apiGetProperty,
.supports_charge_control = apiSupportsChargeControl,
.is_allowed_to_charge = apiIsAllowedToCharge,
.set_allowed_to_charge = apiSetAllowedToCharge,
.supports_quick_charge = apiSupportsQuickCharge,
.is_quick_charge_enabled = apiIsQuickChargeEnabled,
.set_quick_charge_enabled = apiSetQuickChargeEnabled,
.supports_power_off = apiSupportsPowerOff,
.power_off = apiPowerOff,
};
static const char* powerSupplyCompatible[] = { "hal-power-device", nullptr };
static Driver powerSupplyDriver {
.name = "hal-power-device",
.compatible = powerSupplyCompatible,
.start_device = startDevice,
.stop_device = stopDevice,
.api = &powerSupplyApi,
.device_type = &POWER_SUPPLY_TYPE,
.owner = nullptr,
.internal = nullptr,
};
/** Registers the "hal-power-device" driver with the kernel on first use. */
static Driver& getPowerSupplyDriver() {
static const bool registered = [] {
check(driver_construct_add(&powerSupplyDriver) == ERROR_NONE);
return true;
}();
(void)registered;
return powerSupplyDriver;
}
void PowerDevice::createPowerSupplyDevice() {
kernelDeviceName = std::format("power-supply-{}", getId());
kernelDevice.name = kernelDeviceName.c_str();
check(device_construct(&kernelDevice) == ERROR_NONE);
check(device_add(&kernelDevice) == ERROR_NONE);
device_set_driver(&kernelDevice, &getPowerSupplyDriver());
check(device_start(&kernelDevice) == ERROR_NONE);
device_set_driver_data(&kernelDevice, this);
}
void PowerDevice::destroyPowerSupplyDevice() {
device_set_driver_data(&kernelDevice, nullptr);
check(device_stop(&kernelDevice) == ERROR_NONE);
check(device_remove(&kernelDevice) == ERROR_NONE);
check(device_destruct(&kernelDevice) == ERROR_NONE);
}
PowerDevice::PowerDevice() {
createPowerSupplyDevice();
}
PowerDevice::~PowerDevice() {
destroyPowerSupplyDevice();
}
}
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
#include <Tactility/hal/touch/KernelTouchDriver.h>
#include <tactility/drivers/pointer.h>
#include <cassert>
namespace tt::hal::touch {
// Bus reads are expected to complete quickly; bound the wait so a stalled controller can't block the LVGL indev poll.
static constexpr TickType_t READ_TIMEOUT = pdMS_TO_TICKS(10);
KernelTouchDriver::KernelTouchDriver(::Device* device) : device(device) {
assert(device_get_type(device) == &POINTER_TYPE);
}
bool KernelTouchDriver::getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* pointCount, uint8_t maxPointCount) {
if (pointer_read_data(device, READ_TIMEOUT) != ERROR_NONE) {
return false;
}
return pointer_get_touched_points(device, x, y, strength, pointCount, maxPointCount);
}
}
+3 -2
View File
@@ -1,7 +1,8 @@
#include "Tactility/lvgl/Keyboard.h"
#include "Tactility/service/gui/GuiService.h"
#include <Tactility/service/espnow/EspNowService.h>
#include <tactility/device.h>
#include <tactility/drivers/keyboard.h>
namespace tt::lvgl {
@@ -46,7 +47,7 @@ void software_keyboard_deactivate() {
}
bool hardware_keyboard_is_available() {
return keyboard_device != nullptr;
return keyboard_device != nullptr || device_find_first_by_type(&KEYBOARD_TYPE) != nullptr;
}
void hardware_keyboard_set_indev(lv_indev_t* device) {
+18 -17
View File
@@ -9,6 +9,8 @@
#include <Tactility/service/ServiceRegistration.h>
#include <Tactility/settings/DisplaySettings.h>
#include <tactility/device.h>
#include <tactility/drivers/backlight.h>
#include <tactility/log.h>
#include <tactility/lvgl_module.h>
#include <tactility/module.h>
@@ -32,37 +34,36 @@ void attachDevices() {
// Start displays (their related touch devices start automatically within)
LOG_I(TAG, "Start displays");
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (const auto& display: displays) {
auto hal_displays= hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (const auto& display: hal_displays) {
if (display->supportsLvgl()) {
if (display->startLvgl()) {
LOG_I(TAG, "Started %s", display->getName().c_str());
auto lvgl_display = display->getLvglDisplay();
assert(lvgl_display != nullptr);
auto settings = settings::display::loadOrGetDefault();
lv_display_rotation_t rotation = settings::display::toLvglDisplayRotation(settings.orientation);
if (rotation != lv_display_get_rotation(lvgl_display)) {
lv_display_set_rotation(lvgl_display, rotation);
}
} else {
LOG_E(TAG, "Start failed for %s", display->getName().c_str());
}
}
}
auto* primary_lvgl_display = lv_disp_get_default();
if (primary_lvgl_display != nullptr) {
LOG_I(TAG, "Set default display rotation");
auto settings = settings::display::loadOrGetDefault();
lv_display_rotation_t rotation = settings::display::toLvglDisplayRotation(settings.orientation);
if (rotation != lv_display_get_rotation(primary_lvgl_display)) {
lv_display_set_rotation(primary_lvgl_display, rotation);
}
}
// Start touch
// TODO: Consider implementing support for multiple displays
auto primary_display = !displays.empty() ? displays[0] : nullptr;
// Start display-related peripherals
if (primary_display != nullptr) {
if (primary_lvgl_display != nullptr) {
LOG_I(TAG, "Start touch devices");
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (const auto& touch_device: touch_devices) {
// Start any touch devices that haven't been started yet
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
if (touch_device->startLvgl(primary_display->getLvglDisplay())) {
if (touch_device->startLvgl(primary_lvgl_display)) {
LOG_I(TAG, "Started %s", touch_device->getName().c_str());
} else {
LOG_E(TAG, "Start failed for %s", touch_device->getName().c_str());
@@ -75,7 +76,7 @@ void attachDevices() {
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (const auto& keyboard: keyboards) {
if (keyboard->isAttached()) {
if (keyboard->startLvgl(primary_display->getLvglDisplay())) {
if (keyboard->startLvgl(primary_lvgl_display)) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
hardware_keyboard_set_indev(keyboard_indev);
LOG_I(TAG, "Started %s", keyboard->getName().c_str());
@@ -89,7 +90,7 @@ void attachDevices() {
LOG_I(TAG, "Start encoders");
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
for (const auto& encoder: encoders) {
if (encoder->startLvgl(primary_display->getLvglDisplay())) {
if (encoder->startLvgl(primary_lvgl_display)) {
LOG_I(TAG, "Started %s", encoder->getName().c_str());
} else {
LOG_E(TAG, "Start failed for %s", encoder->getName().c_str());
@@ -9,9 +9,8 @@
#include <Tactility/settings/KeyboardSettings.h>
#include <Tactility/Timer.h>
namespace keyboardbacklight {
bool setBrightness(uint8_t brightness);
}
#include <tactility/device.h>
#include <tactility/drivers/backlight.h>
namespace tt::service::keyboardidle {
@@ -25,6 +24,17 @@ class KeyboardIdleService final : public Service {
return hal::findFirstDevice<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
}
static Device* getKeyboardBacklight() {
return device_find_by_name("keyboard_backlight");
}
void setKeyboardBacklightBrightness(uint8_t brightness) {
Device* backlight = getKeyboardBacklight();
if (backlight != nullptr) {
backlight_set_brightness(backlight, brightness);
}
}
void tick() {
// Settings are now cached and event-driven (no file I/O in timer callback!)
// This prevents watchdog timeout from blocking the Timer Service task
@@ -42,15 +52,15 @@ class KeyboardIdleService final : public Service {
// If timeout disabled, ensure backlight restored if we had dimmed it
if (!cachedKeyboardSettings.backlightTimeoutEnabled || cachedKeyboardSettings.backlightTimeoutMs == 0) {
if (keyboardDimmed) {
keyboardbacklight::setBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
setKeyboardBacklightBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
keyboardDimmed = false;
}
} else {
if (!keyboardDimmed && inactive_ms >= cachedKeyboardSettings.backlightTimeoutMs) {
keyboardbacklight::setBrightness(0);
setKeyboardBacklightBrightness(0);
keyboardDimmed = true;
} else if (keyboardDimmed && inactive_ms < 100) {
keyboardbacklight::setBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
setKeyboardBacklightBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
keyboardDimmed = false;
}
}
@@ -62,7 +72,8 @@ public:
// Load settings once at startup and cache them
// This eliminates file I/O from timer callback (prevents watchdog timeout)
cachedKeyboardSettings = settings::keyboard::loadOrGetDefault();
setKeyboardBacklightBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
// Note: Settings changes require service restart to take effect
// TODO: Add KeyboardSettingsChanged events for dynamic updates
@@ -80,7 +91,7 @@ public:
// Ensure keyboard restored on stop
auto keyboard = getKeyboard();
if (keyboard && keyboardDimmed) {
keyboardbacklight::setBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
setKeyboardBacklightBrightness(cachedKeyboardSettings.backlightEnabled ? cachedKeyboardSettings.backlightBrightness : 0);
keyboardDimmed = false;
}
}
@@ -2,7 +2,7 @@
#include <Tactility/Mutex.h>
#include <Tactility/Timer.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <tactility/drivers/power_supply.h>
#include <tactility/filesystem/file_system.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
@@ -90,10 +90,10 @@ static const char* getSdCardStatusIcon(bool mounted) {
static const char* getPowerStatusIcon() {
// TODO: Support multiple power devices?
std::shared_ptr<hal::power::PowerDevice> power;
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&power](const auto& device) {
if (device->supportsMetric(hal::power::PowerDevice::MetricType::ChargeLevel)) {
power = device;
Device* power = nullptr;
device_for_each_of_type(&POWER_SUPPLY_TYPE, &power, [](Device* device, void* context) {
if (device_is_ready(device) && power_supply_supports_property(device, POWER_SUPPLY_PROP_CAPACITY)) {
*static_cast<Device**>(context) = device;
return false;
}
return true;
@@ -103,12 +103,12 @@ static const char* getPowerStatusIcon() {
return nullptr;
}
hal::power::PowerDevice::MetricData charge_level;
if (!power->getMetric(hal::power::PowerDevice::MetricType::ChargeLevel, charge_level)) {
PowerSupplyPropertyValue charge_level;
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &charge_level) != ERROR_NONE) {
return nullptr;
}
uint8_t charge = charge_level.valueAsUint8;
int charge = charge_level.int_value;
if (charge >= 95) {
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_FULL;