modm API documentation
modm::Configuration< Parent, Enum, Mask, Position > Struct Template Reference

#include <modm/architecture/interface/register.hpp>

Inheritance diagram for modm::Configuration< Parent, Enum, Mask, Position >:
modm::FlagsOperators< Parent::EnumType, Parent::UnderlyingType > modm::Register< Parent::UnderlyingType >

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
 
- Public Member Functions inherited from modm::FlagsOperators< Parent::EnumType, Parent::UnderlyingType >
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.
 
FlagsOperatorsoperator= (FlagsOperators const &o) = default
 Copy assignment.
 
FlagsOperatorsoperator= (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
 
FlagsOperatorsoperator&= (FlagsOperators const &o)
 bitwise AND with multiple bits
 
FlagsOperatorsoperator^= (FlagsOperators const &o)
 bitwise XOR with multiple bits
 
FlagsOperatorsoperator|= (FlagsOperators const &o)
 bitwise OR with multiple bits
 
FlagsOperatorsoperator&= (Parent::EnumType const &flag)
 bitwise AND with a single bit
 
FlagsOperatorsoperator^= (Parent::EnumType const &flag)
 bitwise XOR with a single bit
 
FlagsOperatorsoperator|= (Parent::EnumType const &flag)
 bitwise OR with a single bit
 
- Public Member Functions inherited from modm::Register< Parent::UnderlyingType >
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 Public Member Functions inherited from modm::FlagsOperators< Parent::EnumType, Parent::UnderlyingType >
static constexpr FlagsOperators mask ()
 returns the mask of the integer type
 

Additional Inherited Members

- Public Typedefs inherited from modm::FlagsOperators< Parent::EnumType, Parent::UnderlyingType >
typedef Parent::EnumType EnumType
 The enum type.
 
- Public Typedefs inherited from modm::Register< Parent::UnderlyingType >
typedef Parent::UnderlyingType UnderlyingType
 The integer type internally used to represent the register.
 
- Public Attributes inherited from modm::Register< Parent::UnderlyingType >
UnderlyingType value
 The underlying integer value.
 
- Protected Member Functions inherited from modm::Register< Parent::UnderlyingType >
constexpr Register (UnderlyingType initialValue)
 This class is meant to be subclassed.
 

Detailed Description

template<typename Parent, typename Enum, typename Parent::UnderlyingType Mask, typename Parent::UnderlyingType Position = 0>
struct modm::Configuration< Parent, Enum, Mask, Position >

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:

    >
  1. There is only one prescaler configuration at bit position 4, and
  2. There are two or more prescaler configurations at several bit positions.

For the first scenario, no shifting is required, as we can declare the prescaler values already in the shifted position:

enum class
Prescaler : uint8_t
{
Div1 = (0 << 4),
Div2 = (1 << 4),
Div4 = (2 << 4),
Div8 = (3 << 4),
};
typedef Configuration<Control_t, Prescaler, (0b11 << 4)> Prescaler_t;

For the second scenario, shifting is required:

enum class
Prescaler : uint8_t
{
Div1 = 0,
Div2 = 1,
Div4 = 2,
Div8 = 3,
};
// shift position 4
typedef Configuration<Control_t, Prescaler, 0b11, 4> Prescaler_t;
// shift position 6
typedef Configuration<Control_t, Prescaler, 0b11, 6> Prescaler2_t;

However, clever choice of the mask and shift position values can minimize shifting.

enum class
Prescaler : uint8_t
{
Div1 = (0 << 4),
Div2 = (1 << 4),
Div4 = (2 << 4),
Div8 = (3 << 4),
};
// shift position 4, not shifted
typedef Configuration<Control_t, Prescaler, (0b11 << 4)> Prescaler_t;
// shift position 6, shifted only by 2 bits
typedef Configuration<Control_t, Prescaler, (0b11 << 4), 2> Prescaler2_t;

This is especially useful on CPUs, which do not have a barrelshifter like the AVRs.

Template Parameters
Parentthe Flags class to which this configuration belongs to
Enuma strongly-typed enum containing the configuration values
Maskthe (unshifted) bit mask corresponding to the enum values
Positionhow many bits the configuration values need to be shifted
Author
Niklas Hauser

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