Skip to content

Instantly share code, notes, and snippets.

@matthijskooijman
Created January 26, 2016 09:30
Show Gist options
  • Save matthijskooijman/30786c61a08cfa56530c to your computer and use it in GitHub Desktop.
Save matthijskooijman/30786c61a08cfa56530c to your computer and use it in GitHub Desktop.
Arduino.h:
#define digitalPinToPort(P) digitalPinToPortFunction(pin);
static inline uint8_t digitalPinToPortFunction(uint8_t pin) __attribute__((always_inline));
static inline uint8_t digitalPinToPortFunction(uint8_t pin) {
#if !defined(ARDUINO_MAIN)
if __builtin_constant_p(pin)
return digital_pin_to_port[P];
else
#endif
return pgm_read_byte( digital_pin_to_port_PGM + pin );
}
#ifdef ARDUINO_MAIN
#define DIGITAL_PIN_TO_PORT_TABLE const uint8_t PROGMEM digital_pin_to_port_PGM[]
#else
#define DIGITAL_PIN_TO_PORT_TABLE static const uint8_t PROGMEM digital_pin_to_port[]
#endif
pins_arduino.h:
DIGITAL_PIN_TO_PORT_TABLE = {
PD, /* 0 */
PD,
etc.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment