ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
gpio.cpp
Go to the documentation of this file.
1#ifdef USE_HOST
2
3#include "gpio.h"
4#include "esphome/core/hal.h"
5#include "esphome/core/log.h"
6
7namespace esphome {
8namespace host {
9
10ESPHOME_LOG_TAG(TAG, "host");
11
12struct ISRPinArg {
13 uint8_t pin;
14 bool inverted;
15};
16
18 auto *arg = new ISRPinArg{}; // NOLINT(cppcoreguidelines-owning-memory)
19 arg->pin = pin_;
20 arg->inverted = inverted_;
21 return ISRInternalGPIOPin((void *) arg);
22}
23
24void HostGPIOPin::attach_interrupt_(void (*func)(void *), void *arg, gpio::InterruptType type) const {
25 ESP_LOGD(TAG, "Attaching interrupt %p to pin %d and mode %d", func, pin_, (uint32_t) type);
26}
27void HostGPIOPin::pin_mode(gpio::Flags flags) { ESP_LOGD(TAG, "Setting pin %d mode to %02X", pin_, (uint32_t) flags); }
28
29size_t HostGPIOPin::dump_summary(char *buffer, size_t len) const { return snprintf(buffer, len, "GPIO%u", this->pin_); }
30
33 // pass
34 ESP_LOGD(TAG, "Setting pin %d to %s", pin_, value != inverted_ ? "HIGH" : "LOW");
35}
37
38} // namespace host
39
40using namespace host;
41
42bool IRAM_ATTR ISRInternalGPIOPin::digital_read() {
43 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
44 return arg->inverted;
45}
46void IRAM_ATTR ISRInternalGPIOPin::digital_write(bool value) {
47 // pass
48}
50 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
51 ESP_LOGD(TAG, "Clearing interrupt for pin %d", arg->pin);
52}
53
54} // namespace esphome
55
56#endif // USE_HOST
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio_pin.h:98
void digital_write(bool value)
Definition gpio.cpp:227
void detach_interrupt() const
Definition gpio.cpp:36
void attach_interrupt_(void(*func)(void *), void *arg, gpio::InterruptType type) const
Definition gpio.cpp:24
ISRInternalGPIOPin to_isr() const
Definition gpio.cpp:17
bool digital_read() override
Definition gpio.cpp:31
void digital_write(bool value) override
Definition gpio.cpp:32
void pin_mode(gpio::Flags flags) override
Definition gpio.cpp:27
size_t dump_summary(char *buffer, size_t len) const override
Definition gpio.cpp:29
uint16_t flags
uint8_t type
uint32_t buffer
Definition gif.cpp:50
ESPHOME_LOG_TAG(TAG, "host")
const void size_t len
Definition hal.h:68
static void uint32_t