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