38
38
#include " soc/gpio_reg.h"
39
39
40
40
#include " stdlib_noniso.h"
41
- #include " binary.h"
42
41
#include " extra_attr.h"
43
42
44
43
#define PI 3.1415926535897932384626433832795
48
47
#define RAD_TO_DEG 57.295779513082320876798154814105
49
48
#define EULER 2.718281828459045235360287471352
50
49
51
- #define SERIAL 0x0
50
+ #define SERIAL 0x0
52
51
#define DISPLAY 0x1
53
52
54
53
#define LSBFIRST 0
55
54
#define MSBFIRST 1
56
55
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
56
+ // Interrupt Modes
57
+ #define RISING 0x01
58
+ #define FALLING 0x02
59
+ #define CHANGE 0x03
60
+ #define ONLOW 0x04
61
+ #define ONHIGH 0x05
62
+ #define ONLOW_WE 0x0C
64
63
#define ONHIGH_WE 0x0D
65
64
66
65
#define DEFAULT 1
71
70
#endif
72
71
73
72
// can't define max() / min() because of conflicts with C++
74
- #define _min (a,b ) ((a)< (b)? (a): (b))
75
- #define _max (a,b ) ((a)> (b)? (a): (b))
76
- #define _abs (x ) ((x)> 0 ? (x): -(x)) // abs() comes from STL
77
- #define constrain (amt,low,high ) ((amt)< (low)? (low): ((amt)> (high)? (high): (amt)))
78
- #define _round (x ) ((x)>= 0 ? (long )((x)+ 0.5 ): (long )((x)- 0.5 )) // round() comes from STL
79
- #define radians (deg ) ((deg)* DEG_TO_RAD)
80
- #define degrees (rad ) ((rad)* RAD_TO_DEG)
81
- #define sq (x ) ((x)* (x))
73
+ #define _min (a, b ) ((a) < (b) ? (a) : (b))
74
+ #define _max (a, b ) ((a) > (b) ? (a) : (b))
75
+ #define _abs (x ) ((x) > 0 ? (x) : -(x)) // abs() comes from STL
76
+ #define constrain (amt, low, high ) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
77
+ #define _round (x ) ((x) >= 0 ? (long )((x) + 0.5 ) : (long )((x) - 0.5 )) // round() comes from STL
78
+ #define radians (deg ) ((deg) * DEG_TO_RAD)
79
+ #define degrees (rad ) ((rad) * RAD_TO_DEG)
80
+ #define sq (x ) ((x) * (x))
82
81
83
82
// ESP32xx runs FreeRTOS... disabling interrupts can lead to issues, such as Watchdog Timeout
84
83
#define sei () portENABLE_INTERRUPTS()
85
84
#define cli () portDISABLE_INTERRUPTS()
86
85
#define interrupts () sei()
87
86
#define noInterrupts () cli()
88
87
89
- #define clockCyclesPerMicrosecond () ( (long int )getCpuFrequencyMhz() )
90
- #define clockCyclesToMicroseconds (a ) ( (a) / clockCyclesPerMicrosecond() )
91
- #define microsecondsToClockCycles (a ) ( (a) * clockCyclesPerMicrosecond () )
88
+ #define clockCyclesPerMicrosecond () ((long int )getCpuFrequencyMhz())
89
+ #define clockCyclesToMicroseconds (a ) ((a) / clockCyclesPerMicrosecond())
90
+ #define microsecondsToClockCycles (a ) ((a) * clockCyclesPerMicrosecond ())
92
91
93
- #define lowByte (w ) ((uint8_t ) ((w) & 0xff ))
94
- #define highByte (w ) ((uint8_t ) ((w) >> 8 ))
92
+ #define lowByte (w ) ((uint8_t )((w) & 0xff ))
93
+ #define highByte (w ) ((uint8_t )((w) >> 8 ))
95
94
96
95
#define bitRead (value, bit ) (((value) >> (bit)) & 0x01 )
97
96
#define bitSet (value, bit ) ((value) |= (1UL << (bit)))
101
100
102
101
// avr-libc defines _NOP() since 1.6.2
103
102
#ifndef _NOP
104
- #define _NOP () do { __asm__ volatile (" nop" ); } while (0 )
103
+ #define _NOP () \
104
+ do \
105
+ { \
106
+ __asm__ volatile (" nop" ); \
107
+ } while (0 )
105
108
#endif
106
109
107
110
#define bit (b ) (1UL << (b))
108
111
#define _BV (b ) (1UL << (b))
109
112
110
- #define digitalPinToTimer (pin ) (0 )
111
- #define analogInPinToBit (P ) (P)
113
+ #define digitalPinToTimer (pin ) (0 )
114
+ #define analogInPinToBit (P ) (P)
112
115
#if SOC_GPIO_PIN_COUNT <= 32
113
- #define digitalPinToPort (pin ) (0 )
114
- #define digitalPinToBitMask (pin ) (1UL << digitalPinToGPIONumber(pin))
115
- #define portOutputRegister (port ) ((volatile uint32_t *)GPIO_OUT_REG)
116
- #define portInputRegister (port ) ((volatile uint32_t *)GPIO_IN_REG)
117
- #define portModeRegister (port ) ((volatile uint32_t *)GPIO_ENABLE_REG)
116
+ #define digitalPinToPort (pin ) (0 )
117
+ #define digitalPinToBitMask (pin ) (1UL << digitalPinToGPIONumber(pin))
118
+ #define portOutputRegister (port ) ((volatile uint32_t *)GPIO_OUT_REG)
119
+ #define portInputRegister (port ) ((volatile uint32_t *)GPIO_IN_REG)
120
+ #define portModeRegister (port ) ((volatile uint32_t *)GPIO_ENABLE_REG)
118
121
#elif SOC_GPIO_PIN_COUNT <= 64
119
- #define digitalPinToPort (pin ) ((digitalPinToGPIONumber(pin)> 31 )? 1 : 0 )
120
- #define digitalPinToBitMask (pin ) (1UL << (digitalPinToGPIONumber(pin)& 31 ))
121
- #define portOutputRegister (port ) ((volatile uint32_t *)((port)? GPIO_OUT1_REG: GPIO_OUT_REG))
122
- #define portInputRegister (port ) ((volatile uint32_t *)((port)? GPIO_IN1_REG: GPIO_IN_REG))
123
- #define portModeRegister (port ) ((volatile uint32_t *)((port)? GPIO_ENABLE1_REG: GPIO_ENABLE_REG))
122
+ #define digitalPinToPort (pin ) ((digitalPinToGPIONumber(pin) > 31 ) ? 1 : 0 )
123
+ #define digitalPinToBitMask (pin ) (1UL << (digitalPinToGPIONumber(pin) & 31 ))
124
+ #define portOutputRegister (port ) ((volatile uint32_t *)((port) ? GPIO_OUT1_REG : GPIO_OUT_REG))
125
+ #define portInputRegister (port ) ((volatile uint32_t *)((port) ? GPIO_IN1_REG : GPIO_IN_REG))
126
+ #define portModeRegister (port ) ((volatile uint32_t *)((port) ? GPIO_ENABLE1_REG : GPIO_ENABLE_REG))
124
127
#else
125
128
#error SOC_GPIO_PIN_COUNT > 64 not implemented
126
129
#endif
131
134
#define NOT_ON_TIMER 0
132
135
133
136
// some defines generic for all SoC moved from variants/board_name/pins_arduino.h
134
- #define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // All GPIOs
137
+ #define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // All GPIOs
135
138
#if SOC_ADC_PERIPH_NUM == 1
136
- #define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0 )) // Depends on the SoC (ESP32C6, ESP32H2, ESP32C2, ESP32P4)
139
+ #define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0 )) // Depends on the SoC (ESP32C6, ESP32H2, ESP32C2, ESP32P4)
137
140
#elif SOC_ADC_PERIPH_NUM == 2
138
- #define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0 )+ SOC_ADC_CHANNEL_NUM(1 )) // Depends on the SoC (ESP32, ESP32S2, ESP32S3, ESP32C3)
141
+ #define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0 ) + SOC_ADC_CHANNEL_NUM(1 )) // Depends on the SoC (ESP32, ESP32S2, ESP32S3, ESP32C3)
139
142
#endif
140
- #define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs
141
- #define analogInputToDigitalPin (p ) (((p)< NUM_ANALOG_INPUTS)? (analogChannelToDigitalPin(p)): -1 )
142
- #define digitalPinToInterrupt (p ) ((((uint8_t )digitalPinToGPIONumber(p))< NUM_DIGITAL_PINS)? digitalPinToGPIONumber(p): NOT_AN_INTERRUPT)
143
- #define digitalPinHasPWM (p ) (((uint8_t )digitalPinToGPIONumber(p))< NUM_DIGITAL_PINS)
143
+ #define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs
144
+ #define analogInputToDigitalPin (p ) (((p) < NUM_ANALOG_INPUTS) ? (analogChannelToDigitalPin(p)) : -1 )
145
+ #define digitalPinToInterrupt (p ) ((((uint8_t )digitalPinToGPIONumber(p)) < NUM_DIGITAL_PINS) ? digitalPinToGPIONumber(p) : NOT_AN_INTERRUPT)
146
+ #define digitalPinHasPWM (p ) (((uint8_t )digitalPinToGPIONumber(p)) < NUM_DIGITAL_PINS)
144
147
145
148
typedef bool boolean;
146
149
typedef uint8_t byte;
@@ -150,7 +153,7 @@ typedef unsigned int word;
150
153
void setup (void );
151
154
void loop (void );
152
155
153
- // The default is using Real Hardware random number generator
156
+ // The default is using Real Hardware random number generator
154
157
// But when randomSeed() is called, it turns to Psedo random
155
158
// generator, exactly as done in Arduino mainstream
156
159
long random (long );
@@ -166,18 +169,19 @@ void useRealRandomGenerator(bool useRandomHW);
166
169
long map (long , long , long , long , long );
167
170
168
171
#ifdef __cplusplus
169
- extern " C" {
172
+ extern " C"
173
+ {
170
174
#endif
171
175
172
- void init (void );
173
- void initVariant (void );
174
- void initArduino (void );
176
+ void init (void );
177
+ void initVariant (void );
178
+ void initArduino (void );
175
179
176
- unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout);
177
- unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout);
180
+ unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout);
181
+ unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout);
178
182
179
- uint8_t shiftIn (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
180
- void shiftOut (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
183
+ uint8_t shiftIn (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
184
+ void shiftOut (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
181
185
182
186
#ifdef __cplusplus
183
187
}
@@ -211,23 +215,32 @@ uint16_t makeWord(uint8_t h, uint8_t l);
211
215
#define word (...) makeWord(__VA_ARGS__)
212
216
213
217
size_t getArduinoLoopTaskStackSize (void );
214
- #define SET_LOOP_TASK_STACK_SIZE (sz ) size_t getArduinoLoopTaskStackSize () { return sz;}
218
+ #define SET_LOOP_TASK_STACK_SIZE (sz ) \
219
+ size_t getArduinoLoopTaskStackSize () { return sz; }
215
220
216
221
bool shouldPrintChipDebugReport (void );
217
- #define ENABLE_CHIP_DEBUG_REPORT bool shouldPrintChipDebugReport (void ){return true ;}
222
+ #define ENABLE_CHIP_DEBUG_REPORT \
223
+ bool shouldPrintChipDebugReport (void ) { return true ; }
218
224
219
225
// allows user to bypass esp_spiram_test()
220
226
bool esp_psram_extram_test (void );
221
- #define BYPASS_SPIRAM_TEST (bypass ) bool testSPIRAM (void ) { if (bypass) return true ; else return esp_psram_extram_test (); }
227
+ #define BYPASS_SPIRAM_TEST (bypass ) \
228
+ bool testSPIRAM (void ) \
229
+ { \
230
+ if (bypass) \
231
+ return true ; \
232
+ else \
233
+ return esp_psram_extram_test (); \
234
+ }
222
235
223
236
unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout = 1000000L );
224
237
unsigned long pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout = 1000000L );
225
238
226
- extern " C" bool getLocalTime (struct tm * info, uint32_t ms = 5000 );
239
+ extern " C" bool getLocalTime (struct tm *info, uint32_t ms = 5000 );
227
240
extern " C" void configTime (long gmtOffset_sec, int daylightOffset_sec,
228
- const char * server1, const char * server2 = nullptr , const char * server3 = nullptr );
229
- extern " C" void configTzTime (const char * tz,
230
- const char * server1, const char * server2 = nullptr , const char * server3 = nullptr );
241
+ const char * server1, const char * server2 = nullptr , const char * server3 = nullptr );
242
+ extern " C" void configTzTime (const char * tz,
243
+ const char * server1, const char * server2 = nullptr , const char * server3 = nullptr );
231
244
232
245
void setToneChannel (uint8_t channel = 0 );
233
246
void tone (uint8_t _pin, unsigned int frequency, unsigned long duration = 0 );
0 commit comments