macro_rules! register_bitfields {
{
$valtype:ident, $( $(#[$inner:meta])* $vis:vis $reg:ident $fields:tt ),* $(,)?
} => { ... };
}
Expand description
Define register types and fields.
Implementations of memory-mapped registers can use this macro to define the structure and bitwise meaning of individual registers in the peripheral. An example use for a hypothetical UART driver might look like:
ⓘ
register_bitfields![u32,
CONTROL [
ENABLE OFFSET(0) NUMBITS(1),
STOP_BITS OFFSET(1) NUMBITS(2) [
StopBits1 = 0,
StopBits2 = 1,
StopBits0 = 2
]
],
BYTE [
CHARACTER OFFSET(0) NUMBITS(8)
],
INTERRUPT [
TRANSMITTED OFFSET(0) NUMBITS(1),
RECEIVED OFFSET(1) NUMBITS(1),
FIFO_FULL OFFSET(2) NUMBITS(1)
]
];
Each field in the register can be identified by its offset within the register and its bitwidth. Fields that have discrete options with semantic meaning can be enumerated.