Display brightness support (#26)

* cleanup

* brightness control and app

* cleanup

* persistant storage of display settings

* fix for missing include

* header cleanup

* fix pc build

* add docs

* move display app to tactility project
This commit is contained in:
Ken Van Hoeylandt
2024-01-31 20:39:12 +01:00
committed by GitHub
parent ae5c828f42
commit d171b9a231
33 changed files with 626 additions and 94 deletions
+11 -7
View File
@@ -1,13 +1,11 @@
#include "config.h"
#include "kernel.h"
#include "display_i.h"
#include "driver/spi_common.h"
#include "keyboard.h"
#include "log.h"
#include <driver/spi_common.h>
#include "tactility_core.h"
#define TAG "tdeck_bootstrap"
lv_disp_t* tdeck_display_init();
static bool tdeck_power_on() {
gpio_config_t device_power_signal_config = {
.pin_bit_mask = BIT64(TDECK_POWERON_GPIO),
@@ -38,8 +36,7 @@ static bool init_i2c() {
.master.clk_speed = 400000
};
return i2c_param_config(TDECK_I2C_BUS_HANDLE, &i2c_conf) == ESP_OK
&& i2c_driver_install(TDECK_I2C_BUS_HANDLE, i2c_conf.mode, 0, 0, 0) == ESP_OK;
return i2c_param_config(TDECK_I2C_BUS_HANDLE, &i2c_conf) == ESP_OK && i2c_driver_install(TDECK_I2C_BUS_HANDLE, i2c_conf.mode, 0, 0, 0) == ESP_OK;
}
static bool init_spi() {
@@ -89,6 +86,13 @@ bool tdeck_bootstrap() {
return false;
}
// Don't turn the backlight on yet - Tactility init will take care of it
TT_LOG_I(TAG, "Init backlight");
if (!tdeck_backlight_init()) {
TT_LOG_E(TAG, "Init backlight failed");
return false;
}
keyboard_wait_for_response();
return true;
+17 -6
View File
@@ -9,7 +9,7 @@
#define TAG "tdeck_display"
void tdeck_enable_backlight() {
bool tdeck_backlight_init() {
ledc_timer_config_t ledc_timer = {
.speed_mode = TDECK_LCD_BACKLIGHT_LEDC_MODE,
.timer_num = TDECK_LCD_BACKLIGHT_LEDC_TIMER,
@@ -17,20 +17,31 @@ void tdeck_enable_backlight() {
.freq_hz = TDECK_LCD_BACKLIGHT_LEDC_FREQUENCY,
.clk_cfg = LEDC_AUTO_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
TT_LOG_E(TAG, "Backlight led timer config failed");
return false;
}
return true;
}
void tdeck_backlight_set(uint8_t duty) {
ledc_channel_config_t ledc_channel = {
.speed_mode = TDECK_LCD_BACKLIGHT_LEDC_MODE,
.channel = TDECK_LCD_BACKLIGHT_LEDC_CHANNEL,
.timer_sel = TDECK_LCD_BACKLIGHT_LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = TDECK_LCD_BACKLIGHT_LEDC_OUTPUT_IO,
.duty = 0, // Set duty to 0%
.gpio_num = TDECK_LCD_PIN_BACKLIGHT,
.duty = duty,
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
ESP_ERROR_CHECK(ledc_set_duty(TDECK_LCD_BACKLIGHT_LEDC_MODE, TDECK_LCD_BACKLIGHT_LEDC_CHANNEL, TDECK_LCD_BACKLIGHT_LEDC_DUTY));
// Setting the config in the timer init and then calling ledc_set_duty() doesn't work when
// the app is running. For an unknown reason we have to call this config method every time:
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
TT_LOG_E(TAG, "Failed to configure display backlight");
}
}
lv_disp_t* tdeck_display_init() {
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "hal/lv_hal_disp.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
lv_disp_t* tdeck_display_init();
bool tdeck_backlight_init();
void tdeck_backlight_set(uint8_t duty);
#ifdef __cplusplus
}
#endif
+4
View File
@@ -1,4 +1,5 @@
#include "lilygo_tdeck.h"
#include "display_i.h"
#include <stdbool.h>
bool tdeck_bootstrap();
@@ -8,6 +9,9 @@ extern const SdCard tdeck_sdcard;
const HardwareConfig lilygo_tdeck = {
.bootstrap = &tdeck_bootstrap,
.display = {
.set_backlight_duty = &tdeck_backlight_set
},
.init_lvgl = &tdeck_init_lvgl,
.sdcard = &tdeck_sdcard
};
+3 -9
View File
@@ -1,14 +1,13 @@
#include "config.h"
#include "display_i.h"
#include "esp_lvgl_port.h"
#include "keyboard.h"
#include "log.h"
#include "ui/lvgl_sync.h"
#include <thread.h>
#include "thread.h"
#define TAG "tdeck_lvgl"
lv_disp_t* tdeck_display_init();
void tdeck_enable_backlight();
bool tdeck_init_touch(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle);
bool tdeck_init_lvgl() {
@@ -16,11 +15,9 @@ bool tdeck_init_lvgl() {
static esp_lcd_panel_io_handle_t touch_io_handle;
static esp_lcd_touch_handle_t touch_handle;
// Init LVGL Port library
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = THREAD_PRIORITY_RENDER,
.task_stack = TDECK_LVGL_TASK_STACK_DEPTH ,
.task_stack = TDECK_LVGL_TASK_STACK_DEPTH,
.task_affinity = -1, // core pinning
.task_max_sleep_ms = 500,
.timer_period_ms = 5
@@ -66,8 +63,5 @@ bool tdeck_init_lvgl() {
keyboard_alloc(display);
TT_LOG_D(TAG, "enabling backlight");
tdeck_enable_backlight();
return true;
}
@@ -6,5 +6,8 @@ bool ws3t_bootstrap();
const HardwareConfig waveshare_s3_touch = {
.bootstrap = &ws3t_bootstrap,
.display = {
.set_backlight_duty = NULL // TODO: This requires implementing the CH422G IO expander
},
.init_lvgl = &ws3t_init_lvgl
};
+9 -2
View File
@@ -1,6 +1,6 @@
#include "config.h"
#include "kernel.h"
#include "log.h"
#include "tactility_core.h"
#include "display_i.h"
#include <driver/spi_common.h>
#define TAG "twodotfour_bootstrap"
@@ -83,5 +83,12 @@ bool twodotfour_bootstrap() {
return false;
}
// Don't turn the backlight on yet - Tactility init will take care of it
TT_LOG_I(TAG, "Init backlight");
if (!twodotfour_backlight_init()) {
TT_LOG_E(TAG, "Init backlight failed");
return false;
}
return true;
}
+40 -14
View File
@@ -1,28 +1,56 @@
#include "config.h"
#include "log.h"
#include "tactility_core.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_lcd_ili9341.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lvgl_port.h"
#include "hal/lv_hal_disp.h"
#include <esp_lcd_panel_io.h>
#define TAG "twodotfour_ili9341"
static void twodotfour_backlight_on() {
gpio_config_t io_conf = {
.pin_bit_mask = BIT64(TWODOTFOUR_LCD_PIN_BACKLIGHT),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
// Dipslay backlight (PWM)
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_FREQUENCY (1000)
bool twodotfour_backlight_init() {
ledc_timer_config_t ledc_timer = {
.speed_mode = TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE,
.timer_num = TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER,
.duty_resolution = TWODOTFOUR_LCD_BACKLIGHT_LEDC_DUTY_RES,
.freq_hz = TWODOTFOUR_LCD_BACKLIGHT_LEDC_FREQUENCY,
.clk_cfg = LEDC_AUTO_CLK
};
gpio_config(&io_conf);
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
TT_LOG_E(TAG, "Backlight led timer config failed");
return false;
}
if (gpio_set_level(TWODOTFOUR_LCD_PIN_BACKLIGHT, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to turn backlight on");
return true;
}
void twodotfour_backlight_set(uint8_t duty) {
ledc_channel_config_t ledc_channel = {
.speed_mode = TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE,
.channel = TWODOTFOUR_LCD_BACKLIGHT_LEDC_CHANNEL,
.timer_sel = TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = TWODOTFOUR_LCD_PIN_BACKLIGHT,
.duty = duty,
.hpoint = 0
};
// Setting the config in the timer init and then calling ledc_set_duty() doesn't work when
// the app is running. For an unknown reason we have to call this config method every time:
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
TT_LOG_E(TAG, "Failed to configure display backlight");
}
}
@@ -94,7 +122,5 @@ lv_disp_t* twodotfour_display_init() {
lv_disp_t* display = lvgl_port_add_disp(&disp_cfg);
twodotfour_backlight_on();
return display;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
bool twodotfour_backlight_init();
void twodotfour_backlight_set(uint8_t duty);
#ifdef __cplusplus
}
#endif
+4
View File
@@ -1,4 +1,5 @@
#include "yellow_board.h"
#include "display_i.h"
bool twodotfour_lvgl_init();
bool twodotfour_bootstrap();
@@ -7,6 +8,9 @@ extern const SdCard twodotfour_sdcard;
const HardwareConfig yellow_board_24inch_cap = {
.bootstrap = &twodotfour_bootstrap,
.display = {
.set_backlight_duty = &twodotfour_backlight_set
},
.init_lvgl = &twodotfour_lvgl_init,
.sdcard = &twodotfour_sdcard
};