I don't know what's happening here but the pin definitions in variant.h / variant.cpp don't match with those in datasheet.
The controller I have on zero is SAMD21G18. A look at the datasheet says that pin 31 is PA22 for example. However in variant.cpp, PA22 is pin 20! Same goes for all the other pins.
The variant.h I am looking at is located here,
C:\Users.....\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.6\variants\arduino_zero
I am on windows 10.
I am able to run programs using serial, I2c and SPI interface without problems :o , so variant.h must be correct? What am I missing?
The pin number in the variant file is the Arduino pin number. This is just an arbitrary identifier number assigned to each pin that makes it easy to use, e.g.:
digitalWrite(20, HIGH);
sets pin PA22 HIGH.
The Arduino pin number itself doesn't mean anything.
I'm guessing the datasheet you're referring to is the manufacturer's datasheet for the microcontroller? If so then the pin number you're seeing listed there is likely the physical pin number on the chip, which is completely different from the Arduino pin number. If you think about it a little bit you'll see why, it would not be practical for Arduino pin numbers to match physical pin numbers, since every physical pin is numbered rather than just the I/O pins.
Oh I see. I programmed Atmel controllers before using AVR Studio and the pin numbers in definitions were the same as physical pin numbers. That's why I find this Arduino scheme strange.
I programmed Atmel controllers before using AVR Studio and the pin numbers in definitions were the same as physical pin numbers.
No they're not (well, maybe some of the tiny chips.) The ATmega328, for instance, has three separate "ports" (PORTB, PORTC, PORTD), each of which has some subset of bits numbered 0 to 7. A normal AVR programmer has to deal with the multiple PORTS, understand bitmasks vs bit numbers, and some other things that the Arduino/Wiring libraries simplify a great deal...