Skip to content
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

Added #[generate(Debug)] feature #10

Merged
merged 2 commits into from
May 1, 2021
Merged

Added #[generate(Debug)] feature #10

merged 2 commits into from
May 1, 2021

Conversation

diondokter
Copy link
Owner

Closes #8

You can now do this:

implement_registers!(
    MyDevice.registers<u8> = {
        // (comments must go first)
        #[generate(Debug)]              // <- new!
        id(RO, 0, 3) = MSB {
            manufacturer: u16:LE as Manufacturer = RW 0..16,
            version: u8:NE = RO 16..20,
            edition: u8:BE = RO 20..24,
        },
    }
);

Then we can:

let id = device.registers().id().read()?;
println!("{:?}", id);
id::R { raw: 0x010065, manufacturer: Ok(CarmineCrystal), version: 6, edition: 5 }

The generate attribute is optional. If you don't add it to the register, the output is now better too:

id::R { raw: 0x010065 }

When opting in, all field types must impl Debug.

This attribute syntax can be used later for other things as well.

@diondokter
Copy link
Owner Author

I'm now just noticing it... The field values that are just a number are in decimal. All other numbers are Hex. Will this be a problem?
It's only the raw bit values that are hex and they're all prepended with 0x, so I think that's fine.
In the end you're supposed to leave numbers as numbers. Anywhere where the bits are important (so you'd want to see the hex fmt) should be encoded in enums anyways.

Copy link
Collaborator

@korken89 korken89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be changed so paths are internal to the macro

src/ll/mod.rs Outdated Show resolved Hide resolved
src/ll/register.rs Outdated Show resolved Hide resolved
src/ll/register.rs Outdated Show resolved Hide resolved
src/ll/register.rs Outdated Show resolved Hide resolved
src/ll/register.rs Outdated Show resolved Hide resolved
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
@diondokter
Copy link
Owner Author

Good you spotted that!

@korken89
Copy link
Collaborator

korken89 commented May 1, 2021

Now it works when I test it!

@diondokter diondokter merged commit a2fc042 into master May 1, 2021
@diondokter diondokter deleted the debug_support branch May 1, 2021 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support debug prints on R
2 participants