modm API documentation
|
#include <modm/architecture/interface/register.hpp>
Public Typedefs | |
typedef Parent::EnumType | EnumType |
The enum type. | |
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 | operator bool () const |
constexpr bool | operator! () const |
Returns true if value is zero. | |
constexpr FlagsOperators | operator~ () const |
bitwise negation | |
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 | |
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 | |
Public Attributes | |
UnderlyingType | value |
The underlying integer value. | |
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 |
|
inheritedinlineexplicitconstexpr |
Returns true
if value
is non-zero
The compiler will allow implicit conversions to bool in the following contexts: