Skip to content

Commit 1fc3466

Browse files
committed
esphal: add support for detaching an interrupt.
That's needed when a component needs to enable/disable interrupt on a gpio. Signed-off-by: 0hax <[email protected]>
1 parent 984f5a2 commit 1fc3466

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

esphome/core/esphal.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typedef struct { // NOLINT
1212

1313
void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, void (*)(void *), void *fp, // NOLINT
1414
int mode);
15+
void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin);
1516
};
1617
#endif
1718

@@ -226,6 +227,18 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
226227
}
227228
#endif
228229

230+
void GPIOPin::detach_interrupt() const {
231+
this->detach_interrupt_();
232+
}
233+
void GPIOPin::detach_interrupt_() const {
234+
#ifdef ARDUINO_ARCH_ESP8266
235+
__detachInterrupt(get_pin());
236+
#endif
237+
#ifdef ARDUINO_ARCH_ESP32
238+
detach(get_pin());
239+
#endif
240+
241+
}
229242
void GPIOPin::attach_interrupt_(void (*func)(void *), void *arg, int mode) const {
230243
if (this->inverted_) {
231244
if (mode == RISING) {

esphome/core/esphal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ class GPIOPin {
9494
bool is_inverted() const;
9595

9696
template<typename T> void attach_interrupt(void (*func)(T *), T *arg, int mode) const;
97+
void detach_interrupt() const;
9798

9899
ISRInternalGPIOPin *to_isr() const;
99100

100101
protected:
101102
void attach_interrupt_(void (*func)(void *), void *arg, int mode) const;
103+
void detach_interrupt_() const;
102104

103105
const uint8_t pin_;
104106
const uint8_t mode_;
@@ -114,5 +116,4 @@ class GPIOPin {
114116
template<typename T> void GPIOPin::attach_interrupt(void (*func)(T *), T *arg, int mode) const {
115117
this->attach_interrupt_(reinterpret_cast<void (*)(void *)>(func), arg, mode);
116118
}
117-
118119
} // namespace esphome

0 commit comments

Comments
 (0)