lvgl_esp32_drivers
lvgl_esp32_drivers copied to clipboard
Uncover the secret of the undocumented trick in `gpio_set_level()` when initializing the display.
For a long time I did not want to update the drivers for my project, but I did it anyway.
While looking at the innovations, I noticed something new for me.
Explain to me, please, how this can be?
The function from the esp-idf
framework only accepts the following arguments:
/**
* @brief GPIO set output level
*
* @param gpio_num GPIO number. If you want to set the output level of e.g. GPIO16, gpio_num should be GPIO_NUM_16 (16);
* @param level Output level. 0: low ; 1: high
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG GPIO number error
*
*/
esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level);
With gpio_num
, everything me is clear, but with level
there is some misunderstanding.
Watch the headline briefing, it says:
* @param level Output level. 0: low ; 1: high
Now let's turn to the disp_backlight_set()
function:
void disp_backlight_set(disp_backlight_h bckl, int brightness_percent)
{
// Check input paramters
if (bckl == NULL)
return;
if (brightness_percent > 100)
brightness_percent = 100;
if (brightness_percent < 0)
brightness_percent = 0;
disp_backlight_t *bckl_dev = (disp_backlight_t *) bckl;
ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent);
if (bckl_dev->pwm_control) {
uint32_t duty_cycle = (1023 * brightness_percent) / 100; // LEDC resolution set to 10bits, thus: 100% = 1023
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, bckl_dev->index, duty_cycle));
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, bckl_dev->index));
} else {
ESP_ERROR_CHECK(gpio_set_level(bckl_dev->index, brightness_percent));
}
}
This function is called when the display is initialized as follows:
disp_backlight_set(bckl_handle, 100);
As a result, the function gpio_set_level()
receives a argument level
equal to 100
.
Uncover the secret of the undocumented trick in gpio_set_level()
when initializing the display.
P.S. Setting Kconfig: Backlight Control (Switch control)
Point menu [*] Is backlight turn on with a HIGH (1) logic level?
or [*] Is backlight turn on with a HIGH (0) logic level?
does not affect anything.
Hi,
If you follow what's inside the gpio_set_level
you end up in gpio_ll_set_level
, you can see the implementation here, basically it only checks if level
is 0 or not 0, so if level
is 1 or 100 it ends up being the same.
We should update the docs with this comment, thanks for reporting it.