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.

fastpin_esp32.h 3.3KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. FASTLED_NAMESPACE_BEGIN
  3. template<uint8_t PIN, uint32_t MASK> class _ESPPIN {
  4. public:
  5. typedef volatile uint32_t * port_ptr_t;
  6. typedef uint32_t port_t;
  7. inline static void setOutput() { pinMode(PIN, OUTPUT); }
  8. inline static void setInput() { pinMode(PIN, INPUT); }
  9. inline static void hi() __attribute__ ((always_inline)) {
  10. if (PIN < 32) GPIO.out_w1ts = MASK;
  11. else GPIO.out1_w1ts.val = MASK;
  12. }
  13. inline static void lo() __attribute__ ((always_inline)) {
  14. if (PIN < 32) GPIO.out_w1tc = MASK;
  15. else GPIO.out1_w1tc.val = MASK;
  16. }
  17. inline static void set(register port_t val) __attribute__ ((always_inline)) {
  18. if (PIN < 32) GPIO.out = val;
  19. else GPIO.out1.val = val;
  20. }
  21. inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
  22. inline static void toggle() __attribute__ ((always_inline)) {
  23. if(PIN < 32) { GPIO.out ^= MASK; }
  24. else { GPIO.out1.val ^=MASK; }
  25. }
  26. inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { hi(); }
  27. inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { lo(); }
  28. inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { *port = val; }
  29. inline static port_t hival() __attribute__ ((always_inline)) {
  30. if (PIN < 32) return GPIO.out | MASK;
  31. else return GPIO.out1.val | MASK;
  32. }
  33. inline static port_t loval() __attribute__ ((always_inline)) {
  34. if (PIN < 32) return GPIO.out & ~MASK;
  35. else return GPIO.out1.val & ~MASK;
  36. }
  37. inline static port_ptr_t port() __attribute__ ((always_inline)) {
  38. if (PIN < 32) return &GPIO.out;
  39. else return &GPIO.out1.val;
  40. }
  41. inline static port_ptr_t sport() __attribute__ ((always_inline)) {
  42. if (PIN < 32) return &GPIO.out_w1ts;
  43. else return &GPIO.out1_w1ts.val;
  44. }
  45. inline static port_ptr_t cport() __attribute__ ((always_inline)) {
  46. if (PIN < 32) return &GPIO.out_w1tc;
  47. else return &GPIO.out1_w1tc.val;
  48. }
  49. inline static port_t mask() __attribute__ ((always_inline)) { return MASK; }
  50. inline static bool isset() __attribute__ ((always_inline)) {
  51. if (PIN < 32) return GPIO.out & MASK;
  52. else return GPIO.out1.val & MASK;
  53. }
  54. };
  55. #define _FL_DEFPIN(PIN) template<> class FastPin<PIN> : public _ESPPIN<PIN, ((PIN<32)?((uint32_t)1 << PIN):((uint32_t)1 << (PIN-32)))> {};
  56. _FL_DEFPIN(0);
  57. _FL_DEFPIN(1); // WARNING: Using TX causes flashiness when uploading
  58. _FL_DEFPIN(2);
  59. _FL_DEFPIN(3); // WARNING: Using RX causes flashiness when uploading
  60. _FL_DEFPIN(4);
  61. _FL_DEFPIN(5);
  62. // -- These pins are not safe to use:
  63. // _FL_DEFPIN(6,6); _FL_DEFPIN(7,7); _FL_DEFPIN(8,8);
  64. // _FL_DEFPIN(9,9); _FL_DEFPIN(10,10); _FL_DEFPIN(11,11);
  65. _FL_DEFPIN(12);
  66. _FL_DEFPIN(13);
  67. _FL_DEFPIN(14);
  68. _FL_DEFPIN(15);
  69. _FL_DEFPIN(16);
  70. _FL_DEFPIN(17);
  71. _FL_DEFPIN(18);
  72. _FL_DEFPIN(19);
  73. // No pin 20 : _FL_DEFPIN(20,20);
  74. _FL_DEFPIN(21); // Works, but note that GPIO21 is I2C SDA
  75. _FL_DEFPIN(22); // Works, but note that GPIO22 is I2C SCL
  76. _FL_DEFPIN(23);
  77. // No pin 24 : _FL_DEFPIN(24,24);
  78. _FL_DEFPIN(25);
  79. _FL_DEFPIN(26);
  80. _FL_DEFPIN(27);
  81. // No pin 28-31: _FL_DEFPIN(28,28); _FL_DEFPIN(29,29); _FL_DEFPIN(30,30); _FL_DEFPIN(31,31);
  82. // Need special handling for pins > 31
  83. _FL_DEFPIN(32);
  84. _FL_DEFPIN(33);
  85. #define HAS_HARDWARE_PIN_SUPPORT
  86. FASTLED_NAMESPACE_END