9#pragma GCC diagnostic push
10#pragma GCC diagnostic ignored "-Wignored-qualifiers"
13#pragma GCC diagnostic ignored "-Wpragmas"
14#pragma GCC diagnostic ignored "-Wvolatile"
20FASTLED_NAMESPACE_BEGIN
40#if !defined(FASTLED_NO_PINMAP)
44 volatile RwReg *mPort;
45 volatile RoReg *mInPort;
52 mPinMask = digitalPinToBitMask(mPin);
53 mPort = (
volatile RwReg*)portOutputRegister(digitalPinToPort(mPin));
54 mInPort = (
volatile RoReg*)portInputRegister(digitalPinToPort(mPin));
60 Pin(
int pin) : mPin(pin) { _init(); }
69 inline void setInput() { pinMode(mPin, INPUT); }
72 inline void hi() __attribute__ ((always_inline)) { *mPort |= mPinMask; }
74 inline void lo() __attribute__ ((always_inline)) { *mPort &= ~mPinMask; }
80 inline void toggle() __attribute__ ((always_inline)) { *mInPort = mPinMask; }
91 inline void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *mPort = val; }
99 port_t hival() __attribute__ ((always_inline)) {
return *mPort | mPinMask; }
101 port_t loval() __attribute__ ((always_inline)) {
return *mPort & ~mPinMask; }
105 port_t mask() __attribute__ ((always_inline)) {
return mPinMask; }
112 virtual bool isSelected() {
return (*mPort & mPinMask) == mPinMask; }
133 volatile RwReg *mPort;
134 volatile RoReg *mInPort;
146 Pin(
int pin) : mPin(pin) { _init(); }
148 void setPin(
int pin) { mPin = pin; _init(); }
156 inline void hi() __attribute__ ((always_inline)) { *mPort |= mPinMask; }
157 inline void lo() __attribute__ ((always_inline)) { *mPort &= ~mPinMask; }
160 inline void toggle() __attribute__ ((always_inline)) { *mInPort = mPinMask; }
162 inline void hi(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port |= mPinMask; }
163 inline void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port &= ~mPinMask; }
164 inline void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *mPort = val; }
168 port_t hival() __attribute__ ((always_inline)) {
return *mPort | mPinMask; }
169 port_t loval() __attribute__ ((always_inline)) {
return *mPort & ~mPinMask; }
170 port_ptr_t port() __attribute__ ((always_inline)) {
return mPort; }
171 port_t mask() __attribute__ ((always_inline)) {
return mPinMask; }
175 virtual bool isSelected() {
return (*mPort & mPinMask) == mPinMask; }
204#ifdef FASTLED_FORCE_SOFTWARE_PINS
206 static RwReg sPinMask;
207 static volatile RwReg *sPort;
208 static volatile RoReg *sInPort;
209 static void _init() {
210#if !defined(FASTLED_NO_PINMAP)
211 sPinMask = digitalPinToBitMask(PIN);
212 sPort = portOutputRegister(digitalPinToPort(PIN));
213 sInPort = portInputRegister(digitalPinToPort(PIN));
222 inline static void setOutput() { _init(); pinMode(PIN, OUTPUT); }
224 inline static void setInput() { _init(); pinMode(PIN, INPUT); }
227 inline static void hi() __attribute__ ((always_inline)) { *sPort |= sPinMask; }
229 inline static void lo() __attribute__ ((always_inline)) { *sPort &= ~sPinMask; }
235 inline static void toggle() __attribute__ ((always_inline)) { *sInPort = sPinMask; }
240 inline static void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { *
port &= ~sPinMask; }
242 inline static void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { *sPort = val; }
248 static port_t hival() __attribute__ ((always_inline)) {
return *sPort | sPinMask; }
250 static port_t loval() __attribute__ ((always_inline)) {
return *sPort & ~sPinMask; }
254 static port_t mask() __attribute__ ((always_inline)) {
return sPinMask; }
263template<u
int8_t PIN>
class FastPin {
267 constexpr static bool validpin() {
return false; }
268 constexpr static bool LowSpeedOnlyRecommended() {
274 static_assert(validpin(),
"Invalid pin specified");
276 static void _init() { }
288 inline static void hi() __attribute__ ((always_inline)) { }
290 inline static void lo() __attribute__ ((always_inline)) { }
293 inline static void strobe() __attribute__ ((always_inline)) { }
296 inline static void toggle() __attribute__ ((always_inline)) { }
299 inline static void hi(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { }
301 inline static void lo(FASTLED_REGISTER
port_ptr_t port) __attribute__ ((always_inline)) { }
303 inline static void set(FASTLED_REGISTER
port_t val) __attribute__ ((always_inline)) { }
309 static port_t hival() __attribute__ ((always_inline)) {
return 0; }
311 static port_t loval() __attribute__ ((always_inline)) {
return 0;}
313 static port_ptr_t port() __attribute__ ((always_inline)) {
return NULL; }
315 static port_t mask() __attribute__ ((always_inline)) {
return 0; }
346#define _FL_DEFINE_PORT(L, BASE) template<> struct __FL_PORT_INFO<L> { \
347 static bool hasPort() { return 1; } \
348 static const char *portName() { return #L; } \
349 typedef BASE __t_baseType; \
350 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
362#define _FL_DEFINE_PORT3(L, LC, BASE) template<> struct __FL_PORT_INFO<LC> { \
363 static bool hasPort() { return 1; } \
364 static const char *portName() { return #L; } \
365 typedef BASE __t_baseType; \
366 static const void *portAddr() { return (void*)&__t_baseType::r(); } };
370#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.
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.