macro_rules! spmi_register_block {
(
pub struct $name:ident {
$($tail:tt)*
}
) => { ... };
(@fields) => { ... };
(@fields $vis:vis $field:ident => $reg_mod:ident, $($tail:tt)*) => { ... };
(@fields $vis:vis $field:ident => $reg_mod:ident) => { ... };
}Expand description
Defines a struct to group multiple SPMI registers.
This macro generates a public struct named $name that holds a
device client and provides methods to access individual registers
defined by spmi_register!, as well as read_bulk and write_bulk
methods for contiguous accesses.
§Arguments
$name: The identifier for the generated register block struct.{ ... }: A block defining the registers contained within this block. The format of each register definition is:$vis $field_name => $reg_mod,$vis: Visibility of the register accessor method (e.g.,pub).$field_name: The name of the method generated on the block struct to access the register.$reg_mod: The module identifier of the register defined viaspmi_register!.
§Examples
spmi_register! {
my_reg, u8, 0x10, RW, {
pub enable, set_enable: 7;
}
}
spmi_register! {
status_reg, u16, 0x12, RO, LE, {
pub ready: 0;
}
}
spmi_register_block! {
pub struct MyDeviceRegisters {
pub control => my_reg,
pub status => status_reg,
}
}
// Usage:
// let regs = MyDeviceRegisters::new(spmi_device);
// let ctrl_val = regs.control().read().await?;
// let is_ready = regs.status().read().await?.ready();