FastLED 3.9.7
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.

Examples
Pintest.ino.

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

Member Typedef Documentation

◆ port_ptr_t

template<uint8_t PIN>
typedef volatile RwReg* FastPin< PIN >::port_ptr_t

type for a pin read/write register, volatile

Definition at line 230 of file fastpin.h.

◆ port_t

template<uint8_t PIN>
typedef RwReg FastPin< PIN >::port_t

type for a pin read/write register, non-volatile

Definition at line 231 of file fastpin.h.

Member Function Documentation

◆ fastset()

template<uint8_t PIN>
static void FastPin< PIN >::fastset ( FASTLED_REGISTER port_ptr_t port,
FASTLED_REGISTER port_t val )
inlinestatic

Set the state of a port.

Parameters
portthe port to modify
valthe state to set the port to

Definition at line 257 of file fastpin.h.

◆ hi() [1/2]

template<uint8_t PIN>
static void FastPin< PIN >::hi ( )
inlinestatic

Set the pin state to HIGH

Definition at line 239 of file fastpin.h.

◆ hi() [2/2]

template<uint8_t PIN>
static void FastPin< PIN >::hi ( FASTLED_REGISTER port_ptr_t port)
inlinestatic

Set the same pin on another port to HIGH

Parameters
portthe port to modify

Definition at line 250 of file fastpin.h.

◆ hival()

template<uint8_t PIN>
static port_t FastPin< PIN >::hival ( )
inlinestatic

Gets the state of the port with this pin HIGH

Definition at line 260 of file fastpin.h.

◆ lo() [1/2]

template<uint8_t PIN>
static void FastPin< PIN >::lo ( )
inlinestatic

Set the pin state to LOW

Definition at line 241 of file fastpin.h.

◆ lo() [2/2]

template<uint8_t PIN>
static void FastPin< PIN >::lo ( FASTLED_REGISTER port_ptr_t port)
inlinestatic

Set the same pin on another port to LOW

Parameters
portthe port to modify

Definition at line 252 of file fastpin.h.

◆ loval()

template<uint8_t PIN>
static port_t FastPin< PIN >::loval ( )
inlinestatic

Gets the state of the port with this pin LOW

Definition at line 262 of file fastpin.h.

◆ mask()

template<uint8_t PIN>
static port_t FastPin< PIN >::mask ( )
inlinestatic

Get the pin mask.

Definition at line 266 of file fastpin.h.

◆ port()

template<uint8_t PIN>
static port_ptr_t FastPin< PIN >::port ( )
inlinestatic

Get the output state of the port.

Definition at line 264 of file fastpin.h.

◆ set()

template<uint8_t PIN>
static void FastPin< PIN >::set ( FASTLED_REGISTER port_t val)
inlinestatic

Set the state of the output register.

Parameters
valthe state to set the output register to
Note
This function is not limited to the current pin! It modifies the entire register.

Definition at line 254 of file fastpin.h.

◆ setInput()

template<uint8_t PIN>
static void FastPin< PIN >::setInput ( )
inlinestatic

Set the pin mode as INPUT

Definition at line 236 of file fastpin.h.

◆ setOutput()

template<uint8_t PIN>
static void FastPin< PIN >::setOutput ( )
inlinestatic

Set the pin mode as OUTPUT

Definition at line 234 of file fastpin.h.

◆ strobe()

template<uint8_t PIN>
static void FastPin< PIN >::strobe ( )
inlinestatic

Toggle the pin twice to create a short pulse.

Definition at line 244 of file fastpin.h.

◆ toggle()

template<uint8_t PIN>
static void FastPin< PIN >::toggle ( )
inlinestatic

Toggle the pin.

If the pin was high, set it low. If was low, set it high.

Definition at line 247 of file fastpin.h.


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