rust-bitfield
rust-bitfield copied to clipboard
Support `defmt`
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
todefmt
and get all the fields in the output, but this seems like a lot of effort
(ping @brandonros)
Actually, the derive option should already work, but I haven't tested.
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.
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;
}