-
Notifications
You must be signed in to change notification settings - Fork 984
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
NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS breaks cpp conditionals #140
Comments
Right it was added to avoid warning. |
Hi @bperrybap, |
Bummer. when I did my simple test, I only tested that it compiled not that it worked. The issue in my case is that I need a test that works at compile time. I'm not sure how much other code out there does this type of compile time checking using these symbols. Its a tough problem for something so simple. I guess I could switch to using the newer variant PIN_XXX defines which includes the PIN_An defines for the analog pins but the STM core currently does not have any of those defines yet nor does many other cores including the older arduino.cc IDE avr core. |
Could you provide your code? Or at least tell me which operation you performed on the Ax? If only analogRead, why not iterate with index?
edit: Issue closed by error. |
It is in a diagnostic sketch that comes with one of my libraries.
It is showing the digital pin mappings for the analog pins, if they exist. For the most part users of this diagnostic tool wouldn't miss the messages if they didn’t' work, and the messages were more for me to help them when they had issues. |
You may want to consider what it takes to implement all the new variant PIN_XXX defines as it is likely intertwined with this. But you might be able to automate filling in the enum and generating the PIN_An defines if you define NUM_ANALOG_INPUTS as a simple number and conditionally used that to populate the enum and to generate the PIN_An defines. |
What's you proposed is to define NUM_ANALOG_INPUTS in each variant.h file but it will bring some risk to have misalignment. You could be simply replace the code by a loop using the standard macro
Moreover some STM32 could have up to 18 Ax definition. |
I'm not sure how PIN_Ax is a duplicate definition - yes it is a an additional definition over An but that is the direction arduino.cc has chosen to go. In my case I only want to print those two pins and only in certain circumstances. There should not be a risk of having misalignment, not when using the conditionals I talked about. In your variants, it appears that the analog pin numbers all use contiguous Here is an example of what I was mentioning.
In a common file like pins_arduino.h
you could do also do it this way in pins_arduino. h to be more compatible with the newer arduino.cc variant
Like I said not too pretty, but it keeps the variant files simple/clean and the messy stuff is all in the one common file like pins_arduino.h |
I corrected the examples on github, so make sure to look on github rather than the email. |
Ok. I will check that in a week. I'm on vacation this week. |
I've created a dedicated post on stm32duino.com forum: |
Another approach could be to keep the AEND and DEND as-is.
Then add a static_assert somewhere that checks that there are no mismatch
|
First part merged, thanks @lacklustrlabs. (#206) |
Ax definition is now inline with Arduino style Variant has only to define the digital pin number of the first analog input (i.e. which digital pin is A0) Clean variant header include Fix stm32duino#140 Signed-off-by: Frederic Pillon <[email protected]>
@bperrybap @lacklustrlabs |
Ax definition is now inline with Arduino style Variant has only to define the digital pin number of the first analog input (i.e. which digital pin is A0) Clean variant header include Fix stm32duino#140 Signed-off-by: Frederic Pillon <[email protected]>
I checked out and used the branch fpistm:arduino_compatibility_pin_140 and I can now compile my test code and lcd library. I don't have any actual STM32 h/w to test it on yet, but the compile seems to be working as expected when using conditional compilation that use the macros. The only issues were some unrelated warnings in the hal code which vary by board. But for the pins_arduino.h / variant macros, it looks good. BTW, you can test the NUM_ANALOG_INPUTS define by using my hd44780 library (install using the IDE library manager) and then compile the sketch I2CexpDiag in the hd44780_I2Cexp i/o class |
Ax definition is now inline with Arduino style Variant has only to define the digital pin number of the first analog input (i.e. which digital pin is A0) Clean variant header include Fix stm32duino#140 Signed-off-by: Frederic Pillon <[email protected]>
Ax definition is now inline with Arduino style Variant has only to define the digital pin number of the first analog input (i.e. which digital pin is A0) Clean variant header include Fix stm32duino#140 Signed-off-by: Frederic Pillon <[email protected]>
The definitions of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS below:
breaks code that use cpp conditionals like this:
#if NUM_ANALOG_INPUTS > 4
I've not run into this issue in any other core.
The cpp processor is not type aware and so the uint32_t cast is what breaks things.
When the cast is removed, the cpp conditionals that use the macros will work.
I'm not sure why the cast would be necessary in the macros.
enums can normally be used as integers, and the NUM_ANALOG_INPUTS is already depending on that in the calculation.
If there are some places that get warnings because of some sort of int vs unsigned int comparisons, it seems like it should be fixed there vs in the actual macro definitions.
The text was updated successfully, but these errors were encountered: