ESPHome 2026.1.4
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/log.h"
5
6namespace esphome {
7namespace host {
8
9static const char *const TAG = "host";
10
11struct ISRPinArg {
12 uint8_t pin;
13 bool inverted;
14};
15
17 auto *arg = new ISRPinArg{}; // NOLINT(cppcoreguidelines-owning-memory)
18 arg->pin = pin_;
19 arg->inverted = inverted_;
20 return ISRInternalGPIOPin((void *) arg);
21}
22
23void HostGPIOPin::attach_interrupt(void (*func)(void *), void *arg, gpio::InterruptType type) const {
24 ESP_LOGD(TAG, "Attaching interrupt %p to pin %d and mode %d", func, pin_, (uint32_t) type);
25}
26void HostGPIOPin::pin_mode(gpio::Flags flags) { ESP_LOGD(TAG, "Setting pin %d mode to %02X", pin_, (uint32_t) flags); }
27
28size_t HostGPIOPin::dump_summary(char *buffer, size_t len) const { return snprintf(buffer, len, "GPIO%u", this->pin_); }
29
32 // pass
33 ESP_LOGD(TAG, "Setting pin %d to %s", pin_, value != inverted_ ? "HIGH" : "LOW");
34}
36
37} // namespace host
38
39using namespace host;
40
41bool IRAM_ATTR ISRInternalGPIOPin::digital_read() {
42 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
43 return arg->inverted;
44}
45void IRAM_ATTR ISRInternalGPIOPin::digital_write(bool value) {
46 // pass
47}
49 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
50 ESP_LOGD(TAG, "Clearing interrupt for pin %d", arg->pin);
51}
52
53} // namespace esphome
54
55#endif // USE_HOST
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:92
void digital_write(bool value)
Definition gpio.cpp:148
void attach_interrupt(void(*func)(void *), void *arg, gpio::InterruptType type) const override
Definition gpio.cpp:23
void detach_interrupt() const override
Definition gpio.cpp:35
bool digital_read() override
Definition gpio.cpp:30
void digital_write(bool value) override
Definition gpio.cpp:31
void pin_mode(gpio::Flags flags) override
Definition gpio.cpp:26
size_t dump_summary(char *buffer, size_t len) const override
Definition gpio.cpp:28
ISRInternalGPIOPin to_isr() const override
Definition gpio.cpp:16
uint16_t type
uint16_t flags
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:595