|
| 1 | +/* |
| 2 | + Arduino.h - Main include file for the Arduino SDK |
| 3 | + Copyright (c) 2005-2013 Arduino Team. All right reserved. |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef Arduino_h |
| 21 | +#define Arduino_h |
| 22 | + |
| 23 | +#include <stdbool.h> |
| 24 | +#include <stdint.h> |
| 25 | +#include <stdarg.h> |
| 26 | +#include <stddef.h> |
| 27 | +#include <stdio.h> |
| 28 | +#include <stdlib.h> |
| 29 | +#include <string.h> |
| 30 | +#include <inttypes.h> |
| 31 | + |
| 32 | +//--//#include "esp_arduino_version.h" |
| 33 | +#include "freertos/FreeRTOS.h" |
| 34 | +#include "freertos/task.h" |
| 35 | +#include "freertos/semphr.h" |
| 36 | +#include "driver/gpio.h" |
| 37 | +//--//#include "esp32-hal.h" |
| 38 | +//--//#include "esp8266-compat.h" |
| 39 | +//--//#include "soc/gpio_reg.h" |
| 40 | + |
| 41 | +#include "stdlib_noniso.h" |
| 42 | +//--//#include "binary.h" |
| 43 | + |
| 44 | +#include "esp_log.h" |
| 45 | + |
| 46 | +#define log_w(...) ESP_LOGW("Arduino", ##__VA_ARGS__) |
| 47 | +#define log_e(...) ESP_LOGE("Arduino", ##__VA_ARGS__) |
| 48 | + |
| 49 | +#include "esp_timer.h" |
| 50 | + |
| 51 | +#define millis() (esp_timer_get_time() / 1000ULL) |
| 52 | +#define micros64() (esp_timer_get_time()) |
| 53 | +#define micros() ((unsigned long)(esp_timer_get_time())) |
| 54 | + |
| 55 | +#define PI 3.1415926535897932384626433832795 |
| 56 | +#define HALF_PI 1.5707963267948966192313216916398 |
| 57 | +#define TWO_PI 6.283185307179586476925286766559 |
| 58 | +#define DEG_TO_RAD 0.017453292519943295769236907684886 |
| 59 | +#define RAD_TO_DEG 57.295779513082320876798154814105 |
| 60 | +#define EULER 2.718281828459045235360287471352 |
| 61 | + |
| 62 | +//--//#define SERIAL 0x0 |
| 63 | +//--//#define DISPLAY 0x1 |
| 64 | + |
| 65 | +//--//#define LSBFIRST 0 |
| 66 | +//--//#define MSBFIRST 1 |
| 67 | + |
| 68 | +//Interrupt Modes |
| 69 | +#define RISING 0x01 |
| 70 | +#define FALLING 0x02 |
| 71 | +#define CHANGE 0x03 |
| 72 | +#define ONLOW 0x04 |
| 73 | +#define ONHIGH 0x05 |
| 74 | +#define ONLOW_WE 0x0C |
| 75 | +#define ONHIGH_WE 0x0D |
| 76 | + |
| 77 | +//--//#define DEFAULT 1 |
| 78 | +//--//#define EXTERNAL 0 |
| 79 | + |
| 80 | +#ifndef __STRINGIFY |
| 81 | +//--//#define __STRINGIFY(a) #a |
| 82 | +#endif |
| 83 | + |
| 84 | +// can't define max() / min() because of conflicts with C++ |
| 85 | +//--//#define _min(a,b) ((a)<(b)?(a):(b)) |
| 86 | +//--//#define _max(a,b) ((a)>(b)?(a):(b)) |
| 87 | +//--//#define _abs(x) ((x)>0?(x):-(x)) // abs() comes from STL |
| 88 | +//--//#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) |
| 89 | +//--//#define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) // round() comes from STL |
| 90 | +//--//#define radians(deg) ((deg)*DEG_TO_RAD) |
| 91 | +//--//#define degrees(rad) ((rad)*RAD_TO_DEG) |
| 92 | +//--//#define sq(x) ((x)*(x)) |
| 93 | + |
| 94 | +// ESP32xx runs FreeRTOS... disabling interrupts can lead to issues, such as Watchdog Timeout |
| 95 | +//--//#define sei() portENABLE_INTERRUPTS() |
| 96 | +//--//#define cli() portDISABLE_INTERRUPTS() |
| 97 | +//--//#define interrupts() sei() |
| 98 | +//--//#define noInterrupts() cli() |
| 99 | + |
| 100 | +//--//#define clockCyclesPerMicrosecond() ( (long int)getCpuFrequencyMhz() ) |
| 101 | +//--//#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) |
| 102 | +//--//#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) |
| 103 | + |
| 104 | +//--//#define lowByte(w) ((uint8_t) ((w) & 0xff)) |
| 105 | +//--//#define highByte(w) ((uint8_t) ((w) >> 8)) |
| 106 | + |
| 107 | +//--//#define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
| 108 | +//--//#define bitSet(value, bit) ((value) |= (1UL << (bit))) |
| 109 | +//--//#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
| 110 | +//--//#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) |
| 111 | +//--//#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) |
| 112 | + |
| 113 | +// avr-libc defines _NOP() since 1.6.2 |
| 114 | +#ifndef _NOP |
| 115 | +//--//#define _NOP() do { __asm__ volatile ("nop"); } while (0) |
| 116 | +#endif |
| 117 | + |
| 118 | +//--//#define bit(b) (1UL << (b)) |
| 119 | +//--//#define _BV(b) (1UL << (b)) |
| 120 | + |
| 121 | +//--//#define digitalPinToTimer(pin) (0) |
| 122 | +//--//#define analogInPinToBit(P) (P) |
| 123 | +#if SOC_GPIO_PIN_COUNT <= 32 |
| 124 | +//--//#define digitalPinToPort(pin) (0) |
| 125 | +//--//#define digitalPinToBitMask(pin) (1UL << digitalPinToGPIONumber(pin)) |
| 126 | +//--//#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG) |
| 127 | +//--//#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG) |
| 128 | +//--//#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG) |
| 129 | +#elif SOC_GPIO_PIN_COUNT <= 64 |
| 130 | +//--//#define digitalPinToPort(pin) ((digitalPinToGPIONumber(pin)>31)?1:0) |
| 131 | +//--//#define digitalPinToBitMask(pin) (1UL << (digitalPinToGPIONumber(pin)&31)) |
| 132 | +//--//#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG)) |
| 133 | +//--//#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG)) |
| 134 | +//--//#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG)) |
| 135 | +#else |
| 136 | +//--//#error SOC_GPIO_PIN_COUNT > 64 not implemented |
| 137 | +#endif |
| 138 | + |
| 139 | +//--//#define NOT_A_PIN -1 |
| 140 | +//--//#define NOT_A_PORT -1 |
| 141 | +//--//#define NOT_AN_INTERRUPT -1 |
| 142 | +//--//#define NOT_ON_TIMER 0 |
| 143 | + |
| 144 | +typedef bool boolean; |
| 145 | +typedef uint8_t byte; |
| 146 | +typedef unsigned int word; |
| 147 | + |
| 148 | +#ifdef __cplusplus |
| 149 | +void setup(void); |
| 150 | +void loop(void); |
| 151 | + |
| 152 | +class dummySerial{ |
| 153 | +public: |
| 154 | + virtual void println(const char *); |
| 155 | +}; |
| 156 | + |
| 157 | +extern dummySerial dSerial; |
| 158 | + |
| 159 | +#define Serial dSerial |
| 160 | + |
| 161 | +// The default is using Real Hardware random number generator |
| 162 | +// But when randomSeed() is called, it turns to Psedo random |
| 163 | +// generator, exactly as done in Arduino mainstream |
| 164 | +long random(long); |
| 165 | +long random(long, long); |
| 166 | +// Calling randomSeed() will make random() |
| 167 | +// using pseudo random like in Arduino |
| 168 | +void randomSeed(unsigned long); |
| 169 | +// Allow the Application to decide if the random generator |
| 170 | +// will use Real Hardware random generation (true - default) |
| 171 | +// or Pseudo random generation (false) as in Arduino MainStream |
| 172 | +void useRealRandomGenerator(bool useRandomHW); |
| 173 | +#endif |
| 174 | +long map(long, long, long, long, long); |
| 175 | + |
| 176 | +#ifdef __cplusplus |
| 177 | +extern "C" { |
| 178 | +#endif |
| 179 | + |
| 180 | +//--//void init(void); |
| 181 | +//--//void initVariant(void); |
| 182 | +//--//void initArduino(void); |
| 183 | + |
| 184 | +//--//unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); |
| 185 | +//--//unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); |
| 186 | + |
| 187 | +//--//uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); |
| 188 | +//--//void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); |
| 189 | + |
| 190 | +#ifdef __cplusplus |
| 191 | +} |
| 192 | + |
| 193 | +#include <algorithm> |
| 194 | +#include <cmath> |
| 195 | + |
| 196 | +//--//#include "WCharacter.h" |
| 197 | +#include "WString.h" |
| 198 | +#include "Stream.h" |
| 199 | +#include "StreamString.h" |
| 200 | +#include "Printable.h" |
| 201 | +#include "Print.h" |
| 202 | +//--//#include "IPAddress.h" |
| 203 | +//--//#include "Client.h" |
| 204 | +//--//#include "Server.h" |
| 205 | +//--//#include "Udp.h" |
| 206 | +//--//#include "HardwareSerial.h" |
| 207 | +//--//#include "Esp.h" |
| 208 | +//--//#include "esp32/spiram.h" |
| 209 | + |
| 210 | +// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries |
| 211 | +using std::abs; |
| 212 | +using std::isinf; |
| 213 | +using std::isnan; |
| 214 | +using std::max; |
| 215 | +using std::min; |
| 216 | +using std::round; |
| 217 | + |
| 218 | +//--//uint16_t makeWord(uint16_t w); |
| 219 | +//--//uint16_t makeWord(uint8_t h, uint8_t l); |
| 220 | + |
| 221 | +//--//#define word(...) makeWord(__VA_ARGS__) |
| 222 | + |
| 223 | +//--//size_t getArduinoLoopTaskStackSize(void); |
| 224 | +//--//#define SET_LOOP_TASK_STACK_SIZE(sz) size_t getArduinoLoopTaskStackSize() { return sz;} |
| 225 | + |
| 226 | +// allows user to bypass esp_spiram_test() |
| 227 | +//--//#define BYPASS_SPIRAM_TEST(bypass) bool testSPIRAM(void) { if (bypass) return true; else return esp_spiram_test(); } |
| 228 | + |
| 229 | +//--//unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); |
| 230 | +//--//unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); |
| 231 | + |
| 232 | +//--//extern "C" bool getLocalTime(struct tm * info, uint32_t ms = 5000); |
| 233 | +//--//extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, |
| 234 | +//--// const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); |
| 235 | +//--//extern "C" void configTzTime(const char* tz, |
| 236 | +//--// const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); |
| 237 | + |
| 238 | +//--//void setToneChannel(uint8_t channel = 0); |
| 239 | +//--//void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); |
| 240 | +//--//void noTone(uint8_t _pin); |
| 241 | + |
| 242 | +#endif /* __cplusplus */ |
| 243 | + |
| 244 | +//--//#include "pins_arduino.h" |
| 245 | +//--//#include "io_pin_remap.h" |
| 246 | + |
| 247 | +#endif /* _ESP32_CORE_ARDUINO_H_ */ |
0 commit comments