Would anyone know of a documentation for variant.h? I am trying to understand the:
// Number of pins defined in PinDescription array
#define PINS_COUNT (26u)
#define NUM_DIGITAL_PINS (20u)
#define NUM_ANALOG_INPUTS (6u)
#define NUM_ANALOG_OUTPUTS (1u)
#define analogInputToDigitalPin(p) ((p < 6u) ? (p) + 14u : -1)
This particular example is for Arduino Zero, for which there are 44 entries in the PinDescription array, so, for example, I expected PINS_COUNT to be (44u) instead of (26u). Similar for NUM_DIGITAL_PINS. Then why not:
Everyone seems to have their own take on how to setup the Wiring pins and if they should mix Analog channels with Digital pins. If the analog pins can work as digital outputs then they should have digital numbers, but there are some cases where the analog pins don't have digital roles (e.g. ATmega328p-AU has analog channels 6 and 7, which do not have digital capabilities). Personally, I separated my ADC core functions from the Digital Wiring functions. The idea that I could pass a digital number to the analog read function and it would do the right thing just felt more absurd the deeper I looked, so my Analog core only accepts analog channel numbers, not Digital numbers.
I'm not working with ARM devices yet, so this is from my AVR experience.
PINS_COUNT doesn't actually seem to be USED anywhere. (Search of the source repository)
(I particularly like CircuitPlayground, which has the count set to 52, for the 48-pin part.)
(The AVR core apparently doesn't even define PINS_COUNT...)
Presumably, pin numbers over 26 aren't expected to be used by ordinary programmers, since they're the pins connected to the eDBG chip and such. If a user asks "how many pins are available", then "26" is a better answer than "44" (14 digital, 6 analog, 3 SPI, 2 I2C, ... um... (2 LEDS))
That is a convenience function that allows the user to pass an analog channel and get a digital pin number. The idea seems nice on the surface, but it adds the sort of convoluted thinking that is probably a bad mix for this environment. The function is not used in the Arduino core (other than in some variant.h) so it is up to the user to known about and use it.