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
+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
};