esp32-hal-gpio.h
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 MAIN_ESP32_HAL_GPIO_H_ 21 #define MAIN_ESP32_HAL_GPIO_H_ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 28 #define LOW 0x0 29 #define HIGH 0x1 30 31 //GPIO FUNCTIONS 32 #define INPUT 0x01 33 #define OUTPUT 0x02 34 #define PULLUP 0x04 35 #define INPUT_PULLUP 0x05 36 #define PULLDOWN 0x08 37 #define INPUT_PULLDOWN 0x09 38 #define OPEN_DRAIN 0x10 39 #define OUTPUT_OPEN_DRAIN 0x12 40 #define SPECIAL 0xF0 41 #define FUNCTION_1 0x00 42 #define FUNCTION_2 0x20 43 #define FUNCTION_3 0x40 44 #define FUNCTION_4 0x60 45 #define FUNCTION_5 0x80 46 #define FUNCTION_6 0xA0 47 #define ANALOG 0xC0 48 49 //Interrupt Modes 50 #define DISABLED 0x00 51 #define RISING 0x01 52 #define FALLING 0x02 53 #define CHANGE 0x03 54 #define ONLOW 0x04 55 #define ONHIGH 0x05 56 #define ONLOW_WE 0x0C 57 #define ONHIGH_WE 0x0D 58 59 typedef struct { 60 uint8_t reg; /*!< GPIO register offset from DR_REG_IO_MUX_BASE */ 61 int8_t rtc; /*!< RTC GPIO number (-1 if not RTC GPIO pin) */ 62 int8_t adc; /*!< ADC Channel number (-1 if not ADC pin) */ 63 int8_t touch; /*!< Touch Channel number (-1 if not Touch pin) */ 64 } esp32_gpioMux_t; 65 66 extern const esp32_gpioMux_t esp32_gpioMux[40]; 67 extern const int8_t esp32_adc2gpio[20]; 68 69 #define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg) 70 #define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg) 71 #define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1) 72 #define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1) 73 #define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1) 74 #define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1) 75 76 void pinMode(uint8_t pin, uint8_t mode); 77 void digitalWrite(uint8_t pin, uint8_t val); 78 int digitalRead(uint8_t pin); 79 80 void attachInterrupt(uint8_t pin, void (*)(void), int mode); 81 void attachInterruptArg(uint8_t pin, void (*)(void*), void * arg, int mode); 82 void detachInterrupt(uint8_t pin); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif /* MAIN_ESP32_HAL_GPIO_H_ */