Skip to content

Commit 96ae099

Browse files
committed
Replaced the integer macro constants defines with enums in Arduino.h.
1 parent 3cd6c80 commit 96ae099

File tree

1 file changed

+92
-62
lines changed

1 file changed

+92
-62
lines changed

cores/arduino/Arduino.h

Lines changed: 92 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#ifndef Arduino_h
2121
#define Arduino_h
2222

23+
#ifdef __cplusplus
24+
#define ARD_CHAR_ENUM_lAnoShw : char
25+
#else
26+
#define ARD_CHAR_ENUM_lAnoShw
27+
#endif
28+
2329
#include <stdlib.h>
2430
#include <stdbool.h>
2531
#include <string.h>
@@ -37,12 +43,16 @@ extern "C"{
3743

3844
void yield(void);
3945

40-
#define HIGH 0x1
41-
#define LOW 0x0
46+
enum ARD_CHAR_ENUM_lAnoShw{
47+
LOW = 0x0,
48+
HIGH = 0x1
49+
};
4250

43-
#define INPUT 0x0
44-
#define OUTPUT 0x1
45-
#define INPUT_PULLUP 0x2
51+
enum ARD_CHAR_ENUM_lAnoShw{
52+
INPUT = 0x0,
53+
OUTPUT = 0x1,
54+
INPUT_PULLUP = 0x2
55+
};
4656

4757
#define PI 3.1415926535897932384626433832795
4858
#define HALF_PI 1.5707963267948966192313216916398
@@ -51,38 +61,50 @@ void yield(void);
5161
#define RAD_TO_DEG 57.295779513082320876798154814105
5262
#define EULER 2.718281828459045235360287471352
5363

54-
#define SERIAL 0x0
55-
#define DISPLAY 0x1
64+
enum ARD_CHAR_ENUM_lAnoShw{
65+
SERIAL = 0x0,
66+
DISPLAY = 0x1
67+
};
5668

57-
#define LSBFIRST 0
58-
#define MSBFIRST 1
69+
enum ARD_CHAR_ENUM_lAnoShw{
70+
LSBFIRST = 0,
71+
MSBFIRST = 1
72+
};
5973

60-
#define CHANGE 1
61-
#define FALLING 2
62-
#define RISING 3
74+
enum ARD_CHAR_ENUM_lAnoShw{
75+
CHANGE= 1,
76+
FALLING = 2,
77+
RISING = 3
78+
};
6379

6480
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
65-
#define DEFAULT 0
66-
#define EXTERNAL 1
67-
#define INTERNAL1V1 2
68-
#define INTERNAL INTERNAL1V1
81+
enum ARD_CHAR_ENUM_lAnoShw{
82+
DEFAULT = 0,
83+
EXTERNAL = 1,
84+
INTERNAL1V1 = 2,
85+
INTERNAL = INTERNAL1V1,
86+
};
6987
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
70-
#define DEFAULT 0
71-
#define EXTERNAL 4
72-
#define INTERNAL1V1 8
73-
#define INTERNAL INTERNAL1V1
74-
#define INTERNAL2V56 9
75-
#define INTERNAL2V56_EXTCAP 13
76-
#else
88+
enum ARD_CHAR_ENUM_lAnoShw{
89+
DEFAULT = 0,
90+
EXTERNAL = 4,
91+
INTERNAL1V1 = 8,
92+
INTERNAL = INTERNAL1V1,
93+
INTERNAL2V56 = 9,
94+
INTERNAL2V56_EXTCAP = 13,
95+
};
96+
#else
97+
enum ARD_CHAR_ENUM_lAnoShw{
7798
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
78-
#define INTERNAL1V1 2
79-
#define INTERNAL2V56 3
99+
INTERNAL1V1 = 2,
100+
INTERNAL2V56 = 3,
80101
#else
81-
#define INTERNAL 3
102+
INTERNAL = 3,
82103
#endif
83-
#define DEFAULT 1
84-
#define EXTERNAL 0
104+
DEFAULT = 1,
105+
EXTERNAL = 0,
85106
#endif
107+
};
86108

87109
// undefine stdlib's abs if encountered
88110
#ifdef abs
@@ -183,45 +205,51 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
183205
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
184206
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
185207

186-
#define NOT_A_PIN 0
187-
#define NOT_A_PORT 0
208+
enum ARD_CHAR_ENUM_lAnoShw{
209+
NOT_A_PIN = 0,
210+
NOT_A_PORT = 0,
188211

189-
#define NOT_AN_INTERRUPT -1
212+
NOT_AN_INTERRUPT = -1,
213+
};
190214

191215
#ifdef ARDUINO_MAIN
192-
#define PA 1
193-
#define PB 2
194-
#define PC 3
195-
#define PD 4
196-
#define PE 5
197-
#define PF 6
198-
#define PG 7
199-
#define PH 8
200-
#define PJ 10
201-
#define PK 11
202-
#define PL 12
216+
enum ARD_CHAR_ENUM_lAnoShw{
217+
PA = 1,
218+
PB = 2,
219+
PC = 3,
220+
PD = 4,
221+
PE = 5,
222+
PF = 6,
223+
PG = 7,
224+
PH = 8,
225+
PJ = 10,
226+
PK = 11,
227+
PL = 12,
228+
};
203229
#endif
204230

205-
#define NOT_ON_TIMER 0
206-
#define TIMER0A 1
207-
#define TIMER0B 2
208-
#define TIMER1A 3
209-
#define TIMER1B 4
210-
#define TIMER1C 5
211-
#define TIMER2 6
212-
#define TIMER2A 7
213-
#define TIMER2B 8
214-
215-
#define TIMER3A 9
216-
#define TIMER3B 10
217-
#define TIMER3C 11
218-
#define TIMER4A 12
219-
#define TIMER4B 13
220-
#define TIMER4C 14
221-
#define TIMER4D 15
222-
#define TIMER5A 16
223-
#define TIMER5B 17
224-
#define TIMER5C 18
231+
enum ARD_CHAR_ENUM_lAnoShw{
232+
NOT_ON_TIMER = 0,
233+
TIMER0A = 1,
234+
TIMER0B = 2,
235+
TIMER1A = 3,
236+
TIMER1B = 4,
237+
TIMER1C = 5,
238+
TIMER2 = 6,
239+
TIMER2A = 7,
240+
TIMER2B = 8,
241+
242+
TIMER3A = 9,
243+
TIMER3B = 10,
244+
TIMER3C = 11,
245+
TIMER4A = 12,
246+
TIMER4B = 13,
247+
TIMER4C = 14,
248+
TIMER4D = 15,
249+
TIMER5A = 16,
250+
TIMER5B = 17,
251+
TIMER5C = 18,
252+
};
225253

226254
#ifdef __cplusplus
227255
} // extern "C"
@@ -255,6 +283,8 @@ long map(long, long, long, long, long);
255283

256284
#endif
257285

286+
#undef ARD_CHAR_ENUM_lAnoShw
287+
258288
#include "pins_arduino.h"
259289

260290
#endif

0 commit comments

Comments
 (0)