Interrupts.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Interrupts.h
8  *
9  ****/
10 
15 #pragma once
16 
17 #include <cstdint>
18 #include <driver/gpio.h>
19 #include <Delegate.h>
20 #include <WConstants.h>
21 #include <sming_attr.h>
22 
23 using InterruptCallback = void (*)();
24 using InterruptDelegate = Delegate<void()>;
25 
30 __forceinline GPIO_INT_TYPE ConvertArduinoInterruptMode(uint8_t mode)
31 {
32  switch(mode) {
33  case LOW: // to trigger the interrupt whenever the pin is low,
34  return GPIO_PIN_INTR_LOLEVEL;
35  case CHANGE: // to trigger the interrupt whenever the pin changes value
36  return GPIO_PIN_INTR_ANYEDGE;
37  case RISING: // to trigger when the pin goes from low to high,
38  return GPIO_PIN_INTR_POSEDGE;
39  case FALLING: // for when the pin goes from high to low.
40  return GPIO_PIN_INTR_NEGEDGE;
41  case HIGH: // to trigger the interrupt whenever the pin is high.
42  return GPIO_PIN_INTR_HILEVEL;
43  default:
44  return GPIO_PIN_INTR_DISABLE;
45  }
46 }
47 
54 void attachInterrupt(uint8_t pin, InterruptCallback callback, GPIO_INT_TYPE type);
55 
63 __forceinline void attachInterrupt(uint8_t pin, InterruptCallback callback, uint8_t mode)
64 {
66  attachInterrupt(pin, callback, type);
67 }
68 
75 void attachInterrupt(uint8_t pin, InterruptDelegate delegateFunction, GPIO_INT_TYPE type);
76 
85 __forceinline void attachInterrupt(uint8_t pin, InterruptDelegate delegateFunction, uint8_t mode)
86 {
88  attachInterrupt(pin, delegateFunction, type);
89 }
90 
96 void attachInterruptHandler(uint8_t pin, GPIO_INT_TYPE type);
97 
101 void detachInterrupt(uint8_t pin);
102 
108 void interruptMode(uint8_t pin, GPIO_INT_TYPE type);
109 
115 __forceinline void interruptMode(uint8_t pin, uint8_t mode)
116 {
118  interruptMode(pin, type);
119 }
120 
121 // AVR-style interrupt management
122 #define cli() noInterrupts()
123 #define sei() interrupts()
124 
GPIO_INT_TYPE
Definition: Esp8266/Components/esp8266/include/gpio.h:39
#define HIGH
Definition: WConstants.h:38
#define CHANGE
Definition: WConstants.h:58
#define LOW
Definition: WConstants.h:37
#define FALLING
Definition: WConstants.h:59
#define RISING
Definition: WConstants.h:60
@ GPIO_PIN_INTR_NEGEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:42
@ GPIO_PIN_INTR_DISABLE
Definition: Esp8266/Components/esp8266/include/gpio.h:40
@ GPIO_PIN_INTR_HILEVEL
Definition: Esp8266/Components/esp8266/include/gpio.h:45
@ GPIO_PIN_INTR_POSEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:41
@ GPIO_PIN_INTR_ANYEDGE
Definition: Esp8266/Components/esp8266/include/gpio.h:43
@ GPIO_PIN_INTR_LOLEVEL
Definition: Esp8266/Components/esp8266/include/gpio.h:44
void attachInterruptHandler(uint8_t pin, GPIO_INT_TYPE type)
Enable interrupts on GPIO pin.
void attachInterrupt(uint8_t pin, InterruptCallback callback, GPIO_INT_TYPE type)
Attach a function to a GPIO interrupt.
void detachInterrupt(uint8_t pin)
Disable interrupts on GPIO pin.
GPIO_INT_TYPE ConvertArduinoInterruptMode(uint8_t mode)
Convert Arduino interrupt mode to Sming mode.
Definition: Interrupts.h:30
void(*)() InterruptCallback
Definition: Interrupts.h:23
void interruptMode(uint8_t pin, GPIO_INT_TYPE type)
Set interrupt mode.