Skip to content

Instantly share code, notes, and snippets.

@gustavosinbandera1
Created December 2, 2019 22:11
Show Gist options
  • Save gustavosinbandera1/d4e49300f235ff2d82572f2173b1a5ea to your computer and use it in GitHub Desktop.
Save gustavosinbandera1/d4e49300f235ff2d82572f2173b1a5ea to your computer and use it in GitHub Desktop.
/*
* GPIO.h
*
* Created on: Feb 28, 2017
* Author: kolban
*/
#ifndef GPIO_H
#define GPIO_H
#include <driver/gpio.h>
namespace hardware {
/**
* @brief Interface to %GPIO functions.
*
* The %GPIO functions encapsulate the %GPIO access. The GPIOs available to us are
* 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,25,26,27,32,33,34,35,36,37,38,39.
*
* The GPIOs of 34,35,36,37,38 and 39 are input only.
*
* Note that we must not use `int` values for the pin numbers but instead use the `gpio_num_t`. There
* are constants defined for these of the form `GPIO_NUM_xx`.
*
* To toggle a pin we might code:
*
* @code{.cpp}
* ESP32CPP::GPIO::setOutput(pin);
* ESP32CPP::GPIO::high(pin);
* ESP32CPP::GPIO::low(pin);
* @endcode
*/
class GPIO {
public:
static void addISRHandler(gpio_num_t pin, gpio_isr_t handler, void* pArgs);
static void high(gpio_num_t pin);
static void interruptDisable(gpio_num_t pin);
static void interruptEnable(gpio_num_t pin);
static bool inRange(gpio_num_t pin);
static void low(gpio_num_t pin);
static bool read(gpio_num_t pin);
static void setInput(gpio_num_t pin);
static void setInterruptType(gpio_num_t pin, gpio_int_type_t intrType);
static void setOutput(gpio_num_t pin);
static void write(gpio_num_t pin, bool value);
static void writeByte(gpio_num_t pins[], uint8_t value, int bits);
}; // End GPIO
} // End ESP32CPP namespace
#endif /* COMPONENTS_CPP_UTILS_GPIO_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment