Page 1 of 1

How to write Kconfig menu to select GPIO pin as gpio_num_t

Posted: Mon Aug 23, 2021 7:15 pm
by sporniket
Hello,

I am trying to write a Kconfig menu to be able to choose the GPIO pin for a given use.

But it seems that I can only choose an integer value, e.g. :

Code: Select all

    config PIN_STATUS_MAIN
        int "Main LED GPIO number"
        range 0 34
        default 23
        help
            GPIO number (IOxx) for the 'Main status' LED.
And then I cannot call the gpio api because of wrong type.

Now, is there a mean to make this selection so that CONFIG_PIN_STATUS_MAIN will be e.g. GPIO_NUM_23 with the default value ?

Otherwise I plan to have a function that do the mapping, called to initialize a constant, but it's my last resort.

Re: How to write Kconfig menu to select GPIO pin as gpio_num_t

Posted: Tue Aug 24, 2021 5:55 am
by ESP_Sprite
For each xx, the GPIO_NUM_xx enums have the same value as xx; you should be able to just cast it: my_gpio=(gpio_num_t)(CONFIG_PIN_STATUS_MAIN);

Re: How to write Kconfig menu to select GPIO pin as gpio_num_t

Posted: Tue Aug 24, 2021 9:07 pm
by sporniket
Yes, it works with casting. Thank you.