Skip to content

Commit b076c61

Browse files
committed
Merge branch 'conorpp-master'
2 parents cbddcce + 1e4332d commit b076c61

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ rand = "0.6.1"
1717
# Use a 256 byte buffer for control transfers instead of 128.
1818
control-buffer-256 = []
1919

20+
# Use larger endpoint buffers for highspeed operation (default fullspeed)
21+
#
22+
# Note: usb-device doesn't truly support high speed enumeration yet, so setting this will make
23+
# TestClass only compliant with high speed mode. It may still manage to be enumerated as a full
24+
# speed device, but the descriptors will be invalid.
25+
test-class-high-speed = []
26+
2027
[[test]]
2128
name = "test_class_host"
2229
path = "tests/test_class_host/main.rs"

src/test_class.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ use crate::class_prelude::*;
66
use crate::device::{UsbDevice, UsbDeviceBuilder, UsbVidPid};
77
use crate::descriptor;
88

9+
#[cfg(feature = "test-class-highspeed")]
10+
mod sizes {
11+
pub const BUFFER: usize = 1024;
12+
pub const BULK_ENDPOINT: u16 = 512;
13+
pub const INTERRUPT_ENDPOINT: u16 = 1024;
14+
}
15+
16+
#[cfg(not(feature = "test-class-highspeed"))]
17+
mod sizes {
18+
pub const BUFFER: usize = 256;
19+
pub const BULK_ENDPOINT: u16 = 64;
20+
pub const INTERRUPT_ENDPOINT: u16 = 31;
21+
}
22+
923
/// Test USB class for testing USB driver implementations. Supports various endpoint types and
1024
/// requests for testing USB peripheral drivers on actual hardware.
1125
pub struct TestClass<'a, B: UsbBus> {
@@ -15,9 +29,9 @@ pub struct TestClass<'a, B: UsbBus> {
1529
ep_bulk_out: EndpointOut<'a, B>,
1630
ep_interrupt_in: EndpointIn<'a, B>,
1731
ep_interrupt_out: EndpointOut<'a, B>,
18-
control_buf: [u8; 256],
19-
bulk_buf: [u8; 256],
20-
interrupt_buf: [u8; 256],
32+
control_buf: [u8; sizes::BUFFER],
33+
bulk_buf: [u8; sizes::BUFFER],
34+
interrupt_buf: [u8; sizes::BUFFER],
2135
len: usize,
2236
i: usize,
2337
bench: bool,
@@ -43,19 +57,20 @@ pub const REQ_UNKNOWN: u8 = 42;
4357

4458
pub const LONG_DATA: &'static [u8] = &[0x17; 257];
4559

60+
4661
impl<B: UsbBus> TestClass<'_, B> {
4762
/// Creates a new TestClass.
4863
pub fn new(alloc: &UsbBusAllocator<B>) -> TestClass<'_, B> {
4964
TestClass {
5065
custom_string: alloc.string(),
5166
iface: alloc.interface(),
52-
ep_bulk_in: alloc.bulk(64),
53-
ep_bulk_out: alloc.bulk(64),
54-
ep_interrupt_in: alloc.interrupt(31, 1),
55-
ep_interrupt_out: alloc.interrupt(31, 1),
56-
control_buf: [0; 256],
57-
bulk_buf: [0; 256],
58-
interrupt_buf: [0; 256],
67+
ep_bulk_in: alloc.bulk(sizes::BULK_ENDPOINT),
68+
ep_bulk_out: alloc.bulk(sizes::BULK_ENDPOINT),
69+
ep_interrupt_in: alloc.interrupt(sizes::INTERRUPT_ENDPOINT, 1),
70+
ep_interrupt_out: alloc.interrupt(sizes::INTERRUPT_ENDPOINT, 1),
71+
control_buf: [0; sizes::BUFFER],
72+
bulk_buf: [0; sizes::BUFFER],
73+
interrupt_buf: [0; sizes::BUFFER],
5974
len: 0,
6075
i: 0,
6176
bench: false,

0 commit comments

Comments
 (0)