modm API documentation
|
Classes | |
struct | modm::Configuration< Parent, Enum, Mask, Position > |
struct | modm::Flags< Enum, T > |
struct | modm::FlagsGroup< T... > |
struct | modm::FlagsOperators< Enum, T > |
struct | modm::Register< T > |
struct | modm::Value< Parent, Width, Position > |
Macros | |
#define | MODM_FLAGS8(Enum) |
#define | MODM_FLAGS16(Enum) |
#define | MODM_FLAGS32(Enum) |
#define | MODM_TYPE_FLAGS(Parent) |
#define | MODM_FLAGS_CONFIG(Parent, Config) |
Variables | |
modm::FlagsOperators | modm::modm_packed |
using | modm::Register8 = Register< uint8_t > |
Register class with 8-bit wide underlying type. | |
using | modm::Register16 = Register< uint16_t > |
Register class with 16-bit wide underlying type. | |
using | modm::Register32 = Register< uint32_t > |
Register class with 32-bit wide underlying type. | |
template<typename Enum = uint8_t> | |
using | modm::Flags8 = Flags< Enum, uint8_t > |
Flags class with 8-bit wide underlying type. | |
template<typename Enum = uint16_t> | |
using | modm::Flags16 = Flags< Enum, uint16_t > |
Flags class with 16-bit wide underlying type. | |
template<typename Enum = uint32_t> | |
using | modm::Flags32 = Flags< Enum, uint32_t > |
Flags class with 32-bit wide underlying type. | |
lbuild module: modm:architecture:register
Data structures to provide a native register abstraction.
These data structures are used to describe the relationship of single bits, bit groups and bit configurations in registers with type-safe access.
Registers can be made up of three things:
Example of an 8-bit register called Control
The bits can be modelled using strongly-typed enums and the Flags template class as follows:
You can handle all its register bits as you would expect:
You still get raw access if you really need it:
The access is type-safe, you cannot use bits from two different registers:
You can even overload functions on argument type now:
Configurations are also described as a strongly-typed enum and then wrapped into the Configuration template class.
The Prescaler
enum values are already shifted in this example (hence the (Bit5 | Bit4)
mask), however you can also declare the prescaler values non-shifted and let the wrapper shift it:
Why? If you have two or more configurations with the same selections in the same register, you can simply add another one:
Configurations can be used inline:
But do not have to:
Values are described using the Value template class which masks and shifts the value as required. In our example the value has a width of 3 bits and needs to be shifted 1 bit:
This can be used the same way as the Configuration:
See Typesafe Register Access in C++ for a more detailed background on this implementation.
#define MODM_FLAGS16 |
This macro creates a Flags16 class with the enum class provided and adds the required bitwise (Enum op Enum)
operator overloads for it. The resulting Flags16 class type will have the signature Enum_t
.
Enum | a strongly-typed enum containing the bit masks |
#define MODM_FLAGS32 |
This macro creates a Flags32 class with the enum class provided and adds the required bitwise (Enum op Enum)
operator overloads for it. The resulting Flags32 class type will have the signature Enum_t
.
Enum | a strongly-typed enum containing the bit masks |
#define MODM_FLAGS8 |
This macro creates a Flags8 class with the enum class provided and adds the required bitwise (Enum op Enum)
operator overloads for it The resulting Flags8 class type will have the signature Enum_t
.
Enum | a strongly-typed enum containing the bit masks |
#define MODM_FLAGS_CONFIG |
This macro creates a Config_t
type out of the Parent
and Config
enum. The mask is taken from a Parent::Config_Mask
field containing the ORed bits of the configuration.
modm::Configuration
class manually in that case.Parent | a Flags Enum |
Config | a Config Enum |
#define MODM_TYPE_FLAGS |
This macro creates bitwise (Parent::EnumType op Parent::EnumType)
operator overloads for use with the Flags class.
Parent | a Flags class |