Skip to content

feat(backlight): add PWM parameters configuration (#188) #189

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

Merged
merged 2 commits into from
Apr 23, 2025
Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# ChangeLog

## v1.0.2 - 2025-03-24
## v1.0.2 - 2025-04-23

### Enhancements:

* feat(backlight): add PWM parameters configuration (#188)

### Bugfixes:

Expand All @@ -9,6 +13,7 @@
* fix(docs): update README
* fix(conf): update comments of custom config file
* fix(examples): enable CPU 240M and task WDT default in esp_idf/lvgl_v8_port
* fix(lcd): fix ST7701 mirror issue

## v1.0.1 - 2025-03-13

Expand Down
20 changes: 18 additions & 2 deletions esp_panel_board_custom_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
20 changes: 18 additions & 2 deletions examples/platformio/lvgl_v8_port/src/esp_panel_board_custom_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,22 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high

#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (5000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_CUSTOM

/**
Expand Down Expand Up @@ -735,8 +751,8 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

#endif // ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM

Expand Down
17 changes: 17 additions & 0 deletions src/board/custom/Kconfig.board_custom.backlight
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ if ESP_PANEL_BOARD_USE_BACKLIGHT
Active level for backlight control.
endmenu

menu "PWM parameters"
depends on ESP_PANEL_BOARD_BACKLIGHT_TYPE_PWM_LEDC

config ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ
int "Frequency"
default 5000
help
Frequency for PWM control.

config ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION
int "Duty resolution"
default 10
range 1 20
help
Duty resolution for PWM control.
endmenu

config ESP_PANEL_BOARD_BACKLIGHT_IDLE_OFF
bool "Idle off"
default n
Expand Down
20 changes: 20 additions & 0 deletions src/board/custom/esp_panel_board_kconfig_custom_backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@
#error "Missing configuration: ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL"
#endif
#endif

#if (ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC)
#ifndef ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ
#ifdef CONFIG_ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ CONFIG_ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ
#else
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ 5000 // Keep the backward compatibility
#endif
#endif
#endif

#if (ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC)
#ifndef ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION
#ifdef CONFIG_ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION CONFIG_ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION
#else
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION 10 // Keep the backward compatibility
#endif
#endif
#endif
#endif

#ifndef ESP_PANEL_BOARD_BACKLIGHT_IDLE_OFF
Expand Down
4 changes: 4 additions & 0 deletions src/board/esp_panel_board_default_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ const BoardConfig ESP_PANEL_BOARD_DEFAULT_CONFIG = {
},
#elif ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
.config = BacklightPWM_LEDC::Config{
.ledc_timer = BacklightPWM_LEDC::LEDC_TimerPartialConfig{
.freq_hz = ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ,
.duty_resolution = ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION,
},
.ledc_channel = BacklightPWM_LEDC::LEDC_ChannelPartialConfig{
.io_num = ESP_PANEL_BOARD_BACKLIGHT_IO,
.on_level = ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@
#define ESP_PANEL_BOARD_BACKLIGHT_IO (38) // Output GPIO pin number
#define ESP_PANEL_BOARD_BACKLIGHT_ON_LEVEL (1) // Active level, 0: low, 1: high


#if ESP_PANEL_BOARD_BACKLIGHT_TYPE == ESP_PANEL_BACKLIGHT_TYPE_PWM_LEDC
/**
* @brief PWM parameters configuration
*/
#define ESP_PANEL_BOARD_BACKLIGHT_PWM_FREQ_HZ (1000) // LEDC timer frequency.
// Different backlight driver chips may have different
// frequency limits, please refer to the datasheet of
// the specific chip.
// https://github.com/esp-arduino-libs/ESP32_Display_Panel/issues/188

#define ESP_PANEL_BOARD_BACKLIGHT_PWM_DUTY_RESOLUTION (10) // LEDC timer duty resolution.
// The frequency and duty resolution of the LEDC timer
// need to be properly matched, please refer to:
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html#supported-range-of-frequency-and-duty-resolutions
#endif

#endif // ESP_PANEL_BOARD_BACKLIGHT_TYPE

/**
Expand Down Expand Up @@ -381,7 +398,7 @@
* 3. Patch version mismatch: No impact on functionality
*/
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0

// *INDENT-ON*
11 changes: 11 additions & 0 deletions src/drivers/lcd/port/esp_lcd_st7701_rgb.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,20 @@ static esp_err_t panel_st7701_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool
} else {
st7701->madctl_val &= ~LCD_CMD_ML_BIT;
}

// Enable the Command2 BK0
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7701_CMD_CND2BKxSEL, (uint8_t []) {
ST7701_CMD_BKxSEL_BYTE0, ST7701_CMD_BKxSEL_BYTE1, ST7701_CMD_BKxSEL_BYTE2, ST7701_CMD_BKxSEL_BYTE3,
ST7701_CMD_BKxSEL_BK0 | ST7701_CMD_CN2_BIT,
}, 5), TAG, "send command failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7701_CMD_SDIR, (uint8_t[]) {
sdir_val,
}, 1), TAG, "send command failed");;

// Disable Command2
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7701_CMD_CND2BKxSEL, (uint8_t []) {
ST7701_CMD_BKxSEL_BYTE0, ST7701_CMD_BKxSEL_BYTE1, ST7701_CMD_BKxSEL_BYTE2, ST7701_CMD_BKxSEL_BYTE3, 0,
}, 5), TAG, "send command failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
st7701->madctl_val,
}, 1), TAG, "send command failed");;
Expand Down
4 changes: 2 additions & 2 deletions src/esp_panel_versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

/* File `esp_panel_board_custom_conf.h` */
#define ESP_PANEL_BOARD_CUSTOM_VERSION_MAJOR 1
#define ESP_PANEL_BOARD_CUSTOM_VERSION_MINOR 0
#define ESP_PANEL_BOARD_CUSTOM_VERSION_PATCH 2
#define ESP_PANEL_BOARD_CUSTOM_VERSION_MINOR 1
#define ESP_PANEL_BOARD_CUSTOM_VERSION_PATCH 0

/* File `esp_panel_board_supported_conf.h` */
#define ESP_PANEL_BOARD_SUPPORTED_VERSION_MAJOR 1
Expand Down
1 change: 1 addition & 0 deletions tools/check_file_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

exclude_dirs = [
'./build',
'./examples/platformio/lvgl_v8_port/.pio'
]
internal_version_file = 'src/esp_panel_versions.h'
include_files = [
Expand Down
Loading