Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Please post bugs and enhancements for the STM core here
Post Reply
fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by fpiSTM » Sat Nov 04, 2017 10:56 am

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.

victor_pv
Posts: 1682
Joined: Mon Apr 27, 2015 12:12 pm

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by victor_pv » Sat Nov 04, 2017 12:51 pm

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.

zmemw16
Posts: 1450
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by zmemw16 » Sat Nov 04, 2017 2:43 pm

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

User avatar
RogerClark
Posts: 7179
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by RogerClark » Sat Nov 04, 2017 8:40 pm

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

fpiSTM
Posts: 227
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by fpiSTM » Mon Nov 06, 2017 10:12 am

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;

bperrybap
Posts: 2
Joined: Mon Nov 06, 2017 4:55 pm

Re: Definition of NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS

Post by bperrybap » Mon Nov 06, 2017 5:10 pm

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

Post Reply