PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include <FastLED.h>
  2. char fullstrBuffer[64];
  3. const char *getPort(void *portPtr) {
  4. // AVR port checks
  5. #ifdef PORTA
  6. if(portPtr == (void*)&PORTA) { return "PORTA"; }
  7. #endif
  8. #ifdef PORTB
  9. if(portPtr == (void*)&PORTB) { return "PORTB"; }
  10. #endif
  11. #ifdef PORTC
  12. if(portPtr == (void*)&PORTC) { return "PORTC"; }
  13. #endif
  14. #ifdef PORTD
  15. if(portPtr == (void*)&PORTD) { return "PORTD"; }
  16. #endif
  17. #ifdef PORTE
  18. if(portPtr == (void*)&PORTE) { return "PORTE"; }
  19. #endif
  20. #ifdef PORTF
  21. if(portPtr == (void*)&PORTF) { return "PORTF"; }
  22. #endif
  23. #ifdef PORTG
  24. if(portPtr == (void*)&PORTG) { return "PORTG"; }
  25. #endif
  26. #ifdef PORTH
  27. if(portPtr == (void*)&PORTH) { return "PORTH"; }
  28. #endif
  29. #ifdef PORTI
  30. if(portPtr == (void*)&PORTI) { return "PORTI"; }
  31. #endif
  32. #ifdef PORTJ
  33. if(portPtr == (void*)&PORTJ) { return "PORTJ"; }
  34. #endif
  35. #ifdef PORTK
  36. if(portPtr == (void*)&PORTK) { return "PORTK"; }
  37. #endif
  38. #ifdef PORTL
  39. if(portPtr == (void*)&PORTL) { return "PORTL"; }
  40. #endif
  41. // Teensy 3.x port checks
  42. #ifdef GPIO_A_PDOR
  43. if(portPtr == (void*)&GPIO_A_PDOR) { return "GPIO_A_PDOR"; }
  44. #endif
  45. #ifdef GPIO_B_PDOR
  46. if(portPtr == (void*)&GPIO_B_PDOR) { return "GPIO_B_PDOR"; }
  47. #endif
  48. #ifdef GPIO_C_PDOR
  49. if(portPtr == (void*)&GPIO_C_PDOR) { return "GPIO_C_PDOR"; }
  50. #endif
  51. #ifdef GPIO_D_PDOR
  52. if(portPtr == (void*)&GPIO_D_PDOR) { return "GPIO_D_PDOR"; }
  53. #endif
  54. #ifdef GPIO_E_PDOR
  55. if(portPtr == (void*)&GPIO_E_PDOR) { return "GPIO_E_PDOR"; }
  56. #endif
  57. #ifdef REG_PIO_A_ODSR
  58. if(portPtr == (void*)&REG_PIO_A_ODSR) { return "REG_PIO_A_ODSR"; }
  59. #endif
  60. #ifdef REG_PIO_B_ODSR
  61. if(portPtr == (void*)&REG_PIO_B_ODSR) { return "REG_PIO_B_ODSR"; }
  62. #endif
  63. #ifdef REG_PIO_C_ODSR
  64. if(portPtr == (void*)&REG_PIO_C_ODSR) { return "REG_PIO_C_ODSR"; }
  65. #endif
  66. #ifdef REG_PIO_D_ODSR
  67. if(portPtr == (void*)&REG_PIO_D_ODSR) { return "REG_PIO_D_ODSR"; }
  68. #endif
  69. // Teensy 4 port checks
  70. #ifdef GPIO1_DR
  71. if(portPtr == (void*)&GPIO1_DR) { return "GPIO1_DR"; }
  72. #endif
  73. #ifdef GPIO2_DR
  74. if(portPtr == (void*)&GPIO2_DR) { return "GPIO21_DR"; }
  75. #endif
  76. #ifdef GPIO3_DR
  77. if(portPtr == (void*)&GPIO3_DR) { return "GPIO3_DR"; }
  78. #endif
  79. #ifdef GPIO4_DR
  80. if(portPtr == (void*)&GPIO4_DR) { return "GPIO4_DR"; }
  81. #endif
  82. String unknown_str = "Unknown: " + String((size_t)portPtr, HEX);
  83. strncpy(fullstrBuffer, unknown_str.c_str(), unknown_str.length());
  84. fullstrBuffer[sizeof(fullstrBuffer)-1] = '\0';
  85. return fullstrBuffer;
  86. }
  87. template<uint8_t PIN> void CheckPin()
  88. {
  89. CheckPin<PIN - 1>();
  90. void *systemThinksPortIs = (void*)portOutputRegister(digitalPinToPort(PIN));
  91. RwReg systemThinksMaskIs = digitalPinToBitMask(PIN);
  92. Serial.print("Pin "); Serial.print(PIN); Serial.print(": Port ");
  93. if(systemThinksPortIs == (void*)FastPin<PIN>::port()) {
  94. Serial.print("valid & mask ");
  95. } else {
  96. Serial.print("invalid, is "); Serial.print(getPort((void*)FastPin<PIN>::port())); Serial.print(" should be ");
  97. Serial.print(getPort((void*)systemThinksPortIs));
  98. Serial.print(" & mask ");
  99. }
  100. if(systemThinksMaskIs == FastPin<PIN>::mask()) {
  101. Serial.println("valid.");
  102. } else {
  103. Serial.print("invalid, is "); Serial.print(FastPin<PIN>::mask()); Serial.print(" should be "); Serial.println(systemThinksMaskIs);
  104. }
  105. }
  106. template<> void CheckPin<255> () {}
  107. template<uint8_t _PORT> const char *_GetPinPort(void *ptr) {
  108. if (__FL_PORT_INFO<_PORT>::hasPort() && (ptr == (void*)__FL_PORT_INFO<_PORT>::portAddr())) {
  109. return __FL_PORT_INFO<_PORT>::portName();
  110. } else {
  111. return _GetPinPort<_PORT - 1>(ptr);
  112. }
  113. }
  114. template<> const char *_GetPinPort<-1>(void *ptr) {
  115. return NULL;
  116. }
  117. const char *GetPinPort(void *ptr) {
  118. return _GetPinPort<'Z'>(ptr);
  119. }
  120. static uint8_t pcount = 0;
  121. template<uint8_t PIN> void PrintPins() {
  122. PrintPins<PIN - 1>();
  123. RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(PIN));
  124. RwReg systemThinksMaskIs = digitalPinToBitMask(PIN);
  125. int maskBit = 0;
  126. while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; }
  127. const char *pinport = GetPinPort((void*)systemThinksPortIs);
  128. if (pinport) {
  129. Serial.print("__FL_DEFPIN("); Serial.print(PIN);
  130. Serial.print(","); Serial.print(maskBit);
  131. Serial.print(","); Serial.print(pinport);
  132. Serial.print("); ");
  133. pcount++;
  134. if(pcount == 4) { pcount = 0; Serial.println(""); }
  135. } else {
  136. // Serial.print("Not found for pin "); Serial.println(PIN);
  137. }
  138. }
  139. template<> void PrintPins<0>() {
  140. RwReg *systemThinksPortIs = portOutputRegister(digitalPinToPort(0));
  141. RwReg systemThinksMaskIs = digitalPinToBitMask(0);
  142. int maskBit = 0;
  143. while(systemThinksMaskIs > 1) { systemThinksMaskIs >>= 1; maskBit++; }
  144. const char *pinport = GetPinPort((void*)systemThinksPortIs);
  145. if (pinport) {
  146. Serial.print("__FL_DEFPIN("); Serial.print(0);
  147. Serial.print(","); Serial.print(maskBit);
  148. Serial.print(","); Serial.print(pinport);
  149. Serial.print("); ");
  150. pcount++;
  151. if(pcount == 4) { pcount = 0; Serial.println(""); }
  152. }
  153. }
  154. int counter = 0;
  155. void setup() {
  156. delay(5000);
  157. Serial.begin(38400);
  158. Serial.println("resetting!");
  159. }
  160. void loop() {
  161. Serial.println(counter);
  162. #ifdef MAX_PIN
  163. CheckPin<MAX_PIN>();
  164. #endif
  165. Serial.println("-----");
  166. #ifdef NUM_DIGITAL_PINS
  167. PrintPins<NUM_DIGITAL_PINS>();
  168. #endif
  169. Serial.println("------");
  170. delay(100000);
  171. }