-
Notifications
You must be signed in to change notification settings - Fork 31
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
Print array fields separate instead of as array in Debug
and defmt::Format
impls.
#45
Conversation
Debug
and defmt::Format
impls.
Hmm, once concern I have: can we be sure the start index from the datasheet is actually For example, the STM32F405xx ADCs have the registers Maybe |
Adjusted the implementation to print the original field names, by storing them in This does still pose a problem for the stm32 crates though, because the generated YAML files are checked in to the repo. So re-running the |
About field names: I'm not sure what's best. Printing indices starting with 0 will be inconsistent with datasheets/manuals, but printing indices starting with 1 will be inconsistent with the code the user is writing.
They're checked in because they're maintained by hand. Only at the beginning they're extracted from the SVDs. The SVDs are garbage quality so they need fixing, improving, deduplicating across families manually, which is done by hand. So yes there's no easy way to get the "original" field names other than filling them in by hand. |
I understand. I think this is also a matter of how it's printed. For example, for a field called SQ5 which happens to be the first SQ field in a particular fieldset: Personally I think I would say
I understand the choice. But it does complicate what I want to do now :p Maybe I can use the available data to recover field names automatically though. I have a proposal on how to proceed: I can change the Additionally, I will have to remove the If you really don't want to use real field names in order to avoid confusion with the index, I can still do the second part of the proposal to switch to array indexing syntax and (probably) improve compile times. /edit: Pushed a commit implementing the proposal. For stm32 with unknown original field names it generates this: impl core::fmt::Debug for Sqr2 {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Sqr2")
.field("sq[0]", &self.sq(0usize))
.field("sq[1]", &self.sq(1usize))
.field("sq[2]", &self.sq(2usize))
.field("sq[3]", &self.sq(3usize))
.field("sq[4]", &self.sq(4usize))
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Sqr2 {
fn format(&self, f: defmt::Formatter) {
defmt::write!(
f,
"Sqr2 {{ sq[0]: {=u8:?}, sq[1]: {=u8:?}, sq[2]: {=u8:?}, sq[3]: {=u8:?}, sq[4]: {=u8:?} }}",
self.sq(0usize),
self.sq(1usize),
self.sq(2usize),
self.sq(3usize),
self.sq(4usize)
)
}
} |
What do you think of the proposal? I also think that recording original field names is a good idea for the future. It could also be used to improve generated documentation. |
I think adding I like the |
6aba681
to
34fc0dc
Compare
I think the main benefit will come from the ability to generate better documentation. I was quite confused for a while about what value to use for the index parameter of array field accessors in the PAC. If the original field names are known, the documentation could explain better how the index maps to actual fields. This PR itself doesn't do that yet, but I was thinking it could be another use for the field names. For the STM32 yaml files, I have the faint hope that some hacky scripting can restore the original field names from the SVD files.
I also think it's a big improvement already. At-least you don't have to count array elements to find the right one anymore :p I removed the original field names from the PR. Maybe if I find myself with enough time on my hands I will look at a proof of concept for better array field documentation based on original field names and lobby to get it back in :p And then I can propose to print actual field names again ^_^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
The first implementation of
Debug
anddefmt::Format
printed array fields as actual arrays. However, that is rather hard to read. This PR changes them to print as numbered fields (which is also how they are named in the datasheets, so that's nice).For example, it generates this:
instead of this: