@@ -5,6 +5,7 @@ use crate::device::{StringDescriptors, UsbDevice, UsbDeviceBuilder, UsbVidPid};
55use crate :: Result ;
66use core:: cell:: UnsafeCell ;
77use core:: cmp;
8+ use core:: marker:: PhantomData ;
89
910#[ cfg( feature = "test-class-high-speed" ) ]
1011mod sizes {
@@ -24,9 +25,14 @@ mod sizes {
2425
2526static mut CONTROL_BUFFER : UnsafeCell < [ u8 ; 256 ] > = UnsafeCell :: new ( [ 0 ; 256 ] ) ;
2627
28+ pub trait HardwareSupport {
29+ /// Hard reset the test device
30+ fn hard_reset ( ) -> !;
31+ }
32+
2733/// Test USB class for testing USB driver implementations. Supports various endpoint types and
2834/// 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 > {
3036 custom_string : StringIndex ,
3137 interface_string : StringIndex ,
3238 iface : InterfaceNumber ,
@@ -45,6 +51,7 @@ pub struct TestClass<'a, B: UsbBus> {
4551 expect_bulk_out : bool ,
4652 expect_interrupt_in_complete : bool ,
4753 expect_interrupt_out : bool ,
54+ hardware : PhantomData < H > ,
4855}
4956
5057pub const VID : u16 = 0x16c0 ;
@@ -60,13 +67,14 @@ pub const REQ_READ_BUFFER: u8 = 2;
6067pub const REQ_WRITE_BUFFER : u8 = 3 ;
6168pub const REQ_SET_BENCH_ENABLED : u8 = 4 ;
6269pub const REQ_READ_LONG_DATA : u8 = 5 ;
70+ pub const REQ_HARD_RESET : u8 = 6 ;
6371pub const REQ_UNKNOWN : u8 = 42 ;
6472
6573pub const LONG_DATA : & [ u8 ] = & [ 0x17 ; 257 ] ;
6674
67- impl < B : UsbBus > TestClass < ' _ , B > {
75+ impl < B : UsbBus , H : HardwareSupport > TestClass < ' _ , B , H > {
6876 /// Creates a new TestClass.
69- pub fn new ( alloc : & UsbBusAllocator < B > ) -> TestClass < ' _ , B > {
77+ pub fn new ( alloc : & UsbBusAllocator < B > ) -> TestClass < ' _ , B , H > {
7078 TestClass {
7179 custom_string : alloc. string ( ) ,
7280 interface_string : alloc. string ( ) ,
@@ -91,6 +99,7 @@ impl<B: UsbBus> TestClass<'_, B> {
9199 expect_bulk_out : false ,
92100 expect_interrupt_in_complete : false ,
93101 expect_interrupt_out : false ,
102+ hardware : PhantomData ,
94103 }
95104 }
96105
@@ -214,7 +223,7 @@ impl<B: UsbBus> TestClass<'_, B> {
214223 }
215224}
216225
217- impl < B : UsbBus > UsbClass < B > for TestClass < ' _ , B > {
226+ impl < B : UsbBus , H : HardwareSupport > UsbClass < B > for TestClass < ' _ , B , H > {
218227 fn reset ( & mut self ) {
219228 self . len = 0 ;
220229 self . i = 0 ;
@@ -335,6 +344,9 @@ impl<B: UsbBus> UsbClass<B> for TestClass<'_, B> {
335344 xfer. accept ( )
336345 . expect ( "control_out REQ_SET_BENCH_ENABLED failed" ) ;
337346 }
347+ REQ_HARD_RESET => {
348+ H :: hard_reset ( ) ;
349+ }
338350 _ => xfer. reject ( ) . expect ( "control_out reject failed" ) ,
339351 }
340352 }
0 commit comments