lcd: don't turn on disp in init

Closes https://github.com/espressif/esp-idf/issues/8516
This commit is contained in:
morris 2022-04-11 18:48:29 +08:00
parent 4280164be4
commit de433105a2
16 changed files with 81 additions and 48 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -110,6 +110,17 @@ esp_err_t esp_lcd_panel_set_gap(esp_lcd_panel_handle_t panel, int x_gap, int y_g
*/
esp_err_t esp_lcd_panel_invert_color(esp_lcd_panel_handle_t panel, bool invert_color_data);
/**
* @brief Turn on or off the display
*
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
* @param[in] on_off True to turns on display, False to turns off display
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
*/
esp_err_t esp_lcd_panel_disp_on_off(esp_lcd_panel_handle_t panel, bool on_off);
/**
* @brief Turn off the display
*
@ -119,7 +130,8 @@ esp_err_t esp_lcd_panel_invert_color(esp_lcd_panel_handle_t panel, bool invert_c
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
*/
esp_err_t esp_lcd_panel_disp_off(esp_lcd_panel_handle_t panel, bool off);
esp_err_t esp_lcd_panel_disp_off(esp_lcd_panel_handle_t panel, bool off)
__attribute__((deprecated("use esp_lcd_panel_disp_on_off instead")));
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -110,15 +110,15 @@ struct esp_lcd_panel_t {
esp_err_t (*invert_color)(esp_lcd_panel_t *panel, bool invert_color_data);
/**
* @brief Turn off the display
* @brief Turn on or off the display
*
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
* @param[in] off Whether to turn off the screen
* @param[in] on_off True to turns on display, False to turns off display
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
*/
esp_err_t (*disp_off)(esp_lcd_panel_t *panel, bool off);
esp_err_t (*disp_on_off)(esp_lcd_panel_t *panel, bool on_off);
};
#ifdef __cplusplus

View File

@ -33,7 +33,7 @@ static esp_err_t panel_nt35510_invert_color(esp_lcd_panel_t *panel, bool invert_
static esp_err_t panel_nt35510_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_nt35510_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_nt35510_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_nt35510_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t panel_nt35510_disp_on_off(esp_lcd_panel_t *panel, bool off);
typedef struct {
esp_lcd_panel_t base;
@ -105,7 +105,7 @@ esp_err_t esp_lcd_new_panel_nt35510(const esp_lcd_panel_io_handle_t io, const es
nt35510->base.set_gap = panel_nt35510_set_gap;
nt35510->base.mirror = panel_nt35510_mirror;
nt35510->base.swap_xy = panel_nt35510_swap_xy;
nt35510->base.disp_off = panel_nt35510_disp_off;
nt35510->base.disp_on_off = panel_nt35510_disp_on_off;
*ret_panel = &(nt35510->base);
ESP_LOGD(TAG, "new nt35510 panel @%p", nt35510);
@ -166,8 +166,6 @@ static esp_err_t panel_nt35510_init(esp_lcd_panel_t *panel)
esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD << 8, (uint16_t[]) {
nt35510->colmod_cal,
}, 2);
// turn on display
esp_lcd_panel_io_tx_param(io, LCD_CMD_DISPON << 8, NULL, 0);
return ESP_OK;
}
@ -272,15 +270,15 @@ static esp_err_t panel_nt35510_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_
return ESP_OK;
}
static esp_err_t panel_nt35510_disp_off(esp_lcd_panel_t *panel, bool off)
static esp_err_t panel_nt35510_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
nt35510_panel_t *nt35510 = __containerof(panel, nt35510_panel_t, base);
esp_lcd_panel_io_handle_t io = nt35510->io;
int command = 0;
if (off) {
command = LCD_CMD_DISPOFF;
} else {
if (on_off) {
command = LCD_CMD_DISPON;
} else {
command = LCD_CMD_DISPOFF;
}
esp_lcd_panel_io_tx_param(io, command << 8, NULL, 0);
return ESP_OK;

View File

@ -58,8 +58,13 @@ esp_err_t esp_lcd_panel_invert_color(esp_lcd_panel_handle_t panel, bool invert_c
return panel->invert_color(panel, invert_color_data);
}
esp_err_t esp_lcd_panel_disp_off(esp_lcd_panel_handle_t panel, bool off)
esp_err_t esp_lcd_panel_disp_on_off(esp_lcd_panel_handle_t panel, bool on_off)
{
ESP_RETURN_ON_FALSE(panel, ESP_ERR_INVALID_ARG, TAG, "invalid panel handle");
return panel->disp_off(panel, off);
return panel->disp_on_off(panel, on_off);
}
esp_err_t esp_lcd_panel_disp_off(esp_lcd_panel_handle_t panel, bool off)
{
return esp_lcd_panel_disp_on_off(panel, !off);
}

View File

@ -46,7 +46,7 @@ static esp_err_t panel_ssd1306_invert_color(esp_lcd_panel_t *panel, bool invert_
static esp_err_t panel_ssd1306_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_ssd1306_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_ssd1306_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_ssd1306_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t panel_ssd1306_disp_on_off(esp_lcd_panel_t *panel, bool off);
typedef struct {
esp_lcd_panel_t base;
@ -91,7 +91,7 @@ esp_err_t esp_lcd_new_panel_ssd1306(const esp_lcd_panel_io_handle_t io, const es
ssd1306->base.set_gap = panel_ssd1306_set_gap;
ssd1306->base.mirror = panel_ssd1306_mirror;
ssd1306->base.swap_xy = panel_ssd1306_swap_xy;
ssd1306->base.disp_off = panel_ssd1306_disp_off;
ssd1306->base.disp_on_off = panel_ssd1306_disp_on_off;
*ret_panel = &(ssd1306->base);
ESP_LOGD(TAG, "new ssd1306 panel @%p", ssd1306);
@ -144,9 +144,6 @@ static esp_err_t panel_ssd1306_init(esp_lcd_panel_t *panel)
esp_lcd_panel_io_tx_param(io, SSD1306_CMD_SET_CHARGE_PUMP, (uint8_t[]) {
0x14 // enable charge pump
}, 1);
esp_lcd_panel_io_tx_param(io, SSD1306_CMD_DISP_ON, NULL, 0);
// SEG/COM will be ON after 100ms after sending DISP_ON command
vTaskDelay(pdMS_TO_TICKS(100));
return ESP_OK;
}
@ -227,16 +224,18 @@ static esp_err_t panel_ssd1306_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_
return ESP_OK;
}
static esp_err_t panel_ssd1306_disp_off(esp_lcd_panel_t *panel, bool off)
static esp_err_t panel_ssd1306_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
ssd1306_panel_t *ssd1306 = __containerof(panel, ssd1306_panel_t, base);
esp_lcd_panel_io_handle_t io = ssd1306->io;
int command = 0;
if (off) {
command = SSD1306_CMD_DISP_OFF;
} else {
if (on_off) {
command = SSD1306_CMD_DISP_ON;
} else {
command = SSD1306_CMD_DISP_OFF;
}
esp_lcd_panel_io_tx_param(io, command, NULL, 0);
// SEG/COM will be ON/OFF after 100ms after sending DISP_ON/OFF command
vTaskDelay(pdMS_TO_TICKS(100));
return ESP_OK;
}

View File

@ -33,7 +33,7 @@ static esp_err_t panel_st7789_invert_color(esp_lcd_panel_t *panel, bool invert_c
static esp_err_t panel_st7789_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_st7789_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_st7789_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_st7789_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t panel_st7789_disp_on_off(esp_lcd_panel_t *panel, bool off);
typedef struct {
esp_lcd_panel_t base;
@ -102,7 +102,7 @@ esp_err_t esp_lcd_new_panel_st7789(const esp_lcd_panel_io_handle_t io, const esp
st7789->base.set_gap = panel_st7789_set_gap;
st7789->base.mirror = panel_st7789_mirror;
st7789->base.swap_xy = panel_st7789_swap_xy;
st7789->base.disp_off = panel_st7789_disp_off;
st7789->base.disp_on_off = panel_st7789_disp_on_off;
*ret_panel = &(st7789->base);
ESP_LOGD(TAG, "new st7789 panel @%p", st7789);
@ -162,8 +162,6 @@ static esp_err_t panel_st7789_init(esp_lcd_panel_t *panel)
esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) {
st7789->colmod_cal,
}, 1);
// turn on display
esp_lcd_panel_io_tx_param(io, LCD_CMD_DISPON, NULL, 0);
return ESP_OK;
}
@ -256,15 +254,15 @@ static esp_err_t panel_st7789_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_g
return ESP_OK;
}
static esp_err_t panel_st7789_disp_off(esp_lcd_panel_t *panel, bool off)
static esp_err_t panel_st7789_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
st7789_panel_t *st7789 = __containerof(panel, st7789_panel_t, base);
esp_lcd_panel_io_handle_t io = st7789->io;
int command = 0;
if (off) {
command = LCD_CMD_DISPOFF;
} else {
if (on_off) {
command = LCD_CMD_DISPON;
} else {
command = LCD_CMD_DISPOFF;
}
esp_lcd_panel_io_tx_param(io, command, NULL, 0);
return ESP_OK;

View File

@ -60,7 +60,7 @@ static esp_err_t rgb_panel_invert_color(esp_lcd_panel_t *panel, bool invert_colo
static esp_err_t rgb_panel_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t rgb_panel_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t rgb_panel_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t rgb_panel_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t rgb_panel_disp_on_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t lcd_rgb_panel_select_periph_clock(esp_rgb_panel_t *panel, lcd_clock_source_t clk_src);
static esp_err_t lcd_rgb_panel_create_trans_link(esp_rgb_panel_t *panel);
static esp_err_t lcd_rgb_panel_configure_gpio(esp_rgb_panel_t *panel, const esp_lcd_rgb_panel_config_t *panel_config);
@ -190,7 +190,7 @@ esp_err_t esp_lcd_new_rgb_panel(const esp_lcd_rgb_panel_config_t *rgb_panel_conf
rgb_panel->base.reset = rgb_panel_reset;
rgb_panel->base.init = rgb_panel_init;
rgb_panel->base.draw_bitmap = rgb_panel_draw_bitmap;
rgb_panel->base.disp_off = rgb_panel_disp_off;
rgb_panel->base.disp_on_off = rgb_panel_disp_on_off;
rgb_panel->base.invert_color = rgb_panel_invert_color;
rgb_panel->base.mirror = rgb_panel_mirror;
rgb_panel->base.swap_xy = rgb_panel_swap_xy;
@ -374,13 +374,13 @@ static esp_err_t rgb_panel_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
return ESP_OK;
}
static esp_err_t rgb_panel_disp_off(esp_lcd_panel_t *panel, bool off)
static esp_err_t rgb_panel_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
esp_rgb_panel_t *rgb_panel = __containerof(panel, esp_rgb_panel_t, base);
if (rgb_panel->disp_gpio_num < 0) {
return ESP_ERR_NOT_SUPPORTED;
}
if (off) { // turn off screen
if (!on_off) { // turn off screen
gpio_set_level(rgb_panel->disp_gpio_num, !rgb_panel->flags.disp_en_level);
} else { // turn on screen
gpio_set_level(rgb_panel->disp_gpio_num, rgb_panel->flags.disp_en_level);

View File

@ -56,6 +56,8 @@ TEST_CASE("lcd_panel_with_i2c_interface_(ssd1306)", "[lcd]")
TEST_ESP_OK(esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));
TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
TEST_ESP_OK(esp_lcd_panel_init(panel_handle));
// turn on display
TEST_ESP_OK(esp_lcd_panel_disp_on_off(panel_handle, true));
for (int i = 0; i < TEST_LCD_H_RES / 16; i++) {
for (int j = 0; j < TEST_LCD_V_RES / 8; j++) {

View File

@ -437,6 +437,8 @@ TEST_CASE("lcd_panel_with_i80_interface_(st7789, 8bits)", "[lcd]")
esp_lcd_panel_invert_color(panel_handle, true);
// the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 20);
// turn on display
esp_lcd_panel_disp_on_off(panel_handle, true);
// turn on backlight
gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 1);
@ -447,7 +449,8 @@ TEST_CASE("lcd_panel_with_i80_interface_(st7789, 8bits)", "[lcd]")
memset(img, color_byte, TEST_IMG_SIZE);
esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_start + 100, y_start + 100, img);
}
esp_lcd_panel_disp_off(panel_handle, true); // turn off screen
// turn off screen
esp_lcd_panel_disp_on_off(panel_handle, false);
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));

View File

@ -79,6 +79,8 @@ static void lcd_panel_test(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_ha
esp_lcd_panel_invert_color(panel_handle, true);
// the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 20);
// turn on display
esp_lcd_panel_disp_on_off(panel_handle, true);
// turn on backlight
gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 1);
@ -90,7 +92,7 @@ static void lcd_panel_test(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_ha
esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_start + 200, y_start + 200, img);
}
// turn off screen
esp_lcd_panel_disp_off(panel_handle, true);
esp_lcd_panel_disp_on_off(panel_handle, false);
TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
TEST_ESP_OK(spi_bus_free(TEST_SPI_HOST_ID));

View File

@ -116,3 +116,9 @@ I2C
- ``rmt_set_intr_enable_mask`` and ``rmt_clr_intr_enable_mask`` are removed, as the interrupt is handled by the driver, user doesn't need to take care of it.
- ``rmt_set_pin`` is removed, as ``rmt_set_gpio`` can do the same thing.
- ``rmt_memory_rw_rst`` is removed, user can use ``rmt_tx_memory_reset`` and ``rmt_rx_memory_reset`` for TX and RX channel respectively.
LCD
---
- The LCD panel initialization flow is slightly changed. Now the :cpp:func:`esp_lcd_panel_init` won't turn on the display automatically. User needs to call :cpp:func:`esp_lcd_panel_disp_on_off` to manually turn on the display. Note, this is different from turning on backlight. With this breaking change, user can flush a predefined pattern to the screen before turning on the screen. This can help avoid random noise on the screen after a power on reset.
- :cpp:func:`esp_lcd_panel_disp_off` is deprecated, please use :cpp:func:`esp_lcd_panel_disp_on_off` instead.

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -27,7 +27,7 @@ static esp_err_t panel_gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert_c
static esp_err_t panel_gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_gc9a01_disp_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool off);
typedef struct {
esp_lcd_panel_t base;
@ -93,7 +93,7 @@ esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp
gc9a01->base.set_gap = panel_gc9a01_set_gap;
gc9a01->base.mirror = panel_gc9a01_mirror;
gc9a01->base.swap_xy = panel_gc9a01_swap_xy;
gc9a01->base.disp_off = panel_gc9a01_disp_off;
gc9a01->base.disp_on_off = panel_gc9a01_disp_on_off;
*ret_panel = &(gc9a01->base);
ESP_LOGD(TAG, "new gc9a01 panel @%p", gc9a01);
@ -217,8 +217,6 @@ static esp_err_t panel_gc9a01_init(esp_lcd_panel_t *panel)
cmd++;
}
// turn on display
esp_lcd_panel_io_tx_param(io, LCD_CMD_DISPON, NULL, 0);
return ESP_OK;
}
@ -310,15 +308,15 @@ static esp_err_t panel_gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_g
return ESP_OK;
}
static esp_err_t panel_gc9a01_disp_off(esp_lcd_panel_t *panel, bool off)
static esp_err_t panel_gc9a01_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
gc9a01_panel_t *gc9a01 = __containerof(panel, gc9a01_panel_t, base);
esp_lcd_panel_io_handle_t io = gc9a01->io;
int command = 0;
if (off) {
command = LCD_CMD_DISPOFF;
} else {
if (on_off) {
command = LCD_CMD_DISPON;
} else {
command = LCD_CMD_DISPOFF;
}
esp_lcd_panel_io_tx_param(io, command, NULL, 0);
return ESP_OK;

View File

@ -124,6 +124,9 @@ void app_main(void)
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_handle, true));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, true, false));
// user can flush pre-defined pattern to the screen before we turn on the screen or backlight
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
ESP_LOGI(TAG, "Turn on LCD backlight");
gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);

View File

@ -124,6 +124,7 @@ void app_main(void)
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
ESP_LOGI(TAG, "Initialize LVGL library");
lv_init();

View File

@ -191,6 +191,9 @@ void app_main(void)
// the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
esp_lcd_panel_set_gap(panel_handle, 0, 20);
// user can flush pre-defined pattern to the screen before we turn on the screen or backlight
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
ESP_LOGI(TAG, "Turn on LCD backlight");
gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_ON_LEVEL);

View File

@ -145,6 +145,9 @@ void app_main(void)
// Initialize LCD panel
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
// Turn on the screen
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
// Swap x and y axis (Different LCD screens may need different options)
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, true));