Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
NumInterrupts.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <Settings/NamespaceSettings.hpp>
5
6#ifdef ARDUINO_ARCH_NRF52840
7#include <pins_arduino.h>
8#endif
9
11
12// Teensy (and maybe others)
13#if defined(CORE_NUM_INTERRUPT)
14// CORE_NUM_INTERRUPT already defined by core
15
16// Wiring boards
17#elif defined(WIRING)
18#define CORE_NUM_INTERRUPT NUM_EXTERNAL_INTERRUPTS
19
20// MightyCore, MiniCore, etc.
21#elif defined(EXTERNAL_NUM_INTERRUPTS)
22#define CORE_NUM_INTERRUPT EXTERNAL_NUM_INTERRUPTS
23
24// Arduino Uno, Duemilanove, Diecimila, LilyPad, Mini, Fio, etc...
25#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__) || \
26 defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__)
27#define CORE_NUM_INTERRUPT 2
28
29// Arduino Mega
30#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
31#define CORE_NUM_INTERRUPT 6
32
33// Arduino Nano Every, Uno R2 Wifi
34#elif defined(__AVR_ATmega4809__)
35#define CORE_NUM_INTERRUPT 22
36
37// Arduino Leonardo
38#elif defined(__AVR_ATmega32U4__) && !defined(CORE_TEENSY)
39#define CORE_NUM_INTERRUPT 5
40
41// Sanguino (untested) and ATmega1284P
42#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) || \
43 defined(__AVR_ATmega1284P__)
44#define CORE_NUM_INTERRUPT 3
45
46// ATmega32u2 and ATmega32u16 based boards with HoodLoader2
47#elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
48#define CORE_NUM_INTERRUPT 8
49
50#elif defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
51#define CORE_NUM_INTERRUPT 1
52
53// https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/ATtiny_x313.md
54#elif defined(__AVR_ATtinyX313__)
55#define CORE_NUM_INTERRUPT 2
56
57// Attiny167 same core as above
58#elif defined(__AVR_ATtiny167__)
59#define CORE_NUM_INTERRUPT 2
60
61// Arduino Due
62#elif defined(__SAM3X8E__)
63#define CORE_NUM_INTERRUPT 54
64
65// ESP8266 (https://github.com/esp8266/Arduino/)
66#elif defined(ESP8266)
67#define CORE_NUM_INTERRUPT EXTERNAL_NUM_INTERRUPTS
68
69// ESP32 (https://github.com/espressif/arduino-esp32)
70#elif defined(ESP32)
71#define CORE_NUM_INTERRUPT 40
72
73// Arduino Zero - TODO: interrupts do not seem to work
74// please help, contribute a fix!
75#elif defined(__SAMD21G18A__) || defined(__SAMD21E18A__)
76#define CORE_NUM_INTERRUPT 31
77
78// SAMD51
79#elif defined(__SAMD51__)
80#define CORE_NUM_INTERRUPT 26
81
82// Arduino Nano BLE
83#elif defined(ARDUINO_ARCH_NRF52840)
84#define CORE_NUM_INTERRUPT NUM_DIGITAL_PINS
85
86// Arduino Nano RP2040 Connect
87#elif defined(ARDUINO_NANO_RP2040_CONNECT)
88#define CORE_NUM_INTERRUPT 20
89
90#elif defined(ARDUINO_ARCH_RP2040)
91#define CORE_NUM_INTERRUPT 32
92
93// ARM mbed OS
94#elif defined(ARDUINO_ARCH_MBED)
95#define CORE_NUM_INTERRUPT NUM_DIGITAL_PINS
96
97// Arduino UNO R4
98#elif defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_UNOR4_WIFI)
99#define CORE_NUM_INTERRUPT 13
100
101#ifdef NOT_AN_INTERRUPT
102#error \
103 "This version of the ArduinoCore-renesas is not supported. Please open an issue on GitHub: https://github.com/tttapa/Control-Surface/issues"
104#endif
107using not_an_interrupt_t = pin_size_t;
108using interrupt_t = not_an_interrupt_t;
110#define NOT_AN_INTERRUPT ((::AH::not_an_interrupt_t)255)
112using AH::interrupt_t;
113constexpr interrupt_t pin_to_interrupt_index[] {
114 0, // GPIO 0 (P301) IRQ6
115 1, // GPIO 1 (P302) IRQ5
116 2, // GPIO 2 (P104) IRQ1
117 3, // GPIO 3 (P105) IRQ0
118 NOT_AN_INTERRUPT, // GPIO 4 (P106) -
119 NOT_AN_INTERRUPT, // GPIO 5 (P107) -
120 4, // GPIO 6 (P111) IRQ4
121 NOT_AN_INTERRUPT, // GPIO 7 (P112) -
122 5, // GPIO 8 (P304) IRQ9
123 NOT_AN_INTERRUPT, // GPIO 9 (P303) -
124 NOT_AN_INTERRUPT, // GPIO 10 (P103) -
125 6, // GPIO 11 (P411) IRQ4
126 7, // GPIO 12 (P410) IRQ5
127 NOT_AN_INTERRUPT, // GPIO 13 (P102) -
128 NOT_AN_INTERRUPT, // GPIO 14 (P014) -
129 8, // GPIO 15 (P000) IRQ6
130 9, // GPIO 16 (P001) IRQ7
131 10, // GPIO 17 (P002) IRQ2
132 11, // GPIO 18 (P101) IRQ1
133 12, // GPIO 19 (P100) IRQ2
134};
135inline interrupt_t digitalPinToInterrupt(pin_size_t pin) {
136 if (pin_to_interrupt_index[pin] == NOT_AN_INTERRUPT)
137 return NOT_AN_INTERRUPT;
138 return ::digitalPinToInterrupt(pin);
139}
140inline interrupt_t interruptToIndex(interrupt_t interrupt) {
141 return pin_to_interrupt_index[interrupt];
142}
143#define CS_CUSTOM_INTERRUPT_TO_INDEX 1
144
145// Others
146#else
147#warning "Unknown board. Please specify the number of external interrupts."
148#define CORE_NUM_INTERRUPT NUM_DIGITAL_PINS
149
150#endif
151
static interrupt_index_t interruptToIndex(interrupt_index_t i)
Definition AHEncoder.cpp:11
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE