FastArduino  v1.7
C++ library to build fast but small Arduino/AVR projects
gpio::FastPort< PORT_ > Class Template Reference

API that manipulates a whole digital IO port. More...

#include <fastarduino/gpio.h>

Public Member Functions

 FastPort (const FastPort< PORT_ > &)=default
 
FastPort< PORT_ > & operator= (const FastPort< PORT_ > &)=default
 
 FastPort ()=default
 Construct a FastPort without any physical setup on target MCU. More...
 
 FastPort (uint8_t ddr, uint8_t port=0) INLINE
 Construct a FastPort with the given direction byte and initial values byte. More...
 
template<uint8_t BIT>
FastPin< PORT, BIT > get_pin (PinMode mode, bool value=false)
 Create a FastPin instance for a given pin of this port, and sets its direction mode and level value (if output). More...
 
template<uint8_t BIT>
FastPin< PORT, BIT > get_pin ()
 Create a FastPin instance for a given pin of this port. More...
 
void set_PORT (uint8_t port) INLINE
 Set the 8-bits value for port PORT register. More...
 
uint8_t get_PORT () INLINE
 Get the current 8-bit value of port PORT register. More...
 
void set_DDR (uint8_t ddr) INLINE
 Set the 8-bits value for port DDR (direction) register. More...
 
uint8_t get_DDR () INLINE
 Get the current 8-bit value of port DDR (direction) register. More...
 
void set_PIN (uint8_t pin) INLINE
 Set the 8-bits value for port PIN register. More...
 
uint8_t get_PIN () INLINE
 Get the 8-bits value of PIN register for this port, i.e. More...
 

Static Public Attributes

static constexpr const board::Port PORT = PORT_
 The actual port in target MCU.
 

Detailed Description

template<board::Port PORT_>
class gpio::FastPort< PORT_ >

API that manipulates a whole digital IO port.

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

Note that using this API means that every method manipulates ALL pins of a port at a time. If you need to handle several, but not all, pins of a port, consider using gpio::FastMaskedPort instead.

Template Parameters
PORT_the target port
See also
board::Port
gpio::FastMaskedPort

Definition at line 201 of file gpio.h.

Constructor & Destructor Documentation

◆ FastPort() [1/2]

template<board::Port PORT_>
gpio::FastPort< PORT_ >::FastPort ( )
default

Construct a FastPort without any physical setup on target MCU.

This is useful if default pins directions and values are OK for you and you want to avoid calling mode setup on target MCU.

◆ FastPort() [2/2]

template<board::Port PORT_>
gpio::FastPort< PORT_ >::FastPort ( uint8_t  ddr,
uint8_t  port = 0 
)
inline

Construct a FastPort with the given direction byte and initial values byte.

The pins mode is forced on the target MCU.

Parameters
ddrthe direction to set (in DDR register of this port) for each pin (1 bit is one pin, when 1 the pin is set as output, when 0 as input).
portthe initial values for PORT register of this port; each
bit is for one pin of the port, its meaning depends on the pin direction: if input, then it fixes if pullup resistor should be used, if output, then it fixes the output level of the pin.
See also
set_DDR()
set_PORT()

Definition at line 235 of file gpio.h.

Member Function Documentation

◆ get_pin() [1/2]

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

Create a FastPin instance for a given pin of this port, and sets its direction mode and level value (if output).

Note that you would normally not need this method, as each pin should normally already set properly first through this port. You should rather use get_pin() instead.

Template Parameters
BITthe bit position for which to return a FastPin instance; if there is no pin at this bit position, a compilation error will occur.
Returns
a FastPin instance allowing direct manipulation of the given pin
See also
get_pin()

Definition at line 254 of file gpio.h.

◆ get_pin() [2/2]

template<board::Port PORT_>
template<uint8_t BIT>
FastPin<PORT, BIT> gpio::FastPort< PORT_ >::get_pin ( )
inline

Create a FastPin instance for a given pin of this port.

No additional setup is performed on that pin: it just keeps its current direction and value.

Template Parameters
BITthe bit position for which to return a FastPin instance; if there is no pin at this bit position, a compilation error will occur.
Returns
a FastPin instance allowing direct manipulation of the given pin

Definition at line 269 of file gpio.h.

◆ set_PORT()

template<board::Port PORT_>
void gpio::FastPort< PORT_ >::set_PORT ( uint8_t  port)
inline

Set the 8-bits value for port PORT register.

If a pin is set currently set as output, then the matching bit in port will set the output level of this pin. If a pin is set currently as input, then the matching bit in port defines if a pullup resistor is used or not.

Parameters
portthe initial values for PORT register of this port; each
bit is for one pin of the port, its meaning depends on the pin direction: if input, then it fixes if pullup resistor should be used, if output, then it fixes the output level of the pin.
See also
set_DDR()

Definition at line 287 of file gpio.h.

◆ get_PORT()

template<board::Port PORT_>
uint8_t gpio::FastPort< PORT_ >::get_PORT ( )
inline

Get the current 8-bit value of port PORT register.

Each bit maps to a pin configuration in this port. Depending on DDR configuration for a pin, the PORT value is interpreted differently: for an input pin, the matching PORT bit indicates if this pin has a pullup register on it.

Returns
the value of PORT register

Definition at line 301 of file gpio.h.

◆ set_DDR()

template<board::Port PORT_>
void gpio::FastPort< PORT_ >::set_DDR ( uint8_t  ddr)
inline

Set the 8-bits value for port DDR (direction) register.

Each pin direction is decided by the matching bit.

Parameters
ddrthe direction to set (in DDR register of this port) for each pin (1 bit is one pin, when 1 the pin is set as output, when 0 as input).
See also
set_PORT()

Definition at line 315 of file gpio.h.

◆ get_DDR()

template<board::Port PORT_>
uint8_t gpio::FastPort< PORT_ >::get_DDR ( )
inline

Get the current 8-bit value of port DDR (direction) register.

Each pin direction is decided by the matching bit.

Returns
the value of DDR register

Definition at line 326 of file gpio.h.

◆ set_PIN()

template<board::Port PORT_>
void gpio::FastPort< PORT_ >::set_PIN ( uint8_t  pin)
inline

Set the 8-bits value for port PIN register.

Writing a 1 bit in this register will toggle the matching PORT bit; writing 0 has no effect.

Parameters
pinthe value to write to PIN register for this port

Definition at line 337 of file gpio.h.

◆ get_PIN()

template<board::Port PORT_>
uint8_t gpio::FastPort< PORT_ >::get_PIN ( )
inline

Get the 8-bits value of PIN register for this port, i.e.

the current level of every pin of the port, be it an output or an input pin.

Returns
the value of PIN register

Definition at line 348 of file gpio.h.


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