File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ extern const uint8_t PROGMEM digital_pin_to_interrupt[];
8080
8181// Get the bit location within the hardware port of the given virtual pin.
8282// This comes from the pins_*.c file for the active board configuration.
83- //
83+ //
8484// These perform slightly better as macros compared to inline functions
8585//
8686#define digitalPinToPort (pin ) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_port + pin) : NOT_A_PIN )
@@ -90,9 +90,10 @@ extern const uint8_t PROGMEM digital_pin_to_interrupt[];
9090#define analogPinToBitMask (pin ) ( (pin < NUM_ANALOG_INPUTS) ? (1 << analogPinToBitPosition(pin)) : NOT_A_PIN )
9191#define digitalPinToTimer (pin ) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_timer + pin) : NOT_ON_TIMER )
9292
93- #define portToPortStruct (port ) (( PORT_t *)&PORTA + port)
93+ #define portToPortStruct (port ) ( (port < NOT_A_PORT) ? (( PORT_t *)&PORTA + port) : NULL )
9494#define digitalPinToPortStruct (pin ) ( (pin < NUM_TOTAL_PINS) ? ((PORT_t *)&PORTA + digitalPinToPort(pin)) : NULL)
95- #define getPINnCTRLregister (port , bit_pos ) ( (port != NULL) ? ((uint8_t *)&(port->PIN0CTRL) + bit_pos) : NULL )
95+ #define getPINnCTRLregister (port , bit_pos ) ( ((port != NULL) && (bit_pos < NOT_A_PIN)) ? ((uint8_t *)&(port->PIN0CTRL) + bit_pos) : NULL )
96+
9697#define digitalPinToInterrupt (p ) ( pgm_read_byte(digital_pin_to_interrupt + p) )
9798#define portPinToInterrupt (port , bit_pos ) ( pgm_read_byte(port_interrupt_offset + port) + bit_pos )
9899
You can’t perform that action at this time.
0 commit comments