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 typedef void (*InterruptCallback)();
25 
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_INT_TYPE)3; // 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 
void interruptMode(uint8_t pin, GPIO_INT_TYPE type)
Set interrupt mode.
#define __forceinline
Definition: sming_attr.h:13
void(* InterruptCallback)()
Definition: Interrupts.h:23
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:36
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:41
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:38
#define HIGH
Definition: WConstants.h:38
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:40
void detachInterrupt(uint8_t pin)
Disable interrupts on GPIO pin.
#define CHANGE
Definition: WConstants.h:56
GPIO_INT_TYPE ConvertArduinoInterruptMode(uint8_t mode)
Convert Arduino interrupt mode to Sming mode.
Definition: Interrupts.h:30
#define LOW
Definition: WConstants.h:37
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:37
#define FALLING
Definition: WConstants.h:57
void attachInterrupt(uint8_t pin, InterruptCallback callback, GPIO_INT_TYPE type)
Attach a function to a GPIO interrupt.
void attachInterruptHandler(uint8_t pin, GPIO_INT_TYPE type)
Enable interrupts on GPIO pin.
Delegate< void()> InterruptDelegate
Definition: Interrupts.h:24
#define RISING
Definition: WConstants.h:58
GPIO_INT_TYPE
Defines the GPIO interrupt type.
Definition: Esp8266/Components/esp8266/ESP8266_NONOS_SDK/include/gpio.h:35