This commit is contained in:
2020-06-11 11:25:19 +02:00
parent 5cb02880b3
commit 5177cd5cbd
15 changed files with 1090 additions and 411 deletions

View File

@@ -8,7 +8,7 @@
#include "fastGPIO.h"
struct GPIO {
struct MyGPIO {
static inline bool get(const uint8_t num) {
return GPIO_INPUT_GET(num);
@@ -64,6 +64,34 @@
}
}
static inline void setPullUp(const uint8_t num) {
switch(num) {
case 0: GPIO0_INPUT_PULLUP_SET; break;
case 1: GPIO1_INPUT_PULLUP_SET; break;
case 2: GPIO2_INPUT_PULLUP_SET; break;
case 3: GPIO3_INPUT_PULLUP_SET; break;
case 4: GPIO4_INPUT_PULLUP_SET; break;
case 5: GPIO5_INPUT_PULLUP_SET; break;
//case 6: GPIO6_INPUT_PULLUP_SET; break;
//case 7: GPIO7_INPUT_PULLUP_SET; break;
//case 8: GPIO8_INPUT_PULLUP_SET; break;
case 9: GPIO9_INPUT_PULLUP_SET; break;
case 10: GPIO10_INPUT_PULLUP_SET; break;
//case 11: GPIO11_INPUT_PULLUP_SET; break;
case 12: GPIO12_INPUT_PULLUP_SET; break;
case 13: GPIO13_INPUT_PULLUP_SET; break;
case 14: GPIO14_INPUT_PULLUP_SET; break;
case 15: GPIO15_INPUT_PULLUP_SET; break;
}
}
static void toggleBuiltInLED() {
static bool level = false;
setOutput(2);
level = !level;
if (level) {set(2);} else {clear(2);}
}
};
#elif ESP32
@@ -87,24 +115,40 @@
static inline void set(const uint8_t num) {
WRITE_PERI_REG(GPIO_OUT_W1TS_REG, 1 << num);
//gpio_set_level((gpio_num_t)num, 1);
}
static inline void clear(const uint8_t num) {
WRITE_PERI_REG(GPIO_OUT_W1TC_REG, 1 << num);
//gpio_set_level((gpio_num_t)num, 0);
}
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);
//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;
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);
//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;
gpio_config(&io_conf);
}
static void toggleBuiltInLED() {