24#include "boards/board_traits.h"
31 template<DigitalPin PIN>
constexpr uint8_t
BIT()
INLINE;
39 return board_traits::DigitalPin_trait<PIN>::BIT;
45 template<DigitalPin PIN>
constexpr uint8_t
MASK()
47 return bits::BV8(board_traits::DigitalPin_trait<PIN>::BIT);
89 template<board::Port PORT_, u
int8_t BIT_>
class FastPin
92 using TRAIT = board_traits::Port_trait<PORT_>;
103 static constexpr const uint8_t
BIT = BIT_;
114 static_assert(TRAIT::DPIN_MASK &
bits::BV8(
BIT),
"BIT must be compatible with PORT available pins");
128 static_assert(TRAIT::DPIN_MASK &
bits::BV8(
BIT),
"BIT must be compatible with PORT available pins");
206 using TRAIT = board_traits::Port_trait<PORT_>;
382 using TRAIT = board_traits::Port_trait<PORT_>;
394 static constexpr const uint8_t
MASK = MASK_;
457 return TRAIT::PORT &
MASK;
485 return TRAIT::DDR &
MASK;
498 TRAIT::PIN = pin &
MASK;
509 return TRAIT::PIN &
MASK;
553 using TRAIT = board_traits::DigitalPin_trait<DPIN_>;
554 using PTRAIT = board_traits::Port_trait<TRAIT::PORT>;
564 static constexpr const uint8_t
BIT = TRAIT::BIT;
632 template<>
class FastPinType<
board::DigitalPin::NONE>
635 FastPinType() =
delete;
638 static constexpr const uint8_t
BIT = 0;
639 static constexpr const uint8_t
MASK = 0;
640 using TYPE = FastPin<PORT, BIT>;
645 static void clear() {}
655 template<>
class FastPin<
board::Port::NONE, 0>
693 template<board::DigitalPin DPIN_>
716 template<board::InterruptPin IPIN_>
739 template<board::ExternalInterruptPin EPIN_>
API that manipulates a part of a digital IO port.
FastMaskedPort()=default
Construct a FastMaskedPort without any physical setup on target MCU.
FastMaskedPort(uint8_t ddr, uint8_t port=0)
Construct a FastMaskedPort for the pins selected by the provide bits mask, with the given direction b...
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 m...
uint8_t get_DDR() INLINE
Get the current 8-bit value of port DDR (direction) register, masked according to the bit mask provid...
uint8_t get_PORT() INLINE
Get the current 8-bit value of port PORT register, masked according to the bit mask provided at const...
uint8_t get_PIN() INLINE
Get the current 8-bit value of PIN register for this port, masked according to the bit mask provided ...
static constexpr const board::Port PORT
The actual port in target MCU.
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 ...
static constexpr const uint8_t MASK
The bit mask used for this FastMaskedPort.
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 pr...
API that manipulates one digital IO pin of a given port.
void set() INLINE
Set pin level to HIGH (i.e.
void set_mode(PinMode mode, bool value=false) INLINE
Set mode (direction) and value (if output) of this pin.
static constexpr const board::Port PORT
The port to which this pin belongs.
static constexpr const uint8_t MASK
The bit-mask to use when accessing DPIN through PORT.
FastPin() INLINE
Construct a FastPin without any physical setup on target MCU.
bool value() INLINE
Return the current level of this pin.
void toggle() INLINE
Toggle pin level, i.e.
void clear() INLINE
Set pin level to LOW (i.e.
static constexpr const uint8_t BIT
The bit position (from 0 to 7), in port, of this pin.
FastPin(PinMode mode, bool value=false) INLINE
Construct a FastPin with the given mode and initial value.
API that manipulates a given digital IO pin of a the target MCU.
FastPin< PORT, BIT > TYPE
The exact FastPin parameterized type for DPIN IO pin.
static bool value()
Return the current level pin DPIN.
static void set()
Set pin level to HIGH (i.e.
static void clear()
Set pin level to LOW (i.e.
static void toggle()
Toggle pin level, i.e.
FastPort< PORT > PORT_TYPE
The exact FastPort parameterized type that DPIN IO pin belongs to.
static constexpr const uint8_t BIT
The bit position of DPIN within its port.
static constexpr const board::Port PORT
The port to which DPIN belongs.
static constexpr const uint8_t MASK
The bit-mask to use when accessing DPIN through PORT.
static constexpr const board::DigitalPin DPIN
The digital pin for this FastPinType.
static void set_mode(PinMode mode, bool value=false)
Set mode (direction) and value (if output) of DPIN.
API that manipulates a whole digital IO port.
FastPort()=default
Construct a FastPort without any physical setup on target MCU.
uint8_t get_PORT() INLINE
Get the current 8-bit value of port PORT register.
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 (...
uint8_t get_PIN() INLINE
Get the 8-bits value of PIN register for this port, i.e.
void set_PIN(uint8_t pin) INLINE
Set the 8-bits value for port PIN register.
void set_PORT(uint8_t port) INLINE
Set the 8-bits value for port PORT register.
static constexpr const board::Port PORT
The actual port in target MCU.
void set_DDR(uint8_t ddr) INLINE
Set the 8-bits value for port DDR (direction) register.
uint8_t get_DDR() INLINE
Get the current 8-bit value of port DDR (direction) register.
FastPort(uint8_t ddr, uint8_t port=0) INLINE
Construct a FastPort with the given direction byte and initial values byte.
FastPin< PORT, BIT > get_pin()
Create a FastPin instance for a given pin of this port.
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
General API for handling External Interrupt pins.
static constexpr uint8_t COMPL(uint8_t value)
Return the uint8_t 2-complement of a byte.
static constexpr uint8_t CBV8(uint8_t bit)
Create a uint8_t inverted bitmask for the given bit number.
static constexpr uint8_t BV8(uint8_t bit)
Create a uint8_t bitmask for the given bit number.
Defines all types and constants specific to support a specific MCU target.
constexpr uint8_t BIT() INLINE
Determine the bit position, inside its IO port, of the given DigitalPin.
Port
Defines all available ports of the target MCU.
DigitalPin
Defines all available digital input/output pins of the target MCU.
constexpr uint8_t MASK() INLINE
Determine the bit mask representing the given DigitalPin inside its port.
Defines all API to manipulate general-purpose digital input/output pins.
typename FastPinType< DPIN_ >::TYPE FAST_PIN
Useful alias type to the FastPin type matching a given board::DigitalPin.
typename FastPinType< board::EXT_PIN< EPIN_ >()>::TYPE FAST_EXT_PIN
Useful alias type to the FastPin type matching a given board::ExternalInterruptPin.
typename FastPinType< board::PCI_PIN< IPIN_ >()>::TYPE FAST_INT_PIN
Useful alias type to the FastPin type matching a given board::InterruptPin.
PinMode
Defines the configurable mode of a digital IO pin.
@ OUTPUT
Digital pin is configured as output.
@ INPUT
Digital pin is configured as high-impedance (open drain) input.
@ INPUT_PULLUP
Digital pin is configured as input with an internal pullup resistor.
General API for handling Pin Change Interrupts.
General utilities API that have broad application in programs.