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

API that manipulates a part of a digital IO port. More...

#include <fastarduino/gpio.h>

Public Member Functions

 FastMaskedPort (const FastMaskedPort< PORT_, MASK_ > &)=default
 
FastMaskedPort< PORT_, MASK_ > & operator= (const FastMaskedPort< PORT_, MASK_ > &)=default
 
 FastMaskedPort ()=default
 Construct a FastMaskedPort without any physical setup on target MCU. More...
 
 FastMaskedPort (uint8_t ddr, uint8_t port=0)
 Construct a FastMaskedPort for the pins selected by the provide bits mask, with the given direction byte and initial values byte. More...
 
void set_PORT (uint8_t port) INLINE
 Set the 8-bits value for port PORT register, this value will be masked according to the provided bit mask provided in constructor. More...
 
uint8_t get_PORT () INLINE
 Get the current 8-bit value of port PORT register, masked according to the bit mask provided at construction time. More...
 
void set_DDR (uint8_t ddr) INLINE
 Set the 8-bits value for port DDR (direction) register, this value will be masked according to the provided bit mask provided in constructor. More...
 
uint8_t get_DDR () INLINE
 Get the current 8-bit value of port DDR (direction) register, masked according to the bit mask provided at construction time. More...
 
void set_PIN (uint8_t pin) INLINE
 Set the 8-bits value for port PIN register, this value will be masked according to the provided bit mask provided in constructor. More...
 
uint8_t get_PIN () INLINE
 Get the current 8-bit value of PIN register for this port, masked according to the bit mask provided at construction time. More...
 

Static Public Attributes

static constexpr const board::Port PORT = PORT_
 The actual port in target MCU.
 
static constexpr const uint8_t MASK = MASK_
 The bit mask used for this FastMaskedPort.
 

Detailed Description

template<board::Port PORT_, uint8_t MASK_>
class gpio::FastMaskedPort< PORT_, MASK_ >

API that manipulates a part of a digital IO port.

Implementation is highly optimized for size and speed: instances use 1 byte SRAM only.

Using this API allows you to manipulate several pins of a port at once, but without having to care for other pins of that port: the API always ensure that only those selected pins get modified. This is useful when, for instance, you handle a 4x4 keypad with one port, 4 pins out and 4 pins in, then you can define 2 FastMaskedPort instances, one for output pins, the other for input pins.

Note that, although more efficient than using individual FastPins, it is not as efficient as using only one single FastPort to handle all its pins.

Template Parameters
PORT_the target port
MASK_the bit mask determining which pins of the port are handled by this instance; only these pins will be impacted by FastMaskedPort methods.
See also
board::Port

Definition at line 375 of file gpio.h.

Constructor & Destructor Documentation

◆ FastMaskedPort() [1/2]

template<board::Port PORT_, uint8_t MASK_>
gpio::FastMaskedPort< PORT_, MASK_ >::FastMaskedPort ( )
default

Construct a FastMaskedPort 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.

◆ FastMaskedPort() [2/2]

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

Construct a FastMaskedPort for the pins selected by the provide bits mask, with the given direction byte and initial values byte.

The pins mode are 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 413 of file gpio.h.

Member Function Documentation

◆ set_PORT()

template<board::Port PORT_, uint8_t MASK_>
void gpio::FastMaskedPort< PORT_, MASK_ >::set_PORT ( uint8_t  port)
inline

Set the 8-bits value for port PORT register, this value will be masked according to the provided bit mask provided in constructor.

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 433 of file gpio.h.

◆ get_PORT()

template<board::Port PORT_, uint8_t MASK_>
uint8_t gpio::FastMaskedPort< PORT_, MASK_ >::get_PORT ( )
inline

Get the current 8-bit value of port PORT register, masked according to the bit mask provided at construction time.

Each bit maps to a pin configuration in this port. For all pins not part of the mask, returned value is 0. 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 masked with constructor-provided bit mask

Definition at line 449 of file gpio.h.

◆ set_DDR()

template<board::Port PORT_, uint8_t MASK_>
void gpio::FastMaskedPort< PORT_, MASK_ >::set_DDR ( uint8_t  ddr)
inline

Set the 8-bits value for port DDR (direction) register, this value will be masked according to the provided bit mask provided in constructor.

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 464 of file gpio.h.

◆ get_DDR()

template<board::Port PORT_, uint8_t MASK_>
uint8_t gpio::FastMaskedPort< PORT_, MASK_ >::get_DDR ( )
inline

Get the current 8-bit value of port DDR (direction) register, masked according to the bit mask provided at construction time.

Each pin direction is decided by the matching bit. For all pins not part of the mask, returned value is 0.

Returns
the value of DDR register masked with constructor-provided bit mask

Definition at line 477 of file gpio.h.

◆ set_PIN()

template<board::Port PORT_, uint8_t MASK_>
void gpio::FastMaskedPort< PORT_, MASK_ >::set_PIN ( uint8_t  pin)
inline

Set the 8-bits value for port PIN register, this value will be masked according to the provided bit mask provided in constructor.

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 490 of file gpio.h.

◆ get_PIN()

template<board::Port PORT_, uint8_t MASK_>
uint8_t gpio::FastMaskedPort< PORT_, MASK_ >::get_PIN ( )
inline

Get the current 8-bit value of PIN register for this port, masked according to the bit mask provided at construction time.

Returns
the value of PIN register masked with constructor-provided bit mask

Definition at line 501 of file gpio.h.


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