Skip to content

Commit 46d045b

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

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: 24 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,24 @@ 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+
394+
return ESP_OK;
395+
}

components/lcd/esp_lcd_st7796/esp_lcd_st7796_mipi.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,23 @@ static esp_err_t panel_st7796_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
323323
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
324324
return ESP_OK;
325325
}
326+
327+
static esp_err_t panel_st7796_disp_sleep(esp_lcd_panel_t *panel, bool sleep)
328+
{
329+
st7796_panel_t *st7796 = __containerof(panel, st7796_panel_t, base);
330+
esp_lcd_panel_io_handle_t io = st7796->io;
331+
int command;
332+
333+
if (sleep) {
334+
command = LCD_CMD_SLPIN;
335+
} else {
336+
command = LCD_CMD_SLPOUT;
337+
}
338+
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
339+
340+
/* According to the ST7796 datasheet, a delay of at least 120ms is required after sleep in/out commands */
341+
vTaskDelay(pdMS_TO_TICKS(120));
342+
return ESP_OK;
343+
}
344+
326345
#endif

0 commit comments

Comments
 (0)