From fc504a4a7cd57b62ef84b067566ec82a6f7dfce5 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Sun, 14 Feb 2021 17:59:43 -0800 Subject: Add Particle Photon(STM32F2XX) support Pinout and other changes upstreamed from https://github.com/focalintent/FastLED-Sparkcore/blob/master/firmware/fastpin_arm_stm32.h --- src/led_sysdefs.h | 2 +- src/platforms.h | 2 +- src/platforms/arm/stm32/clockless_arm_stm32.h | 21 ++++++--- src/platforms/arm/stm32/fastpin_arm_stm32.h | 62 +++++++++++++++++++++---- src/platforms/arm/stm32/led_sysdefs_arm_stm32.h | 13 +++++- 5 files changed, 80 insertions(+), 20 deletions(-) diff --git a/src/led_sysdefs.h b/src/led_sysdefs.h index 8ee568bf..36be2cdd 100644 --- a/src/led_sysdefs.h +++ b/src/led_sysdefs.h @@ -24,7 +24,7 @@ #elif defined(__SAM3X8E__) // Include sam/due headers #include "platforms/arm/sam/led_sysdefs_arm_sam.h" -#elif defined(STM32F10X_MD) || defined(__STM32F1__) +#elif defined(STM32F10X_MD) || defined(__STM32F1__) || defined(STM32F2XX) #include "platforms/arm/stm32/led_sysdefs_arm_stm32.h" #elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) || defined(__SAMD51G19A__) || defined(__SAMD51J19A__) #include "platforms/arm/d21/led_sysdefs_arm_d21.h" diff --git a/src/platforms.h b/src/platforms.h index 7969c9e4..d3ecfc56 100644 --- a/src/platforms.h +++ b/src/platforms.h @@ -24,7 +24,7 @@ #elif defined(__SAM3X8E__) // Include sam/due headers #include "platforms/arm/sam/fastled_arm_sam.h" -#elif defined(STM32F10X_MD) || defined(__STM32F1__) +#elif defined(STM32F10X_MD) || defined(__STM32F1__) || defined(STM32F2XX) #include "platforms/arm/stm32/fastled_arm_stm32.h" #elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) #include "platforms/arm/d21/fastled_arm_d21.h" diff --git a/src/platforms/arm/stm32/clockless_arm_stm32.h b/src/platforms/arm/stm32/clockless_arm_stm32.h index 0ac8a5d4..d87b78c6 100644 --- a/src/platforms/arm/stm32/clockless_arm_stm32.h +++ b/src/platforms/arm/stm32/clockless_arm_stm32.h @@ -7,6 +7,13 @@ FASTLED_NAMESPACE_BEGIN #define FASTLED_HAS_CLOCKLESS 1 +#if defined(STM32F2XX) +// The photon runs faster than the others +#define ADJ 8 +#else +#define ADJ 20 +#endif + template class ClocklessController : public CPixelLEDController { typedef typename FastPin::port_ptr_t data_ptr_t; @@ -23,7 +30,7 @@ public: mPort = FastPin::port(); } - virtual uint16_t getMaxRefreshRate() const { return 400; } + virtual uint16_t getMaxRefreshRate() const { return 400; } protected: virtual void showPixels(PixelController & pixels) { @@ -39,28 +46,28 @@ protected: template __attribute__ ((always_inline)) inline static void writeBits(register uint32_t & next_mark, register data_ptr_t port, register data_t hi, register data_t lo, register uint8_t & b) { for(register uint32_t i = BITS-1; i > 0; --i) { - while(_CYCCNT < (T1+T2+T3-20)); + while(_CYCCNT < (T1+T2+T3-ADJ)); FastPin::fastset(port, hi); _CYCCNT = 4; if(b&0x80) { - while(_CYCCNT < (T1+T2-20)); + while(_CYCCNT < (T1+T2-ADJ)); FastPin::fastset(port, lo); } else { - while(_CYCCNT < (T1-10)); + while(_CYCCNT < (T1-ADJ/2)); FastPin::fastset(port, lo); } b <<= 1; } - while(_CYCCNT < (T1+T2+T3-20)); + while(_CYCCNT < (T1+T2+T3-ADJ)); FastPin::fastset(port, hi); _CYCCNT = 4; if(b&0x80) { - while(_CYCCNT < (T1+T2-20)); + while(_CYCCNT < (T1+T2-ADJ)); FastPin::fastset(port, lo); } else { - while(_CYCCNT < (T1-10)); + while(_CYCCNT < (T1-ADJ/2)); FastPin::fastset(port, lo); } } diff --git a/src/platforms/arm/stm32/fastpin_arm_stm32.h b/src/platforms/arm/stm32/fastpin_arm_stm32.h index bc69912c..548fdc9d 100644 --- a/src/platforms/arm/stm32/fastpin_arm_stm32.h +++ b/src/platforms/arm/stm32/fastpin_arm_stm32.h @@ -35,9 +35,14 @@ public: inline static void setOutput() { pinMode(PIN, OUTPUT); } // TODO: perform MUX config { _PDDR::r() |= _MASK; } inline static void setInput() { pinMode(PIN, INPUT); } // TODO: preform MUX config { _PDDR::r() &= ~_MASK; } +#if defined(STM32F2XX) + inline static void hi() __attribute__ ((always_inline)) { _GPIO::r()->BSRRL = _MASK; } + inline static void lo() __attribute__ ((always_inline)) { _GPIO::r()->BSRRH = _MASK; } +#else inline static void hi() __attribute__ ((always_inline)) { _GPIO::r()->BSRR = _MASK; } inline static void lo() __attribute__ ((always_inline)) { _GPIO::r()->BRR = _MASK; } // inline static void lo() __attribute__ ((always_inline)) { _GPIO::r()->BSRR = (_MASK<<16); } +#endif inline static void set(register port_t val) __attribute__ ((always_inline)) { _GPIO::r()->ODR = val; } inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); } @@ -51,25 +56,37 @@ public: inline static port_t hival() __attribute__ ((always_inline)) { return _GPIO::r()->ODR | _MASK; } inline static port_t loval() __attribute__ ((always_inline)) { return _GPIO::r()->ODR & ~_MASK; } inline static port_ptr_t port() __attribute__ ((always_inline)) { return &_GPIO::r()->ODR; } + +#if defined(STM32F2XX) + inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &_GPIO::r()->BSRRL; } + inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &_GPIO::r()->BSRRH; } +#else inline static port_ptr_t sport() __attribute__ ((always_inline)) { return &_GPIO::r()->BSRR; } inline static port_ptr_t cport() __attribute__ ((always_inline)) { return &_GPIO::r()->BRR; } +#endif + inline static port_t mask() __attribute__ ((always_inline)) { return _MASK; } }; -#if defined(STM32F10X_MD) + #define _R(T) struct __gen_struct_ ## T +#define _FL_DEFPIN(PIN, BIT, L) template<> class FastPin : public _ARMPIN {}; + +#if defined(STM32F10X_MD) #define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline volatile GPIO_TypeDef * r() { return T; } }; #define _FL_IO(L,C) _RD32(GPIO ## L); _FL_DEFINE_PORT3(L, C, _R(GPIO ## L)); + #elif defined(__STM32F1__) -#define _R(T) struct __gen_struct_ ## T #define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline gpio_reg_map* r() { return T->regs; } }; -#define _FL_IO(L,C) _RD32(GPIO ## L); _FL_DEFINE_PORT3(L, C, _R(GPIO ## L)); +#define _FL_IO(L,C) _RD32(GPIO ## L); _FL_DEFINE_PORT3(L, C, _R(GPIO ## L)); + +#elif defined(STM32F2XX) +#define _RD32(T) struct __gen_struct_ ## T { static __attribute__((always_inline)) inline volatile GPIO_TypeDef * r() { return T; } }; +#define _FL_IO(L,C) _RD32(GPIO ## L); #else #error "Platform not supported" #endif -#define _FL_DEFPIN(PIN, BIT, L) template<> class FastPin : public _ARMPIN {}; - #ifdef GPIOA _FL_IO(A,0); #endif @@ -93,7 +110,36 @@ _FL_IO(G,6); #endif // Actual pin definitions -#if defined(SPARK) // Sparkfun STM32F103 based board +#if defined(STM32F2XX) // Photon Particle + +// https://github.com/focalintent/FastLED-Sparkcore/blob/master/firmware/fastpin_arm_stm32.h +#define MAX_PIN 20 +_FL_DEFPIN(0, 7, B); +_FL_DEFPIN(1, 6, B); +_FL_DEFPIN(2, 5, B); +_FL_DEFPIN(3, 4, B); +_FL_DEFPIN(4, 3, B); +_FL_DEFPIN(5, 15, A); +_FL_DEFPIN(6, 14, A); +_FL_DEFPIN(7, 13, A); +_FL_DEFPIN(10, 5, C); +_FL_DEFPIN(11, 3, C); +_FL_DEFPIN(12, 2, C); +_FL_DEFPIN(13, 5, A); +_FL_DEFPIN(14, 6, A); +_FL_DEFPIN(15, 7, A); +_FL_DEFPIN(16, 4, A); +_FL_DEFPIN(17, 0, A); +_FL_DEFPIN(18, 10, A); +_FL_DEFPIN(19, 9, A); +_FL_DEFPIN(20, 7, C); + +#define SPI_DATA 15 +#define SPI_CLOCK 13 + +#define HAS_HARDWARE_PIN_SUPPORT + +#elif defined(SPARK) // Sparkfun STM32F103 based board #define MAX_PIN 19 _FL_DEFPIN(0, 7, B); @@ -122,9 +168,7 @@ _FL_DEFPIN(19, 2, A); #define HAS_HARDWARE_PIN_SUPPORT -#endif // SPARK - -#if defined(__STM32F1__) // Generic STM32F103 aka "Blue Pill" +#elif defined(__STM32F1__) // Generic STM32F103 aka "Blue Pill" #define MAX_PIN 46 diff --git a/src/platforms/arm/stm32/led_sysdefs_arm_stm32.h b/src/platforms/arm/stm32/led_sysdefs_arm_stm32.h index afcf1785..b58779ff 100644 --- a/src/platforms/arm/stm32/led_sysdefs_arm_stm32.h +++ b/src/platforms/arm/stm32/led_sysdefs_arm_stm32.h @@ -1,7 +1,7 @@ #ifndef __INC_LED_SYSDEFS_ARM_SAM_H #define __INC_LED_SYSDEFS_ARM_SAM_H -#if defined(STM32F10X_MD) +#if defined(STM32F10X_MD) || defined(STM32F2XX) #include @@ -55,7 +55,16 @@ typedef volatile uint8_t RwReg; /**< Read-Write 8-bit register (volatile u #define FASTLED_NO_PINMAP -#ifndef F_CPU +#if defined(STM32F2XX) +#define F_CPU 120000000 +#else #define F_CPU 72000000 #endif + +#if defined(STM32F2XX) +// Photon doesn't provide yield +#define FASTLED_NEEDS_YIELD +extern "C" void yield(); #endif + +#endif // defined(STM32F10X_MD) || defined(STM32F2XX) -- cgit v1.2.3