FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
gpio::FastPin< PORT_, BIT_ > Class Template Reference

API that manipulates one digital IO pin of a given port. More...

#include <fastarduino/gpio.h>

Public Member Functions

 FastPin () INLINE
 Construct a FastPin without any physical setup on target MCU. More...
 
 FastPin (PinMode mode, bool value=false) INLINE
 Construct a FastPin with the given mode and initial value. More...
 
void set_mode (PinMode mode, bool value=false) INLINE
 Set mode (direction) and value (if output) of this pin. More...
 
void set () INLINE
 Set pin level to HIGH (i.e. More...
 
void clear () INLINE
 Set pin level to LOW (i.e. More...
 
void toggle () INLINE
 Toggle pin level, i.e. More...
 
bool value () INLINE
 Return the current level of this pin. More...
 

Static Public Attributes

static constexpr const board::Port PORT = PORT_
 The port to which this pin belongs. More...
 
static constexpr const uint8_t BIT = BIT_
 The bit position (from 0 to 7), in port, of this pin. More...
 
static constexpr const uint8_t MASK = bits::BV8(BIT)
 The bit-mask to use when accessing DPIN through PORT. More...
 

Detailed Description

template<board::Port PORT_, uint8_t BIT_>
class gpio::FastPin< PORT_, BIT_ >

API that manipulates one digital IO pin of a given port.

Implementation is highly optimized for size and speed: instances use no SRAM at all, most common methods use only 1 AVR instruction.

Note that, although it has public constructors, you generally do not construct FastPin instances directly. You better use FastPinType, which is directly provided a board::DigitalPin constant, or even better, use FAST_PIN alias type. You may also obtain a FastPin instance through FastPort::get_pin().

Template Parameters
PORT_the target port to which this pin belongs
BIT_the bit position (from 0 to 7), in port, of this pin; note that if this position is not mapped to a physical IO of the MCU target, then a compilation error will occur.
See also
board::Port
gpio::FastPinType
gpio::FAST_PIN
gpio::FastPort::get_pin()

Definition at line 89 of file gpio.h.

Constructor & Destructor Documentation

◆ FastPin() [1/2]

template<board::Port PORT_, uint8_t BIT_>
gpio::FastPin< PORT_, BIT_ >::FastPin ( )
inline

Construct a FastPin without any physical setup on target MCU.

This is useful if default pin direction and value are OK for you and you want to avoid calling mode setup on target MCU.

Definition at line 112 of file gpio.h.

◆ FastPin() [2/2]

template<board::Port PORT_, uint8_t BIT_>
gpio::FastPin< PORT_, BIT_ >::FastPin ( PinMode  mode,
bool  value = false 
)
inline

Construct a FastPin with the given mode and initial value.

The pin mode is forced on the target MCU.

Parameters
modethe mode of this pin
valuethe initial pin level, if mode == PinMode::OUTPUT; not used otherwise.
See also
set_mode()

Definition at line 126 of file gpio.h.

Member Function Documentation

◆ set_mode()

template<board::Port PORT_, uint8_t BIT_>
void gpio::FastPin< PORT_, BIT_ >::set_mode ( PinMode  mode,
bool  value = false 
)
inline

Set mode (direction) and value (if output) of this pin.

Parameters
modethe mode of this pin
valuethe initial pin level, if mode == PinMode::OUTPUT; not used otherwise.

Definition at line 139 of file gpio.h.

◆ set()

template<board::Port PORT_, uint8_t BIT_>
void gpio::FastPin< PORT_, BIT_ >::set ( )
inline

Set pin level to HIGH (i.e.

Vcc). This method will generally use 1 single instruction in most cases.

Definition at line 155 of file gpio.h.

◆ clear()

template<board::Port PORT_, uint8_t BIT_>
void gpio::FastPin< PORT_, BIT_ >::clear ( )
inline

Set pin level to LOW (i.e.

GND). This method will generally use 1 single instruction in most cases.

Definition at line 164 of file gpio.h.

◆ toggle()

template<board::Port PORT_, uint8_t BIT_>
void gpio::FastPin< PORT_, BIT_ >::toggle ( )
inline

Toggle pin level, i.e.

set it to LOW if it was HIGH, and HIGH if it was LOW. This method will generally use 1 single instruction in most cases.

Definition at line 174 of file gpio.h.

◆ value()

template<board::Port PORT_, uint8_t BIT_>
bool gpio::FastPin< PORT_, BIT_ >::value ( )
inline

Return the current level of this pin.

Return values
trueif current pin level is HIGH (i.e. Vcc)
falseif current pin level is LOW (i.e. GND)

Definition at line 184 of file gpio.h.

Member Data Documentation

◆ PORT

template<board::Port PORT_, uint8_t BIT_>
constexpr const board::Port gpio::FastPin< PORT_, BIT_ >::PORT = PORT_
staticconstexpr

The port to which this pin belongs.

Definition at line 101 of file gpio.h.

◆ BIT

template<board::Port PORT_, uint8_t BIT_>
constexpr const uint8_t gpio::FastPin< PORT_, BIT_ >::BIT = BIT_
staticconstexpr

The bit position (from 0 to 7), in port, of this pin.

Definition at line 103 of file gpio.h.

◆ MASK

template<board::Port PORT_, uint8_t BIT_>
constexpr const uint8_t gpio::FastPin< PORT_, BIT_ >::MASK = bits::BV8(BIT)
staticconstexpr

The bit-mask to use when accessing DPIN through PORT.

Definition at line 105 of file gpio.h.


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