@@ -32,6 +32,7 @@ static esp_err_t panel_st7796_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool
3232static esp_err_t panel_st7796_swap_xy (esp_lcd_panel_t * panel , bool swap_axes );
3333static esp_err_t panel_st7796_set_gap (esp_lcd_panel_t * panel , int x_gap , int y_gap );
3434static 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
3637typedef 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+ }
0 commit comments