Skip to content

Commit dcdbd80

Browse files
committed
Start adding support for Apollo3 devices
Signed-off-by: Carey Sonsino <csonsino@gmail.com>
1 parent 48da9b3 commit dcdbd80

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

Adafruit_NeoPixel.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,10 @@ void Adafruit_NeoPixel::show(void) {
17001700
}
17011701
#endif
17021702

1703+
#elif defined (AM_PART_APOLLO3) // Apollo3
1704+
1705+
apollo3Show(pin, pixels, numBytes, is800KHz);
1706+
17031707
#elif defined (__SAMD51__) // M4
17041708

17051709
uint8_t *ptr, *end, p, bitMask, portNum, bit;
@@ -2210,7 +2214,18 @@ void Adafruit_NeoPixel::show(void) {
22102214
@param p Arduino pin number (-1 = no pin).
22112215
*/
22122216
void Adafruit_NeoPixel::setPin(uint16_t p) {
2213-
if(begun && (pin >= 0)) pinMode(pin, INPUT);
2217+
if(begun && (pin >= 0)) {
2218+
#if defined(AM_PART_APOLLO3)
2219+
// The pin has been mapped to the Apollo3 pad
2220+
apollo3UnsetPad(pin);
2221+
#endif
2222+
pinMode(pin, INPUT);
2223+
}
2224+
#if defined(AM_PART_APOLLO3)
2225+
// Map the specified pin to the Apollo3 pad
2226+
p = ap3_gpio_pin2pad(p);
2227+
apollo3SetPad(p);
2228+
#endif
22142229
pin = p;
22152230
if(begun) {
22162231
pinMode(p, OUTPUT);

Adafruit_NeoPixel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ class Adafruit_NeoPixel {
334334

335335
protected:
336336

337+
#if defined (AM_PART_APOLLO3)
338+
void apollo3UnsetPad(ap3_gpio_pad_t pad);
339+
void apollo3SetPad(ap3_gpio_pad_t pad);
340+
void apollo3Show(ap3_gpio_pad_t pad, uint8_t *pixels, uint32_t numBytes, boolean is800KHz);
341+
#endif // AM_PART_APOLLO3
342+
337343
#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled...
338344
boolean is800KHz; ///< true if 800 KHz pixels
339345
#endif

apollo3.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// This provides the functionality for Apollo3 devices.
2+
3+
#if defined(AM_PART_APOLLO3)
4+
5+
#include <ap3_types.h>
6+
#include <am_hal_gpio.h>
7+
8+
#include "Adafruit_NeoPixel.h"
9+
10+
// The timing method used to control the NeoPixels
11+
// TODO: Implement something better (interrupts, DMA, etc)
12+
#define PIN_METHOD_FAST_GPIO
13+
14+
/*!
15+
@brief Unset the NeoPixel output pad number.
16+
@param pad Apollo3 pad number
17+
*/
18+
void Adafruit_NeoPixel::apollo3UnsetPad(ap3_gpio_pad_t pad) {
19+
#if defined(PIN_METHOD_FAST_GPIO)
20+
// Unconfigure the pad for Fast GPIO.
21+
am_hal_gpio_fastgpio_disable(pad);
22+
#endif
23+
}
24+
25+
/*!
26+
@brief Set the NeoPixel output pad number.
27+
@param pad Apollo3 pad number
28+
*/
29+
void Adafruit_NeoPixel::apollo3SetPad(ap3_gpio_pad_t pad) {
30+
#if defined(PIN_METHOD_FAST_GPIO)
31+
// Configure the pad to be used for Fast GPIO.
32+
am_hal_gpio_fastgpio_disable(pad);
33+
am_hal_gpio_fastgpio_clr(pad);
34+
35+
am_hal_gpio_fast_pinconfig((uint64_t)0x1 << pad,
36+
g_AM_HAL_GPIO_OUTPUT, 0);
37+
// uint32_t ui32Ret = am_hal_gpio_fast_pinconfig((uint64_t)0x1 << pad,
38+
// g_AM_HAL_GPIO_OUTPUT, 0);
39+
// if (ui32Ret) {
40+
// am_util_stdio_printf(
41+
// "Error returned from am_hal_gpio_fast_pinconfig() = .\n", ui32Ret);
42+
// }
43+
#endif
44+
}
45+
46+
// Note - The timings used below are based on the Arduino Zero,
47+
// Gemma/Trinket M0 code.
48+
49+
/*!
50+
@brief Transmit pixel data in RAM to NeoPixels.
51+
@note The current design is a quick hack and should be replaced with
52+
a more robust timing mechanism.
53+
*/
54+
void Adafruit_NeoPixel::apollo3Show(
55+
ap3_gpio_pad_t pad, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
56+
57+
uint8_t *ptr, *end, p, bitMask;
58+
ptr = pixels;
59+
end = ptr + numBytes;
60+
p = *ptr++;
61+
bitMask = 0x80;
62+
63+
#if defined(PIN_METHOD_FAST_GPIO)
64+
65+
// disable interrupts
66+
am_hal_interrupt_master_disable();
67+
68+
#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled
69+
if(is800KHz) {
70+
#endif
71+
for(;;) {
72+
am_hal_gpio_fastgpio_set(pad);
73+
//asm("nop; nop; nop; nop; nop; nop; nop; nop;");
74+
asm("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;");
75+
if(p & bitMask) {
76+
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
77+
"nop; nop; nop; nop; nop; nop; nop; nop;"
78+
"nop; nop; nop; nop;");
79+
am_hal_gpio_fastgpio_clr(pad);
80+
} else {
81+
am_hal_gpio_fastgpio_clr(pad);
82+
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
83+
"nop; nop; nop; nop; nop; nop; nop; nop;"
84+
"nop; nop; nop; nop;");
85+
}
86+
if(bitMask >>= 1) {
87+
asm("nop; nop; nop; nop; nop; nop; nop; nop; nop;");
88+
} else {
89+
if(ptr >= end) break;
90+
p = *ptr++;
91+
bitMask = 0x80;
92+
}
93+
}
94+
#ifdef NEO_KHZ400
95+
} else { // 400 KHz bitstream
96+
// NOTE - These timings may need to be tweaked
97+
for(;;) {
98+
am_hal_gpio_fastgpio_set(pad);
99+
//asm("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;");
100+
asm("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;");
101+
if(p & bitMask) {
102+
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
103+
"nop; nop; nop; nop; nop; nop; nop; nop;"
104+
"nop; nop; nop; nop; nop; nop; nop; nop;"
105+
"nop; nop; nop;");
106+
am_hal_gpio_fastgpio_clr(pad);
107+
} else {
108+
am_hal_gpio_fastgpio_clr(pad);
109+
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
110+
"nop; nop; nop; nop; nop; nop; nop; nop;"
111+
"nop; nop; nop; nop; nop; nop; nop; nop;"
112+
"nop; nop; nop;");
113+
}
114+
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
115+
"nop; nop; nop; nop; nop; nop; nop; nop;"
116+
"nop; nop; nop; nop; nop; nop; nop; nop;"
117+
"nop; nop; nop; nop; nop; nop; nop; nop;");
118+
if(bitMask >>= 1) {
119+
asm("nop; nop; nop; nop; nop; nop; nop;");
120+
} else {
121+
if(ptr >= end) break;
122+
p = *ptr++;
123+
bitMask = 0x80;
124+
}
125+
}
126+
}
127+
128+
// re-enable interrupts
129+
am_hal_interrupt_master_enable();
130+
131+
#endif // NEO_KHZ400
132+
#endif // PIN_METHOD_FAST_GPIO
133+
}
134+
135+
#endif // AM_PART_APOLLO3

0 commit comments

Comments
 (0)