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

Support defmt #34

Open
dzamlo opened this issue Jul 28, 2023 · 3 comments
Open

Support defmt #34

dzamlo opened this issue Jul 28, 2023 · 3 comments

Comments

@dzamlo
Copy link
Owner

dzamlo commented Jul 28, 2023

This depends on the level of support we want:

  • We could simply support #[derive(Format)] but we will not get all the fields in the debug output only .0
  • We could port the bitfield_debug to defmt and get all the fields in the output, but this seems like a lot of effort

(ping @brandonros)

@dzamlo
Copy link
Owner Author

dzamlo commented Jul 28, 2023

Actually, the derive option should already work, but I haven't tested.

@dvdsk
Copy link

dvdsk commented Apr 23, 2024

Actually, the derive option should already work, but I haven't tested.

It does not seem to work for me, and it should not right?

If I read the macro correct:

macro_rules! bitfield {
    ($(#[$attribute:meta])* pub struct $($rest:tt)*) => { ... };
    ($(#[$attribute:meta])* struct $($rest:tt)*) => { ... };
    ($(#[$attribute:meta])* ($($vis:tt)*) struct $name:ident($($type:tt)*); impl Debug; no default 
BitRange; $($rest:tt)*) => { ... };

   etc etc etc

In that last line the macro matches directly on impl Debug. Honestly I do not get while it compiles at all with impl defmt::Format. Adding a line impl defmt::Format could work as a interim solution.

As a embedded user (where bitfields are rather commen) I would love to get all the fields in the output though.

dvdsk added a commit to dvdsk/async-bosch-bme680 that referenced this issue Apr 23, 2024
@dzamlo
Copy link
Owner Author

dzamlo commented Apr 25, 2024

The correct syntax to auto derive defmt::Format that display .0 should be #[derive(defmt::Format)] above the struct name.

Like so:

bitfield! {
+   #[derive(defmt::Format)]
     struct CtrlMeasurement(u8);
-   impl defmt::Format;
    u8;
    pub from into Oversampling, temperature_os, set_temperature_os: 7, 5;
    pub from into Oversampling, pressure_os, set_pressure_os: 4, 2;
    pub from into SensorMode, mode, set_mode: 1, 0;
}

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

No branches or pull requests

2 participants