FastLED 3.9.15
Loading...
Searching...
No Matches
FastPin< PIN > Class Template Reference

Detailed Description

template<uint8_t PIN>
class FastPin< PIN >

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.

Definition at line 217 of file fastpin.h.

#include <fastpin.h>

+ Inheritance diagram for FastPin< PIN >:

Public Types

typedef volatile RwReg * port_ptr_t
 type for a pin read/write register, volatile
 
typedef RwReg port_t
 type for a pin read/write register, non-volatile
 

Static Public Member Functions

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 hi (FASTLED_REGISTER port_ptr_t port)
 Set the same pin on another port to HIGH
 
static port_t hival ()
 Gets the state of the port with this pin HIGH
 
static void lo ()
 Set the pin state to LOW
 
static void lo (FASTLED_REGISTER port_ptr_t port)
 Set the same pin on another port to LOW
 
static port_t loval ()
 Gets the state of the port with this pin LOW
 
static port_t mask ()
 Get the pin mask.
 
static port_ptr_t port ()
 Get the output state of the port.
 
static void set (FASTLED_REGISTER port_t val)
 Set the state of the output register.
 
static void setInput ()
 Set the pin mode as INPUT
 
static void setOutput ()
 Set the pin mode as OUTPUT
 
static void strobe ()
 Toggle the pin twice to create a short pulse.
 
static void toggle ()
 Toggle the pin.
 

Static Private Member Functions

static void _init ()
 

Static Private Attributes

static volatile RoReg * sInPort
 Input register for the pin.
 
static RwReg sPinMask
 Bitmask for the pin within its register.
 
static volatile RwReg * sPort
 Output register for the pin.
 

The documentation for this class was generated from the following file: