Skip to content

Commit 6824c32

Browse files
authored
Merge branch 'master' into master
2 parents f99fb98 + 202e5ee commit 6824c32

File tree

16 files changed

+259
-84
lines changed

16 files changed

+259
-84
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
push:
3+
branches: [ staging, trying, master ]
4+
pull_request:
5+
6+
name: CI
7+
8+
jobs:
9+
ci-linux:
10+
name: CI
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
rust: [stable]
16+
17+
include:
18+
# Test nightly but don't fail
19+
- rust: nightly
20+
experimental: true
21+
TARGET: x86_64-unknown-linux-gnu
22+
23+
steps:
24+
- uses: actions/checkout@v2
25+
26+
- uses: actions-rs/toolchain@v1
27+
with:
28+
profile: minimal
29+
toolchain: ${{ matrix.rust }}
30+
target: ${{ matrix.TARGET }}
31+
override: true
32+
33+
- name: Install libusb library
34+
run: sudo apt-get install -y libusb-1.0.0-dev
35+
36+
- uses: actions-rs/cargo@v1
37+
with:
38+
command: check
39+
args: --all-targets
40+
41+
- uses: actions-rs/cargo@v1
42+
with:
43+
command: check
44+
args: --features control-buffer-256
45+
46+
- uses: actions-rs/cargo@v1
47+
with:
48+
command: check
49+
args: --features defmt

.github/workflows/rustfmt.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
push:
3+
branches: [ staging, trying, master ]
4+
pull_request:
5+
6+
name: Code formatting check
7+
8+
jobs:
9+
fmt:
10+
name: Rustfmt
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
profile: minimal
17+
toolchain: stable
18+
override: true
19+
components: rustfmt
20+
- uses: actions-rs/cargo@v1
21+
with:
22+
command: fmt
23+
args: --all -- --check

.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Fixed
11+
* Fixed an issue where USB devices were not enumerating on Windows ([#32](https://github.com/rust-embedded-community/usb-device/issues/82))
12+
* Add optional support for defmt ([#76](https://github.com/rust-embedded-community/usb-device/pull/76))
13+
14+
...
15+
16+
## [0.2.8] - 2021-03-13
17+
18+
## [0.2.7] - 2020-10-03
19+
20+
## [0.2.6] - 2020-09-22
21+
22+
## [0.2.5] - 2020-02-10
23+
24+
## [0.2.4] - 2020-02-01
25+
26+
## [0.2.3] - 2019-08-28
27+
28+
## [0.2.2] - 2019-07-27
29+
30+
## [0.2.1] - 2019-06-07
31+
32+
## [0.2.0] - 2019-06-07
33+
34+
## 0.1.0 - 2019-06-07
35+
36+
This is the initial release to crates.io.
37+
38+
[Unreleased]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.8...HEAD
39+
[0.2.8]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.7...v0.2.8
40+
[0.2.7]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.6...v0.2.7
41+
[0.2.6]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.5...v0.2.6
42+
[0.2.5]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.4...v0.2.5
43+
[0.2.4]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.3...v0.2.4
44+
[0.2.3]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.2...v0.2.3
45+
[0.2.2]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.1...v0.2.2
46+
[0.2.1]: https://github.com/rust-embedded-community/usb-device/compare/v0.2.0...v0.2.1
47+
[0.2.0]: https://github.com/rust-embedded-community/usb-device/compare/v0.1.0...v0.2.0

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ license = "MIT"
99
authors = ["Matti Virkkunen <[email protected]>"]
1010
repository = "https://github.com/mvirkkunen/usb-device"
1111

12+
[dependencies]
13+
defmt = { version = "0.3", optional = true }
14+
1215
[dev-dependencies]
1316
rusb = "0.8.0"
1417
rand = "0.6.1"

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@ each device's USB peripheral.
2020
Hardware driver crates
2121
----------------------
2222

23-
* [stm32-usbd](https://github.com/stm32-rs/stm32-usbd) - device-driver implementation for multiple STM32 microcontroller families.
24-
Examples can be found in each individual HAL crate that implements the USB peripheral.
23+
* [atsam4](https://github.com/atsam-rs/atsam4-hal) - device-driver implementation for atsam4e & atsam4s microcontrollers (UDP). Examples can be found [here](https://github.com/atsam-rs/sam_xplained). While not expressly supported with this crate, atsam3s and atsam55g could also be supported with a similar code-base.
2524

2625
* [atsamd](https://github.com/atsamd-rs/atsamd) - device-driver implementation for samd21 & samd51 microcontrollers. An example for the
2726
itsybitsy_m4 board from Adafruit can be found [here](https://github.com/atsamd-rs/atsamd/blob/master/boards/itsybitsy_m4/examples/usb_serial.rs).
2827

2928
* [imxrt-usbd](https://github.com/imxrt-rs/imxrt-usbd) - device-driver implementation for NXP i.MX RT microcontrollers. Examples for
3029
i.MX RT boards, like the Teensy 4, are maintained with the driver.
3130

31+
* [stm32-usbd](https://github.com/stm32-rs/stm32-usbd) - device-driver implementation for multiple STM32 microcontroller families.
32+
Examples can be found in each individual HAL crate that implements the USB peripheral.
33+
3234
Class crates
3335
------------
3436

35-
* [usbd-serial](https://github.com/mvirkkunen/usbd-serial) [![Crates.io](https://img.shields.io/crates/v/usbd-serial.svg)](https://crates.io/crates/usbd-serial) - CDC-ACM serial port class
3637
* [usbd-hid](https://github.com/twitchyliquid64/usbd-hid) [![Crates.io](https://img.shields.io/crates/v/usbd-hid.svg)](https://crates.io/crates/usbd-hid) - HID class
38+
* [usbd-serial](https://github.com/mvirkkunen/usbd-serial) [![Crates.io](https://img.shields.io/crates/v/usbd-serial.svg)](https://crates.io/crates/usbd-serial) - CDC-ACM serial port class
39+
40+
41+
Others
42+
------
43+
44+
Other implementations for USB in Rust
45+
* [embassy-usb](https://github.com/embassy-rs/embassy/blob/master/embassy-usb/src/driver.rs), an async variant.

src/bus.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<B: UsbBus> UsbBusAllocator<B> {
211211
///
212212
/// This directly delegates to [`UsbBus::alloc_ep`], so see that method for details. In most
213213
/// cases classes should call the endpoint type specific methods instead.
214-
pub fn alloc<'a, D: EndpointDirection>(
214+
pub fn alloc<D: EndpointDirection>(
215215
&self,
216216
ep_addr: Option<EndpointAddress>,
217217
ep_type: EndpointType,
@@ -281,6 +281,7 @@ impl<B: UsbBus> UsbBusAllocator<B> {
281281

282282
/// A handle for a USB interface that contains its number.
283283
#[derive(Copy, Clone, Eq, PartialEq)]
284+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
284285
pub struct InterfaceNumber(u8);
285286

286287
impl From<InterfaceNumber> for u8 {
@@ -291,6 +292,7 @@ impl From<InterfaceNumber> for u8 {
291292

292293
/// A handle for a USB string descriptor that contains its index.
293294
#[derive(Copy, Clone, Eq, PartialEq)]
295+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
294296
pub struct StringIndex(u8);
295297

296298
impl StringIndex {

src/control.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::mem;
44
/// Control request type.
55
#[repr(u8)]
66
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
7+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
78
pub enum RequestType {
89
/// Request is a USB standard request. Usually handled by
910
/// [`UsbDevice`](crate::device::UsbDevice).
@@ -18,6 +19,7 @@ pub enum RequestType {
1819

1920
/// Control request recipient.
2021
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
22+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2123
pub enum Recipient {
2224
/// Request is intended for the entire device.
2325
Device = 0,
@@ -35,6 +37,7 @@ pub enum Recipient {
3537

3638
/// A control request read from a SETUP packet.
3739
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
40+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
3841
pub struct Request {
3942
/// Direction of the request.
4043
pub direction: UsbDirection,

src/control_pipe.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{Result, UsbDirection, UsbError};
55
use core::cmp::min;
66

77
#[derive(Debug)]
8+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
89
#[allow(unused)]
910
enum ControlState {
1011
Idle,
@@ -51,10 +52,10 @@ impl<B: UsbBus> ControlPipe<'_, B> {
5152
}
5253

5354
pub fn waiting_for_response(&self) -> bool {
54-
match self.state {
55-
ControlState::CompleteOut | ControlState::CompleteIn(_) => true,
56-
_ => false,
57-
}
55+
matches!(
56+
self.state,
57+
ControlState::CompleteOut | ControlState::CompleteIn(_)
58+
)
5859
}
5960

6061
pub fn data(&self) -> &[u8] {
@@ -65,7 +66,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
6566
self.state = ControlState::Idle;
6667
}
6768

68-
pub fn handle_setup<'p>(&'p mut self) -> Option<Request> {
69+
pub fn handle_setup(&mut self) -> Option<Request> {
6970
let count = match self.ep_out.read(&mut self.buf[..]) {
7071
Ok(count) => count,
7172
Err(UsbError::WouldBlock) => return None,
@@ -122,10 +123,10 @@ impl<B: UsbBus> ControlPipe<'_, B> {
122123
return Some(req);
123124
}
124125

125-
return None;
126+
None
126127
}
127128

128-
pub fn handle_out<'p>(&'p mut self) -> Option<Request> {
129+
pub fn handle_out(&mut self) -> Option<Request> {
129130
match self.state {
130131
ControlState::DataOut(req) => {
131132
let i = self.i;
@@ -147,6 +148,8 @@ impl<B: UsbBus> ControlPipe<'_, B> {
147148
return Some(req);
148149
}
149150
}
151+
// The host may terminate a DATA stage early by sending a zero-length status packet
152+
// acknowledging the data we sent it.
150153
ControlState::DataIn
151154
| ControlState::DataInLast
152155
| ControlState::DataInZlp
@@ -163,7 +166,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
163166
}
164167
}
165168

166-
return None;
169+
None
167170
}
168171

169172
pub fn handle_in_complete(&mut self) -> bool {
@@ -194,7 +197,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
194197
}
195198
};
196199

197-
return false;
200+
false
198201
}
199202

200203
fn write_in_chunk(&mut self) {

0 commit comments

Comments
 (0)