Skip to content

Commit 34fc586

Browse files
committed
feat(lcd): ST7796 Add Sleep command support
1 parent 74c3b0d commit 34fc586

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

components/lcd/esp_lcd_st7796/esp_lcd_st7796_general.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool
3232
static esp_err_t panel_st7796_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
3333
static esp_err_t panel_st7796_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
3434
static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool off);
35+
static esp_err_t panel_st7796_disp_sleep(esp_lcd_panel_t *panel, bool sleep);
3536

3637
typedef struct {
3738
esp_lcd_panel_t base;
@@ -141,6 +142,8 @@ esp_err_t esp_lcd_new_panel_st7796_general(const esp_lcd_panel_io_handle_t io,
141142
#else
142143
st7796->base.disp_on_off = panel_st7796_disp_on_off;
143144
#endif
145+
st7796->base.disp_sleep = panel_st7796_disp_sleep;
146+
144147
*ret_panel = &(st7796->base);
145148
ESP_LOGD(TAG, "new st7796 panel @%p", st7796);
146149

@@ -369,3 +372,23 @@ static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
369372
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
370373
return ESP_OK;
371374
}
375+
376+
static esp_err_t panel_st7796_disp_sleep(esp_lcd_panel_t *panel, bool sleep)
377+
{
378+
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
379+
esp_lcd_panel_io_handle_t io = st7796->io;
380+
int command;
381+
382+
if (sleep) {
383+
command = LCD_CMD_SLPIN;
384+
} else {
385+
command = LCD_CMD_SLPOUT;
386+
}
387+
388+
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
389+
390+
/* According to the ST7796 datasheet, a delay of at least 120ms is required after sleep in/out commands */
391+
vTaskDelay(pdMS_TO_TICKS(120));
392+
393+
return ESP_OK;
394+
}

components/lcd/esp_lcd_st7796/esp_lcd_st7796_mipi.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ esp_err_t esp_lcd_new_panel_st7796_mipi(const esp_lcd_panel_io_handle_t io,
143143
panel_handle->mirror = panel_st7796_mirror;
144144
panel_handle->invert_color = panel_st7796_invert_color;
145145
panel_handle->disp_on_off = panel_st7796_disp_on_off;
146+
panel_handle->disp_sleep = panel_st7796_disp_sleep;
146147
panel_handle->user_data = st7796;
147148
*ret_panel = panel_handle;
148149
ESP_LOGD(TAG, "new st7796 panel @%p", st7796);
@@ -323,4 +324,23 @@ static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
323324
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
324325
return ESP_OK;
325326
}
327+
328+
static esp_err_t panel_st7796_disp_sleep(esp_lcd_panel_t *panel, bool sleep)
329+
{
330+
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
331+
esp_lcd_panel_io_handle_t io = st7796->io;
332+
int command;
333+
334+
if (sleep) {
335+
command = LCD_CMD_SLPIN;
336+
} else {
337+
command = LCD_CMD_SLPOUT;
338+
}
339+
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
340+
341+
/* According to the ST7796 datasheet, a delay of at least 120ms is required after sleep in/out commands */
342+
vTaskDelay(pdMS_TO_TICKS(120));
343+
return ESP_OK;
344+
}
345+
326346
#endif

0 commit comments

Comments
 (0)