Page 1 of 1

Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Sat Nov 04, 2017 10:56 am
by fpiSTM
Hi guy,
An issue has been opened here:
https://github.com/stm32duino/Arduino_C ... issues/140

I will really appreciate your feedback about that.
To sum up the request is to able to use the NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS in a valued conditional preprocessing:

Code: Select all

#if NUM_ANALOG_INPUTS > 4
It is currently not possible as those defined are based on an enum value not directly a value.

Thanks in advance.

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Sat Nov 04, 2017 12:51 pm
by victor_pv
While working in the marlin firmware, which uses macros a lot, xC000005 found the same exact issue. All enums evaluate to 0, so macros using the pins, which are in an enum, would fail to work properly.

Not sure what solution to propose. I have been reading about using mixing macros and enums with some tricks, but have not found anything definitive.
xC00005 changed the pins list to #defines, but then you can not use the last value of the enum as a count.

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Sat Nov 04, 2017 2:43 pm
by zmemw16
post above prodded a braincell.
once upon a time drifting pleasantly along listening to the greater skilled, a wisp descended muttering something about how and when enums are populated &| valued.
stephen

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Sat Nov 04, 2017 8:40 pm
by RogerClark
I am sure everyone else googled for this, but as far as I can see, the only workaround is to define an END_xxxxx to each enum and defined the number to be the name of END_xxxxx - NAME_OF_FIRST_ENUM

as the enum names are in global scope the END would need to have a different name for each enum group, hence the xxxxx in my example

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Mon Nov 06, 2017 10:12 am
by fpiSTM
Probably the NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS could be defined in the variant with the correct value.
And Ax enum could be moved to core.
I'm currently trying to understand the rational of Arduino to define pin like that:

Code: Select all

#define PIN_A0   (14)
static const uint8_t A0 = PIN_A0;

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Posted: Mon Nov 06, 2017 5:10 pm
by bperrybap
Guys,
Read the github issue.
I posted about why there are both PIN_Ax and Ax symbols and why one is const and the other is a macro define.
I also proposed a solution to resolve this.
In the proposal, there are two defines in each variant file and all the other stuff needed to create the proper symbols is common and can moved to the pins_arduino.h file.

--- bill