10#pragma GCC diagnostic push
11#pragma GCC diagnostic ignored "-Wignored-qualifiers"
14#pragma GCC diagnostic ignored "-Wpragmas"
15#pragma GCC diagnostic ignored "-Wvolatile"
44#if !defined(FASTLED_NO_PINMAP)
48 volatile RwReg *mPort;
49 volatile RoReg *mInPort;
56 mPinMask = digitalPinToBitMask(mPin);
57 mPort = (
volatile RwReg*)portOutputRegister(digitalPinToPort(mPin));
58 mInPort = (
volatile RoReg*)portInputRegister(digitalPinToPort(mPin));
64 Pin(
int pin) : mPin(pin) { _init(); }
76 inline void setInput() { pinMode(mPin, INPUT); }
79 inline void hi() __attribute__ ((always_inline)) { *mPort |= mPinMask; }
81 inline void lo() __attribute__ ((always_inline)) { *mPort &= ~mPinMask; }
87 inline void toggle() __attribute__ ((always_inline)) { *mInPort = mPinMask; }
98 inline void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *mPort = val; }
106 port_t hival() __attribute__ ((always_inline)) {
return *mPort | mPinMask; }
108 port_t loval() __attribute__ ((always_inline)) {
return *mPort & ~mPinMask; }
112 port_t mask() __attribute__ ((always_inline)) {
return mPinMask; }
119 virtual bool isSelected() {
return (*mPort & mPinMask) == mPinMask; }
140 volatile RwReg *mPort;
141 volatile RoReg *mInPort;
155 Pin(
int pin) : mPin(pin) { _init(); }
160 void setPin(
int pin) { mPin = pin; _init(); }
168 inline void hi() __attribute__ ((always_inline)) { *mPort |= mPinMask; }
169 inline void lo() __attribute__ ((always_inline)) { *mPort &= ~mPinMask; }
172 inline void toggle() __attribute__ ((always_inline)) { *mInPort = mPinMask; }
174 inline void hi(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port |= mPinMask; }
175 inline void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port &= ~mPinMask; }
176 inline void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *mPort = val; }
180 port_t hival() __attribute__ ((always_inline)) {
return *mPort | mPinMask; }
181 port_t loval() __attribute__ ((always_inline)) {
return *mPort & ~mPinMask; }
182 port_ptr_t port() __attribute__ ((always_inline)) {
return mPort; }
183 port_t mask() __attribute__ ((always_inline)) {
return mPinMask; }
185 virtual void select()
override {
hi(); }
186 virtual void release()
override {
lo(); }
187 virtual bool isSelected()
override {
return (*mPort & mPinMask) == mPinMask; }
216#ifdef FASTLED_FORCE_SOFTWARE_PINS
218 static RwReg sPinMask;
219 static volatile RwReg *sPort;
220 static volatile RoReg *sInPort;
221 static void _init() {
222#if !defined(FASTLED_NO_PINMAP)
223 sPinMask = digitalPinToBitMask(PIN);
224 sPort = portOutputRegister(digitalPinToPort(PIN));
225 sInPort = portInputRegister(digitalPinToPort(PIN));
234 inline static void setOutput() { _init(); pinMode(PIN, OUTPUT); }
236 inline static void setInput() { _init(); pinMode(PIN, INPUT); }
239 inline static void hi() __attribute__ ((always_inline)) { *sPort |= sPinMask; }
241 inline static void lo() __attribute__ ((always_inline)) { *sPort &= ~sPinMask; }
247 inline static void toggle() __attribute__ ((always_inline)) { *sInPort = sPinMask; }
252 inline static void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port &= ~sPinMask; }
254 inline static void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *sPort = val; }
260 static port_t hival() __attribute__ ((always_inline)) {
return *sPort | sPinMask; }
262 static port_t loval() __attribute__ ((always_inline)) {
return *sPort & ~sPinMask; }
266 static port_t mask() __attribute__ ((always_inline)) {
return sPinMask; }
275template<u
int8_t PIN>
class FastPin {
279 constexpr static bool validpin() {
return false; }
280 constexpr static bool LowSpeedOnlyRecommended() {
286 static_assert(validpin(),
"Invalid pin specified");
288 static void _init() { }
300 inline static void hi() __attribute__ ((always_inline)) { }
302 inline static void lo() __attribute__ ((always_inline)) { }
305 inline static void strobe() __attribute__ ((always_inline)) { }
308 inline static void toggle() __attribute__ ((always_inline)) { }
311 inline static void hi(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) {
312 FASTLED_UNUSED(
port);
315 inline static void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) {
316 FASTLED_UNUSED(
port);
319 inline static void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) {
325 FASTLED_UNUSED(
port);
330 static port_t hival() __attribute__ ((always_inline)) {
return 0; }
332 static port_t loval() __attribute__ ((always_inline)) {
return 0;}
334 static port_ptr_t port() __attribute__ ((always_inline)) {
return NULL; }
336 static port_t mask() __attribute__ ((always_inline)) {
return 0; }
367#define _FL_DEFINE_PORT(L, BASE) template<> struct __FL_PORT_INFO<L> { \
368 static bool hasPort() { return 1; } \
369 static const char *portName() { return #L; } \
370 typedef BASE __t_baseType; \
371 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
383#define _FL_DEFINE_PORT3(L, LC, BASE) template<> struct __FL_PORT_INFO<LC> { \
384 static bool hasPort() { return 1; } \
385 static const char *portName() { return #L; } \
386 typedef BASE __t_baseType; \
387 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
391#pragma GCC diagnostic pop
central include file for FastLED, defines the CFastLED class/object
FastPin implementation for bit-banded access.
The simplest level of Pin class.
static port_t hival()
Gets the state of the port with this pin HIGH
RwReg port_t
type for a pin read/write register, non-volatile
static void toggle()
Toggle the pin.
static void hi(FASTLED_REGISTER port_ptr_t port)
Set the same pin on another port to HIGH
static port_t loval()
Gets the state of the port with this pin LOW
static void lo(FASTLED_REGISTER port_ptr_t port)
Set the same pin on another port to LOW
static void set(FASTLED_REGISTER port_t val)
Set the state of the output register.
static port_t mask()
Get the pin mask.
volatile RwReg * port_ptr_t
type for a pin read/write register, volatile
static void lo()
Set the pin state to LOW
static port_ptr_t port()
Get the output state of the port.
static void setOutput()
Set the pin mode as OUTPUT
static void strobe()
Toggle the pin twice to create a short pulse.
static void fastset(FASTLED_REGISTER port_ptr_t port, FASTLED_REGISTER port_t val)
Set the state of a port.
static void hi()
Set the pin state to HIGH
static void setInput()
Set the pin mode as INPUT
I/O pin initially set to OUTPUT.
OutputPin(int pin)
Constructor.
Naive fallback solution for low level pin access.
void fastset(FASTLED_REGISTER port_ptr_t port, FASTLED_REGISTER port_t val)
Set the state of a port.
void lo(FASTLED_REGISTER port_ptr_t port)
Set the same pin on another port to LOW
virtual void release()
Set the pin state to LOW
void setOutput()
Set the pin mode as OUTPUT
void set(FASTLED_REGISTER port_t val)
Set the state of the output register.
port_t loval()
Gets the state of the port with this pin LOW
void setInput()
Set the pin mode as INPUT
void hi()
Set the pin state to HIGH
void toggle()
Toggle the pin.
void hi(FASTLED_REGISTER port_ptr_t port)
Set the same pin on another port to HIGH
void lo()
Set the pin state to LOW
virtual void select()
Set the pin state to HIGH
volatile RwReg * port_ptr_t
type for a pin read/write register, volatile
virtual bool isSelected()
Checks if the pin is currently HIGH
RwReg port_t
type for a pin read/write register, non-volatile
port_t mask()
Get the pin mask.
port_ptr_t port()
Get the output state of the port.
void strobe()
Toggle the pin twice to create a short pulse.
port_t hival()
Gets the state of the port with this pin HIGH
Abstract class for "selectable" things.
virtual void release()=0
Release this object.
virtual void select()=0
Select this object.
virtual bool isSelected()=0
Check if this object is currently selected.
volatile uint32_t * ptr_reg32_t
Pointer to a 32-bit register, volatile.
volatile uint32_t & reg32_t
Reference to a 32-bit register, volatile.
Determines which platform system definitions to include.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Utility template for tracking down information about pins and ports.
static const void * portAddr()
Gets the raw address of the port.
static bool hasPort()
Checks whether a port exists.
static const char * portName()
Gets the name of the port, as a C-string.