macro_rules! register_structs {
{
$(
$(#[$attr:meta])*
$vis_struct:vis $name:ident $(<$life:lifetime>)? {
$( $fields:tt )*
}
),*
} => { ... };
}
Expand description
Define a peripheral memory map containing registers.
Implementations of memory-mapped registers can use this macro to define the individual registers in the peripheral and their relative address offset from the start of the peripheral’s mapped address. An example use for a hypothetical UART driver might look like:
ⓘ
register_structs! {
pub UartRegisters {
(0x00 => control: ReadWrite<u32, CONTROL::Register>),
(0x04 => write_byte: ReadWrite<u32, BYTE::Register>),
(0x08 => _reserved1),
(0x20 => interrupt_enable: ReadWrite<u32, INTERRUPT::Register>),
(0x24 => interrupt_status: ReadWrite<u32, INTERRUPT::Register>),
(0x28 => @END),
}
}
By convention, gaps in the register memory map are named _reserved
. The
macro will automatically compute the size of the reserved field so that the
next register is at the correct address.
The size of the register is denoted by the first parameter in the
ReadWrite
type. The second parameter in the
ReadWrite
type is a register definition
which is specified with the
register_bitfields!()
macro.