Closed korken89 closed 3 years ago
Right, this is actually more elaborate than I thought because I'd just print the buffer in hex format. But this is clearly better! So we can do both :)
How should we deal with field types that don't implement Debug themselves? Ideally we'd detect that and print the raw numbers, but I don't think we can... Or maybe we should require all fields to implement Debug? But that'd be kinda strict and not always necessary...
Maybe have a flag to request debug that puts a requirement on Debug
and else just print it in HEX?
Then the user can choose to do it or not :)
So I imagine we'll like more of these extensions and restrictions the user can opt in to.
Could try to emulate (only syntactically) what derive
does and maybe call it generate
.
implement_registers!(
MyChip.registers<u8> = {
#[generate(Debug)] // <- New!
status(RO, 0, 1) = {
flag1: u8 as Bit = RO 0..=0,
flag2: u8 as Bit = RO 1..=1,
},
// ...
}
}
I try to avoid completely alien syntax in the macro and I think this would feel familiar and also distinct enough.
Looks good to me!
@korken89 I added support for it! Would you mind trying it out before I merge it?
Hi,
For example when I read a register it would be really nice in development to be able to add debug prints of the register. Eg, lets say I have a register with 2 flags:
Debug-printing with
{:?}
I'd expect something likestatus::R { flag1: Set, flag2: Cleared }
, and with{:#?}
It would also be preferable if one use custom enums that there are also debug printed with correct variants.