FastLED 3.9.3
Loading...
Searching...
No Matches
Pintest.ino
Go to the documentation of this file.
1
4
5#include <FastLED.h>
6
7char fullstrBuffer[64];
8
9const char *getPort(void *portRef) {
10// AVR port checks
11#ifdef PORTA
12 if(portRef == (void*)&PORTA) { return "PORTA"; }
13#endif
14#ifdef PORTB
15 if(portRef == (void*)&PORTB) { return "PORTB"; }
16#endif
17#ifdef PORTC
18 if(portRef == (void*)&PORTC) { return "PORTC"; }
19#endif
20#ifdef PORTD
21 if(portRef == (void*)&PORTD) { return "PORTD"; }
22#endif
23#ifdef PORTE
24 if(portRef == (void*)&PORTE) { return "PORTE"; }
25#endif
26#ifdef PORTF
27 if(portRef == (void*)&PORTF) { return "PORTF"; }
28#endif
29#ifdef PORTG
30 if(portRef == (void*)&PORTG) { return "PORTG"; }
31#endif
32#ifdef PORTH
33 if(portRef == (void*)&PORTH) { return "PORTH"; }
34#endif
35#ifdef PORTI
36 if(portRef == (void*)&PORTI) { return "PORTI"; }
37#endif
38#ifdef PORTJ
39 if(portRef == (void*)&PORTJ) { return "PORTJ"; }
40#endif
41#ifdef PORTK
42 if(portRef == (void*)&PORTK) { return "PORTK"; }
43#endif
44#ifdef PORTL
45 if(portRef == (void*)&PORTL) { return "PORTL"; }
46#endif
47
48// Teensy 3.x port checks
49#ifdef GPIO_A_PDOR
50 if(portRef == (void*)&GPIO_A_PDOR) { return "GPIO_A_PDOR"; }
51#endif
52#ifdef GPIO_B_PDOR
53 if(portRef == (void*)&GPIO_B_PDOR) { return "GPIO_B_PDOR"; }
54#endif
55#ifdef GPIO_C_PDOR
56 if(portRef == (void*)&GPIO_C_PDOR) { return "GPIO_C_PDOR"; }
57#endif
58#ifdef GPIO_D_PDOR
59 if(portRef == (void*)&GPIO_D_PDOR) { return "GPIO_D_PDOR"; }
60#endif
61#ifdef GPIO_E_PDOR
62 if(portRef == (void*)&GPIO_E_PDOR) { return "GPIO_E_PDOR"; }
63#endif
64#ifdef REG_PIO_A_ODSR
65 if(portRef == (void*)&REG_PIO_A_ODSR) { return "REG_PIO_A_ODSR"; }
66#endif
67#ifdef REG_PIO_B_ODSR
68 if(portRef == (void*)&REG_PIO_B_ODSR) { return "REG_PIO_B_ODSR"; }
69#endif
70#ifdef REG_PIO_C_ODSR
71 if(portRef == (void*)&REG_PIO_C_ODSR) { return "REG_PIO_C_ODSR"; }
72#endif
73#ifdef REG_PIO_D_ODSR
74 if(portRef == (void*)&REG_PIO_D_ODSR) { return "REG_PIO_D_ODSR"; }
75#endif
76
77// Teensy 4 port checks
78#ifdef GPIO1_DR
79 if(portRef == (void*)&GPIO1_DR) { return "GPIO1_DR"; }
80#endif
81#ifdef GPIO2_DR
82if(portRef == (void*)&GPIO2_DR) { return "GPIO21_DR"; }
83#endif
84#ifdef GPIO3_DR
85if(portRef == (void*)&GPIO3_DR) { return "GPIO3_DR"; }
86#endif
87#ifdef GPIO4_DR
88if(portRef == (void*)&GPIO4_DR) { return "GPIO4_DR"; }
89#endif
90 String unknown_str = "Unknown: " + String((size_t)portRef, HEX);
91 strncpy(fullstrBuffer, unknown_str.c_str(), unknown_str.length());
92 fullstrBuffer[sizeof(fullstrBuffer)-1] = '\0';
93 return fullstrBuffer;
94}
95
96template<uint8_t PIN> void CheckPin()
97{
98 CheckPin<PIN - 1>();
99
100 void *systemThinksPortIs = (void*)portOutputRegister(digitalPinToPort(PIN));
101 RwReg systemThinksMaskIs = digitalPinToBitMask(PIN);
102
103 Serial.print("Pin "); Serial.print(PIN); Serial.print(": Port ");
104
105 if(systemThinksPortIs == (void*)FastPin<PIN>::port()) {
106 Serial.print("valid & mask ");
107 } else {
108 Serial.print("invalid, is "); Serial.print(getPort((void*)FastPin<PIN>::port())); Serial.print(" should be ");
109 Serial.print(getPort((void*)systemThinksPortIs));
110 Serial.print(" & mask ");
111 }
112
113 if(systemThinksMaskIs == FastPin<PIN>::mask()) {
114 Serial.println("valid.");
115 } else {
116 Serial.print("invalid, is "); Serial.print(FastPin<PIN>::mask()); Serial.print(" should be "); Serial.println(systemThinksMaskIs);
117 }
118}
119
120template<> void CheckPin<255> () {}
121
122
123template<uint8_t _PORT> const char *_GetPinPort(void *ptr) {
126 } else {
127 return _GetPinPort<_PORT - 1>(ptr);
128 }
129}
130template<> const char *_GetPinPort<-1>(void *ptr) {
131 return NULL;
132}
133
134const char *GetPinPort(void *ptr) {
135 return _GetPinPort<'Z'>(ptr);
136}
137
138static uint8_t pcount = 0;
139
140
141template<uint8_t PIN> void PrintPins() {
142 PrintPins<PIN - 1>();
143
144 RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(PIN));
145 RwReg systemThinksMaskIs = digitalPinToBitMask(PIN);
146
147 int maskBit = 0;
148 while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; }
149
150 const char *pinport = GetPinPort((void*)systemThinksPortIs);
151 if (pinport) {
152 Serial.print("__FL_DEFPIN("); Serial.print(PIN);
153 Serial.print(","); Serial.print(maskBit);
154 Serial.print(","); Serial.print(pinport);
155 Serial.print("); ");
156 pcount++;
157 if(pcount == 4) { pcount = 0; Serial.println(""); }
158 } else {
159 // Serial.print("Not found for pin "); Serial.println(PIN);
160 }
161}
162
163template<> void PrintPins<0>() {
164 RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(0));
165 RwReg systemThinksMaskIs = digitalPinToBitMask(0);
166
167 int maskBit = 0;
168 while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; }
169
170 const char *pinport = GetPinPort((void*)systemThinksPortIs);
171 if (pinport) {
172 Serial.print("__FL_DEFPIN("); Serial.print(0);
173 Serial.print(","); Serial.print(maskBit);
174 Serial.print(","); Serial.print(pinport);
175 Serial.print("); ");
176 pcount++;
177 if(pcount == 4) { pcount = 0; Serial.println(""); }
178 }
179}
180
181int counter = 0;
182void setup() {
183 delay(5000);
184 Serial.begin(38400);
185 Serial.println("resetting!");
186}
187
188void loop() {
189 Serial.println(counter);
190
191#ifdef MAX_PIN
192 CheckPin<MAX_PIN>();
193#endif
194
195 Serial.println("-----");
196#ifdef NUM_DIGITAL_PINS
197 PrintPins<NUM_DIGITAL_PINS>();
198#endif
199 Serial.println("------");
200
201 delay(100000);
202}
central include file for FastLED, defines the CFastLED class/object
The simplest level of Pin class.
Definition fastpin.h:205
Utility template for tracking down information about pins and ports.
Definition fastpin.h:330
static const char * portName()
Gets the name of the port, as a C-string.
Definition fastpin.h:334