Mixin base class that provides the default validpin() implementation for explicitly declared pins. All platform-specific pin classes (_ARMPIN, _ESPPIN, etc.) should inherit from this to indicate that explicitly defined pins are valid by default. Undefined pins use the default FastPin<> template which returns false.
All explicitly declared pins are valid by default Platforms can override this in specific cases to mark pins as invalid (e.g., ground pins, UART pins)
Abstract class for "selectable" things
< Select this object
< Release this object
< Check if this object is currently selected
The simplest level of Pin class. This relies on runtime functions during initialization to get the port/pin mask for the pin. Most of the accesses involve references to these static globals that get set up. This won't be the fastest set of pin operations, but it will provide pin level access on pretty much all Arduino environments. In addition, it includes some methods to help optimize access in various ways. Namely, the versions of hi(), lo(), and fastset() that take the port register as a passed in register variable (saving a global dereference), since these functions are aggressively inlined, that can help collapse out a lot of extraneous memory loads/dereferences.
In addition, if, while writing a bunch of data to a pin, you know no other pins will be getting written to, you can get/cache a value of the pin's port register and use that to do a full set to the register. This results in one being able to simply do a store to the register, vs. the load, and/or, and store that would be done normally.
There are platform specific instantiations of this class that provide direct i/o register access to pins for much higher speed pin twiddling.
Note that these classes are all static functions. So the proper usage is Pin<13>::hi(); or such. Instantiating objects is not recommended, as passing Pin objects around will likely -not- have the effect you're expecting.
<
<
FastPin implementation for bit-banded access. Only for MCUs that support bitbanding.
- Note
- This bitband class is optional!
< Reference to a 32-bit register, volatile
< Pointer to a 32-bit register, volatile
Utility template for tracking down information about pins and ports
- Template Parameters
-
| port | the port to check information for |
Checks whether a port exists
Gets the name of the port, as a C-string
Gets the raw address of the port
Macro to create the instantiations for defined ports. We're going to abuse this later for auto discovery of pin/port mappings for new variants. Use this for ports that are numeric in nature, e.g. GPIO0, GPIO1, etc.
- Parameters
-
| L | the number of the port |
| BASE | the data type for the register |
Macro to create the instantiations for defined ports. We're going to abuse this later for auto discovery of pin/port mappings for new variants. Use this for ports that are letters. The first parameter will be the letter, the second parameter will be an integer/counter of some kind. This is because attempts to turn macro parameters into character constants break in some compilers.
- Parameters
-
| L | the letter of the port |
| LC | an integer counter |
| BASE | the data type for the register |
Definition at line 34 of file fastpin_base.h.
41 {
42
44
45
46
48
53struct ValidPinBase {
56 static constexpr bool validpin()
FL_NO_EXCEPT {
return true; }
57};
58
60class Selectable {
61public:
62 #ifndef FL_IS_AVR
64 #endif
68};
69
84
85
86#if defined(FASTLED_FORCE_SOFTWARE_PINS) && \
87 (defined(FASTLED_NO_PINMAP) || defined(FL_IS_ESP32) || defined(FL_IS_ESP8266))
88#define FL_FASTPIN_HAS_NO_PINMAP
90#if defined(FL_IS_ESP32) || defined(FL_IS_ESP8266) || \
91 defined(FL_IS_ARM_LPC_845) || defined(FL_IS_ARM_LPC_804)
92
93
94template<fl::u8 PIN>
class FastPin :
public NoPinMapPin<PIN> {
95public:
96 static constexpr bool validpin()
FL_NO_EXCEPT {
return false; }
99 }
100};
101#else
102template<fl::u8 PIN>
class FastPin :
public NoPinMapPin<PIN> {};
103#endif
104#elif defined(FASTLED_FORCE_SOFTWARE_PINS)
105#define FL_FASTPIN_HAS_RUNTIME_PORT
106template<fl::u8 PIN>
class FastPin {
107 static RwReg sPinMask;
108 static volatile RwReg *sPort;
109 static volatile RoReg *sInPort;
110 static void _init() {
111 sPinMask = digitalPinToBitMask(
PIN);
112 sPort = portOutputRegister(digitalPinToPort(
PIN));
113 sInPort = portInputRegister(digitalPinToPort(
PIN));
114 }
115
116public:
117 typedef volatile RwReg * port_ptr_t;
118 typedef RwReg port_t;
119
121 inline static void setOutput() { _init(); (
fl::pinMode)(
PIN, PinMode::Output); }
123 inline static void setInput() { _init(); (
fl::pinMode)(
PIN, PinMode::Input); }
124
126 inline static void hi() __attribute__ ((always_inline)) { *sPort |= sPinMask; }
128 inline static void lo() __attribute__ ((always_inline)) { *sPort &= ~sPinMask; }
129
131 inline static void strobe() __attribute__ ((always_inline)) {
toggle();
toggle(); }
132
134 inline static void toggle() __attribute__ ((always_inline)) {
135#ifdef FL_IS_AVR
136 *sInPort = sPinMask;
137#else
138 *sPort ^= sPinMask;
139#endif
140 }
141
143 inline static void hi(
FASTLED_REGISTER port_ptr_t port) __attribute__ ((always_inline)) { *port |= sPinMask; }
145 inline static void lo(
FASTLED_REGISTER port_ptr_t port) __attribute__ ((always_inline)) { *port &= ~sPinMask; }
147 inline static void set(
FASTLED_REGISTER port_t val) __attribute__ ((always_inline)) { *sPort = val; }
148
151
153 static port_t hival() __attribute__ ((always_inline)) { return *sPort | sPinMask; }
155 static port_t loval() __attribute__ ((always_inline)) { return *sPort & ~sPinMask; }
157 static port_ptr_t port() __attribute__ ((always_inline)) { return sPort; }
159 static port_t mask() __attribute__ ((always_inline)) { return sPinMask; }
160};
161
162template<fl::u8 PIN> RwReg FastPin<PIN>::sPinMask;
163template<fl::u8 PIN> volatile RwReg *FastPin<PIN>::sPort;
164template<fl::u8 PIN> volatile RoReg *FastPin<PIN>::sInPort;
165
166#else
167
168template<fl::u8 PIN>
class FastPin {
169
170
171
172
173
174
175#ifdef FASTLED_ALL_PINS_VALID
176 constexpr static bool validpin()
FL_NO_EXCEPT {
return true; }
177#else
178 constexpr static bool validpin() { return false; }
179#endif
180 constexpr static bool LowSpeedOnlyRecommended()
FL_NO_EXCEPT {
181
182
183 return false;
184 }
185
186 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).");
187
189
190public:
191 typedef volatile RwReg * port_ptr_t;
192 typedef RwReg port_t;
193
198
200 inline static void hi()
FL_NO_EXCEPT __attribute__ ((always_inline)) { }
202 inline static void lo()
FL_NO_EXCEPT __attribute__ ((always_inline)) { }
203
205 inline static void strobe()
FL_NO_EXCEPT __attribute__ ((always_inline)) { }
206
209
213 }
217 }
221 }
222
227 }
228
230 static port_t hival()
FL_NO_EXCEPT __attribute__ ((always_inline)) {
return 0; }
232 static port_t loval()
FL_NO_EXCEPT __attribute__ ((always_inline)) {
return 0;}
234 static port_ptr_t port()
FL_NO_EXCEPT __attribute__ ((always_inline)) {
return nullptr; }
236 static port_t mask()
FL_NO_EXCEPT __attribute__ ((always_inline)) {
return 0; }
237};
238
239#endif
240
245
246typedef volatile fl::u32 & reg32_t;
247typedef volatile fl::u32 * ptr_reg32_t;
248
251template<fl::u8 port> struct __FL_PORT_INFO {
255 static const char *portName()
FL_NO_EXCEPT {
return "--"; }
257 static const void *portAddr()
FL_NO_EXCEPT {
return nullptr; }
258};
259
260
267#define _FL_DEFINE_PORT(L, BASE) template<> struct __FL_PORT_INFO<L> { \
268 typedef BASE __t_baseType; \
269 static bool hasPort() { return 1; } \
270 static const char *portName() { return #L; } \
271 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
272
283#define _FL_DEFINE_PORT3(L, LC, BASE) template<> struct __FL_PORT_INFO<LC> { \
284 typedef BASE __t_baseType; \
285 static bool hasPort() { return 1; } \
286 static const char *portName() { return #L; } \
287 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
288
289}
fl::FastPinBB< PIN > FastPinBB
fl::FastPin< PIN > FastPin
void pinMode(int pin, PinMode mode) FL_NO_EXCEPT
Set pin mode (input, output, pull-up, pull-down)
#define FL_STATIC_ASSERT(...)
#define FASTLED_UNUSED(x)
References FASTLED_REGISTER, FASTLED_UNUSED, FL_DISABLE_WARNING_VOLATILE, FL_NO_EXCEPT, FL_STATIC_ASSERT, PIN, fl::pinMode(), and toggle.