Skip to content

Commit 1801416

Browse files
Merge pull request #95 from lvgl/feature/esp_lcd_backlight
LCD backlight controller
2 parents 678779c + 2d6ea13 commit 1801416

29 files changed

+285
-546
lines changed

CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ if(ESP_PLATFORM)
33
file(GLOB SOURCES *.c)
44
set(LVGL_INCLUDE_DIRS . lvgl_tft)
55
list(APPEND SOURCES "lvgl_tft/disp_driver.c")
6-
7-
#@todo add SimleInclude macro here
6+
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
87

98
# Include only the source file of the selected
109
# display controller.
@@ -79,11 +78,6 @@ if(CONFIG_LV_TOUCH_CONTROLLER)
7978
endif()
8079
endif()
8180

82-
# Add backlight control to compilation only if it is selected in menuconfig
83-
if(CONFIG_LV_ENABLE_BACKLIGHT_CONTROL)
84-
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
85-
endif()
86-
8781
if(CONFIG_LV_I2C)
8882
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
8983
endif()

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ For a ready to use ESP32 project take look at the [lv_port_esp32](https://github
77
- [Supported indev controllers](#supported-indev-controllers)
88
- [Support for predefined development kits](#support-for-predefined-development-kits)
99
- [Thread-safe I2C with I2C Manager](#thread-safe-i2c-with-i2c-manager)
10+
- [Backlight control](#backlight-control)
1011

1112
**NOTE:** You need to set the display horizontal and vertical size, color depth and
1213
swap of RGB565 color on the LVGL configuration menuconfig (it's not handled automatically).
@@ -79,3 +80,14 @@ talk to devices on the I2C ports without getting in each other's way. These driv
7980
use a built-in copy of I2C Manager to talk to the I2C port, but you can also use
8081
the I2C Manager component itself and have others play nice with LVGL and vice-versa.
8182
[Click here](i2c_manager/README.md) for details.
83+
84+
85+
## Backlight control
86+
87+
Control of LCD's backlight is provided by separate module that is independent from the display driver.
88+
Configuration of the backlight controller can be found in menuconfig `LVGL ESP Drivers -> LVGL TFT Display controller`.
89+
90+
There are three modes of operation:
91+
1. Off - No backlight control
92+
2. Switch - Allows ON/OFF control
93+
3. PWM - Allows brightness control (by Pulse-Width-Modulated signal)

lvgl_tft/GC9A01.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,14 @@ void GC9A01_init(void)
111111

112112
};
113113

114-
#if GC9A01_BCKL == 15
115-
gpio_config_t io_conf;
116-
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
117-
io_conf.mode = GPIO_MODE_OUTPUT;
118-
io_conf.pin_bit_mask = GPIO_SEL_15;
119-
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
120-
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
121-
gpio_config(&io_conf);
122-
#endif
123-
124114
//Initialize non-SPI GPIOs
125-
gpio_pad_select_gpio(GC9A01_DC);
115+
gpio_pad_select_gpio(GC9A01_DC);
126116
gpio_set_direction(GC9A01_DC, GPIO_MODE_OUTPUT);
127117

128118
#if GC9A01_USE_RST
129-
gpio_pad_select_gpio(GC9A01_RST);
119+
gpio_pad_select_gpio(GC9A01_RST);
130120
gpio_set_direction(GC9A01_RST, GPIO_MODE_OUTPUT);
131-
#endif
132-
133-
#if GC9A01_ENABLE_BACKLIGHT_CONTROL
134-
gpio_pad_select_gpio(GC9A01_BCKL);
135-
gpio_set_direction(GC9A01_BCKL, GPIO_MODE_OUTPUT);
136-
#endif
137121

138-
#if GC9A01_USE_RST
139122
//Reset the display
140123
gpio_set_level(GC9A01_RST, 0);
141124
vTaskDelay(100 / portTICK_RATE_MS);
@@ -156,8 +139,6 @@ void GC9A01_init(void)
156139
cmd++;
157140
}
158141

159-
GC9A01_enable_backlight(true);
160-
161142
GC9A01_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
162143

163144
#if GC9A01_INVERT_COLORS == 1
@@ -197,22 +178,6 @@ void GC9A01_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
197178
GC9A01_send_color((void*)color_map, size * 2);
198179
}
199180

200-
void GC9A01_enable_backlight(bool backlight)
201-
{
202-
#if GC9A01_ENABLE_BACKLIGHT_CONTROL
203-
ESP_LOGI(TAG, "%s backlight.", backlight ? "Enabling" : "Disabling");
204-
uint32_t tmp = 0;
205-
206-
#if (GC9A01_BCKL_ACTIVE_LVL==1)
207-
tmp = backlight ? 1 : 0;
208-
#else
209-
tmp = backlight ? 0 : 1;
210-
#endif
211-
212-
gpio_set_level(GC9A01_BCKL, tmp);
213-
#endif
214-
}
215-
216181
void GC9A01_sleep_in()
217182
{
218183
uint8_t data[] = {0x08};

lvgl_tft/GC9A01.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,9 @@ extern "C" {
2525
/*********************
2626
* DEFINES
2727
*********************/
28-
#define GC9A01_DC CONFIG_LV_DISP_PIN_DC
29-
#define GC9A01_RST CONFIG_LV_DISP_PIN_RST
30-
#define GC9A01_USE_RST CONFIG_LV_DISP_USE_RST
31-
#define GC9A01_BCKL CONFIG_LV_DISP_PIN_BCKL
32-
33-
#define GC9A01_ENABLE_BACKLIGHT_CONTROL CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
34-
35-
#if CONFIG_LV_BACKLIGHT_ACTIVE_LVL
36-
#define GC9A01_BCKL_ACTIVE_LVL 1
37-
#else
38-
#define GC9A01_BCKL_ACTIVE_LVL 0
39-
#endif
40-
28+
#define GC9A01_DC CONFIG_LV_DISP_PIN_DC
29+
#define GC9A01_RST CONFIG_LV_DISP_PIN_RST
30+
#define GC9A01_USE_RST CONFIG_LV_DISP_USE_RST
4131
#define GC9A01_INVERT_COLORS CONFIG_LV_INVERT_COLORS
4232

4333
/**********************
@@ -50,7 +40,6 @@ extern "C" {
5040

5141
void GC9A01_init(void);
5242
void GC9A01_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
53-
void GC9A01_enable_backlight(bool backlight);
5443
void GC9A01_sleep_in(void);
5544
void GC9A01_sleep_out(void);
5645

lvgl_tft/Kconfig

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -910,51 +910,6 @@ menu "LVGL TFT Display controller"
910910
help
911911
Configure the display Busy pin here.
912912

913-
config LV_ENABLE_BACKLIGHT_CONTROL
914-
bool "Enable control of the display backlight by using an GPIO." if \
915-
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
916-
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
917-
default y if LV_PREDEFINED_DISPLAY_M5STACK
918-
default n if LV_PREDEFINED_DISPLAY_M5CORE2
919-
default y if LV_PREDEFINED_DISPLAY_WROVER4
920-
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
921-
default y if LV_PREDEFINED_DISPLAY_TTGO
922-
default y if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
923-
default y if LV_PREDEFINED_DISPLAY_WT32_SC01
924-
help
925-
Enable controlling the display backlight using an GPIO
926-
927-
config LV_BACKLIGHT_ACTIVE_LVL
928-
bool "Is backlight turn on with a HIGH (1) logic level?"
929-
depends on LV_ENABLE_BACKLIGHT_CONTROL
930-
default y if LV_PREDEFINED_DISPLAY_M5STACK
931-
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
932-
default y if LV_PREDEFINED_DISPLAY_TTGO
933-
default y if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
934-
default y if LV_PREDEFINED_DISPLAY_WT32_SC01
935-
help
936-
Some backlights are turned on with a high signal, others held low.
937-
If enabled, a value of 1 will be sent to the display to enable the backlight,
938-
otherwise a 0 will be expected to enable it.
939-
940-
config LV_DISP_PIN_BCKL
941-
int "GPIO for Backlight Control"
942-
depends on LV_ENABLE_BACKLIGHT_CONTROL
943-
default 23 if LV_PREDEFINED_PINS_38V1
944-
default 26 if LV_PREDEFINED_PINS_38V4
945-
default 32 if LV_PREDEFINED_DISPLAY_M5STACK
946-
default 5 if LV_PREDEFINED_DISPLAY_WROVER4
947-
default 2 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
948-
default 27 if LV_PREDEFINED_DISPLAY_ERTFT0356
949-
default 0 if LV_PREDEFINED_PINS_TKOALA
950-
default 4 if LV_PREDEFINED_DISPLAY_TTGO
951-
default 2 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
952-
default 23 if LV_PREDEFINED_DISPLAY_WT32_SC01
953-
default 27
954-
955-
help
956-
Configure the display BCLK (LED) pin here.
957-
958913
endmenu
959914

960915
choice
@@ -965,19 +920,86 @@ menu "LVGL TFT Display controller"
965920
config LV_I2C_DISPLAY_PORT_0
966921
bool
967922
prompt "I2C port 0"
968-
help
923+
help
969924
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
970925
Component config->I2C Port Settings.
971926

972927
config LV_I2C_DISPLAY_PORT_1
973928
bool
974929
prompt "I2C port 1"
975-
help
930+
help
976931
I2C is shared peripheral managed by I2C Manager. In order to configure I2C Manager (pinout, etc.) see menu
977932
Component config->I2C Port Settings.
978933

979934
endchoice
980935

936+
choice
937+
prompt "Backlight Control" if \
938+
(! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) )
939+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_M5STACK
940+
default LV_DISP_BACKLIGHT_OFF if LV_PREDEFINED_DISPLAY_M5CORE2
941+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_WROVER4
942+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_ERTFT0356
943+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_TTGO
944+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
945+
default LV_DISP_BACKLIGHT_SWITCH if LV_PREDEFINED_DISPLAY_WT32_SC01
946+
default LV_DISP_BACKLIGHT_OFF
947+
948+
config LV_DISP_BACKLIGHT_OFF
949+
bool
950+
prompt "Not Used"
951+
help
952+
Display backlight is not controlled by this driver, must be hardwired in hardware.
953+
954+
config LV_DISP_BACKLIGHT_SWITCH
955+
bool
956+
prompt "Switch control"
957+
help
958+
Display backlight can be switched on or off.
959+
960+
config LV_DISP_BACKLIGHT_PWM
961+
bool
962+
prompt "PWM control"
963+
help
964+
Display backlight is controlled by pulse-width modulation, allowing brightness settings.
965+
966+
endchoice
967+
968+
config LV_BACKLIGHT_ACTIVE_LVL
969+
bool "Is backlight turn on with a HIGH (1) logic level?" if \
970+
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
971+
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
972+
depends on !LV_DISP_BACKLIGHT_OFF
973+
default y if LV_PREDEFINED_DISPLAY_M5STACK
974+
default y if LV_PREDEFINED_DISPLAY_ERTFT0356
975+
default y if LV_PREDEFINED_DISPLAY_TTGO
976+
default y if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
977+
default y if LV_PREDEFINED_DISPLAY_WT32_SC01
978+
help
979+
Some backlights are turned on with a high signal, others held low.
980+
If enabled, a value of 1 will be sent to the display to enable the backlight,
981+
otherwise a 0 will be expected to enable it.
982+
983+
config LV_DISP_PIN_BCKL
984+
int "GPIO for Backlight Control" if \
985+
( LV_PREDEFINED_DISPLAY_NONE && ! ( LV_TFT_DISPLAY_CONTROLLER_SH1107 || LV_TFT_DISPLAY_CONTROLLER_SSD1306 ) ) \
986+
|| LV_PREDEFINED_DISPLAY_RPI_MPI3501
987+
depends on !LV_DISP_BACKLIGHT_OFF
988+
default 23 if LV_PREDEFINED_PINS_38V1
989+
default 26 if LV_PREDEFINED_PINS_38V4
990+
default 32 if LV_PREDEFINED_DISPLAY_M5STACK
991+
default 5 if LV_PREDEFINED_DISPLAY_WROVER4
992+
default 2 if LV_PREDEFINED_DISPLAY_ADA_FEATHERWING
993+
default 27 if LV_PREDEFINED_DISPLAY_ERTFT0356
994+
default 0 if LV_PREDEFINED_PINS_TKOALA
995+
default 4 if LV_PREDEFINED_DISPLAY_TTGO
996+
default 2 if LV_PREDEFINED_DISPLAY_TTGO_CAMERA_PLUS
997+
default 23 if LV_PREDEFINED_DISPLAY_WT32_SC01
998+
default 27
999+
1000+
help
1001+
Configure the display BCLK (LED) pin here.
1002+
9811003
config LV_I2C
9821004
bool
9831005
default y if LV_I2C_DISPLAY

lvgl_tft/disp_driver.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
#include "disp_driver.h"
66
#include "disp_spi.h"
7+
#include "esp_lcd_backlight.h"
8+
#include "sdkconfig.h"
79

8-
void disp_driver_init(void)
10+
void *disp_driver_init(void)
911
{
1012
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
1113
ili9341_init();
@@ -42,6 +44,34 @@ void disp_driver_init(void)
4244
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
4345
ili9163c_init();
4446
#endif
47+
48+
// We still use menuconfig for these settings
49+
// It will be set up during runtime in the future
50+
#ifndef CONFIG_LV_DISP_BACKLIGHT_OFF
51+
const disp_backlight_config_t bckl_config = {
52+
.gpio_num = CONFIG_LV_DISP_PIN_BCKL,
53+
#if defined CONFIG_LV_DISP_BACKLIGHT_PWM
54+
.pwm_control = true,
55+
#else
56+
.pwm_control = false,
57+
#endif
58+
#if defined CONFIG_LV_BACKLIGHT_ACTIVE_LVL
59+
.output_invert = false, // Backlight on high
60+
#else
61+
.output_invert = true, // Backlight on low
62+
#endif
63+
.timer_idx = 0,
64+
.channel_idx = 0 // @todo this prevents us from having two PWM controlled displays
65+
};
66+
const disp_backlight_config_t *bckl_config_p = &bckl_config;
67+
#else
68+
const disp_backlight_config_t *bckl_config_p = NULL;
69+
#endif
70+
71+
disp_backlight_h bckl_handle = disp_backlight_new(bckl_config_p);
72+
disp_backlight_set(bckl_handle, 100);
73+
74+
return bckl_handle;
4575
}
4676

4777
void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)

lvgl_tft/disp_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern "C" {
6767
**********************/
6868

6969
/* Initialize display */
70-
void disp_driver_init(void);
70+
void *disp_driver_init(void);
7171

7272
/* Display flush callback */
7373
void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);

0 commit comments

Comments
 (0)