10 static const char *
const TAG =
"esp32";
17 return GPIO_MODE_INPUT;
19 return GPIO_MODE_OUTPUT;
21 return GPIO_MODE_OUTPUT_OD;
23 return GPIO_MODE_INPUT_OUTPUT_OD;
25 return GPIO_MODE_INPUT_OUTPUT;
28 return GPIO_MODE_DISABLE;
38 auto *arg =
new ISRPinArg{};
40 arg->inverted = inverted_;
45 gpio_int_type_t idf_type = GPIO_INTR_ANYEDGE;
48 idf_type = inverted_ ? GPIO_INTR_NEGEDGE : GPIO_INTR_POSEDGE;
51 idf_type = inverted_ ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE;
54 idf_type = GPIO_INTR_ANYEDGE;
57 idf_type = inverted_ ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL;
60 idf_type = inverted_ ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL;
63 gpio_set_intr_type(pin_, idf_type);
64 gpio_intr_enable(pin_);
65 if (!isr_service_installed) {
66 auto res = gpio_install_isr_service(ESP_INTR_FLAG_LEVEL3);
68 ESP_LOGE(TAG,
"attach_interrupt(): call to gpio_install_isr_service() failed, error code: %d", res);
71 isr_service_installed =
true;
73 gpio_isr_handler_add(pin_, func, arg);
78 snprintf(buffer,
sizeof(buffer),
"GPIO%" PRIu32, static_cast<uint32_t>(pin_));
84 conf.pin_bit_mask = 1ULL << static_cast<uint32_t>(pin_);
85 conf.mode = flags_to_mode(flags_);
86 conf.pull_up_en = flags_ &
gpio::FLAG_PULLUP ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
87 conf.pull_down_en = flags_ &
gpio::FLAG_PULLDOWN ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE;
88 conf.intr_type = GPIO_INTR_DISABLE;
91 gpio_set_drive_capability(pin_, drive_strength_);
97 gpio_set_direction(pin_, flags_to_mode(flags));
98 gpio_pull_mode_t pull_mode = GPIO_FLOATING;
100 pull_mode = GPIO_PULLUP_PULLDOWN;
101 }
else if (flags & gpio::FLAG_PULLUP) {
102 pull_mode = GPIO_PULLUP_ONLY;
103 }
else if (flags & gpio::FLAG_PULLDOWN) {
104 pull_mode = GPIO_PULLDOWN_ONLY;
106 gpio_set_pull_mode(pin_, pull_mode);
115 using namespace esp32;
118 auto *arg =
reinterpret_cast<ISRPinArg *
>(arg_);
119 return bool(gpio_get_level(arg->pin)) != arg->inverted;
122 auto *arg =
reinterpret_cast<ISRPinArg *
>(arg_);
123 gpio_set_level(arg->pin, value != arg->inverted ? 1 : 0);
129 auto *arg =
reinterpret_cast<ISRPinArg *
>(arg_);
130 gpio_set_direction(arg->pin, flags_to_mode(flags));
131 gpio_pull_mode_t pull_mode = GPIO_FLOATING;
133 pull_mode = GPIO_PULLUP_PULLDOWN;
134 }
else if (flags & gpio::FLAG_PULLUP) {
135 pull_mode = GPIO_PULLUP_ONLY;
136 }
else if (flags & gpio::FLAG_PULLDOWN) {
137 pull_mode = GPIO_PULLDOWN_ONLY;
139 gpio_set_pull_mode(arg->pin, pull_mode);
ISRInternalGPIOPin to_isr() const override
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
void detach_interrupt() const override
void pin_mode(gpio::Flags flags)
bool digital_read() override
static bool isr_service_installed
void digital_write(bool value) override
void pin_mode(gpio::Flags flags) override
void attach_interrupt(void(*func)(void *), void *arg, gpio::InterruptType type) const override
Implementation of SPI Controller mode.
std::string dump_summary() const override
void digital_write(bool value)