Skip to content

Commit

Permalink
Fix digitalRead for controllers with big flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dovgalyuk committed Nov 18, 2022
1 parent 42fa4a1 commit 35edd08
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,22 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
//
// These perform slightly better as macros compared to inline functions
//
#define analogInPinToBit(P) (P)
#if (FLASHEND > 0xFFFF)
#define digitalPinToPort(P) ( pgm_read_byte_far( pgm_get_far_address( digital_pin_to_port_PGM ) + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte_far( pgm_get_far_address( digital_pin_to_bit_mask_PGM ) + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte_far( pgm_get_far_address( digital_pin_to_timer_PGM ) + (P) ) )
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word_far( pgm_get_far_address( port_to_output_PGM ) + 2 * (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word_far( pgm_get_far_address( port_to_input_PGM ) + 2 * (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word_far( pgm_get_far_address( port_to_mode_PGM ) + 2 * (P))) )
#else
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
#endif

#define NOT_A_PIN 0
#define NOT_A_PORT 0
Expand Down

0 comments on commit 35edd08

Please sign in to comment.