modm API documentation
|
#include <modm/architecture/interface/register.hpp>
Public Member Functions | |
constexpr | Configuration (UnderlyingType config) |
explicit constructor for the underlying type | |
constexpr | Configuration (Enum config) |
explicit constructor for the enum type | |
constexpr | Configuration (Configuration const &o) = default |
copy constructor | |
constexpr | Configuration (Configuration &&o) = default |
move constructor | |
![]() | |
constexpr FlagsOperators | operator~ () const |
bitwise negation | |
constexpr | FlagsOperators () |
default constructor initializes value to zero | |
constexpr | FlagsOperators (Parent::EnumType flag) |
constructs itself out of a strongly-typed enum | |
constexpr | FlagsOperators (UnderlyingType flag) |
When explicitly called, this class constructs itself out of the underlying type. | |
constexpr | FlagsOperators (Register< Parent::UnderlyingType > const &o) |
When explicitly called, this class constructs itself out of the superclass. | |
constexpr | FlagsOperators (FlagsOperators const &o) = default |
Copy constructor. | |
constexpr | FlagsOperators (FlagsOperators &&o) = default |
Move constructor. | |
FlagsOperators & | operator= (FlagsOperators const &o) = default |
Copy assignment. | |
FlagsOperators & | operator= (FlagsOperators &&o) = default |
Move assignment. | |
constexpr FlagsOperators | operator& (FlagsOperators const &o) const |
bitwise AND with multiple bits | |
constexpr FlagsOperators | operator^ (FlagsOperators const &o) const |
bitwise XOR with multiple bits | |
constexpr FlagsOperators | operator| (FlagsOperators const &o) const |
bitwise OR with multiple bits | |
FlagsOperators & | operator&= (FlagsOperators const &o) |
bitwise AND with multiple bits | |
FlagsOperators & | operator^= (FlagsOperators const &o) |
bitwise XOR with multiple bits | |
FlagsOperators & | operator|= (FlagsOperators const &o) |
bitwise OR with multiple bits | |
FlagsOperators & | operator&= (Parent::EnumType const &flag) |
bitwise AND with a single bit | |
FlagsOperators & | operator^= (Parent::EnumType const &flag) |
bitwise XOR with a single bit | |
FlagsOperators & | operator|= (Parent::EnumType const &flag) |
bitwise OR with a single bit | |
![]() | |
constexpr | Register () |
Default constructor initializes value to zero. | |
constexpr | operator bool () const |
constexpr bool | operator! () const |
Returns true if value is zero. | |
Static Public Member Functions | |
static constexpr Parent | mask () |
returns the shifted mask for this configuration | |
static void | set (Parent &parent, Enum config) |
clears and sets a new configuration in a Flags register | |
static void | reset (Parent &parent) |
clears the configuration in a Flags register | |
static constexpr Enum | get (Parent const &parent) |
returns the configuration from a Flags register | |
![]() | |
static constexpr FlagsOperators | mask () |
returns the mask of the integer type | |
Additional Inherited Members | |
![]() | |
typedef Parent::EnumType | EnumType |
The enum type. | |
![]() | |
typedef Parent::UnderlyingType | UnderlyingType |
The integer type internally used to represent the register. | |
![]() | |
UnderlyingType | value |
The underlying integer value. | |
![]() | |
constexpr | Register (UnderlyingType initialValue) |
This class is meant to be subclassed. | |
Class for accessing a configuration in a register.
A configuration is a combination of bits, whose meaning is different from their numerical value. A typical example is a 2-bit prescaler with the values [0,1,2,3] correspond to the meanings [Div1, Div2, Div4, Div8].
The Configuration class belongs to a specific Flags class and connects a corresponding strongly typed enum with a specific mask and bit position. This means that the Configuration class will mask and shift the values whenever needed. However, shifting is only done when the Position template parameter is non-zero.
To understand when shifting is necessary, consider the following two scenarios:
For the first scenario, no shifting is required, as we can declare the prescaler values already in the shifted position:
For the second scenario, shifting is required:
However, clever choice of the mask and shift position values can minimize shifting.
This is especially useful on CPUs, which do not have a barrelshifter like the AVRs.
Parent | the Flags class to which this configuration belongs to |
Enum | a strongly-typed enum containing the configuration values |
Mask | the (unshifted) bit mask corresponding to the enum values |
Position | how many bits the configuration values need to be shifted |