Skip to content

Commit a23bf39

Browse files
KOLANICHobrafacchinm
committed
Replaced the integer macro constants defines with enums in Arduino.h.
Incorporates the changes from arduino/ArduinoCore-API@4986a66, arduino/ArduinoCore-API@445594a and . Co-Authored-By: Jesse Vincent <jesse@keyboard.io> Co-Authored-By: Martino Facchin <m.facchin@arduino.cc>
1 parent 0428ad8 commit a23bf39

File tree

1 file changed

+93
-64
lines changed

1 file changed

+93
-64
lines changed

cores/arduino/Arduino.h

Lines changed: 93 additions & 64 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_XWEZPiBoACuGnH : char
25+
#else
26+
#define ARD_CHAR_ENUM_XWEZPiBoACuGnH __attribute__ ((__packed__))
27+
#endif
28+
2329
#include <stdlib.h>
2430
#include <stdbool.h>
2531
#include <string.h>
@@ -37,12 +43,21 @@ extern "C"{
3743

3844
void yield(void);
3945

40-
#define HIGH 0x1
41-
#define LOW 0x0
42-
43-
#define INPUT 0x0
44-
#define OUTPUT 0x1
45-
#define INPUT_PULLUP 0x2
46+
typedef enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
47+
LOW = 0,
48+
HIGH = 1,
49+
CHANGE = 2,
50+
FALLING = 3,
51+
RISING = 4,
52+
} PinStatus;
53+
54+
typedef enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
55+
INPUT = 0,
56+
OUTPUT = 1,
57+
INPUT_PULLUP = 2,
58+
INPUT_PULLDOWN = 3,
59+
OUTPUT_OPENDRAIN = 4,
60+
} PinMode;
4661

4762
#define PI 3.1415926535897932384626433832795
4863
#define HALF_PI 1.5707963267948966192313216916398
@@ -51,38 +66,44 @@ void yield(void);
5166
#define RAD_TO_DEG 57.295779513082320876798154814105
5267
#define EULER 2.718281828459045235360287471352
5368

54-
#define SERIAL 0x0
55-
#define DISPLAY 0x1
56-
57-
#define LSBFIRST 0
58-
#define MSBFIRST 1
69+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
70+
SERIAL = 0x0,
71+
DISPLAY = 0x1
72+
};
5973

60-
#define CHANGE 1
61-
#define FALLING 2
62-
#define RISING 3
74+
typedef enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
75+
LSBFIRST = 0,
76+
MSBFIRST = 1,
77+
} BitOrder;
6378

6479
#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
80+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
81+
DEFAULT = 0,
82+
EXTERNAL = 1,
83+
INTERNAL1V1 = 2,
84+
INTERNAL = INTERNAL1V1,
85+
};
6986
#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
87+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
88+
DEFAULT = 0,
89+
EXTERNAL = 4,
90+
INTERNAL1V1 = 8,
91+
INTERNAL = INTERNAL1V1,
92+
INTERNAL2V56 = 9,
93+
INTERNAL2V56_EXTCAP = 13,
94+
};
95+
#else
96+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
7797
#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
98+
INTERNAL1V1 = 2,
99+
INTERNAL2V56 = 3,
80100
#else
81-
#define INTERNAL 3
101+
INTERNAL = 3,
82102
#endif
83-
#define DEFAULT 1
84-
#define EXTERNAL 0
103+
DEFAULT = 1,
104+
EXTERNAL = 0,
85105
#endif
106+
};
86107

87108
// undefine stdlib's abs if encountered
88109
#ifdef abs
@@ -183,45 +204,51 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
183204
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
184205
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
185206

186-
#define NOT_A_PIN 0
187-
#define NOT_A_PORT 0
207+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
208+
NOT_A_PIN = 0,
209+
NOT_A_PORT = 0,
188210

189-
#define NOT_AN_INTERRUPT -1
211+
NOT_AN_INTERRUPT = -1,
212+
};
190213

191214
#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
215+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
216+
PA = 1,
217+
PB = 2,
218+
PC = 3,
219+
PD = 4,
220+
PE = 5,
221+
PF = 6,
222+
PG = 7,
223+
PH = 8,
224+
PJ = 10,
225+
PK = 11,
226+
PL = 12,
227+
};
203228
#endif
204229

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
230+
enum ARD_CHAR_ENUM_XWEZPiBoACuGnH{
231+
NOT_ON_TIMER = 0,
232+
TIMER0A = 1,
233+
TIMER0B = 2,
234+
TIMER1A = 3,
235+
TIMER1B = 4,
236+
TIMER1C = 5,
237+
TIMER2 = 6,
238+
TIMER2A = 7,
239+
TIMER2B = 8,
240+
241+
TIMER3A = 9,
242+
TIMER3B = 10,
243+
TIMER3C = 11,
244+
TIMER4A = 12,
245+
TIMER4B = 13,
246+
TIMER4C = 14,
247+
TIMER4D = 15,
248+
TIMER5A = 16,
249+
TIMER5B = 17,
250+
TIMER5C = 18,
251+
};
225252

226253
#ifdef __cplusplus
227254
} // extern "C"
@@ -255,6 +282,8 @@ long map(long, long, long, long, long);
255282

256283
#endif
257284

285+
#undef ARD_CHAR_ENUM_XWEZPiBoACuGnH
286+
258287
#include "pins_arduino.h"
259288

260289
#endif

0 commit comments

Comments
 (0)