Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 Add lcd sleep command (IDFGH-11203) #12370

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/esp_lcd/include/esp_lcd_panel_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ esp_err_t esp_lcd_panel_disp_on_off(esp_lcd_panel_handle_t panel, bool on_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")));

/**
* @brief Turn display in sleep mode
*
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
* @param[in] sleep True turn display on sleep mode, False wake up
* @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_sleep(esp_lcd_panel_handle_t panel, bool sleep);

#ifdef __cplusplus
}
#endif
11 changes: 11 additions & 0 deletions components/esp_lcd/interface/esp_lcd_panel_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ struct esp_lcd_panel_t {
*/
esp_err_t (*disp_on_off)(esp_lcd_panel_t *panel, bool on_off);

/**
* @brief Turn display in sleep mode
*
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
* @param[in] sleep True turn display on sleep mode, False wake up
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
*/
esp_err_t (*disp_sleep)(esp_lcd_panel_t *panel, bool sleep);

void *user_data; /*!< User data, used to store externally customized data */
};

Expand Down
10 changes: 10 additions & 0 deletions components/esp_lcd/src/esp_lcd_panel_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ 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);
}

esp_err_t esp_lcd_panel_disp_sleep(esp_lcd_panel_handle_t panel, bool sleep)
{
ESP_RETURN_ON_FALSE(panel, ESP_ERR_INVALID_ARG, TAG, "invalid panel handle");
if (panel->disp_sleep) {
return panel->disp_sleep(panel, sleep);
} else {
return ESP_ERR_NOT_SUPPORTED;
}
}
27 changes: 27 additions & 0 deletions components/esp_lcd/src/esp_lcd_panel_st7789.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +54,7 @@ typedef struct {
uint8_t colmod_val; // save current value of LCD_CMD_COLMOD register
uint8_t ramctl_val_1;
uint8_t ramctl_val_2;
bool sleep;
} st7789_panel_t;

esp_err_t
Expand Down Expand Up @@ -124,6 +126,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);

Expand Down Expand Up @@ -179,6 +182,7 @@ static esp_err_t panel_st7789_init(esp_lcd_panel_t *panel)
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0), TAG,
"io tx param LCD_CMD_SLPOUT failed");
vTaskDelay(pdMS_TO_TICKS(100));
st7789->sleep = false;
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");
Expand Down Expand Up @@ -287,7 +291,12 @@ 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 (on_off) {
if (st7789->sleep) {
esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0);
vTaskDelay(pdMS_TO_TICKS(100));
}
command = LCD_CMD_DISPON;
} else {
command = LCD_CMD_DISPOFF;
Expand All @@ -296,3 +305,21 @@ static esp_err_t panel_st7789_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
"io tx param LCD_CMD_DISPON/LCD_CMD_DISPOFF 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_lcd_panel_io_tx_param(io, command, NULL, 0);

st7789->sleep = sleep;
vTaskDelay(pdMS_TO_TICKS(100));

return ESP_OK;
}