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 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
 
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
 

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.
 

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

Member Function Documentation

constexpr modm::Register< Parent::UnderlyingType >::operator bool ( ) const
inheritedinlineexplicitconstexpr

Returns true if value is non-zero

The compiler will allow implicit conversions to bool in the following contexts:

  • conditions of if, while, for, do-while statements
  • logical operators (&&, ||)
  • negation (operator !)
  • static_assert

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