mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(lcd): add brightness control for LCD panels
Merges https://github.com/espressif/esp-idf/pull/18273 Closes https://github.com/espressif/esp-idf/issues/16230
This commit is contained in:
@@ -144,6 +144,17 @@ __attribute__((deprecated("use esp_lcd_panel_disp_on_off instead")));
|
||||
*/
|
||||
esp_err_t esp_lcd_panel_disp_sleep(esp_lcd_panel_handle_t panel, bool sleep);
|
||||
|
||||
/**
|
||||
* @brief Set the brightness of the display
|
||||
*
|
||||
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
|
||||
* @param[in] brightness Brightness value (range depends on panel implementation, typically 0-255, 0-1023, or 0-100)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
|
||||
*/
|
||||
esp_err_t esp_lcd_panel_set_brightness(esp_lcd_panel_handle_t panel, int brightness);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -131,6 +131,17 @@ struct esp_lcd_panel_t {
|
||||
*/
|
||||
esp_err_t (*disp_sleep)(esp_lcd_panel_t *panel, bool sleep);
|
||||
|
||||
/**
|
||||
* @brief Set the brightness of the display
|
||||
*
|
||||
* @param[in] panel LCD panel handle, which is created by other factory API like `esp_lcd_new_panel_st7789()`
|
||||
* @param[in] brightness Brightness value (range depends on panel implementation, typically 0-255, 0-1023, or 0-100)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by the panel
|
||||
*/
|
||||
esp_err_t (*set_brightness)(esp_lcd_panel_t *panel, int brightness);
|
||||
|
||||
void *user_data; /*!< User data, used to store externally customized data */
|
||||
};
|
||||
|
||||
|
||||
@@ -83,3 +83,10 @@ esp_err_t esp_lcd_panel_disp_sleep(esp_lcd_panel_handle_t panel, bool sleep)
|
||||
ESP_RETURN_ON_FALSE(panel->disp_sleep, ESP_ERR_NOT_SUPPORTED, TAG, "sleep is not supported by this panel");
|
||||
return panel->disp_sleep(panel, sleep);
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_panel_set_brightness(esp_lcd_panel_handle_t panel, int brightness)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(panel, ESP_ERR_INVALID_ARG, TAG, "invalid panel handle");
|
||||
ESP_RETURN_ON_FALSE(panel->set_brightness, ESP_ERR_NOT_SUPPORTED, TAG, "set_brightness is not supported by this panel");
|
||||
return panel->set_brightness(panel, brightness);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ static esp_err_t panel_st7789_invert_color(esp_lcd_panel_t *panel, bool invert_c
|
||||
static esp_err_t panel_st7789_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
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_set_brightness(esp_lcd_panel_t *panel, int brightness);
|
||||
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);
|
||||
|
||||
@@ -125,6 +126,7 @@ esp_lcd_new_panel_st7789(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel
|
||||
st7789->base.draw_bitmap = panel_st7789_draw_bitmap;
|
||||
st7789->base.invert_color = panel_st7789_invert_color;
|
||||
st7789->base.set_gap = panel_st7789_set_gap;
|
||||
st7789->base.set_brightness = panel_st7789_set_brightness;
|
||||
st7789->base.mirror = panel_st7789_mirror;
|
||||
st7789->base.swap_xy = panel_st7789_swap_xy;
|
||||
st7789->base.disp_on_off = panel_st7789_disp_on_off;
|
||||
@@ -287,6 +289,18 @@ static esp_err_t panel_st7789_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_g
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_st7789_set_brightness(esp_lcd_panel_t *panel, int brightness)
|
||||
{
|
||||
st7789_panel_t *st7789 = __containerof(panel, st7789_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = st7789->io;
|
||||
ESP_RETURN_ON_FALSE(brightness >= 0 && brightness <= 0xFF, ESP_ERR_INVALID_ARG, TAG,
|
||||
"brightness out of range");
|
||||
uint8_t brightness_value = (uint8_t)brightness;
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_WRDISBV, &brightness_value, 1), TAG,
|
||||
"io tx param failed");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user