Skip to content

Commit f133d25

Browse files
committed
Fix defmt issuse with unions
1 parent 679d47d commit f133d25

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

hid-io-protocol/src/commands/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ pub mod h0021 {
471471
}
472472

473473
#[derive(Clone, Copy)]
474-
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
475474
pub union Argument {
476475
pub raw: u16,
477476
pub control: args::Control,
@@ -486,6 +485,13 @@ pub mod h0021 {
486485
}
487486
}
488487

488+
#[cfg(feature = "defmt")]
489+
impl defmt::Format for Argument {
490+
fn format(&self, fmt: defmt::Formatter) {
491+
defmt::write!(fmt, "{}", unsafe { self.raw })
492+
}
493+
}
494+
489495
pub mod args {
490496
use num_enum::TryFromPrimitive;
491497

@@ -741,7 +747,6 @@ pub mod h0050 {
741747
}
742748

743749
#[derive(Clone, Copy)]
744-
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
745750
pub union Argument {
746751
pub raw: u16,
747752
pub led_test_sequence: args::LedTestSequence,
@@ -755,6 +760,13 @@ pub mod h0050 {
755760
}
756761
}
757762

763+
#[cfg(feature = "defmt")]
764+
impl defmt::Format for Argument {
765+
fn format(&self, fmt: defmt::Formatter) {
766+
defmt::write!(fmt, "{}", unsafe { self.raw })
767+
}
768+
}
769+
758770
#[derive(Clone, Debug)]
759771
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
760772
pub struct Cmd {
@@ -815,7 +827,6 @@ pub mod h0051 {
815827
}
816828

817829
#[derive(Clone, Copy)]
818-
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
819830
pub union Argument {
820831
pub raw: u16,
821832
pub led_test_sequence: args::LedTestSequence,
@@ -829,6 +840,13 @@ pub mod h0051 {
829840
}
830841
}
831842

843+
#[cfg(feature = "defmt")]
844+
impl defmt::Format for Argument {
845+
fn format(&self, fmt: defmt::Formatter) {
846+
defmt::write!(fmt, "{}", unsafe { self.raw })
847+
}
848+
}
849+
832850
#[derive(Clone, Debug)]
833851
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
834852
pub struct Cmd<const D: usize> {

hid-io-protocol/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ impl<const H: usize> HidIoPacketBuffer<H> {
607607
let id_num = packet_id(packet_data)?;
608608
let id = match HidIoCommandId::try_from(id_num) {
609609
Ok(id) => id,
610-
Err(_e) => {
611-
error!("Failed to convert {} to HidIoCommandId: {}", id_num, _e);
610+
Err(_) => {
611+
error!("Failed to convert {} to HidIoCommandId", id_num);
612612
return Err(HidIoParseError::InvalidHidIoCommandId(id_num));
613613
}
614614
};

0 commit comments

Comments
 (0)