Skip to content

Commit 01fd2eb

Browse files
committed
Use static asserts to give better error messaging about not enough clock cycles and bad pin choices in environments that support C++11.
1 parent ccf1226 commit 01fd2eb

File tree

13 files changed

+89
-68
lines changed

13 files changed

+89
-68
lines changed

FastLED.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <stdint.h>
3232

33+
#include "cpp_compat.h"
34+
3335
#include "fastled_config.h"
3436
#include "led_sysdefs.h"
3537

chipsets.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -481,87 +481,51 @@ class GW6205Controller800Khz : public ClocklessController<DATA_PIN, 2 * FMUL, 4
481481
// GW6205@400khz - 800ns, 800ns, 800ns
482482
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
483483
class GW6205Controller400Khz : public ClocklessController<DATA_PIN, NS(800), NS(800), NS(800), RGB_ORDER, 4> {};
484-
#if NO_TIME(800, 800, 800)
485-
#warning "Not enough clock cycles available for the GW6205@400khz"
486-
#endif
487484

488485
// GW6205@400khz - 400ns, 400ns, 400ns
489486
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
490487
class GW6205Controller800Khz : public ClocklessController<DATA_PIN, NS(400), NS(400), NS(400), RGB_ORDER, 4> {};
491-
#if NO_TIME(400, 400, 400)
492-
#warning "Not enough clock cycles available for the GW6205@400khz"
493-
#endif
494488

495489
// UCS1903 - 500ns, 1500ns, 500ns
496490
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
497491
class UCS1903Controller400Khz : public ClocklessController<DATA_PIN, NS(500), NS(1500), NS(500), RGB_ORDER> {};
498-
#if NO_TIME(500, 1500, 500)
499-
#warning "Not enough clock cycles available for the UCS1903@400khz"
500-
#endif
501492

502493
// UCS1903B - 400ns, 450ns, 450ns
503494
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
504495
class UCS1903BController800Khz : public ClocklessController<DATA_PIN, NS(400), NS(450), NS(450), RGB_ORDER> {};
505-
#if NO_TIME(400, 450, 450)
506-
#warning "Not enough clock cycles available for the UCS1903B@800khz"
507-
#endif
508496

509497
// UCS1904 - 400ns, 400ns, 450ns
510498
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
511499
class UCS1904Controller800Khz : public ClocklessController<DATA_PIN, NS(400), NS(400), NS(450), RGB_ORDER> {};
512-
#if NO_TIME(400, 400, 450)
513-
#warning "Not enough clock cycles available for the UCS1904@800khz"
514-
#endif
515500

516501
// TM1809 - 350ns, 350ns, 550ns
517502
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
518503
class TM1809Controller800Khz : public ClocklessController<DATA_PIN, NS(350), NS(350), NS(450), RGB_ORDER> {};
519-
#if NO_TIME(350, 350, 550)
520-
#warning "Not enough clock cycles available for the TM1809"
521-
#endif
522504

523505
// WS2811 - 320ns, 320ns, 640ns
524506
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
525507
class WS2811Controller800Khz : public ClocklessController<DATA_PIN, NS(320), NS(320), NS(640), RGB_ORDER> {};
526-
#if NO_TIME(320, 320, 640)
527-
#warning "Not enough clock cycles available for the WS2811 (800khz)"
528-
#endif
529508

530509
// WS2812 - 250ns, 625ns, 375ns
531510
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
532511
class WS2812Controller800Khz : public ClocklessController<DATA_PIN, NS(250), NS(625), NS(375), RGB_ORDER> {};
533-
#if NO_TIME(250, 625, 375)
534-
#warning "Not enough clock cycles available for the WS2812 (800khz)"
535-
#endif
536512

537513
// WS2811@400khz - 800ns, 800ns, 900ns
538514
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
539515
class WS2811Controller400Khz : public ClocklessController<DATA_PIN, NS(800), NS(800), NS(900), RGB_ORDER> {};
540-
#if NO_TIME(800, 800, 900)
541-
#warning "Not enough clock cycles available for the WS2811 (400Khz)"
542-
#endif
543516

544517
// 750NS, 750NS, 750NS
545518
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
546519
class TM1803Controller400Khz : public ClocklessController<DATA_PIN, NS(700), NS(1100), NS(700), RGB_ORDER> {};
547-
#if NO_TIME(750, 750, 750)
548-
#warning "Not enough clock cycles available for the TM1803"
549-
#endif
550520

551521
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
552522
class TM1829Controller800Khz : public ClocklessController<DATA_PIN, NS(340), NS(340), NS(550), RGB_ORDER, 0, true, 500> {};
553523

554524
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
555525
class TM1829Controller1600Khz : public ClocklessController<DATA_PIN, NS(100), NS(300), NS(200), RGB_ORDER, 0, true, 500> {};
556-
#if NO_TIME(100, 300, 200)
557-
#warning "Not enough clock cycles available for [email protected]"
558-
#endif
559526

560527
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
561528
class LPD1886Controller1250Khz : public ClocklessController<DATA_PIN, NS(200), NS(400), NS(200), RGB_ORDER, 4> {};
562-
#if NO_TIME(200,400,200)
563-
#warning "Not enough clock cycles for LPD1886"
564-
#endif
565529

566530
template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
567531
class SK6812Controller : public ClocklessController<DATA_PIN, NS(300), NS(300), NS(600), RGB_ORDER> {};

cpp_compat.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __INC_CPP_COMPAT_H
2+
#define __INC_CPP_COMPAT_H
3+
4+
#if __cplusplus <= 199711L
5+
6+
#define static_assert(expression, message)
7+
#define constexpr const
8+
9+
#else
10+
11+
// things that we can turn on if we're in a C++11 environment
12+
#endif
13+
14+
#endif

fastpin.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class InputPin : public Pin {
154154
///
155155
/// Note that these classes are all static functions. So the proper usage is Pin<13>::hi(); or such. Instantiating objects is not recommended,
156156
/// as passing Pin objects around will likely -not- have the effect you're expecting.
157+
#ifdef FASTLED_FORCE_SOFTWARE_PINS
157158
template<uint8_t PIN> class FastPin {
158159
static RwReg sPinMask;
159160
static volatile RwReg *sPort;
@@ -195,6 +196,43 @@ template<uint8_t PIN> RwReg FastPin<PIN>::sPinMask;
195196
template<uint8_t PIN> volatile RwReg *FastPin<PIN>::sPort;
196197
template<uint8_t PIN> volatile RoReg *FastPin<PIN>::sInPort;
197198

199+
#else
200+
201+
template<uint8_t PIN> class FastPin {
202+
constexpr static bool validpin() { return false; }
203+
204+
static_assert(validpin(), "Invalid pin specified");
205+
206+
static void _init() {
207+
}
208+
public:
209+
typedef volatile RwReg * port_ptr_t;
210+
typedef RwReg port_t;
211+
212+
inline static void setOutput() { }
213+
inline static void setInput() { }
214+
215+
inline static void hi() __attribute__ ((always_inline)) { }
216+
inline static void lo() __attribute__ ((always_inline)) { }
217+
218+
inline static void strobe() __attribute__ ((always_inline)) { }
219+
220+
inline static void toggle() __attribute__ ((always_inline)) { }
221+
222+
inline static void hi(register port_ptr_t port) __attribute__ ((always_inline)) { }
223+
inline static void lo(register port_ptr_t port) __attribute__ ((always_inline)) { }
224+
inline static void set(register port_t val) __attribute__ ((always_inline)) { }
225+
226+
inline static void fastset(register port_ptr_t port, register port_t val) __attribute__ ((always_inline)) { }
227+
228+
static port_t hival() __attribute__ ((always_inline)) { return 0; }
229+
static port_t loval() __attribute__ ((always_inline)) { return 0;}
230+
static port_ptr_t port() __attribute__ ((always_inline)) { return NULL; }
231+
static port_t mask() __attribute__ ((always_inline)) { return 0; }
232+
};
233+
234+
#endif
235+
198236
template<uint8_t PIN> class FastPinBB : public FastPin<PIN> {};
199237

200238
typedef volatile uint32_t & reg32_t;

platforms/arm/d21/fastpin_arm_d21.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ template<uint8_t PIN, uint8_t _BIT, uint32_t _MASK, int _GRP> class _ARMPIN {
6060

6161
#define _IO32(L) _RD32(GPIO ## L)
6262

63-
#define _DEFPIN_ARM(PIN, L, BIT) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1 << BIT, L> {};
63+
#define _DEFPIN_ARM(PIN, L, BIT) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1 << BIT, L> { constexpr static bool validpin() { return false; } };
6464

6565
// Actual pin definitions
6666
#if defined(ARDUINO_SAMD_ZERO)

platforms/arm/k20/fastpin_arm_k20.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ template<uint8_t PIN, int _BIT, typename _PDOR, typename _PSOR, typename _PCOR,
8181
#define _IO32(L) _RD32(GPIO ## L ## _PDOR); _RD32(GPIO ## L ## _PSOR); _RD32(GPIO ## L ## _PCOR); _RD32(GPIO ## L ## _PTOR); _RD32(GPIO ## L ## _PDIR); _RD32(GPIO ## L ## _PDDR);
8282

8383
#define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, 1 << BIT, _R(GPIO ## L ## _PDOR), _R(GPIO ## L ## _PSOR), _R(GPIO ## L ## _PCOR), \
84-
_R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> {}; \
84+
_R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> { constexpr static bool validpin() { return false; } }; \
8585
template<> class FastPinBB<PIN> : public _ARMPIN_BITBAND<PIN, BIT, _R(GPIO ## L ## _PDOR), _R(GPIO ## L ## _PSOR), _R(GPIO ## L ## _PCOR), \
86-
_R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> {};
86+
_R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> { constexpr static bool validpin() { return false; } };
8787

8888
// Actual pin definitions
8989
#if defined(FASTLED_TEENSY3) && defined(CORE_TEENSY)

platforms/arm/kl26/fastpin_arm_kl26.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ template<int BIT> static __attribute__((always_inline)) inline ptr_reg32_t rx()
5353
#define _IO32(L) _RD32(FGPIO ## L ## _PDOR); _RD32(FGPIO ## L ## _PSOR); _RD32(FGPIO ## L ## _PCOR); _RD32(GPIO ## L ## _PTOR); _RD32(FGPIO ## L ## _PDIR); _RD32(FGPIO ## L ## _PDDR);
5454

5555
#define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, 1 << BIT, _R(FGPIO ## L ## _PDOR), _R(FGPIO ## L ## _PSOR), _R(FGPIO ## L ## _PCOR), \
56-
_R(GPIO ## L ## _PTOR), _R(FGPIO ## L ## _PDIR), _R(FGPIO ## L ## _PDDR)> {}; \
56+
_R(GPIO ## L ## _PTOR), _R(FGPIO ## L ## _PDIR), _R(FGPIO ## L ## _PDDR)> { constexpr static bool validpin() { return false; } }; \
5757
/* template<> class FastPinBB<PIN> : public _ARMPIN_BITBAND<PIN, BIT, _R(GPIO ## L ## _PDOR), _R(GPIO ## L ## _PSOR), _R(GPIO ## L ## _PCOR), \
5858
_R(GPIO ## L ## _PTOR), _R(GPIO ## L ## _PDIR), _R(GPIO ## L ## _PDDR)> {}; */
5959

platforms/arm/nrf51/fastpin_arm_nrf51.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ template<uint8_t PIN, uint32_t _MASK> class _ARMPIN {
9898
};
9999

100100

101-
#define _DEFPIN_ARM(PIN) template<> class FastPin<PIN> : public _ARMPIN<PIN, 1 << PIN> {};
101+
#define _DEFPIN_ARM(PIN) template<> class FastPin<PIN> : public _ARMPIN<PIN, 1 << PIN> { constexpr static bool validpin() { return false; } };
102102
#endif
103103

104104
// Actual pin definitions

platforms/arm/sam/fastpin_arm_sam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ template<uint8_t PIN, uint32_t _BIT, typename _PDOR, typename _PSOR, typename _P
8181
#define DUE_IO32(L) _RD32(REG_PIO ## L ## _ODSR); _RD32(REG_PIO ## L ## _SODR); _RD32(REG_PIO ## L ## _CODR); _RD32(REG_PIO ## L ## _OER);
8282

8383
#define _DEFPIN_DUE(PIN, BIT, L) template<> class FastPin<PIN> : public _DUEPIN<PIN, 1 << BIT, _R(REG_PIO ## L ## _ODSR), _R(REG_PIO ## L ## _SODR), _R(REG_PIO ## L ## _CODR), \
84-
_R(GPIO ## L ## _OER)> {}; \
84+
_R(GPIO ## L ## _OER)> { constexpr static bool validpin() { return false; } }; \
8585
template<> class FastPinBB<PIN> : public _DUEPIN_BITBAND<PIN, BIT, _R(REG_PIO ## L ## _ODSR), _R(REG_PIO ## L ## _SODR), _R(REG_PIO ## L ## _CODR), \
86-
_R(GPIO ## L ## _OER)> {};
86+
_R(GPIO ## L ## _OER)> { constexpr static bool validpin() { return false; } };
8787

8888
#if defined(__SAM3X8E__)
8989

platforms/arm/stm32/fastpin_arm_stm32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ template<uint8_t PIN, uint8_t _BIT, uint32_t _MASK, typename _GPIO> class _ARMPI
6060

6161
#define _IO32(L) _RD32(GPIO ## L)
6262

63-
#define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1 << BIT, _R(GPIO ## L)> {};
63+
#define _DEFPIN_ARM(PIN, BIT, L) template<> class FastPin<PIN> : public _ARMPIN<PIN, BIT, 1 << BIT, _R(GPIO ## L)> { constexpr static bool validpin() { return false; } };
6464

6565
// Actual pin definitions
6666
#if defined(SPARK)

0 commit comments

Comments
 (0)