Pin-mapping (non)conventions for custom Arduino boards?

Yes, I understand hardware peripheral functions are tied to specific AVR pins by design :stuck_out_tongue: I am referring specifically to GPIOs. Specifically, in the SD library's SD2PinMap.h, there is a bunch of code like:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Mega

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 20;
uint8_t const SCL_PIN = 21;

// SPI port
uint8_t const SS_PIN = 53;
uint8_t const MOSI_PIN = 51;
uint8_t const MISO_PIN = 50;
uint8_t const SCK_PIN = 52;

static const pin_map_t digitalPinMap[] = {
  {&DDRE, &PINE, &PORTE, 0},  // E0  0
  {&DDRE, &PINE, &PORTE, 1},  // E1  1
  {&DDRE, &PINE, &PORTE, 4},  // E4  2
  {&DDRE, &PINE, &PORTE, 5},  // E5  3
  {&DDRG, &PING, &PORTG, 5},  // G5  4
  {&DDRE, &PINE, &PORTE, 3},  // E3  5
[...]

If I understand it correctly, the lib "tries to" use the hardware peripheral (e.g. if SOFTWARE_SPI is not defined...I ass-ume this is defined by libs such as NewSoftSerial maybe???), but the hardcoded GPIO identifier is used for initially setting the pins' states, or when SOFTWARE_SPI defined. The large structure following it I understand to be part of a speed-hack vs. digitalWrite(...), but these still limit portability to other boards or a configuration (e.g. hand-soldered SD socket) that does not match the unpublished assumption of "Arduino Pin Numbers" for a particular CPU.

I guess the latter structure answers my other question; "Arduino Pin Number" vs. port/bit seem to be in no particular order. For someone rolling my own board that I hope other people will use someday, my big question is how common this practice is among 'major' Arduino libraries - i.e. whether I should just crib the pin numberings from e.g. Sanguino (even if it turns my PCB traces into spaghetti) rather than "innovate" in this area :slight_smile: Or if I don't, to what extent I will have to petition library authors to include an #ifdef for my board that comparatively few people will use, and/or maintain my own forks of various libraries with the pin numbers changed / settable in constructor.

Thanks!