@@ -5,6 +5,7 @@ use crate::device::{StringDescriptors, UsbDevice, UsbDeviceBuilder, UsbVidPid};
5
5
use crate :: Result ;
6
6
use core:: cell:: UnsafeCell ;
7
7
use core:: cmp;
8
+ use core:: marker:: PhantomData ;
8
9
9
10
#[ cfg( feature = "test-class-high-speed" ) ]
10
11
mod sizes {
@@ -24,9 +25,14 @@ mod sizes {
24
25
25
26
static mut CONTROL_BUFFER : UnsafeCell < [ u8 ; 256 ] > = UnsafeCell :: new ( [ 0 ; 256 ] ) ;
26
27
28
+ pub trait HardwareSupport {
29
+ /// Hard reset the test device
30
+ fn hard_reset ( ) -> !;
31
+ }
32
+
27
33
/// Test USB class for testing USB driver implementations. Supports various endpoint types and
28
34
/// requests for testing USB peripheral drivers on actual hardware.
29
- pub struct TestClass < ' a , B : UsbBus > {
35
+ pub struct TestClass < ' a , B : UsbBus , H : HardwareSupport > {
30
36
custom_string : StringIndex ,
31
37
interface_string : StringIndex ,
32
38
iface : InterfaceNumber ,
@@ -45,6 +51,7 @@ pub struct TestClass<'a, B: UsbBus> {
45
51
expect_bulk_out : bool ,
46
52
expect_interrupt_in_complete : bool ,
47
53
expect_interrupt_out : bool ,
54
+ hardware : PhantomData < H > ,
48
55
}
49
56
50
57
pub const VID : u16 = 0x16c0 ;
@@ -60,13 +67,14 @@ pub const REQ_READ_BUFFER: u8 = 2;
60
67
pub const REQ_WRITE_BUFFER : u8 = 3 ;
61
68
pub const REQ_SET_BENCH_ENABLED : u8 = 4 ;
62
69
pub const REQ_READ_LONG_DATA : u8 = 5 ;
70
+ pub const REQ_HARD_RESET : u8 = 6 ;
63
71
pub const REQ_UNKNOWN : u8 = 42 ;
64
72
65
73
pub const LONG_DATA : & [ u8 ] = & [ 0x17 ; 257 ] ;
66
74
67
- impl < B : UsbBus > TestClass < ' _ , B > {
75
+ impl < B : UsbBus , H : HardwareSupport > TestClass < ' _ , B , H > {
68
76
/// Creates a new TestClass.
69
- pub fn new ( alloc : & UsbBusAllocator < B > ) -> TestClass < ' _ , B > {
77
+ pub fn new ( alloc : & UsbBusAllocator < B > ) -> TestClass < ' _ , B , H > {
70
78
TestClass {
71
79
custom_string : alloc. string ( ) ,
72
80
interface_string : alloc. string ( ) ,
@@ -91,6 +99,7 @@ impl<B: UsbBus> TestClass<'_, B> {
91
99
expect_bulk_out : false ,
92
100
expect_interrupt_in_complete : false ,
93
101
expect_interrupt_out : false ,
102
+ hardware : PhantomData ,
94
103
}
95
104
}
96
105
@@ -214,7 +223,7 @@ impl<B: UsbBus> TestClass<'_, B> {
214
223
}
215
224
}
216
225
217
- impl < B : UsbBus > UsbClass < B > for TestClass < ' _ , B > {
226
+ impl < B : UsbBus , H : HardwareSupport > UsbClass < B > for TestClass < ' _ , B , H > {
218
227
fn reset ( & mut self ) {
219
228
self . len = 0 ;
220
229
self . i = 0 ;
@@ -335,6 +344,9 @@ impl<B: UsbBus> UsbClass<B> for TestClass<'_, B> {
335
344
xfer. accept ( )
336
345
. expect ( "control_out REQ_SET_BENCH_ENABLED failed" ) ;
337
346
}
347
+ REQ_HARD_RESET => {
348
+ H :: hard_reset ( ) ;
349
+ }
338
350
_ => xfer. reject ( ) . expect ( "control_out reject failed" ) ,
339
351
}
340
352
}
0 commit comments