You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While playing around with different I2C/SPI LCDs I noticed that various boards have different implementation for LCD initialization (cleanup is a separate TODO).
Some LCD displays have pins definition in Kconfig what makes it really easy to test different displays on various boards quickly and easily by just peeking / modification of the .config.
Some LCD displays have pins hardcoded into board definitions. This makes impossible to quickly test and use displays without board source files modification.
It would be nice to have all LCD pins definition in Kconfig files :-)
@cederom there are many discussions about moving pins to Kconfig and why it is not a good idea, although at first glance seems like a better and cool idea. Search for the PR from @vrmay23 about STM32H7 and @resyfer about Raspiberry Pi 4B
Maybe we need to write a Documentation about it to avoid it coming again and again.
@raiden00pl could you please comment?
I think we should close and/or create a Document explaining why not to move pins definition to Kconfig, especially when it is for a MCU where pins MUX (ALT modes) are complex.
pin configuration is part of board so it can't be configured from Kconfig unless this is board-specific Kconfig. Currently we have several examples where pins are configured with Kconfig, e.g. ST devkits where UARTs are configured via Kconfig options and change the configuration between connection to VCOM and to the Arduino header. If the pin configuration is done in board-specific Kconfig, then I think it's OK, especially for devkits with many useful pins. I use this approach myself in my out-of-tree boards and it works well.
Hmm, I see this quite the other way - lets take the ESP32 as the first example:
SPI GPIOs can be assigned from Kconfig, this is fine.
Additional lines could be part of Board Kconfig and/or LCD driver Kconfig. This way there is no need to modify board source code and Kconfig values can be used.
For ESP32 this is a lot easier to test different displays that way by only .config mdodification and no source code modification.
For ESP32 (and others) this would enable different defconfig board configurations to easily switch to testing different LCD drivers.
I know some MCUs have only selected pins available for some functions (i.e. STM32). There this trick would not be possible and some board initialization could could take these values for GPIO init.
For sure where necessary board code would initialize the GPIO but the GPIO number could be taken out of the Kconfig value, verified, and error returned when invalid choice is provided.
It would me still more versatile to provide pin numbers it in the Kconfig, even if it is used by board code.
Right now for every LCD driver I need to modify the board source code.. and it seems it would be better to provide just generic setup in the board code while the numbers in the Kconfig?
I am writing right now WaveSahre ESP32-S3-Touch-LCD-1.28 and ESP32-S3-LCD-1.28. These are almost exacly the same boards, except one has touchscreen sensor, the other not, and some LCD control lines are a bit different.
I am creating single board definition for both variants.
There is Kconfig switch wherhet TOUCH or NOTOUCH variant is used.
Based on what variant is used, board code assigns different pins for the LCD driver.
The "board has fixed pins that are not shared externally, in this case the Kconfig could map a feature to these pins" part is true for the first half, the other half is not used by the Kconfig but the board code except Kconfig selects variant that code uses. So here board hardcode is okay with exception that it is selected by Kconfig tune :-)
For more generic board like ESP32-DevKitC with no predefined constant lines a Kconfig could define LCD pin number and then board code would initialize these pins when option is selected.
This seems more flexible joint use of variable pin numbers from the Kconfig and board init code rather than board code modification every time different peripheral is used?
Maybe I am explaining it the wrong way or I still miss something? :-)
You miss the most important thing: the NuttX architecture and rigidly defined architecture boundaries. In NuttX, pin definitions are the responsibility of the board, not the arch. Just because you can do these tricks in one architecture doesn't mean you can do them in every one. The current solution, where pins are part of the board, is the most universal and purposeful. This often involves duplicating board code, but that's how it's supposed to be.
pin configuration is part of board so it can't be configured from Kconfig unless this is board-specific Kconfig. Currently we have several examples where pins are configured with Kconfig, e.g. ST devkits where UARTs are configured via Kconfig options and change the configuration between connection to VCOM and to the Arduino header. If the pin configuration is done in board-specific Kconfig, then I think it's OK, especially for devkits with many useful pins. I use this approach myself in my out-of-tree boards and it works well.
Thanks @raiden00pl :-) Except here we are talking about non-board-specific perihperal like LCD. Its just about defining LCD pins in the Kconfig to be more flexible and non-board-specific. Then board code init would have to contain LCD initialization routine, including GPIO initialization, and then LCD initialization.
But if we provide only pin numbers from the Kconfig then no need to change hardcodes is necessary each time we use different LCD just the Kconfig pin number / defconfig, so this should allow build out of the box various different diplays configs on the same generic devkit (i.e. ESP32-DevKitC) :-)
You miss the most important thing: the NuttX architecture and rigidly defined architecture boundaries. In NuttX, pin definitions are the responsibility of the board, not the arch. Just because you can do these tricks in one architecture doesn't mean you can do them in every one. The current solution, where pins are part of the board, is the most universal and purposeful. This often involves duplicating board code, but that's how it's supposed to be.
Yes, board contains GPIO init, and optional peripherals, but the optional peripherals can provide pin numbers via Kconfig not only the board's code #define right?
If the arch provides SPI then this is part of the arch. Then board contains peripheral config and code that initializes SPI accorting to pins from Kconfig.
For LCD only several optional pins are sometimes required that can be used over any generic GPIO. I can see that tese pins are currently hardcoded into board defines.. while these could be provided from Kconfig as well.. and this would bring more flexibility.
Yes I should show the code will create an example in a free moment thanks guys!! :-)
Yes, board contains GPIO init, and optional peripherals, but the optional peripherals can provide pin numbers via Kconfig not only the board's code #define right?
Pin configuration often involves more than just specifying a pin number. Just because some architectures can work with just a pin number doesn't mean it will work with all architectures. Many architectures require much more complex configuration for pins (such as port number, alternate function connection or pin speed)
Moreover, the configuration and ability to select a given pin with a given parameters may be tied to other configurations that must be configured. For example, to use pin 1 of port A at the highest possible speed, the port A clock must be enabled and the appropriate bits in the board configuration must be set (something similar is required for stm32). This cannot be achieved with a single option in Kconfig.
@acassis So you think is better to hardcore rather to use a simple menu to change the SPI / I2C pinset /a.f? The Kconfig in board level can support it not only for fix pin (otherwise in this case we should hardcore, since it is static). For sure shall not have any conflict among these pins neither in the board.h nor in the rest of the defconfig. I can't really understand why we "can not" use like I have proposed. It changed my life to become quite better :)
Can we actually write a documentation explain how to do it? I remember that in my PR I was requested to adjust some part of the code because it was reductant for the GPIOs. It was, indeed, but I could use the same "pattern" for switch/ case that Im using for SPI and I2C.
Activity
acassis commentedon Mar 23, 2026
@cederom there are many discussions about moving pins to Kconfig and why it is not a good idea, although at first glance seems like a better and cool idea. Search for the PR from @vrmay23 about STM32H7 and @resyfer about Raspiberry Pi 4B
Maybe we need to write a Documentation about it to avoid it coming again and again.
acassis commentedon Mar 27, 2026
@raiden00pl could you please comment?
I think we should close and/or create a Document explaining why not to move pins definition to Kconfig, especially when it is for a MCU where pins MUX (ALT modes) are complex.
raiden00pl commentedon Mar 27, 2026
pin configuration is part of board so it can't be configured from Kconfig unless this is board-specific Kconfig. Currently we have several examples where pins are configured with Kconfig, e.g. ST devkits where UARTs are configured via Kconfig options and change the configuration between connection to VCOM and to the Arduino header. If the pin configuration is done in board-specific Kconfig, then I think it's OK, especially for devkits with many useful pins. I use this approach myself in my out-of-tree boards and it works well.
acassis commentedon Mar 27, 2026
Exactly, the exception is when a board has fixed pins that are not shared externally, in this case the Kconfig could map a feature to these pins
cederom commentedon Mar 28, 2026
Hmm, I see this quite the other way - lets take the ESP32 as the first example:
.configmdodification and no source code modification.defconfigboard configurations to easily switch to testing different LCD drivers.I know some MCUs have only selected pins available for some functions (i.e. STM32). There this trick would not be possible and some board initialization could could take these values for GPIO init.
For sure where necessary board code would initialize the GPIO but the GPIO number could be taken out of the Kconfig value, verified, and error returned when invalid choice is provided.
It would me still more versatile to provide pin numbers it in the Kconfig, even if it is used by board code.
Right now for every LCD driver I need to modify the board source code.. and it seems it would be better to provide just generic setup in the board code while the numbers in the Kconfig?
What do I miss? :-P
cederom commentedon Mar 28, 2026
Another example here
For more generic board like ESP32-DevKitC with no predefined constant lines a Kconfig could define LCD pin number and then board code would initialize these pins when option is selected.
This seems more flexible joint use of variable pin numbers from the Kconfig and board init code rather than board code modification every time different peripheral is used?
Maybe I am explaining it the wrong way or I still miss something? :-)
raiden00pl commentedon Mar 28, 2026
You miss the most important thing: the NuttX architecture and rigidly defined architecture boundaries. In NuttX, pin definitions are the responsibility of the board, not the arch. Just because you can do these tricks in one architecture doesn't mean you can do them in every one. The current solution, where pins are part of the board, is the most universal and purposeful. This often involves duplicating board code, but that's how it's supposed to be.
cederom commentedon Mar 28, 2026
Thanks @raiden00pl :-) Except here we are talking about non-board-specific perihperal like LCD. Its just about defining LCD pins in the Kconfig to be more flexible and non-board-specific. Then board code init would have to contain LCD initialization routine, including GPIO initialization, and then LCD initialization.
But if we provide only pin numbers from the Kconfig then no need to change hardcodes is necessary each time we use different LCD just the Kconfig pin number / defconfig, so this should allow build out of the box various different diplays configs on the same generic devkit (i.e. ESP32-DevKitC) :-)
raiden00pl commentedon Mar 28, 2026
It would be better if you showed the code you're referring to. We might be talking about completely different things :P
cederom commentedon Mar 28, 2026
Yes, board contains GPIO init, and optional peripherals, but the optional peripherals can provide pin numbers via Kconfig not only the board's code
#defineright?If the arch provides SPI then this is part of the arch. Then board contains peripheral config and code that initializes SPI accorting to pins from Kconfig.
For LCD only several optional pins are sometimes required that can be used over any generic GPIO. I can see that tese pins are currently hardcoded into board defines.. while these could be provided from Kconfig as well.. and this would bring more flexibility.
Yes I should show the code will create an example in a free moment thanks guys!! :-)
raiden00pl commentedon Mar 28, 2026
Pin configuration often involves more than just specifying a pin number. Just because some architectures can work with just a pin number doesn't mean it will work with all architectures. Many architectures require much more complex configuration for pins (such as port number, alternate function connection or pin speed)
raiden00pl commentedon Mar 28, 2026
Moreover, the configuration and ability to select a given pin with a given parameters may be tied to other configurations that must be configured. For example, to use pin 1 of port A at the highest possible speed, the port A clock must be enabled and the appropriate bits in the board configuration must be set (something similar is required for stm32). This cannot be achieved with a single option in Kconfig.
vrmay23 commentedon Mar 28, 2026
@acassis So you think is better to hardcore rather to use a simple menu to change the SPI / I2C pinset /a.f? The Kconfig in board level can support it not only for fix pin (otherwise in this case we should hardcore, since it is static). For sure shall not have any conflict among these pins neither in the board.h nor in the rest of the defconfig. I can't really understand why we "can not" use like I have proposed. It changed my life to become quite better :)
Can we actually write a documentation explain how to do it? I remember that in my PR I was requested to adjust some part of the code because it was reductant for the GPIOs. It was, indeed, but I could use the same "pattern" for switch/ case that Im using for SPI and I2C.