-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
If we expand the SysReg trait definitions to include an associated type, we can reduce a lot of the boiler-plate and add read, write and modify functions effectively for free.
/// MPIDR (*Multiprocessor Affinity Register*)
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Mpidr(pub u32);
impl SysReg for Mpidr {
const CP: u32 = 15;
const CRN: u32 = 0;
const OP1: u32 = 0;
const CRM: u32 = 0;
const OP2: u32 = 5;
}
impl crate::register::SysRegRead for Mpidr {}
impl Mpidr {
#[inline]
/// Reads MPIDR (*Multiprocessor Affinity Register*)
pub fn read() -> Mpidr {
unsafe { Self(<Self as SysRegRead>::read_raw()) }
}
}could become
/// MPIDR (*Multiprocessor Affinity Register*)
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Mpidr(pub u32);
impl SysReg for Mpidr {
const CP: u32 = 15;
const CRN: u32 = 0;
const OP1: u32 = 0;
const CRM: u32 = 0;
const OP2: u32 = 5;
}
impl SysRegRead for Mpidr {
type R = Mpidr;
fn convert(value: u32) -> Self { Self(value) }
}However, I'd want to check that the readability of the documentation doesn't suffer if we do this, and the fn read() method is still easily discoverable. Perhaps examples of how to read the register would help. Or, we could do it with a macro instead:
/// MPIDR (*Multiprocessor Affinity Register*)
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Mpidr(pub u32);
sysreg_read!(cp = p15, crn = 0, op1 = 0, crm = 0, op2 = 5, Mpidr, Self(value));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels