ESPHome 2025.5.0
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
28std::string HostGPIOPin::dump_summary() const {
29 char buffer[32];
30 snprintf(buffer, sizeof(buffer), "GPIO%u", pin_);
31 return buffer;
32}
33
36 // pass
37 ESP_LOGD(TAG, "Setting pin %d to %s", pin_, value != inverted_ ? "HIGH" : "LOW");
38}
40
41} // namespace host
42
43using namespace host;
44
45bool IRAM_ATTR ISRInternalGPIOPin::digital_read() {
46 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
47 return arg->inverted;
48}
49void IRAM_ATTR ISRInternalGPIOPin::digital_write(bool value) {
50 // pass
51}
53 auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
54 ESP_LOGD(TAG, "Clearing interrupt for pin %d", arg->pin);
55}
56
57} // namespace esphome
58
59#endif // USE_HOST
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:73
void digital_write(bool value)
Definition gpio.cpp:147
void attach_interrupt(void(*func)(void *), void *arg, gpio::InterruptType type) const override
Definition gpio.cpp:23
std::string dump_summary() const override
Definition gpio.cpp:28
void detach_interrupt() const override
Definition gpio.cpp:39
bool digital_read() override
Definition gpio.cpp:34
void digital_write(bool value) override
Definition gpio.cpp:35
void pin_mode(gpio::Flags flags) override
Definition gpio.cpp:26
ISRInternalGPIOPin to_isr() const override
Definition gpio.cpp:16
uint8_t type
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7