FastLED 3.9.15
Loading...
Searching...
No Matches
fastpin_base.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include "platforms/is_platform.h"
11#include "fl/stl/noexcept.h"
13
17
19FL_DISABLE_WARNING(ignored-qualifiers)
20#ifdef FL_IS_ESP32
21// Get rid of the endless volatile warnings in ESP32
22FL_DISABLE_WARNING(pragmas)
24#endif
25
26namespace fl {
27
29//
30// Pin access class - needs to tune for various platforms (naive fallback solution?)
31//
33
38struct ValidPinBase {
41 static constexpr bool validpin() FL_NOEXCEPT { return true; }
42};
43
45class Selectable {
46public:
47 #ifndef FL_IS_AVR
48 virtual ~Selectable() FL_NOEXCEPT {}
49 #endif
50 virtual void select() FL_NOEXCEPT = 0;
51 virtual void release() FL_NOEXCEPT = 0;
52 virtual bool isSelected() FL_NOEXCEPT = 0;
53};
54
69#ifdef FASTLED_FORCE_SOFTWARE_PINS
70template<fl::u8 PIN> class FastPin {
71 static RwReg sPinMask;
72 static volatile RwReg *sPort;
73 static volatile RoReg *sInPort;
74 static void _init() {
75#if !defined(FASTLED_NO_PINMAP)
76 sPinMask = digitalPinToBitMask(PIN);
77 sPort = portOutputRegister(digitalPinToPort(PIN));
78 sInPort = portInputRegister(digitalPinToPort(PIN));
79#endif
80 }
81
82public:
83 typedef volatile RwReg * port_ptr_t;
84 typedef RwReg port_t;
85
87 inline static void setOutput() { _init(); pinMode(PIN, PinMode::Output); }
89 inline static void setInput() { _init(); pinMode(PIN, PinMode::Input); }
90
92 inline static void hi() __attribute__ ((always_inline)) { *sPort |= sPinMask; }
94 inline static void lo() __attribute__ ((always_inline)) { *sPort &= ~sPinMask; }
95
97 inline static void strobe() __attribute__ ((always_inline)) { toggle(); toggle(); }
98
100 inline static void toggle() __attribute__ ((always_inline)) { *sInPort = sPinMask; }
101
103 inline static void hi(FASTLED_REGISTER port_ptr_t port) __attribute__ ((always_inline)) { *port |= sPinMask; }
105 inline static void lo(FASTLED_REGISTER port_ptr_t port) __attribute__ ((always_inline)) { *port &= ~sPinMask; }
107 inline static void set(FASTLED_REGISTER port_t val) __attribute__ ((always_inline)) { *sPort = val; }
108
110 inline static void fastset(FASTLED_REGISTER port_ptr_t port, FASTLED_REGISTER port_t val) __attribute__ ((always_inline)) { *port = val; }
111
113 static port_t hival() __attribute__ ((always_inline)) { return *sPort | sPinMask; }
115 static port_t loval() __attribute__ ((always_inline)) { return *sPort & ~sPinMask; }
117 static port_ptr_t port() __attribute__ ((always_inline)) { return sPort; }
119 static port_t mask() __attribute__ ((always_inline)) { return sPinMask; }
120};
121
122template<fl::u8 PIN> RwReg FastPin<PIN>::sPinMask;
123template<fl::u8 PIN> volatile RwReg *FastPin<PIN>::sPort;
124template<fl::u8 PIN> volatile RoReg *FastPin<PIN>::sInPort;
125
126#else
127
128template<fl::u8 PIN> class FastPin {
129 // This is a default implementation. If you are hitting this then FastPin<> is either:
130 // 1) Not defined -or-
131 // 2) Not part of the set of defined FastPin<> specializations for your platform
132 // You need to define a FastPin<> specialization
133 // or change what get's included for your particular build target.
134 // Keep in mind that these messages are cryptic, so it's best to define an invalid in type.
135#ifdef FASTLED_ALL_PINS_VALID
136 constexpr static bool validpin() FL_NOEXCEPT { return true; }
137#else
138 constexpr static bool validpin() { return false; }
139#endif
140 constexpr static bool LowSpeedOnlyRecommended() FL_NOEXCEPT { // Some implementations assume this exists.
141 // Caller must always determine if high speed use if allowed on a given pin,
142 // because it depends on more than just the chip packaging ... it depends on entire board (and even system) design.
143 return false; // choosing default to be FALSE, to allow users to ATTEMPT to use high-speed on pins where support is not known
144 }
145
146 FL_STATIC_ASSERT(validpin(), "This pin has been marked as an invalid pin, common reasons includes it being a ground pin, read only, or too noisy (e.g. hooked up to the uart).");
147
148 static void _init() FL_NOEXCEPT { }
149
150public:
151 typedef volatile RwReg * port_ptr_t;
152 typedef RwReg port_t;
153
155 inline static void setOutput() FL_NOEXCEPT { }
157 inline static void setInput() FL_NOEXCEPT { }
158
160 inline static void hi() FL_NOEXCEPT __attribute__ ((always_inline)) { }
162 inline static void lo() FL_NOEXCEPT __attribute__ ((always_inline)) { }
163
165 inline static void strobe() FL_NOEXCEPT __attribute__ ((always_inline)) { }
166
168 inline static void toggle() FL_NOEXCEPT __attribute__ ((always_inline)) { }
169
171 inline static void hi(FASTLED_REGISTER port_ptr_t port) FL_NOEXCEPT __attribute__ ((always_inline)) {
172 FASTLED_UNUSED(port);
173 }
175 inline static void lo(FASTLED_REGISTER port_ptr_t port) FL_NOEXCEPT __attribute__ ((always_inline)) {
176 FASTLED_UNUSED(port);
177 }
179 inline static void set(FASTLED_REGISTER port_t val) FL_NOEXCEPT __attribute__ ((always_inline)) {
180 FASTLED_UNUSED(val);
181 }
182
184 inline static void fastset(FASTLED_REGISTER port_ptr_t port, FASTLED_REGISTER port_t val) FL_NOEXCEPT __attribute__ ((always_inline)) {
185 FASTLED_UNUSED(port);
186 FASTLED_UNUSED(val);
187 }
188
190 static port_t hival() FL_NOEXCEPT __attribute__ ((always_inline)) { return 0; }
192 static port_t loval() FL_NOEXCEPT __attribute__ ((always_inline)) { return 0;}
194 static port_ptr_t port() FL_NOEXCEPT __attribute__ ((always_inline)) { return nullptr; }
196 static port_t mask() FL_NOEXCEPT __attribute__ ((always_inline)) { return 0; }
197};
198
199#endif
200
204template<fl::u8 PIN> class FastPinBB : public FastPin<PIN> {};
205
206typedef volatile fl::u32 & reg32_t;
207typedef volatile fl::u32 * ptr_reg32_t;
208
211template<fl::u8 port> struct __FL_PORT_INFO {
213 static bool hasPort() FL_NOEXCEPT { return 0; }
215 static const char *portName() FL_NOEXCEPT { return "--"; }
217 static const void *portAddr() FL_NOEXCEPT { return nullptr; }
218};
219
220
227#define _FL_DEFINE_PORT(L, BASE) template<> struct __FL_PORT_INFO<L> { \
228 typedef BASE __t_baseType; \
229 static bool hasPort() { return 1; } \
230 static const char *portName() { return #L; } \
231 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
232
243#define _FL_DEFINE_PORT3(L, LC, BASE) template<> struct __FL_PORT_INFO<LC> { \
244 typedef BASE __t_baseType; \
245 static bool hasPort() { return 1; } \
246 static const char *portName() { return #L; } \
247 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
248
249} // namespace fl
250
252
bool toggle
Definition Blur.ino:12
#define PIN
Definition PinMode.ino:7
fl::FastPinBB< PIN > FastPinBB
Definition fastpin.h:20
fl::FastPin< PIN > FastPin
Definition fastpin.h:19
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_DISABLE_WARNING(warning)
#define FASTLED_REGISTER
#define FL_STATIC_ASSERT(...)
#define FL_DISABLE_WARNING_VOLATILE
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
#define FASTLED_UNUSED(x)
#define FL_DISABLE_WARNING_DEPRECATED_REGISTER
#define FL_NOEXCEPT
Portable compile-time assertion wrapper.