Skip to content

Commit ebf28ee

Browse files
committed
feat(esp_lcd_sh8601): add brightness control to the panel
Goes with IDF espressif/esp-idf#18273
1 parent 4bb8948 commit ebf28ee

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

components/display/lcd/esp_lcd_sh8601/esp_lcd_sh8601.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static esp_err_t panel_sh8601_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool
3535
static esp_err_t panel_sh8601_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
3636
static esp_err_t panel_sh8601_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
3737
static esp_err_t panel_sh8601_disp_on_off(esp_lcd_panel_t *panel, bool off);
38+
static esp_err_t panel_sh8601_set_brightness(esp_lcd_panel_t *panel, int brightness);
3839

3940
typedef struct {
4041
esp_lcd_panel_t base;
@@ -121,6 +122,7 @@ esp_err_t esp_lcd_new_panel_sh8601(const esp_lcd_panel_io_handle_t io, const esp
121122
sh8601->base.mirror = panel_sh8601_mirror;
122123
sh8601->base.swap_xy = panel_sh8601_swap_xy;
123124
sh8601->base.disp_on_off = panel_sh8601_disp_on_off;
125+
sh8601->base.set_brightness = panel_sh8601_set_brightness;
124126
*ret_panel = &(sh8601->base);
125127
ESP_LOGD(TAG, "new sh8601 panel @%p", sh8601);
126128

@@ -345,3 +347,19 @@ static esp_err_t panel_sh8601_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
345347
ESP_RETURN_ON_ERROR(tx_param(sh8601, io, command, NULL, 0), TAG, "send command failed");
346348
return ESP_OK;
347349
}
350+
351+
static esp_err_t panel_sh8601_set_brightness(esp_lcd_panel_t *panel, int brightness)
352+
{
353+
sh8601_panel_t *sh8601 = __containerof(panel, sh8601_panel_t, base);
354+
esp_lcd_panel_io_handle_t io = sh8601->io;
355+
356+
// Clamp brightness to 0-1023 range (10-bit)
357+
uint16_t brightness_val = (brightness < 0) ? 0 : (brightness > 1023) ? 1023 : (uint16_t)brightness;
358+
// Send as 2 bytes: MSB and LSB
359+
return tx_param(sh8601, io, LCD_CMD_WRDISBV, (uint8_t[]) { (brightness_val >> 8) & 0xFF, brightness_val & 0xFF }, 2);
360+
}
361+
362+
esp_err_t esp_lcd_sh8601_set_brightness(esp_lcd_panel_handle_t panel, uint16_t brightness)
363+
{
364+
return esp_lcd_panel_set_brightness(panel, brightness);
365+
}

components/display/lcd/esp_lcd_sh8601/include/esp_lcd_sh8601.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ typedef struct {
5555
*/
5656
esp_err_t esp_lcd_new_panel_sh8601(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel);
5757

58+
/**
59+
* @brief Set the brightness level of the SH8601 panel
60+
*
61+
* @param[in] panel LCD panel handle
62+
* @param[in] brightness Brightness level (0-1023, where 0 is lowest and 1023 is highest)
63+
* @return
64+
* - ESP_OK: Success
65+
* - Otherwise: Fail
66+
*/
67+
esp_err_t esp_lcd_sh8601_set_brightness(esp_lcd_panel_handle_t panel, uint16_t brightness);
68+
5869
/**
5970
* @brief LCD panel bus configuration structure
6071
*

0 commit comments

Comments
 (0)