From 35edd08f5daf27bb4611b7933e40a6e667e2898d Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Nov 2022 12:51:17 +0300 Subject: [PATCH] Fix digitalRead for controllers with big flash --- cores/arduino/Arduino.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 91eeb16bc..7d82868f0 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -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