Skip to content

Commit 3b5508e

Browse files
MCUdudefacchinm
authored andcommitted
Remove PROGMEM attribute and pgm_read_byte Not needed since the megaAVR 0-series have a unified address space. Using pgm_read* will only increase memory usage
1 parent 46ed5eb commit 3b5508e

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

Diff for: cores/arduino/Arduino.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ unsigned long microsecondsToClockCycles(unsigned long microseconds);
8686
// Get the bit location within the hardware port of the given virtual pin.
8787
// This comes from the pins_*.c file for the active board configuration.
8888

89-
extern const uint8_t PROGMEM digital_pin_to_port[];
90-
extern const uint8_t PROGMEM digital_pin_to_bit_mask[];
91-
extern const uint8_t PROGMEM digital_pin_to_bit_position[];
92-
extern const uint8_t PROGMEM digital_pin_to_timer[];
89+
extern const uint8_t digital_pin_to_port[];
90+
extern const uint8_t digital_pin_to_bit_mask[];
91+
extern const uint8_t digital_pin_to_bit_position[];
92+
extern const uint8_t digital_pin_to_timer[];
9393

9494
// Get the bit location within the hardware port of the given virtual pin.
9595
// This comes from the pins_*.c file for the active board configuration.
@@ -118,12 +118,12 @@ extern const uint8_t PROGMEM digital_pin_to_timer[];
118118
void setup_timers();
119119
bool isDoubleBondedActive(uint8_t pin);
120120

121-
#define digitalPinToPort(pin) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_port + pin) : NOT_A_PIN )
122-
#define digitalPinToBitPosition(pin) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_bit_position + pin) : NOT_A_PIN )
123-
#define analogPinToBitPosition(pin) ( (pin < NUM_ANALOG_INPUTS) ? pgm_read_byte(digital_pin_to_bit_position + pin + ANALOG_INPUT_OFFSET) : NOT_A_PIN )
124-
#define digitalPinToBitMask(pin) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_bit_mask + pin) : NOT_A_PIN )
125-
#define analogPinToBitMask(pin) ( (pin < NUM_ANALOG_INPUTS) ? pgm_read_byte(digital_pin_to_bit_mask + pin + ANALOG_INPUT_OFFSET) : NOT_A_PIN )
126-
#define digitalPinToTimer(pin) ( (pin < NUM_TOTAL_PINS) ? pgm_read_byte(digital_pin_to_timer + pin) : NOT_ON_TIMER )
121+
#define digitalPinToPort(pin) ( (pin < NUM_TOTAL_PINS) ? digital_pin_to_port[pin] : NOT_A_PIN )
122+
#define digitalPinToBitPosition(pin) ( (pin < NUM_TOTAL_PINS) ? digital_pin_to_bit_position[pin] : NOT_A_PIN )
123+
#define digitalPinToBitMask(pin) ( (pin < NUM_TOTAL_PINS) ? digital_pin_to_bit_mask[pin] : NOT_A_PIN )
124+
#define digitalPinToTimer(pin) ( (pin < NUM_TOTAL_PINS) ? digital_pin_to_timer[pin] : NOT_ON_TIMER )
125+
#define analogPinToBitPosition(pin) ( (digitalPinToAnalogInput(pin) != NOT_A_PIN) ? digital_pin_to_bit_position[pin + ANALOG_INPUT_OFFSET] : NOT_A_PIN )
126+
#define analogPinToBitMask(pin) ( (digitalPinToAnalogInput(pin) != NOT_A_PIN) ? digital_pin_to_bit_mask[pin + ANALOG_INPUT_OFFSET] : NOT_A_PIN )
127127

128128
#define portToPortStruct(port) ( (port < NUM_TOTAL_PORTS) ? ((PORT_t *)&PORTA + port) : NULL)
129129
#define digitalPinToPortStruct(pin) ( (pin < NUM_TOTAL_PINS) ? ((PORT_t *)&PORTA + digitalPinToPort(pin)) : NULL)

Diff for: variants/nona4809/pins_arduino.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static const uint8_t A7 = PIN_A7;
142142

143143
//
144144

145-
const uint8_t PROGMEM digital_pin_to_port[] = {
145+
const uint8_t digital_pin_to_port[] = {
146146
PC, // 0 PC5/USART1_Rx
147147
PC, // 1 PC4/USART1_Tx
148148
PA, // 2 PA0
@@ -172,7 +172,7 @@ const uint8_t PROGMEM digital_pin_to_port[] = {
172172
};
173173

174174
/* Use this for accessing PINnCTRL register */
175-
const uint8_t PROGMEM digital_pin_to_bit_position[] = {
175+
const uint8_t digital_pin_to_bit_position[] = {
176176
PIN5_bp, // 0 PC5/USART1_Rx
177177
PIN4_bp, // 1 PC4/USART1_Tx
178178
PIN0_bp, // 2 PA0
@@ -202,7 +202,7 @@ const uint8_t PROGMEM digital_pin_to_bit_position[] = {
202202
};
203203

204204
/* Use this for accessing PINnCTRL register */
205-
const uint8_t PROGMEM digital_pin_to_bit_mask[] = {
205+
const uint8_t digital_pin_to_bit_mask[] = {
206206
PIN5_bm, // 0 PC5/USART1_Rx
207207
PIN4_bm, // 1 PC4/USART1_Tx
208208
PIN0_bm, // 2 PA0
@@ -231,7 +231,7 @@ const uint8_t PROGMEM digital_pin_to_bit_mask[] = {
231231
PIN4_bm, // 25 PB4/USART3_Tx
232232
};
233233

234-
const uint8_t PROGMEM digital_pin_to_timer[] = {
234+
const uint8_t digital_pin_to_timer[] = {
235235
NOT_ON_TIMER, // 0 PC5/USART1_Rx
236236
NOT_ON_TIMER, // 1 PC4/USART1_Tx
237237
NOT_ON_TIMER, // 2 PA0
@@ -260,7 +260,7 @@ const uint8_t PROGMEM digital_pin_to_timer[] = {
260260
NOT_ON_TIMER, // 25 PB4/USART3_Tx
261261
};
262262

263-
const uint8_t PROGMEM analog_pin_to_channel[] = {
263+
const uint8_t analog_pin_to_channel[] = {
264264
3,
265265
2,
266266
1,
@@ -274,7 +274,7 @@ const uint8_t PROGMEM analog_pin_to_channel[] = {
274274
#endif
275275

276276
extern const uint8_t analog_pin_to_channel[];
277-
#define digitalPinToAnalogInput(p) ((p < ANALOG_INPUT_OFFSET) ? pgm_read_byte(analog_pin_to_channel + p) : pgm_read_byte(analog_pin_to_channel + p - ANALOG_INPUT_OFFSET) )
277+
#define digitalPinToAnalogInput(p) ((p < ANALOG_INPUT_OFFSET) ? analog_pin_to_channel[p] : analog_pin_to_channel[p - ANALOG_INPUT_OFFSET] )
278278

279279
// These serial port names are intended to allow libraries and architecture-neutral
280280
// sketches to automatically default to the correct port name for a particular type

Diff for: variants/uno2018/pins_arduino.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static const uint8_t A5 = PIN_A5;
163163

164164
//
165165

166-
const uint8_t PROGMEM digital_pin_to_port[] = {
166+
const uint8_t digital_pin_to_port[] = {
167167
PC, // 0 PC5/USART1_Rx
168168
PC, // 1 PC4/USART1_Tx
169169
PA, // 2 PA0
@@ -208,7 +208,7 @@ const uint8_t PROGMEM digital_pin_to_port[] = {
208208
};
209209

210210
/* Use this for accessing PINnCTRL register */
211-
const uint8_t PROGMEM digital_pin_to_bit_position[] = {
211+
const uint8_t digital_pin_to_bit_position[] = {
212212
PIN5_bp, // 0 PC5/USART1_Rx
213213
PIN4_bp, // 1 PC4/USART1_Tx
214214
PIN0_bp, // 2 PA0
@@ -253,7 +253,7 @@ const uint8_t PROGMEM digital_pin_to_bit_position[] = {
253253
};
254254

255255
/* Use this for accessing PINnCTRL register */
256-
const uint8_t PROGMEM digital_pin_to_bit_mask[] = {
256+
const uint8_t digital_pin_to_bit_mask[] = {
257257
PIN5_bm, // 0 PC5/USART1_Rx
258258
PIN4_bm, // 1 PC4/USART1_Tx
259259
PIN0_bm, // 2 PA0
@@ -297,7 +297,7 @@ const uint8_t PROGMEM digital_pin_to_bit_mask[] = {
297297
PIN6_bm // 40 PF6 RESET
298298
};
299299

300-
const uint8_t PROGMEM digital_pin_to_timer[] = {
300+
const uint8_t digital_pin_to_timer[] = {
301301
NOT_ON_TIMER, // 0 PC5/USART1_Rx
302302
NOT_ON_TIMER, // 1 PC4/USART1_Tx
303303
NOT_ON_TIMER, // 2 PA0

0 commit comments

Comments
 (0)