PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.7KB

  1. #pragma once
  2. FASTLED_NAMESPACE_BEGIN
  3. struct FASTLED_ESP_IO {
  4. volatile uint32_t _GPO;
  5. volatile uint32_t _GPOS;
  6. volatile uint32_t _GPOC;
  7. };
  8. #define _GPB (*(FASTLED_ESP_IO*)(0x60000000+(0x300)))
  9. template<uint8_t PIN, uint32_t MASK> class _ESPPIN {
  10. public:
  11. typedef volatile uint32_t * port_ptr_t;
  12. typedef uint32_t port_t;
  13. inline static void setOutput() { pinMode(PIN, OUTPUT); }
  14. inline static void setInput() { pinMode(PIN, INPUT); }
  15. inline static void hi() __attribute__ ((always_inline)) { if(PIN < 16) { _GPB._GPOS = MASK; } else { GP16O |= MASK; } }
  16. inline static void lo() __attribute__ ((always_inline)) { if(PIN < 16) { _GPB._GPOC = MASK; } else { GP16O &= ~MASK; } }
  17. inline static void set(register port_t val) __attribute__ ((always_inline)) { if(PIN < 16) { _GPB._GPO = val; } else { GP16O = val; }}
  18. inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
  19. inline static void toggle() __attribute__ ((always_inline)) { if(PIN < 16) { _GPB._GPO ^= MASK; } else { GP16O ^= MASK; } }
  20. inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); }
  21. inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); }
  22. inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
  23. inline static port_t hival() __attribute__ ((always_inline)) { if (PIN<16) { return GPO | MASK; } else { return GP16O | MASK; } }
  24. inline static port_t loval() __attribute__ ((always_inline)) { if (PIN<16) { return GPO & ~MASK; } else { return GP16O & ~MASK; } }
  25. inline static port_ptr_t port() __attribute__ ((always_inline)) { if(PIN<16) { return &_GPB._GPO; } else { return &GP16O; } }
  26. inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &_GPB._GPOS; } // there is no GP160 support for this
  27. inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &_GPB._GPOC; }
  28. inline static port_t mask() __attribute__ ((always_inline)) { return MASK; }
  29. inline static bool isset() __attribute__ ((always_inline)) { return (PIN < 16) ? (GPO & MASK) : (GP16O & MASK); }
  30. };
  31. #define _FL_DEFPIN(PIN, REAL_PIN) template<> class FastPin<PIN> : public _ESPPIN<REAL_PIN, (1<<(REAL_PIN & 0xFF))> {};
  32. #ifdef FASTLED_ESP8266_RAW_PIN_ORDER
  33. #define MAX_PIN 16
  34. _FL_DEFPIN(0,0); _FL_DEFPIN(1,1); _FL_DEFPIN(2,2); _FL_DEFPIN(3,3);
  35. _FL_DEFPIN(4,4); _FL_DEFPIN(5,5);
  36. // These pins should be disabled, as they always cause WDT resets
  37. // _FL_DEFPIN(6,6); _FL_DEFPIN(7,7);
  38. // _FL_DEFPIN(8,8); _FL_DEFPIN(9,9); _FL_DEFPIN(10,10); _FL_DEFPIN(11,11);
  39. _FL_DEFPIN(12,12); _FL_DEFPIN(13,13); _FL_DEFPIN(14,14); _FL_DEFPIN(15,15);
  40. _FL_DEFPIN(16,16);
  41. #define PORTA_FIRST_PIN 12
  42. #elif defined(FASTLED_ESP8266_D1_PIN_ORDER)
  43. #define MAX_PIN 15
  44. _FL_DEFPIN(0,3);
  45. _FL_DEFPIN(1,1);
  46. _FL_DEFPIN(2,16);
  47. _FL_DEFPIN(3,5);
  48. _FL_DEFPIN(4,4);
  49. _FL_DEFPIN(5,14);
  50. _FL_DEFPIN(6,12);
  51. _FL_DEFPIN(7,13);
  52. _FL_DEFPIN(8,0);
  53. _FL_DEFPIN(9,2);
  54. _FL_DEFPIN(10,15);
  55. _FL_DEFPIN(11,13);
  56. _FL_DEFPIN(12,12);
  57. _FL_DEFPIN(13,14);
  58. _FL_DEFPIN(14,4);
  59. _FL_DEFPIN(15,5);
  60. #define PORTA_FIRST_PIN 12
  61. #else // if defined(FASTLED_ESP8266_NODEMCU_PIN_ORDER)
  62. #define MAX_PIN 10
  63. // This seems to be the standard Dxx pin mapping on most of the esp boards that i've found
  64. _FL_DEFPIN(0,16); _FL_DEFPIN(1,5); _FL_DEFPIN(2,4); _FL_DEFPIN(3,0);
  65. _FL_DEFPIN(4,2); _FL_DEFPIN(5,14); _FL_DEFPIN(6,12); _FL_DEFPIN(7,13);
  66. _FL_DEFPIN(8,15); _FL_DEFPIN(9,3); _FL_DEFPIN(10,1);
  67. #define PORTA_FIRST_PIN 6
  68. // The rest of the pins - these are generally not available
  69. // _FL_DEFPIN(11,6);
  70. // _FL_DEFPIN(12,7); _FL_DEFPIN(13,8); _FL_DEFPIN(14,9); _FL_DEFPIN(15,10);
  71. // _FL_DEFPIN(16,11);
  72. #endif
  73. #define HAS_HARDWARE_PIN_SUPPORT
  74. FASTLED_NAMESPACE_END