diff --git a/embassy-usb-driver/src/host.rs b/embassy-usb-driver/src/host.rs index d73fc0586..830aae118 100644 --- a/embassy-usb-driver/src/host.rs +++ b/embassy-usb-driver/src/host.rs @@ -28,40 +28,17 @@ pub enum ChannelError { Disconnected, } -#[cfg(feature = "defmt")] -defmt::bitflags! { - /// RequestType bitfields for the setup packet - pub struct RequestType: u8 { - // Recipient - /// The request is intended for the entire device. - const RECIPIENT_DEVICE = 0; - /// The request is intended for an interface. - const RECIPIENT_INTERFACE = 1; - /// The request is intended for an endpoint. - const RECIPIENT_ENDPOINT = 2; - /// The recipient of the request is unspecified. - const RECIPIENT_OTHER = 3; - - // Type - /// The request is a standard USB request. - const TYPE_STANDARD = 0 << 5; - /// The request is a class-specific request. - const TYPE_CLASS = 1 << 5; - /// The request is a vendor-specific request. - const TYPE_VENDOR = 2 << 5; - /// Reserved. - const TYPE_RESERVED = 3 << 5; - // Direction - /// The request will send data to the device. - const OUT = 0 << 7; - /// The request expects to receive data from the device. - const IN = 1 << 7; - } +macro_rules! bitflags { + ($($tt:tt)*) => { + #[cfg(feature = "defmt")] + defmt::bitflags! { $($tt)* } + #[cfg(not(feature = "defmt"))] + bitflags::bitflags! { $($tt)* } + }; } -#[cfg(not(feature = "defmt"))] -bitflags::bitflags! { - #[derive(Copy, Clone, Eq, PartialEq, Debug)] +bitflags! { + #[cfg_attr(not(feature = "defmt"), derive(Copy, Clone, Eq, PartialEq, Debug))] /// RequestType bitfields for the setup packet pub struct RequestType: u8 { // Recipient @@ -83,6 +60,7 @@ bitflags::bitflags! { const TYPE_VENDOR = 2 << 5; /// Reserved. const TYPE_RESERVED = 3 << 5; + // Direction /// The request will send data to the device. const OUT = 0 << 7;