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:
committed by
GitHub
parent
c4406b24ba
commit
50c0a14a93
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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*/) {
|
||||
|
||||
Reference in New Issue
Block a user