|
| 1 | +#ifndef ArduinoLite_h |
| 2 | +#define ArduinoLite_h |
| 3 | + |
| 4 | +#include "driver/gpio.h" |
| 5 | +#include "esp_timer.h" |
| 6 | +#include "esp_log.h" |
| 7 | +#include "unistd.h" |
| 8 | +#include "WString.h" |
| 9 | + |
| 10 | +#ifdef __cplusplus |
| 11 | +#include <algorithm> |
| 12 | +#include <cmath> |
| 13 | +using std::abs; |
| 14 | +using std::cos; |
| 15 | +using std::sin; |
| 16 | +using std::tan; |
| 17 | +using std::max; |
| 18 | +using std::min; |
| 19 | +#endif |
| 20 | + |
| 21 | +typedef bool boolean; |
| 22 | +typedef uint8_t byte; |
| 23 | +typedef unsigned int word; |
| 24 | + |
| 25 | +#define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U) |
| 26 | + |
| 27 | +#define LSBFIRST 0 |
| 28 | +#define MSBFIRST 1 |
| 29 | + |
| 30 | +#define LOW 0x0 |
| 31 | +#define HIGH 0x1 |
| 32 | +#define INPUT GPIO_MODE_INPUT|(GPIO_FLOATING << 8) |
| 33 | +#define INPUT_PULLUP GPIO_MODE_INPUT|(GPIO_PULLUP_ONLY << 8) |
| 34 | +#define INPUT_PULLDOWN GPIO_MODE_INPUT|(GPIO_PULLDOWN_ONLY << 8) |
| 35 | +#define OUTPUT GPIO_MODE_OUTPUT|(GPIO_FLOATING << 8) |
| 36 | + |
| 37 | +#define pinMode(pin, mode) gpio_set_direction((gpio_num_t)(pin), (gpio_mode_t)((mode) & 0xFF)); \ |
| 38 | + gpio_set_pull_mode((gpio_num_t)(pin), (gpio_pull_mode_t)((mode) >> 8)) |
| 39 | +#define digitalWrite(pin, val) gpio_set_level((gpio_num_t)(pin), (uint32_t)(val)) |
| 40 | +#define digitalRead(pin) gpio_get_level((gpio_num_t)(pin)) |
| 41 | +#define digitalPinIsValid(pin) ((pin) < 40) |
| 42 | +#define digitalPinCanOutput(pin) ((pin) < 34) |
| 43 | +#define digitalPinToInterrupt(pin) (digitalPinIsValid(pin) ? (pin) : -1) |
| 44 | +#define digitalPinHasPWM(pin) (digitalPinCanOutput(pin)) |
| 45 | + |
| 46 | +#define analogWrite(pin, val) |
| 47 | +#define analogRead(pin) |
| 48 | + |
| 49 | +#define attachInterrupt(pin, cb, mode) |
| 50 | +#define attachInterruptArg(pin, cb, arg, mode) |
| 51 | +#define detachInterrupt(pin) |
| 52 | + |
| 53 | +#define micros() ((unsigned long)esp_timer_get_time()) |
| 54 | +#define millis() ((unsigned long)(esp_timer_get_time() / 1000ULL)) |
| 55 | +#define delay(ms) delayMicroseconds((ms) * 1000) |
| 56 | +#define delayMicroseconds(us) usleep(us) |
| 57 | +#define yield() vPortYield() |
| 58 | +#define NOP() asm volatile ("nop") |
| 59 | +#define PROGMEM |
| 60 | + |
| 61 | +#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) |
| 62 | +#define pgm_read_word(addr) ({ typeof(addr) _addr = (addr); *(const unsigned short *)(_addr); }) |
| 63 | +#define pgm_read_dword(addr) ({ typeof(addr) _addr = (addr); *(const unsigned long *)(_addr); }) |
| 64 | +#define pgm_read_float(addr) ({ typeof(addr) _addr = (addr); *(const float *)(_addr); }) |
| 65 | +#define pgm_read_ptr(addr) ({ typeof(addr) _addr = (addr); *(void * const *)(_addr); }) |
| 66 | + |
| 67 | +inline long map(long x, long in_min, long in_max, long out_min, long out_max) { |
| 68 | + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
| 69 | +} |
| 70 | + |
| 71 | +inline void interrupts() {} |
| 72 | +inline void noInterrupts() {} |
| 73 | + |
| 74 | +// To do: |
| 75 | +// pulseIn() |
| 76 | +// pulseInLong() |
| 77 | +// shiftIn() |
| 78 | +// shiftOut() |
| 79 | +// bit() |
| 80 | +// bitClear() |
| 81 | +// bitRead() |
| 82 | +// bitSet() |
| 83 | +// bitWrite() |
| 84 | +// highByte() |
| 85 | +// lowByte() |
| 86 | + |
| 87 | +#endif |
0 commit comments