avr-classes
Public Member Functions | List of all members
PinArray< PINTYPE, DATATYPE, WIDTH > Class Template Reference

#include <pinarray.h>

Public Member Functions

 PinArray ()
 
void setPin (uint8_t index, PINTYPE *pin)
 
DATATYPE getValue (void) const
 
void setValue (DATATYPE value, DATATYPE mask)
 

Detailed Description

template<class PINTYPE, typename DATATYPE, uint8_t WIDTH>
class PinArray< PINTYPE, DATATYPE, WIDTH >

Template class that allows to build an array of pins with arbitrary type. The use-case is to form a virtual port consisting of pins that can be located anywhere. Although PinArray features both, a getValue() and a setValue() method, depending on the pin type being used only one or the other might be actually available. Using DATATYPE and WIDTH it is possible to even form virtual ports of sizes greater than 8 bit. For convenient access the classes VirtualInputPort and VirtualOutputPort exist, which implement 8 bit ports.

Parameters
PINTYPEType of pin to use, e.g. InputPin. Type must be provided by user, e.g. by proper #include.
DATATYPEData type internally used for bit shifting and as parameters, e.g. uint8_t.
WIDTHWidth of virtual port, may be smaller than DATATYPE supports, e.g. 6 bit.
Note
Be warned: just because this template compiles, it doesn't need to make sense. You can create a virtual port with 32 or even more bits, but using it will be a pain for an 8 bit CPU...
You can mix real pins with null pointers, or even reference the same pins multiple times.

Constructor & Destructor Documentation

◆ PinArray()

template<class PINTYPE, typename DATATYPE, uint8_t WIDTH>
PinArray< PINTYPE, DATATYPE, WIDTH >::PinArray ( )
inline

Constructor, sets all pins to null pointers.

Member Function Documentation

◆ getValue()

template<class PINTYPE, typename DATATYPE, uint8_t WIDTH>
DATATYPE PinArray< PINTYPE, DATATYPE, WIDTH >::getValue ( void  ) const
inline

Get value being represented by set of pins.

Returns
Value read from pins.
Note
Supported only if underlying PINTYPE supports getValue().
Bits that are not associated with a pin read as 0.

◆ setPin()

template<class PINTYPE, typename DATATYPE, uint8_t WIDTH>
void PinArray< PINTYPE, DATATYPE, WIDTH >::setPin ( uint8_t  index,
PINTYPE *  pin 
)
inline

Sets the pin to be used for the specified bit position.

Parameters
indexBit position to set pin for.
pinPin to use for this bit position.

◆ setValue()

template<class PINTYPE, typename DATATYPE, uint8_t WIDTH>
void PinArray< PINTYPE, DATATYPE, WIDTH >::setValue ( DATATYPE  value,
DATATYPE  mask 
)
inline

Set value being represented by set of pins.

Parameters
valueValue to be set.
maskMask with pins to manipulate according to value.
Note
Supported only if underlying PINTYPE supports setValue().