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#include <fl/stl/stdio.h>
10
12
13const char *getPort(void *portRef) {
14// AVR port checks
15#ifdef PORTA
16 if(portRef == (void*)&PORTA) { return "PORTA"; }
17#endif
18#ifdef PORTB
19 if(portRef == (void*)&PORTB) { return "PORTB"; }
20#endif
21#ifdef PORTC
22 if(portRef == (void*)&PORTC) { return "PORTC"; }
23#endif
24#ifdef PORTD
25 if(portRef == (void*)&PORTD) { return "PORTD"; }
26#endif
27#ifdef PORTE
28 if(portRef == (void*)&PORTE) { return "PORTE"; }
29#endif
30#ifdef PORTF
31 if(portRef == (void*)&PORTF) { return "PORTF"; }
32#endif
33#ifdef PORTG
34 if(portRef == (void*)&PORTG) { return "PORTG"; }
35#endif
36#ifdef PORTH
37 if(portRef == (void*)&PORTH) { return "PORTH"; }
38#endif
39#ifdef PORTI
40 if(portRef == (void*)&PORTI) { return "PORTI"; }
41#endif
42#ifdef PORTJ
43 if(portRef == (void*)&PORTJ) { return "PORTJ"; }
44#endif
45#ifdef PORTK
46 if(portRef == (void*)&PORTK) { return "PORTK"; }
47#endif
48#ifdef PORTL
49 if(portRef == (void*)&PORTL) { return "PORTL"; }
50#endif
51
52// Teensy 3.x port checks
53#ifdef GPIO_A_PDOR
54 if(portRef == (void*)&GPIO_A_PDOR) { return "GPIO_A_PDOR"; }
55#endif
56#ifdef GPIO_B_PDOR
57 if(portRef == (void*)&GPIO_B_PDOR) { return "GPIO_B_PDOR"; }
58#endif
59#ifdef GPIO_C_PDOR
60 if(portRef == (void*)&GPIO_C_PDOR) { return "GPIO_C_PDOR"; }
61#endif
62#ifdef GPIO_D_PDOR
63 if(portRef == (void*)&GPIO_D_PDOR) { return "GPIO_D_PDOR"; }
64#endif
65#ifdef GPIO_E_PDOR
66 if(portRef == (void*)&GPIO_E_PDOR) { return "GPIO_E_PDOR"; }
67#endif
68#ifdef REG_PIO_A_ODSR
69 if(portRef == (void*)&REG_PIO_A_ODSR) { return "REG_PIO_A_ODSR"; }
70#endif
71#ifdef REG_PIO_B_ODSR
72 if(portRef == (void*)&REG_PIO_B_ODSR) { return "REG_PIO_B_ODSR"; }
73#endif
74#ifdef REG_PIO_C_ODSR
75 if(portRef == (void*)&REG_PIO_C_ODSR) { return "REG_PIO_C_ODSR"; }
76#endif
77#ifdef REG_PIO_D_ODSR
78 if(portRef == (void*)&REG_PIO_D_ODSR) { return "REG_PIO_D_ODSR"; }
79#endif
80
81// Teensy 4 port checks
82#ifdef GPIO1_DR
83 if(portRef == (void*)&GPIO1_DR) { return "GPIO1_DR"; }
84#endif
85#ifdef GPIO2_DR
86if(portRef == (void*)&GPIO2_DR) { return "GPIO21_DR"; }
87#endif
88#ifdef GPIO3_DR
89if(portRef == (void*)&GPIO3_DR) { return "GPIO3_DR"; }
90#endif
91#ifdef GPIO4_DR
92if(portRef == (void*)&GPIO4_DR) { return "GPIO4_DR"; }
93#endif
94 fl::snprintf(fullstrBuffer, sizeof(fullstrBuffer), "Unknown: %zx", (size_t)portRef);
95 return fullstrBuffer;
96}
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) {
128 if (__FL_PORT_INFO<_PORT>::hasPort() && (ptr == (void*)__FL_PORT_INFO<_PORT>::portAddr())) {
129 return __FL_PORT_INFO<_PORT>::portName();
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())) {
137 return __FL_PORT_INFO<0>::portName();
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}
#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:11
const char * GetPinPort(void *ptr)
Definition Pintest.h:143
const char * getPort(void *portRef)
Definition Pintest.h:13
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
fl::FastPin< PIN > FastPin
Definition fastpin.h:19
#define NULL
int snprintf(char *buffer, fl::size size, const char *format, const Args &... args) FL_NOEXCEPT
Snprintf-like formatting function that writes to a buffer.
Definition stdio.h:666
#define Serial
Definition serial.h:304