Use macro to prevent code repetition

This commit is contained in:
Łukasz Dobrowolski 2025-04-07 01:46:38 +02:00 committed by ferris
parent 455c2c708b
commit e573807e53

View File

@ -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;