Skip to main content

register_block

Macro register_block 

Source
macro_rules! register_block {
    (
        $vis:vis struct $name:ident <$mmio:ident> {
            $(
                $(#[$attr:meta])*
                $field_vis:vis $field:ident : $reg_type:ident
            ),* $(,)?
        }
    ) => { ... };
}
Expand description

A macro for generating a block of registers over an MMIO region.

This generates a wrapper struct that contains an MMIO region, and provides proxy methods to interact with the registers defined in the block.

Access modes (read/write and indexed) are automatically determined from each register’s definition using the RegisterReadAccess and RegisterWriteAccess traits.

§Examples

register_block! {
    pub struct MyBlock<M> {
        pub status: StatusReg,
        pub control: ControlReg,
        pub data: DataReg, // Can be an IndexedRegister
    }
}

// Usage:
let block = MyBlock::new(mmio);
let status = block.status().read();