|
41 | 41 | #include "binary.h"
|
42 | 42 | #include "extra_attr.h"
|
43 | 43 |
|
44 |
| -#define PI 3.1415926535897932384626433832795 |
45 |
| -#define HALF_PI 1.5707963267948966192313216916398 |
46 |
| -#define TWO_PI 6.283185307179586476925286766559 |
| 44 | +#define PI 3.1415926535897932384626433832795 |
| 45 | +#define HALF_PI 1.5707963267948966192313216916398 |
| 46 | +#define TWO_PI 6.283185307179586476925286766559 |
47 | 47 | #define DEG_TO_RAD 0.017453292519943295769236907684886
|
48 | 48 | #define RAD_TO_DEG 57.295779513082320876798154814105
|
49 |
| -#define EULER 2.718281828459045235360287471352 |
| 49 | +#define EULER 2.718281828459045235360287471352 |
50 | 50 |
|
51 |
| -#define SERIAL 0x0 |
| 51 | +#define SERIAL 0x0 |
52 | 52 | #define DISPLAY 0x1
|
53 | 53 |
|
54 | 54 | #define LSBFIRST 0
|
55 | 55 | #define MSBFIRST 1
|
56 | 56 |
|
57 | 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 |
| 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 | 64 | #define ONHIGH_WE 0x0D
|
65 | 65 |
|
66 |
| -#define DEFAULT 1 |
| 66 | +#define DEFAULT 1 |
67 | 67 | #define EXTERNAL 0
|
68 | 68 |
|
69 | 69 | #ifndef __STRINGIFY
|
70 | 70 | #define __STRINGIFY(a) #a
|
71 | 71 | #endif
|
72 | 72 |
|
73 | 73 | // 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 |
| 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 | 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)) |
| 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)) |
82 | 82 |
|
83 | 83 | // ESP32xx runs FreeRTOS... disabling interrupts can lead to issues, such as Watchdog Timeout
|
84 |
| -#define sei() portENABLE_INTERRUPTS() |
85 |
| -#define cli() portDISABLE_INTERRUPTS() |
86 |
| -#define interrupts() sei() |
| 84 | +#define sei() portENABLE_INTERRUPTS() |
| 85 | +#define cli() portDISABLE_INTERRUPTS() |
| 86 | +#define interrupts() sei() |
87 | 87 | #define noInterrupts() cli()
|
88 | 88 |
|
89 |
| -#define clockCyclesPerMicrosecond() ((long int)getCpuFrequencyMhz()) |
| 89 | +#define clockCyclesPerMicrosecond() ((long int)getCpuFrequencyMhz()) |
90 | 90 | #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
|
91 |
| -#define microsecondsToClockCycles(a) ((a)*clockCyclesPerMicrosecond()) |
| 91 | +#define microsecondsToClockCycles(a) ((a) * clockCyclesPerMicrosecond()) |
92 | 92 |
|
93 |
| -#define lowByte(w) ((uint8_t)((w)&0xff)) |
| 93 | +#define lowByte(w) ((uint8_t)((w) & 0xff)) |
94 | 94 | #define highByte(w) ((uint8_t)((w) >> 8))
|
95 | 95 |
|
96 |
| -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
97 |
| -#define bitSet(value, bit) ((value) |= (1UL << (bit))) |
98 |
| -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
99 |
| -#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) |
| 96 | +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
| 97 | +#define bitSet(value, bit) ((value) |= (1UL << (bit))) |
| 98 | +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
| 99 | +#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) |
100 | 100 | #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
|
101 | 101 |
|
102 | 102 | // avr-libc defines _NOP() since 1.6.2
|
103 | 103 | #ifndef _NOP
|
104 |
| -#define _NOP() \ |
105 |
| - do { __asm__ volatile("nop"); } while (0) |
| 104 | +#define _NOP() \ |
| 105 | + do { \ |
| 106 | + __asm__ volatile("nop"); \ |
| 107 | + } while (0) |
106 | 108 | #endif
|
107 | 109 |
|
108 | 110 | #define bit(b) (1UL << (b))
|
109 | 111 | #define _BV(b) (1UL << (b))
|
110 | 112 |
|
111 | 113 | #define digitalPinToTimer(pin) (0)
|
112 |
| -#define analogInPinToBit(P) (P) |
| 114 | +#define analogInPinToBit(P) (P) |
113 | 115 | #if SOC_GPIO_PIN_COUNT <= 32
|
114 |
| -#define digitalPinToPort(pin) (0) |
| 116 | +#define digitalPinToPort(pin) (0) |
115 | 117 | #define digitalPinToBitMask(pin) (1UL << digitalPinToGPIONumber(pin))
|
116 |
| -#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG) |
117 |
| -#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG) |
118 |
| -#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG) |
| 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) |
119 | 121 | #elif SOC_GPIO_PIN_COUNT <= 64
|
120 |
| -#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin) > 31) ? 1 : 0) |
| 122 | +#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin) > 31) ? 1 : 0) |
121 | 123 | #define digitalPinToBitMask(pin) (1UL << (digitalPinToGPIONumber(pin) & 31))
|
122 |
| -#define portOutputRegister(port) ((volatile uint32_t*)((port) ? GPIO_OUT1_REG : GPIO_OUT_REG)) |
123 |
| -#define portInputRegister(port) ((volatile uint32_t*)((port) ? GPIO_IN1_REG : GPIO_IN_REG)) |
124 |
| -#define portModeRegister(port) ((volatile uint32_t*)((port) ? GPIO_ENABLE1_REG : GPIO_ENABLE_REG)) |
| 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)) |
125 | 127 | #else
|
126 | 128 | #error SOC_GPIO_PIN_COUNT > 64 not implemented
|
127 | 129 | #endif
|
128 | 130 |
|
129 |
| -#define NOT_A_PIN -1 |
130 |
| -#define NOT_A_PORT -1 |
| 131 | +#define NOT_A_PIN -1 |
| 132 | +#define NOT_A_PORT -1 |
131 | 133 | #define NOT_AN_INTERRUPT -1
|
132 |
| -#define NOT_ON_TIMER 0 |
| 134 | +#define NOT_ON_TIMER 0 |
133 | 135 |
|
134 | 136 | // some defines generic for all SoC moved from variants/board_name/pins_arduino.h
|
135 | 137 | #define NUM_DIGITAL_PINS SOC_GPIO_PIN_COUNT // All GPIOs
|
136 | 138 | #if SOC_ADC_PERIPH_NUM == 1
|
137 | 139 | #define NUM_ANALOG_INPUTS (SOC_ADC_CHANNEL_NUM(0)) // Depends on the SoC (ESP32C6, ESP32H2, ESP32C2, ESP32P4)
|
138 | 140 | #elif SOC_ADC_PERIPH_NUM == 2
|
139 |
| -#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 \ |
| 142 | + (SOC_ADC_CHANNEL_NUM(0) + SOC_ADC_CHANNEL_NUM(1)) // Depends on the SoC (ESP32, ESP32S2, ESP32S3, ESP32C3) |
140 | 143 | #endif
|
141 |
| -#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs |
| 144 | +#define EXTERNAL_NUM_INTERRUPTS NUM_DIGITAL_PINS // All GPIOs |
142 | 145 | #define analogInputToDigitalPin(p) (((p) < NUM_ANALOG_INPUTS) ? (analogChannelToDigitalPin(p)) : -1)
|
143 |
| -#define digitalPinToInterrupt(p) ((((uint8_t)digitalPinToGPIONumber(p)) < NUM_DIGITAL_PINS) ? digitalPinToGPIONumber(p) : NOT_AN_INTERRUPT) |
| 146 | +#define digitalPinToInterrupt(p) \ |
| 147 | + ((((uint8_t)digitalPinToGPIONumber(p)) < NUM_DIGITAL_PINS) ? digitalPinToGPIONumber(p) : NOT_AN_INTERRUPT) |
144 | 148 | #define digitalPinHasPWM(p) (((uint8_t)digitalPinToGPIONumber(p)) < NUM_DIGITAL_PINS)
|
145 | 149 |
|
146 | 150 | typedef bool boolean;
|
@@ -170,15 +174,15 @@ long map(long, long, long, long, long);
|
170 | 174 | extern "C" {
|
171 | 175 | #endif
|
172 | 176 |
|
173 |
| - void init(void); |
174 |
| - void initVariant(void); |
175 |
| - void initArduino(void); |
| 177 | +void init(void); |
| 178 | +void initVariant(void); |
| 179 | +void initArduino(void); |
176 | 180 |
|
177 |
| - unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); |
178 |
| - unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); |
| 181 | +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); |
| 182 | +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); |
179 | 183 |
|
180 |
| - uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); |
181 |
| - void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); |
| 184 | +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); |
| 185 | +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); |
182 | 186 |
|
183 | 187 | #ifdef __cplusplus
|
184 | 188 | }
|
@@ -212,29 +216,37 @@ uint16_t makeWord(uint8_t h, uint8_t l);
|
212 | 216 | #define word(...) makeWord(__VA_ARGS__)
|
213 | 217 |
|
214 | 218 | size_t getArduinoLoopTaskStackSize(void);
|
215 |
| -#define SET_LOOP_TASK_STACK_SIZE(sz) \ |
216 |
| - size_t getArduinoLoopTaskStackSize() { return sz; } |
| 219 | +#define SET_LOOP_TASK_STACK_SIZE(sz) \ |
| 220 | + size_t getArduinoLoopTaskStackSize() { \ |
| 221 | + return sz; \ |
| 222 | + } |
217 | 223 |
|
218 | 224 | bool shouldPrintChipDebugReport(void);
|
219 |
| -#define ENABLE_CHIP_DEBUG_REPORT \ |
220 |
| - bool shouldPrintChipDebugReport(void) { return true; } |
| 225 | +#define ENABLE_CHIP_DEBUG_REPORT \ |
| 226 | + bool shouldPrintChipDebugReport(void) { \ |
| 227 | + return true; \ |
| 228 | + } |
221 | 229 |
|
222 | 230 | // allows user to bypass esp_spiram_test()
|
223 | 231 | bool esp_psram_extram_test(void);
|
224 |
| -#define BYPASS_SPIRAM_TEST(bypass) \ |
225 |
| - bool testSPIRAM(void) { \ |
226 |
| - if (bypass) return true; \ |
227 |
| - else return esp_psram_extram_test(); \ |
| 232 | +#define BYPASS_SPIRAM_TEST(bypass) \ |
| 233 | + bool testSPIRAM(void) { \ |
| 234 | + if (bypass) \ |
| 235 | + return true; \ |
| 236 | + else \ |
| 237 | + return esp_psram_extram_test(); \ |
228 | 238 | }
|
229 | 239 |
|
230 | 240 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
231 | 241 | unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
232 | 242 |
|
233 |
| -extern "C" bool getLocalTime(struct tm* info, uint32_t ms = 5000); |
234 |
| -extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, |
235 |
| - const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); |
236 |
| -extern "C" void configTzTime(const char* tz, |
237 |
| - const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); |
| 243 | +extern "C" bool getLocalTime(struct tm *info, uint32_t ms = 5000); |
| 244 | +extern "C" void configTime( |
| 245 | + long gmtOffset_sec, int daylightOffset_sec, const char *server1, const char *server2 = nullptr, |
| 246 | + const char *server3 = nullptr |
| 247 | +); |
| 248 | +extern "C" void |
| 249 | + configTzTime(const char *tz, const char *server1, const char *server2 = nullptr, const char *server3 = nullptr); |
238 | 250 |
|
239 | 251 | void setToneChannel(uint8_t channel = 0);
|
240 | 252 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
|
0 commit comments