-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(read|modify|write)_register should take/return typed structures rather than u8 #10
Comments
This probably requires some broader macro that replaces the per-register-type enum with macro expansion as there's not really a good link between the register value wrappers and the register address enums. |
Finally took a stab at this. self.modify_register(Config::MCSM0, |r| {
MCSM0(r).modify().fs_autocal(autocal.into()).bits() // untyped in/out u8
})?; becomes: self.modify_register(config::MCSM0, |r /* inferred as &mut MCSM0<W> which exposes writable api */ | {
r.fs_autocal(autocal.into()) // fully type safe builder in/out
})?; Register categories declared as: registers!(Config, {
Read => Any, /* category specific access behavior of registers, Any|Burst|Single|Reject */
Write => Any,
}, {
#[doc = "Main Radio Cntrl State Machine config"]
MCSM0(addr: 0x18, reset: 0b0000_0100) {
#[doc = "Automatically calibrate when going to RX or TX, or back to IDLE"]
fs_autocal @ 4..6, /* bit fields */
....
},
MCSM1(...) { .. }
....
} wdyt? @Andrei-Basarab @SebKuzminsky Going to be a bit of an OCD grind to transform the declarations, but think it looks pretty neat with register address and doc near the field declarations, and away with the noise around the access functions. |
I like the sound of that :-) Is your prototype code available for inspection anywhere? I volunteer to help with the OCD grind part of this update if you want. Oh and while we're talking about the register macros, it would be super handy if How did you make the decision to implement the register bitfields yourself, instead of using an existing no_std bitfield crate like |
@dsvensson If you can provide a working example of the change you're thinking of implementing, I can look into that and help with the change. |
The following code:
... should ideally not mention MDMCFG2 in the body, nor modify():
And similarily, calling
self.read_register(config::Register.:MDMCFG2)
should return aMDMCFG2
rather than anu8
.Can probably be fixed by introducing some good traits. Figure out how.
The text was updated successfully, but these errors were encountered: