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