dunno, changes and stuff
This commit is contained in:
82
io/GPIO.h
82
io/GPIO.h
@@ -6,6 +6,8 @@
|
||||
|
||||
#if IS_ESP8266
|
||||
|
||||
|
||||
/*
|
||||
#include "fastGPIO.h"
|
||||
|
||||
struct MyGPIO {
|
||||
@@ -93,6 +95,86 @@
|
||||
}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "esp8266/gpio_struct.h"
|
||||
|
||||
struct MyGPIO {
|
||||
|
||||
static inline bool get(const uint8_t num) {
|
||||
return get((gpio_num_t)num);
|
||||
}
|
||||
static inline bool get(const gpio_num_t num) {
|
||||
return gpio_get_level(num); // TODO faster access like READ_PERI_REG??
|
||||
}
|
||||
|
||||
template <typename T> static inline void setOrClear(const uint8_t num, const T val) {
|
||||
if (val) {set(num);} else {clear(num);}
|
||||
//WRITE_PERI_REG(GPIO_OUT_W1TS_REG, (val != 0) << num); // branchless but usually slower
|
||||
//WRITE_PERI_REG(GPIO_OUT_W1TC_REG, (val == 0) << num);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void set(const uint8_t num) {
|
||||
//gpio_set_level((gpio_num_t)num, 1); // TODO: faster
|
||||
GPIO.out_w1ts |= (0x1 << num);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void clear(const uint8_t num) {
|
||||
//gpio_set_level((gpio_num_t)num, 0); // TODO: faster
|
||||
GPIO.out_w1tc |= (0x1 << num);
|
||||
}
|
||||
|
||||
static inline void setOutput(const uint8_t num) {
|
||||
setOutput((gpio_num_t)num);
|
||||
}
|
||||
static inline void setOutput(const gpio_num_t num) {
|
||||
//gpio_set_direction(num, GPIO_MODE_OUTPUT); // does not always suffice?!
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static inline void setInput(const uint8_t num) {
|
||||
setInput((gpio_num_t)num);
|
||||
}
|
||||
static inline void setInput(const gpio_num_t num) {
|
||||
//gpio_set_direction(num, GPIO_MODE_INPUT); // does not always suffice?!
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static inline void setInputPullUp(const uint8_t num) {
|
||||
setInputPullUp((gpio_num_t)num);
|
||||
}
|
||||
static inline void setInputPullUp(const gpio_num_t num) {
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE; // here
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static void toggleBuiltInLED() {
|
||||
static bool level = false;
|
||||
setOutput(GPIO_NUM_2);
|
||||
level = !level;
|
||||
if (level) {set(GPIO_NUM_2);} else {clear(GPIO_NUM_2);}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#elif IS_ESP32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user