Skip to content

Commit b7cf238

Browse files
authored
Merge branch 'master' into feature/alternate-settings
2 parents f95217b + c9e28ff commit b7cf238

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
910
### Added
10-
* New enums and allocators for Isochronous endpoints
11-
* Added support for alternate settings on interfaces
11+
* New enums and allocators for Isochronous endpoints ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)).
12+
* Ability to select USB revision ([#116](https://github.com/rust-embedded-community/usb-device/pull/116)).
13+
* Added support for alternate settings on interfaces ([#114](https://github.com/rust-embedded-community/usb-device/pull/114)).
1214

1315
### Changed
14-
* `EndpointType` enum now has fields for isochronous synchronization and usage.
16+
* `EndpointType` enum now has fields for isochronous synchronization and usage ([#60](https://github.com/rust-embedded-community/usb-device/pull/60)).
1517

1618
## [0.2.9] - 2022-08-02
1719

20+
### Added
21+
* Optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76)).
22+
1823
### Fixed
1924
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
20-
* Add optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76))
2125
* Fixed Suspend state transition so it goes back to the previous state, not just Default ([#97](https://github.com/rust-embedded-community/usb-device/pull/97))
2226

2327
## [0.2.8] - 2021-03-13

src/descriptor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ impl DescriptorWriter<'_> {
110110
self.write(
111111
descriptor_type::DEVICE,
112112
&[
113-
0x10,
114-
0x02, // bcdUSB 2.1
115-
config.device_class, // bDeviceClass
116-
config.device_sub_class, // bDeviceSubClass
117-
config.device_protocol, // bDeviceProtocol
118-
config.max_packet_size_0, // bMaxPacketSize0
113+
(config.usb_rev as u16) as u8,
114+
(config.usb_rev as u16 >> 8) as u8, // bcdUSB
115+
config.device_class, // bDeviceClass
116+
config.device_sub_class, // bDeviceSubClass
117+
config.device_protocol, // bDeviceProtocol
118+
config.max_packet_size_0, // bMaxPacketSize0
119119
config.vendor_id as u8,
120120
(config.vendor_id >> 8) as u8, // idVendor
121121
config.product_id as u8,

src/device.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ pub enum UsbDeviceState {
3030
// Maximum number of endpoints in one direction. Specified by the USB specification.
3131
const MAX_ENDPOINTS: usize = 16;
3232

33+
/// Usb spec revision.
34+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
35+
#[repr(u16)]
36+
pub enum UsbRev {
37+
/// USB 2.0 compliance
38+
Usb200 = 0x200,
39+
/// USB 2.1 compliance.
40+
///
41+
/// Typically adds support for BOS requests.
42+
Usb210 = 0x210,
43+
}
44+
3345
/// A USB device consisting of one or more device classes.
3446
pub struct UsbDevice<'a, B: UsbBus> {
3547
bus: &'a B,
@@ -49,6 +61,7 @@ pub(crate) struct Config<'a> {
4961
pub max_packet_size_0: u8,
5062
pub vendor_id: u16,
5163
pub product_id: u16,
64+
pub usb_rev: UsbRev,
5265
pub device_release: u16,
5366
pub manufacturer: Option<&'a str>,
5467
pub product: Option<&'a str>,
@@ -506,7 +519,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
506519
}
507520

508521
match dtype {
509-
descriptor_type::BOS => accept_writer(xfer, |w| {
522+
descriptor_type::BOS if config.usb_rev > UsbRev::Usb200 => accept_writer(xfer, |w| {
510523
let mut bw = BosWriter::new(w);
511524
bw.bos()?;
512525

src/device_builder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bus::{UsbBus, UsbBusAllocator};
2-
use crate::device::{Config, UsbDevice};
2+
use crate::device::{Config, UsbDevice, UsbRev};
33

44
/// A USB vendor ID and product ID pair.
55
pub struct UsbVidPid(pub u16, pub u16);
@@ -34,6 +34,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
3434
max_packet_size_0: 8,
3535
vendor_id: vid_pid.0,
3636
product_id: vid_pid.1,
37+
usb_rev: UsbRev::Usb210,
3738
device_release: 0x0010,
3839
manufacturer: None,
3940
product: None,
@@ -87,6 +88,11 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
8788
///
8889
/// Default: `false`
8990
supports_remote_wakeup: bool,
91+
92+
/// Sets which Usb 2 revision to comply to.
93+
///
94+
/// Default: `UsbRev::Usb210`
95+
usb_rev: UsbRev,
9096
}
9197

9298
/// Configures the device as a composite device with interface association descriptors.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub mod class_prelude {
198198
}
199199

200200
fn _ensure_sync() {
201-
use crate::bus::{PollResult, UsbBus, UsbBusAllocator};
201+
use crate::bus::PollResult;
202202
use crate::class_prelude::*;
203203

204204
struct DummyBus<'a> {

0 commit comments

Comments
 (0)