diff --git a/Cargo.toml b/Cargo.toml index 389a9c9..75fd355 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,13 +16,18 @@ delog = "0.1.0" heapless-bytes = "0.5" interchange = "0.3.0" serde = { version = "1.0", default-features = false } -usb-device = "0.2.3" +# Selects the usb-device version; see the `usb_device` alias in src/lib.rs. +usb-device-0-2 = { package = "usb-device", version = "0.2.3", optional = true } +usb-device-0-3 = { package = "usb-device", version = "0.3.2", optional = true } ref-swap = "0.1.2" trussed-core = "0.2" [features] -default = [] +default = ["usb-device-0-2"] + +"usb-device-0-2" = ["dep:usb-device-0-2"] +"usb-device-0-3" = ["dep:usb-device-0-3"] log-all = [] log-none = [] diff --git a/src/class.rs b/src/class.rs index 44cc90b..f787e8f 100644 --- a/src/class.rs +++ b/src/class.rs @@ -11,8 +11,7 @@ use crate::{ types::Status, }; -use ctaphid_dispatch::Requester; -use usb_device::{ +use crate::usb_device::{ bus::{InterfaceNumber, UsbBus, UsbBusAllocator}, class::{ControlIn, ControlOut, UsbClass}, control, @@ -20,6 +19,7 @@ use usb_device::{ endpoint::{EndpointAddress, EndpointIn, EndpointOut}, Result as UsbResult, }; +use ctaphid_dispatch::Requester; /// Packet-level implementation of the CTAPHID protocol. pub struct CtapHid<'alloc, 'pipe, 'interrupt, Bus: UsbBus, const N: usize> { diff --git a/src/lib.rs b/src/lib.rs index edc9474..3258c4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,15 @@ See "proposed standard": extern crate delog; generate_macros!(); +#[cfg(all(feature = "usb-device-0-2", not(feature = "usb-device-0-3")))] +pub use usb_device_0_2 as usb_device; +/// The selected `usb-device` version; 0.3 wins if both features are enabled. +#[cfg(feature = "usb-device-0-3")] +pub use usb_device_0_3 as usb_device; + +#[cfg(not(any(feature = "usb-device-0-2", feature = "usb-device-0-3")))] +compile_error!("No usb-device version chosen! Enable `usb-device-0-2` or `usb-device-0-3`."); + // use heapless_bytes as bytes; // pub mod authenticator; diff --git a/src/pipe.rs b/src/pipe.rs index fab5147..55ef134 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -23,7 +23,7 @@ use heapless_bytes::Bytes; use ref_swap::OptionRefSwap; use trussed_core::InterruptFlag; // use serde::Serialize; -use usb_device::{ +use crate::usb_device::{ bus::UsbBus, endpoint::{EndpointAddress, EndpointIn, EndpointOut}, UsbError,