ESPHome  2024.3.2
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 
6 namespace esphome {
7 namespace host {
8 
9 static const char *const TAG = "host";
10 
11 struct 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 
23 void 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 }
26 void HostGPIOPin::pin_mode(gpio::Flags flags) { ESP_LOGD(TAG, "Setting pin %d mode to %02X", pin_, (uint32_t) flags); }
27 
28 std::string HostGPIOPin::dump_summary() const {
29  char buffer[32];
30  snprintf(buffer, sizeof(buffer), "GPIO%u", pin_);
31  return buffer;
32 }
33 
34 bool HostGPIOPin::digital_read() { return inverted_; }
35 void HostGPIOPin::digital_write(bool value) {
36  // pass
37  ESP_LOGD(TAG, "Setting pin %d to %s", pin_, value != inverted_ ? "HIGH" : "LOW");
38 }
40 
41 } // namespace host
42 
43 using namespace host;
44 
45 bool IRAM_ATTR ISRInternalGPIOPin::digital_read() {
46  auto *arg = reinterpret_cast<ISRPinArg *>(arg_);
47  return arg->inverted;
48 }
49 void IRAM_ATTR ISRInternalGPIOPin::digital_write(bool value) {
50  // pass
51 }
52 void IRAM_ATTR ISRInternalGPIOPin::clear_interrupt() {
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:66
void detach_interrupt() const override
Definition: gpio.cpp:39
std::string dump_summary() const override
Definition: gpio.cpp:28
void digital_write(bool value) override
Definition: gpio.cpp:35
bool digital_read() override
Definition: gpio.cpp:34
uint8_t type
void pin_mode(gpio::Flags flags) override
Definition: gpio.cpp:26
const uint32_t flags
Definition: stm32flash.h:85
void attach_interrupt(void(*func)(void *), void *arg, gpio::InterruptType type) const override
Definition: gpio.cpp:23
InterruptType
Definition: gpio.h:40
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
ISRInternalGPIOPin to_isr() const override
Definition: gpio.cpp:16
void digital_write(bool value)
Definition: gpio.cpp:121