-
Notifications
You must be signed in to change notification settings - Fork 13.3k
LED_BUILTIN in variant header file needs to be a define #2769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@bperrybap In the latest git version of core, we have a LED menu for the generic board which uses such a #define. Would give a try ? |
I'm not seeing it in either the latest 2.4 core available through the IDE boards manager or on the master git branch.
With what I have seen in the master branch, you could modify each variant file like this:
to this:
|
I myself can see it in the menu. If you updated from git (master branch) you need to restart the IDE so it reloads board.txt defining the menu. The menu only shows with generic boards esp8266 or esp8285 selected. The generic variant uses the define if provided, otherwise the former value is used as default. I'm not saying it works otherwise I wouldn't ask to try. Still I'm confident. |
LED_BUILTIN not beeing a define, your sketch should not test for it. |
The define I mentioned was named LED_BUILTIN and it isn't being used. |
Code does need be able check for its existence at compile time. Just having a const int named LED_BUILTIN isn't good enough. IMO using LED_BUILTIN would have made more sense to use rather than USERLED to define the default built in LED since the define LED_BUILTIN is needed anyway. |
You can't do that. |
I think you've made the point here. |
PR is merged |
There was lots of discussion about this several years ago on the Arduino developers lists and the resolution was to always ensure that there is a LED_BUILTIN define so that sketches and libraries could run time detect the presence of a built in LED.
So for years there has been a LED_BUILTIN define on all the Arduino.cc supplied AVR cores and some of the newer non AVR cores.
All the variant files in the esp8266 core declare LED_BUILTIN as a static const uint8_t
The problem with not having a define is that it breaks any code that depends on LED_BUILTIN as being a define to enable/disable use of a built in LED.
There are two solutions
Either will work.
My suggestion would be to use the latter and create a define that matches the variable name.
i.e.
That way you get the best of both worlds.
A define that code can use to compile time verify the existence of a built in led and a variable by the same name that allows for a typed variable rather than using a simple define.
This ensures full backward compatibility with other cores and older IDEs.
Doing something like adding a new PIN_LED_BUILTIN define is not a workable solution as it is not backward compatible and would require updating code ot use messy Arduino defines to try to compile detect which core and which core version is being used to know what defines or variable names to use.
The text was updated successfully, but these errors were encountered: