diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/platforms/arm/d51/fastpin_arm_d51.h | 35 | ||||
-rw-r--r-- | src/platforms/avr/clockless_trinket.h | 17 | ||||
-rw-r--r-- | src/platforms/avr/fastpin_avr.h | 22 | ||||
-rw-r--r-- | src/platforms/esp/32/clockless_rmt_esp32.cpp | 4 | ||||
-rw-r--r-- | src/platforms/esp/32/clockless_rmt_esp32.h | 6 |
6 files changed, 75 insertions, 11 deletions
@@ -69,7 +69,7 @@ Right now the library is supported on a variety of arduino compatable platforms. * Arduino & compatibles - straight up arduino devices, uno, duo, leonardo, mega, nano, etc... * Arduino Yún * Adafruit Trinket & Gemma - Trinket Pro may be supported, but haven't tested to confirm yet -* Teensy 2, Teensy++ 2, Teensy 3.0, Teensy 3.1/3.2, Teensy LC, Teensy 3.5, Teensy 3.6, and Teensy 4.0 - arduino compataible from pjrc.com with some extra goodies (note the teensy 3, 3.1, and LC are ARM, not AVR!) +* Teensy 2, Teensy++ 2, Teensy 3.0, Teensy 3.1/3.2, Teensy LC, Teensy 3.5, Teensy 3.6, and Teensy 4.0 - arduino compatible from pjrc.com with some extra goodies (note the teensy LC, 3.2, 3.5, 3.6, 4.0 are ARM, not AVR!) * Arduino Due and the digistump DigiX * RFDuino * SparkCore diff --git a/src/platforms/arm/d51/fastpin_arm_d51.h b/src/platforms/arm/d51/fastpin_arm_d51.h index 9d31cedb..e4483aff 100644 --- a/src/platforms/arm/d51/fastpin_arm_d51.h +++ b/src/platforms/arm/d51/fastpin_arm_d51.h @@ -59,7 +59,7 @@ public: #define _FL_IO(L) _RD32(GPIO ## L) -#define _FL_DEFPIN(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1 << BIT, L> {}; +#define _FL_DEFPIN(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1ul << BIT, L> {}; // Actual pin definitions #if defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) @@ -127,6 +127,39 @@ _FL_DEFPIN(23, 22, 1); _FL_DEFPIN(24, 23, 1); _FL_DEFPIN(25, 17, 0); #define SPI_CLOCK 25 #define HAS_HARDWARE_PIN_SUPPORT 1 + +#elif defined(ADAFRUIT_MATRIXPORTAL_M4_EXPRESS) + +#define MAX_PIN 21 +// 0/1 - SERCOM/UART (Serial1) +_FL_DEFPIN( 0, 1, 0); _FL_DEFPIN( 1, 0, 0); +// 2..3 buttons +_FL_DEFPIN( 2, 22, 1); _FL_DEFPIN( 3, 23, 1); +// 4 neopixel +_FL_DEFPIN( 4, 23, 0); +// SDA/SCL +_FL_DEFPIN( 5, 31, 1); _FL_DEFPIN( 6, 30, 1); +// 7..12 RGBRGB pins +_FL_DEFPIN( 7, 0, 1); _FL_DEFPIN( 8, 1, 1); _FL_DEFPIN( 9, 2, 1); _FL_DEFPIN(10, 3, 1); +_FL_DEFPIN(11, 4, 1); _FL_DEFPIN(12, 5, 1); +// 13 LED +_FL_DEFPIN(13, 14, 0); +// 14..21 Control pins +_FL_DEFPIN(14, 6, 1); _FL_DEFPIN(15, 14, 1); _FL_DEFPIN(16, 12, 1); _FL_DEFPIN(17, 7, 1); +_FL_DEFPIN(18, 8, 1); _FL_DEFPIN(19, 9, 1); _FL_DEFPIN(20, 15, 1); _FL_DEFPIN(21, 13, 1); +// 22..26 Analog pins +_FL_DEFPIN(22, 2, 1); _FL_DEFPIN(23, 5, 1); _FL_DEFPIN(24, 4, 1); _FL_DEFPIN(25, 6, 1); +_FL_DEFPIN(26, 7, 1); +// 34..36 ESP SPI +_FL_DEFPIN(34, 16, 0); _FL_DEFPIN(35, 17, 0); _FL_DEFPIN(36, 19, 0); +// 48..50 external SPI #2 on sercom 0 +_FL_DEFPIN(48, 5, 0); _FL_DEFPIN(49, 4, 0); _FL_DEFPIN(50, 7, 0); + +#define SPI_DATA 4 +#define SPI_CLOCK 7 + +#define HAS_HARDWARE_PIN_SUPPORT 1 + #endif diff --git a/src/platforms/avr/clockless_trinket.h b/src/platforms/avr/clockless_trinket.h index 971a5a71..2cfbef0d 100644 --- a/src/platforms/avr/clockless_trinket.h +++ b/src/platforms/avr/clockless_trinket.h @@ -172,7 +172,8 @@ protected: #define USE_ASM_MACROS #if defined(__AVR_ATmega4809__) -#define ASM_VAR_PORT "r" (((PORT_t*)FastPin<DATA_PIN>::port())->OUT) +// Not used - place holder so existing ASM_VARS macro can remain the same +#define ASM_VAR_PORT "r" (*FastPin<DATA_PIN>::port()) #else #define ASM_VAR_PORT "M" (FastPin<DATA_PIN>::port() - 0x20) #endif @@ -204,12 +205,24 @@ protected: [O1] "M" (RGB_BYTE1(RGB_ORDER)), \ [O2] "M" (RGB_BYTE2(RGB_ORDER)) \ : "cc" /* clobber registers */ -// Note: the code in the else in HI1/LO1 will be turned into an sts (2 cycle, 2 word) opcode + +#if defined(__AVR_ATmega4809__) + +// 1 cycle, write hi to the port +#define HI1 do {*FastPin<DATA_PIN>::port()=hi;} while(0); +// 1 cycle, write lo to the port +#define LO1 do {*FastPin<DATA_PIN>::port()=lo;} while(0); + +#else + +// Note: the code in the else in HI1/LO1 will be turned into an sts (2 cycle, 2 word) // 1 cycle, write hi to the port #define HI1 FASTLED_SLOW_CLOCK_ADJUST if((int)(FastPin<DATA_PIN>::port())-0x20 < 64) { asm __volatile__("out %[PORT], %[hi]" ASM_VARS ); } else { *FastPin<DATA_PIN>::port()=hi; } // 1 cycle, write lo to the port #define LO1 if((int)(FastPin<DATA_PIN>::port())-0x20 < 64) { asm __volatile__("out %[PORT], %[lo]" ASM_VARS ); } else { *FastPin<DATA_PIN>::port()=lo; } +#endif + // 2 cycles, sbrs on flipping the line to lo if we're pushing out a 0 #define QLO2(B, N) asm __volatile__("sbrs %[" #B "], " #N ASM_VARS ); LO1; // load a byte from ram into the given var with the given offset diff --git a/src/platforms/avr/fastpin_avr.h b/src/platforms/avr/fastpin_avr.h index 99a78958..741d3f34 100644 --- a/src/platforms/avr/fastpin_avr.h +++ b/src/platforms/avr/fastpin_avr.h @@ -37,6 +37,7 @@ public: inline static port_t hival() __attribute__ ((always_inline)) { return _PORT::r() | _MASK; } inline static port_t loval() __attribute__ ((always_inline)) { return _PORT::r() & ~_MASK; } inline static port_ptr_t port() __attribute__ ((always_inline)) { return &_PORT::r(); } + inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; } }; @@ -46,15 +47,25 @@ public: /// a custom type for each GPIO register with a single, static, aggressively inlined function that returns that specific GPIO register. A similar /// trick is used a bit further below for the ARM GPIO registers (of which there are far more than on AVR!) typedef volatile uint8_t & reg8_t; + #define _R(T) struct __gen_struct_ ## T #define _RD8(T) struct __gen_struct_ ## T { static inline reg8_t r() { return T; }}; // Register name equivalent (using flat names) -#if defined(AVR_ATtinyxy7) || defined(AVR_ATtinyxy6) || defined(AVR_ATtinyxy4) || defined(AVR_ATtinyxy2) || defined(__AVR_ATmega4809__) +#if defined(AVR_ATtinyxy7) || defined(AVR_ATtinyxy6) || defined(AVR_ATtinyxy4) || defined(AVR_ATtinyxy2) + // ATtiny series 0/1 and ATmega series 0 #define _FL_IO(L,C) _RD8(PORT ## L ## _DIR); _RD8(PORT ## L ## _OUT); _RD8(PORT ## L ## _IN); _FL_DEFINE_PORT3(L, C, _R(PORT ## L ## _OUT)); #define _FL_DEFPIN(_PIN, BIT, L) template<> class FastPin<_PIN> : public _AVRPIN<_PIN, 1<<BIT, _R(PORT ## L ## _OUT), _R(PORT ## L ## _DIR), _R(PORT ## L ## _IN)> {}; + +#elif defined(__AVR_ATmega4809__) + +// Leverage VPORTs instead of PORTs for faster access +#define _FL_IO(L,C) _RD8(VPORT ## L ## _DIR); _RD8(VPORT ## L ## _OUT); _RD8(VPORT ## L ## _IN); _FL_DEFINE_PORT3(L, C, _R(VPORT ## L ## _OUT)); +#define _FL_DEFPIN(_PIN, BIT, L) template<> class FastPin<_PIN> : public _AVRPIN<_PIN, 1<<BIT, _R(VPORT ## L ## _OUT), _R(VPORT ## L ## _DIR), _R(VPORT ## L ## _IN)> {}; + #else + // Others #define _FL_IO(L,C) _RD8(DDR ## L); _RD8(PORT ## L); _RD8(PIN ## L); _FL_DEFINE_PORT3(L, C, _R(PORT ## L)); #define _FL_DEFPIN(_PIN, BIT, L) template<> class FastPin<_PIN> : public _AVRPIN<_PIN, 1<<BIT, _R(PORT ## L), _R(DDR ## L), _R(PIN ## L)> {}; @@ -231,11 +242,10 @@ _FL_DEFPIN(12, 1, E); _FL_DEFPIN(13, 2, E); _FL_DEFPIN(14, 3, D); _FL_DEFPIN(15, _FL_DEFPIN(16, 1, D); _FL_DEFPIN(17, 0, D); _FL_DEFPIN(18, 2, A); _FL_DEFPIN(19, 3, A); _FL_DEFPIN(20, 4, D); _FL_DEFPIN(21, 5, D); -// To confirm for the SPI interfaces -//#define SPI_DATA 18 -//#define SPI_CLOCK 13 -//#define SPI_SELECT 19 -//#define AVR_HARDWARE_SPI 1 +#define SPI_DATA 11 +#define SPI_CLOCK 13 +#define SPI_SELECT 8 +#define AVR_HARDWARE_SPI 1 #define HAS_HARDWARE_PIN_SUPPORT 1 //#define SPI_UART0_DATA 1 diff --git a/src/platforms/esp/32/clockless_rmt_esp32.cpp b/src/platforms/esp/32/clockless_rmt_esp32.cpp index 9fbdab59..42db3415 100644 --- a/src/platforms/esp/32/clockless_rmt_esp32.cpp +++ b/src/platforms/esp/32/clockless_rmt_esp32.cpp @@ -328,7 +328,11 @@ void IRAM_ATTR ESP32RMTController::interruptHandler(void *arg) for (channel = 0; channel < gMaxChannel; channel++) { int tx_done_bit = channel * 3; + #ifdef CONFIG_IDF_TARGET_ESP32S2 + int tx_next_bit = channel + 12; + #else int tx_next_bit = channel + 24; + #endif ESP32RMTController * pController = gOnChannel[channel]; if (pController != NULL) { diff --git a/src/platforms/esp/32/clockless_rmt_esp32.h b/src/platforms/esp/32/clockless_rmt_esp32.h index faa31dc5..2a8555ab 100644 --- a/src/platforms/esp/32/clockless_rmt_esp32.h +++ b/src/platforms/esp/32/clockless_rmt_esp32.h @@ -188,10 +188,14 @@ __attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { #define FASTLED_RMT_MAX_CONTROLLERS 32 #endif -// -- Max RMT channel (default to 8) +// -- Max RMT channel (default to 8 on ESP32 and 4 on ESP32-S2) #ifndef FASTLED_RMT_MAX_CHANNELS +#ifdef CONFIG_IDF_TARGET_ESP32S2 +#define FASTLED_RMT_MAX_CHANNELS 4 +#else #define FASTLED_RMT_MAX_CHANNELS 8 #endif +#endif class ESP32RMTController { |