Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ embedded-time = "0.12"
heapless = "0.9"
# heapless-bytes = "0.3"
interchange = "0.3"
usb-device = { version = "0.2.3", features = ["control-buffer-256"] }
# Selects the usb-device version; see the `usb_device` alias in src/lib.rs.
# control-buffer-256 is needed either way: CCID descriptors exceed 128 bytes.
usb-device-0-2 = { package = "usb-device", version = "0.2.3", features = ["control-buffer-256"], optional = true }
usb-device-0-3 = { package = "usb-device", version = "0.3.2", features = ["control-buffer-256"], optional = true }

[features]
default = []
default = ["usb-device-0-2"]
highspeed-usb = []

"usb-device-0-2" = ["dep:usb-device-0-2"]
"usb-device-0-3" = ["dep:usb-device-0-3"]

log-all = []
log-none = []
log-trace = []
Expand Down
14 changes: 10 additions & 4 deletions src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ use crate::{
types::{packet::RawPacket, ClassRequest, Status},
};

use usb_device::class_prelude::*;
use crate::usb_device::class_prelude::*;
type Result<T> = core::result::Result<T, UsbError>;

/// usb-device 0.3 changed the `get_string` lang id from `u16` to `LangID`.
#[cfg(feature = "usb-device-0-3")]
type LangId = LangID;
#[cfg(not(feature = "usb-device-0-3"))]
type LangId = u16;

pub struct Ccid<'bus, 'pipe, Bus, const N: usize>
where
Bus: 'static + UsbBus,
Expand Down Expand Up @@ -101,7 +107,7 @@ where
Ok(())
}

fn get_string(&self, index: StringIndex, _lang_id: u16) -> Option<&str> {
fn get_string(&self, index: StringIndex, _lang_id: LangId) -> Option<&str> {
(self.string_index == index).then_some(FUNCTIONAL_INTERFACE_STRING)
}

Expand Down Expand Up @@ -150,7 +156,7 @@ where
}

fn control_in(&mut self, transfer: ControlIn<Bus>) {
use usb_device::control::*;
use crate::usb_device::control::*;
let Request {
request_type,
recipient,
Expand Down Expand Up @@ -191,7 +197,7 @@ where
}

fn control_out(&mut self, transfer: ControlOut<Bus>) {
use usb_device::control::*;
use crate::usb_device::control::*;
let Request {
request_type,
recipient,
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
extern crate delog;
generate_macros!();

// The selected `usb-device` version; 0.3 wins if both features are enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have it just be a breaking change release that removes support for 0.2 . Anyway making 0.2 support go behind an enabled by default feature flag is already technically semver breaking.

#[cfg(all(feature = "usb-device-0-2", not(feature = "usb-device-0-3")))]
pub use usb_device_0_2 as usb_device;
#[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`.");

mod class;
mod constants;
mod pipe;
Expand Down
2 changes: 1 addition & 1 deletion src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
},
};

use usb_device::class_prelude::*;
use crate::usb_device::class_prelude::*;

#[allow(clippy::assertions_on_constants)]
const _: () = assert!(MAX_MSG_LENGTH >= PACKET_SIZE);
Expand Down