Skip to content

Uncover the secret of the undocumented trick in gpio_set_level() when initializing the display. #123

Open
@SinglWolf

Description

@SinglWolf

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.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions