diff --git a/components/esp_lcd/src/esp_lcd_panel_st7789.c b/components/esp_lcd/src/esp_lcd_panel_st7789.c index 36c39110bf5c..76e26fd6daea 100644 --- a/components/esp_lcd/src/esp_lcd_panel_st7789.c +++ b/components/esp_lcd/src/esp_lcd_panel_st7789.c @@ -40,6 +40,7 @@ static esp_err_t panel_st7789_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool 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_on_off(esp_lcd_panel_t *panel, bool off); +static esp_err_t panel_st7789_sleep(esp_lcd_panel_t *panel, bool sleep); typedef struct { esp_lcd_panel_t base; @@ -124,6 +125,7 @@ esp_lcd_new_panel_st7789(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel st7789->base.mirror = panel_st7789_mirror; st7789->base.swap_xy = panel_st7789_swap_xy; st7789->base.disp_on_off = panel_st7789_disp_on_off; + st7789->base.disp_sleep = panel_st7789_sleep; *ret_panel = &(st7789->base); ESP_LOGD(TAG, "new st7789 panel @%p", st7789); @@ -164,7 +166,7 @@ static esp_err_t panel_st7789_reset(esp_lcd_panel_t *panel) vTaskDelay(pdMS_TO_TICKS(10)); } else { // perform software reset ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, - "io tx param LCD_CMD_SWRESET failed"); + "io tx param failed"); vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5m before sending new command } @@ -177,17 +179,17 @@ static esp_err_t panel_st7789_init(esp_lcd_panel_t *panel) esp_lcd_panel_io_handle_t io = st7789->io; // LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0), TAG, - "io tx param LCD_CMD_SLPOUT failed"); + "io tx param failed"); vTaskDelay(pdMS_TO_TICKS(100)); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { st7789->madctl_val, - }, 1), TAG, "io tx param LCD_CMD_MADCTL failed"); + }, 1), TAG, "io tx param failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) { st7789->colmod_val, - }, 1), TAG, "io tx param LCD_CMD_COLMOD failed"); + }, 1), TAG, "io tx param failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7789_CMD_RAMCTRL, (uint8_t[]) { st7789->ramctl_val_1, st7789->ramctl_val_2 - }, 2), TAG, "io tx param RAMCTRL failed"); + }, 2), TAG, "io tx param failed"); return ESP_OK; } @@ -210,13 +212,13 @@ static esp_err_t panel_st7789_draw_bitmap(esp_lcd_panel_t *panel, int x_start, i x_start & 0xFF, ((x_end - 1) >> 8) & 0xFF, (x_end - 1) & 0xFF, - }, 4), TAG, "io tx param LCD_CMD_CASET failed"); + }, 4), TAG, "io tx param failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_RASET, (uint8_t[]) { (y_start >> 8) & 0xFF, y_start & 0xFF, ((y_end - 1) >> 8) & 0xFF, (y_end - 1) & 0xFF, - }, 4), TAG, "io tx param LCD_CMD_RASET failed"); + }, 4), TAG, "io tx param failed"); // transfer frame buffer size_t len = (x_end - x_start) * (y_end - y_start) * st7789->fb_bits_per_pixel / 8; ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR, color_data, len), TAG, "io tx color failed"); @@ -235,7 +237,7 @@ static esp_err_t panel_st7789_invert_color(esp_lcd_panel_t *panel, bool invert_c command = LCD_CMD_INVOFF; } ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, - "io tx param LCD_CMD_INVON/LCD_CMD_INVOFF failed"); + "io tx param failed"); return ESP_OK; } @@ -255,7 +257,7 @@ static esp_err_t panel_st7789_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool } ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { st7789->madctl_val - }, 1), TAG, "io tx param LCD_CMD_MADCTL failed"); + }, 1), TAG, "io tx param failed"); return ESP_OK; } @@ -270,7 +272,7 @@ static esp_err_t panel_st7789_swap_xy(esp_lcd_panel_t *panel, bool swap_axes) } ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) { st7789->madctl_val - }, 1), TAG, "io tx param LCD_CMD_MADCTL failed"); + }, 1), TAG, "io tx param failed"); return ESP_OK; } @@ -293,6 +295,23 @@ static esp_err_t panel_st7789_disp_on_off(esp_lcd_panel_t *panel, bool on_off) command = LCD_CMD_DISPOFF; } ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, - "io tx param LCD_CMD_DISPON/LCD_CMD_DISPOFF failed"); + "io tx param failed"); + return ESP_OK; +} + +static esp_err_t panel_st7789_sleep(esp_lcd_panel_t *panel, bool sleep) +{ + st7789_panel_t *st7789 = __containerof(panel, st7789_panel_t, base); + esp_lcd_panel_io_handle_t io = st7789->io; + int command = 0; + if (sleep) { + command = LCD_CMD_SLPIN; + } else { + command = LCD_CMD_SLPOUT; + } + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, + "io tx param failed"); + vTaskDelay(pdMS_TO_TICKS(100)); + return ESP_OK; }