Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix digitalRead for controllers with big flash #512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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