Skip to content

Commit 29feaaa

Browse files
committed
add some missing Arduino defines
1 parent d7aed63 commit 29feaaa

File tree

4 files changed

+99
-53
lines changed

4 files changed

+99
-53
lines changed

cores/esp32/Arduino.h

+93-8
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
extern "C" {
2525
#endif
2626

27-
#include "freertos/FreeRTOS.h"
28-
#include "freertos/task.h"
29-
#include "freertos/semphr.h"
30-
#include "esp32-hal.h"
31-
#include "pins_arduino.h"
32-
3327
#include <stdbool.h>
3428
#include <stdint.h>
3529
#include <stdarg.h>
@@ -39,15 +33,104 @@ extern "C" {
3933
#include <string.h>
4034
#include <inttypes.h>
4135

42-
typedef bool boolean;
43-
typedef uint8_t byte;
36+
#include "freertos/FreeRTOS.h"
37+
#include "freertos/task.h"
38+
#include "freertos/semphr.h"
39+
#include "esp32-hal.h"
40+
#include "soc/gpio_reg.h"
4441

4542
#include "binary.h"
4643

44+
#define PI 3.1415926535897932384626433832795
45+
#define HALF_PI 1.5707963267948966192313216916398
46+
#define TWO_PI 6.283185307179586476925286766559
47+
#define DEG_TO_RAD 0.017453292519943295769236907684886
48+
#define RAD_TO_DEG 57.295779513082320876798154814105
49+
#define EULER 2.718281828459045235360287471352
50+
51+
#define SERIAL 0x0
52+
#define DISPLAY 0x1
53+
54+
#define LSBFIRST 0
55+
#define MSBFIRST 1
56+
57+
//Interrupt Modes
58+
#define RISING 0x01
59+
#define FALLING 0x02
60+
#define CHANGE 0x03
61+
#define ONLOW 0x04
62+
#define ONHIGH 0x05
63+
#define ONLOW_WE 0x0C
64+
#define ONHIGH_WE 0x0D
65+
66+
#define DEFAULT 1
67+
#define EXTERNAL 0
68+
69+
#ifndef __STRINGIFY
70+
#define __STRINGIFY(a) #a
71+
#endif
72+
73+
// undefine stdlib's abs if encountered
74+
#ifdef abs
75+
#undef abs
76+
#endif
77+
78+
#define abs(x) ((x)>0?(x):-(x))
79+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
80+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
81+
#define radians(deg) ((deg)*DEG_TO_RAD)
82+
#define degrees(rad) ((rad)*RAD_TO_DEG)
83+
#define sq(x) ((x)*(x))
84+
85+
#define sei()
86+
#define cli()
87+
#define interrupts() sei()
88+
#define noInterrupts() cli()
89+
90+
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
91+
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
92+
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
93+
94+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
95+
#define highByte(w) ((uint8_t) ((w) >> 8))
96+
97+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
98+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
99+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
100+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
101+
102+
#define bit(b) (1UL << (b))
103+
#define _BV(b) (1UL << (b))
104+
105+
#define digitalPinToPort(pin) (((pin)>31)?1:0)
106+
#define digitalPinToBitMask(pin) (1UL << (pin))
107+
#define digitalPinToTimer(pin) (0)
108+
#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))
109+
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
110+
#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG))
111+
112+
#define NOT_A_PIN -1
113+
#define NOT_A_PORT -1
114+
#define NOT_AN_INTERRUPT -1
115+
#define NOT_ON_TIMER 0
116+
117+
typedef bool boolean;
118+
typedef uint8_t byte;
119+
typedef unsigned int word;
120+
47121
#ifdef __cplusplus
48122
}
49123
#endif
50124

125+
#ifndef _GLIBCXX_VECTOR
126+
// arduino is not compatible with std::vector
127+
#define min(a,b) ((a)<(b)?(a):(b))
128+
#define max(a,b) ((a)>(b)?(a):(b))
129+
#endif
130+
131+
#define _min(a,b) ((a)<(b)?(a):(b))
132+
#define _max(a,b) ((a)>(b)?(a):(b))
133+
51134
#include "WCharacter.h"
52135
#include "WString.h"
53136
#include "Stream.h"
@@ -60,4 +143,6 @@ typedef uint8_t byte;
60143
#include "HardwareSerial.h"
61144
#include "Esp.h"
62145

146+
#include "pins_arduino.h"
147+
63148
#endif /* _ESP32_CORE_ARDUINO_H_ */

variants/esp32/pins_arduino.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
#ifndef Pins_Arduino_h
22
#define Pins_Arduino_h
33

4-
5-
#define digitalPinToPort(pin) (0)
6-
#define digitalPinToBitMask(pin) (1UL << (pin))
7-
#define digitalPinToTimer(pin) (0)
8-
#define portOutputRegister(port)
9-
#define portInputRegister(port)
10-
#define portModeRegister(port)
11-
12-
#define NOT_A_PIN -1
13-
#define NOT_A_PORT -1
14-
#define NOT_AN_INTERRUPT -1
15-
#define NOT_ON_TIMER 0
16-
174
#define EXTERNAL_NUM_INTERRUPTS 16
185
#define NUM_DIGITAL_PINS 40
196
#define NUM_ANALOG_INPUTS 18
207

218
#define analogInputToDigitalPin(p)
22-
#define digitalPinToInterrupt(p)
23-
#define digitalPinHasPWM(p)
9+
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
10+
#define digitalPinHasPWM(p) (p < 34)
2411

2512
static const uint8_t SDA = 21;
2613
static const uint8_t SCL = 22;

variants/esp320/pins_arduino.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
#ifndef Pins_Arduino_h
22
#define Pins_Arduino_h
33

4-
5-
#define digitalPinToPort(pin) (0)
6-
#define digitalPinToBitMask(pin) (1UL << (pin))
7-
#define digitalPinToTimer(pin) (0)
8-
#define portOutputRegister(port)
9-
#define portInputRegister(port)
10-
#define portModeRegister(port)
11-
12-
#define NOT_A_PIN -1
13-
#define NOT_A_PORT -1
14-
#define NOT_AN_INTERRUPT -1
15-
#define NOT_ON_TIMER 0
16-
174
#define EXTERNAL_NUM_INTERRUPTS 11
185
#define NUM_DIGITAL_PINS 12
196
#define NUM_ANALOG_INPUTS 5
207

218
#define analogInputToDigitalPin(p)
22-
#define digitalPinToInterrupt(p)
23-
#define digitalPinHasPWM(p)
9+
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
10+
#define digitalPinHasPWM(p) (p < 34)
2411

2512
static const uint8_t SDA = 2;
2613
static const uint8_t SCL = 14;

variants/nano32/pins_arduino.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
#ifndef Pins_Arduino_h
22
#define Pins_Arduino_h
33

4-
5-
#define digitalPinToPort(pin) (0)
6-
#define digitalPinToBitMask(pin) (1UL << (pin))
7-
#define digitalPinToTimer(pin) (0)
8-
#define portOutputRegister(port)
9-
#define portInputRegister(port)
10-
#define portModeRegister(port)
11-
12-
#define NOT_A_PIN -1
13-
#define NOT_A_PORT -1
14-
#define NOT_AN_INTERRUPT -1
15-
#define NOT_ON_TIMER 0
16-
174
#define EXTERNAL_NUM_INTERRUPTS 16
185
#define NUM_DIGITAL_PINS 38
196
#define NUM_ANALOG_INPUTS 18
207

218
#define analogInputToDigitalPin(p)
22-
#define digitalPinToInterrupt(p)
23-
#define digitalPinHasPWM(p)
9+
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
10+
#define digitalPinHasPWM(p) (p < 34)
2411

2512
#define LED_BUILTIN 16
2613

0 commit comments

Comments
 (0)