Skip to content

Commit

Permalink
Merge branch 'master' into feature/alternate-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
eldruin authored Apr 24, 2023
2 parents f95217b + c9e28ff commit b7cf238
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

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

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

## [0.2.9] - 2022-08-02

### Added
* Optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76)).

### Fixed
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
* Add optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76))
* 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))

## [0.2.8] - 2021-03-13
Expand Down
12 changes: 6 additions & 6 deletions src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ impl DescriptorWriter<'_> {
self.write(
descriptor_type::DEVICE,
&[
0x10,
0x02, // bcdUSB 2.1
config.device_class, // bDeviceClass
config.device_sub_class, // bDeviceSubClass
config.device_protocol, // bDeviceProtocol
config.max_packet_size_0, // bMaxPacketSize0
(config.usb_rev as u16) as u8,
(config.usb_rev as u16 >> 8) as u8, // bcdUSB
config.device_class, // bDeviceClass
config.device_sub_class, // bDeviceSubClass
config.device_protocol, // bDeviceProtocol
config.max_packet_size_0, // bMaxPacketSize0
config.vendor_id as u8,
(config.vendor_id >> 8) as u8, // idVendor
config.product_id as u8,
Expand Down
15 changes: 14 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ pub enum UsbDeviceState {
// Maximum number of endpoints in one direction. Specified by the USB specification.
const MAX_ENDPOINTS: usize = 16;

/// Usb spec revision.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u16)]
pub enum UsbRev {
/// USB 2.0 compliance
Usb200 = 0x200,
/// USB 2.1 compliance.
///
/// Typically adds support for BOS requests.
Usb210 = 0x210,
}

/// A USB device consisting of one or more device classes.
pub struct UsbDevice<'a, B: UsbBus> {
bus: &'a B,
Expand All @@ -49,6 +61,7 @@ pub(crate) struct Config<'a> {
pub max_packet_size_0: u8,
pub vendor_id: u16,
pub product_id: u16,
pub usb_rev: UsbRev,
pub device_release: u16,
pub manufacturer: Option<&'a str>,
pub product: Option<&'a str>,
Expand Down Expand Up @@ -506,7 +519,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
}

match dtype {
descriptor_type::BOS => accept_writer(xfer, |w| {
descriptor_type::BOS if config.usb_rev > UsbRev::Usb200 => accept_writer(xfer, |w| {
let mut bw = BosWriter::new(w);
bw.bos()?;

Expand Down
8 changes: 7 additions & 1 deletion src/device_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::bus::{UsbBus, UsbBusAllocator};
use crate::device::{Config, UsbDevice};
use crate::device::{Config, UsbDevice, UsbRev};

/// A USB vendor ID and product ID pair.
pub struct UsbVidPid(pub u16, pub u16);
Expand Down Expand Up @@ -34,6 +34,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
max_packet_size_0: 8,
vendor_id: vid_pid.0,
product_id: vid_pid.1,
usb_rev: UsbRev::Usb210,
device_release: 0x0010,
manufacturer: None,
product: None,
Expand Down Expand Up @@ -87,6 +88,11 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
///
/// Default: `false`
supports_remote_wakeup: bool,

/// Sets which Usb 2 revision to comply to.
///
/// Default: `UsbRev::Usb210`
usb_rev: UsbRev,
}

/// Configures the device as a composite device with interface association descriptors.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub mod class_prelude {
}

fn _ensure_sync() {
use crate::bus::{PollResult, UsbBus, UsbBusAllocator};
use crate::bus::PollResult;
use crate::class_prelude::*;

struct DummyBus<'a> {
Expand Down

0 comments on commit b7cf238

Please sign in to comment.