Skip to content

Commit 4e78606

Browse files
Add support for Arduino 101 (full) & Zero (partial, interrupts not working)
1 parent 665346f commit 4e78606

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

utility/direct_pin_read.h

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,53 @@
2222
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
2323
#define DIRECT_PIN_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0)
2424

25-
/* ESP8266 v2.0.0 Arduino workaround for bug https://github.com/esp8266/Arduino/issues/1110
26-
Once ESP8266 Arduino v2.1.0 is released, this #elif should be removed and line 11 of this
27-
file should read:
28-
#elif defined(__SAM3X8E__) || defined(ESP8266)
29-
*/
25+
/* ESP8266 v2.0.0 Arduino workaround for bug https://github.com/esp8266/Arduino/issues/1110 */
3026
#elif defined(ESP8266)
3127

3228
#define IO_REG_TYPE uint32_t
33-
#define PIN_TO_BASEREG(pin) ((volatile uint32_t *)(0x60000000+(0x318))) //Bypassing erroneous preprocessor macros
29+
#define PIN_TO_BASEREG(pin) ((volatile uint32_t *)(0x60000000+(0x318)))
3430
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
3531
#define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
36-
/* End of workaround */
32+
33+
#elif defined(__SAMD21G18A__)
34+
35+
#define IO_REG_TYPE uint32_t
36+
#define PIN_TO_BASEREG(pin) portModeRegister(digitalPinToPort(pin))
37+
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
38+
#define DIRECT_PIN_READ(base, mask) (((*((base)+8)) & (mask)) ? 1 : 0)
39+
40+
#elif defined(RBL_NRF51822)
41+
42+
#define IO_REG_TYPE uint32_t
43+
#define PIN_TO_BASEREG(pin) (0)
44+
#define PIN_TO_BITMASK(pin) (pin)
45+
#define DIRECT_PIN_READ(base, pin) nrf_gpio_pin_read(pin)
46+
47+
#elif defined(__arc__) /* Arduino101/Genuino101 specifics */
48+
49+
#include "scss_registers.h"
50+
#include "portable.h"
51+
#include "avr/pgmspace.h"
52+
#define GPIO_ID(pin) (g_APinDescription[pin].ulGPIOId)
53+
#define GPIO_TYPE(pin) (g_APinDescription[pin].ulGPIOType)
54+
#define GPIO_BASE(pin) (g_APinDescription[pin].ulGPIOBase)
55+
#define EXT_PORT_OFFSET_SS 0x0A
56+
#define EXT_PORT_OFFSET_SOC 0x50
57+
#define PIN_TO_BASEREG(pin) ((volatile uint32_t *)g_APinDescription[pin].ulGPIOBase)
58+
#define PIN_TO_BITMASK(pin) pin
59+
#define IO_REG_TYPE uint32_t
60+
static inline __attribute__((always_inline))
61+
IO_REG_TYPE directRead(volatile IO_REG_TYPE *base, IO_REG_TYPE pin)
62+
{
63+
IO_REG_TYPE ret;
64+
if (SS_GPIO == GPIO_TYPE(pin)) {
65+
ret = READ_ARC_REG(((IO_REG_TYPE)base + EXT_PORT_OFFSET_SS));
66+
} else {
67+
ret = MMIO_REG_VAL_FROM_BASE((IO_REG_TYPE)base, EXT_PORT_OFFSET_SOC);
68+
}
69+
return ((ret >> GPIO_ID(pin)) & 0x01);
70+
}
71+
#define DIRECT_PIN_READ(base, pin) directRead(base, pin)
3772

3873
#endif
3974

utility/interrupt_pins.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#define CORE_NUM_INTERRUPT 1
8686
#define CORE_INT0_PIN 2
8787

88-
// Arduino Due (untested)
88+
// Arduino Due
8989
#elif defined(__SAM3X8E__)
9090
#define CORE_NUM_INTERRUPT 54
9191
#define CORE_INT0_PIN 0
@@ -159,6 +159,42 @@
159159
#define CORE_INT14_PIN 14
160160
#define CORE_INT15_PIN 15
161161

162+
// Arduino Zero - TODO: interrupts do not seem to work
163+
// please help, contribute a fix!
164+
#elif defined(__SAMD21G18A__)
165+
#define CORE_NUM_INTERRUPT 20
166+
#define CORE_INT0_PIN 0
167+
#define CORE_INT1_PIN 1
168+
#define CORE_INT2_PIN 2
169+
#define CORE_INT3_PIN 3
170+
#define CORE_INT5_PIN 5
171+
#define CORE_INT6_PIN 6
172+
#define CORE_INT7_PIN 7
173+
#define CORE_INT8_PIN 8
174+
#define CORE_INT9_PIN 9
175+
#define CORE_INT10_PIN 10
176+
#define CORE_INT11_PIN 11
177+
#define CORE_INT12_PIN 12
178+
#define CORE_INT13_PIN 13
179+
#define CORE_INT14_PIN 14
180+
#define CORE_INT15_PIN 15
181+
#define CORE_INT16_PIN 16
182+
#define CORE_INT17_PIN 17
183+
#define CORE_INT18_PIN 18
184+
#define CORE_INT19_PIN 19
185+
186+
// Arduino 101
187+
#elif defined(__arc__)
188+
#define CORE_NUM_INTERRUPT 14
189+
#define CORE_INT2_PIN 2
190+
#define CORE_INT5_PIN 5
191+
#define CORE_INT7_PIN 7
192+
#define CORE_INT8_PIN 8
193+
#define CORE_INT10_PIN 10
194+
#define CORE_INT11_PIN 11
195+
#define CORE_INT12_PIN 12
196+
#define CORE_INT13_PIN 13
197+
162198
#endif
163199
#endif
164200

0 commit comments

Comments
 (0)