How to write Kconfig menu to select GPIO pin as gpio_num_t

sporniket
Posts: 4
Joined: Mon Aug 23, 2021 5:52 pm

How to write Kconfig menu to select GPIO pin as gpio_num_t

Postby sporniket » Mon Aug 23, 2021 7:15 pm

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.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Tue Aug 24, 2021 5:55 am

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);

sporniket
Posts: 4
Joined: Mon Aug 23, 2021 5:52 pm

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

Postby sporniket » Tue Aug 24, 2021 9:07 pm

Yes, it works with casting. Thank you.

Who is online

Users browsing this forum: No registered users and 102 guests