1
+ use crate :: endpoint:: { Endpoint , EndpointAddress , EndpointDirection , EndpointType } ;
2
+ use crate :: { Result , UsbDirection , UsbError } ;
1
3
use core:: cell:: RefCell ;
2
- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
3
4
use core:: mem;
4
5
use core:: ptr;
5
- use crate :: { Result , UsbDirection , UsbError } ;
6
- use crate :: endpoint:: { Endpoint , EndpointDirection , EndpointType , EndpointAddress } ;
6
+ use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
7
7
8
8
/// A trait for device-specific USB peripherals. Implement this to add support for a new hardware
9
9
/// platform.
@@ -41,7 +41,8 @@ pub trait UsbBus: Sync + Sized {
41
41
ep_addr : Option < EndpointAddress > ,
42
42
ep_type : EndpointType ,
43
43
max_packet_size : u16 ,
44
- interval : u8 ) -> Result < EndpointAddress > ;
44
+ interval : u8 ,
45
+ ) -> Result < EndpointAddress > ;
45
46
46
47
/// Enables and initializes the USB peripheral. Soon after enabling the device will be reset, so
47
48
/// there is no need to perform a USB reset in this method.
@@ -215,14 +216,11 @@ impl<B: UsbBus> UsbBusAllocator<B> {
215
216
ep_addr : Option < EndpointAddress > ,
216
217
ep_type : EndpointType ,
217
218
max_packet_size : u16 ,
218
- interval : u8 ) -> Result < Endpoint < ' _ , B , D > >
219
- {
220
- self . bus . borrow_mut ( )
221
- . alloc_ep (
222
- D :: DIRECTION ,
223
- ep_addr, ep_type,
224
- max_packet_size,
225
- interval)
219
+ interval : u8 ,
220
+ ) -> Result < Endpoint < ' _ , B , D > > {
221
+ self . bus
222
+ . borrow_mut ( )
223
+ . alloc_ep ( D :: DIRECTION , ep_addr, ep_type, max_packet_size, interval)
226
224
. map ( |a| Endpoint :: new ( & self . bus_ptr , a, ep_type, max_packet_size, interval) )
227
225
}
228
226
@@ -242,7 +240,8 @@ impl<B: UsbBus> UsbBusAllocator<B> {
242
240
/// feasibly recoverable.
243
241
#[ inline]
244
242
pub fn control < D : EndpointDirection > ( & self , max_packet_size : u16 ) -> Endpoint < ' _ , B , D > {
245
- self . alloc ( None , EndpointType :: Control , max_packet_size, 0 ) . expect ( "alloc_ep failed" )
243
+ self . alloc ( None , EndpointType :: Control , max_packet_size, 0 )
244
+ . expect ( "alloc_ep failed" )
246
245
}
247
246
248
247
/// Allocates a bulk endpoint.
@@ -257,7 +256,8 @@ impl<B: UsbBus> UsbBusAllocator<B> {
257
256
/// feasibly recoverable.
258
257
#[ inline]
259
258
pub fn bulk < D : EndpointDirection > ( & self , max_packet_size : u16 ) -> Endpoint < ' _ , B , D > {
260
- self . alloc ( None , EndpointType :: Bulk , max_packet_size, 0 ) . expect ( "alloc_ep failed" )
259
+ self . alloc ( None , EndpointType :: Bulk , max_packet_size, 0 )
260
+ . expect ( "alloc_ep failed" )
261
261
}
262
262
263
263
/// Allocates an interrupt endpoint.
@@ -269,11 +269,12 @@ impl<B: UsbBus> UsbBusAllocator<B> {
269
269
/// Panics if endpoint allocation fails, because running out of endpoints or memory is not
270
270
/// feasibly recoverable.
271
271
#[ inline]
272
- pub fn interrupt < D : EndpointDirection > ( & self , max_packet_size : u16 , interval : u8 )
273
- -> Endpoint < ' _ , B , D >
274
- {
275
- self
276
- . alloc ( None , EndpointType :: Interrupt , max_packet_size, interval)
272
+ pub fn interrupt < D : EndpointDirection > (
273
+ & self ,
274
+ max_packet_size : u16 ,
275
+ interval : u8 ,
276
+ ) -> Endpoint < ' _ , B , D > {
277
+ self . alloc ( None , EndpointType :: Interrupt , max_packet_size, interval)
277
278
. expect ( "alloc_ep failed" )
278
279
}
279
280
}
@@ -283,7 +284,9 @@ impl<B: UsbBus> UsbBusAllocator<B> {
283
284
pub struct InterfaceNumber ( u8 ) ;
284
285
285
286
impl From < InterfaceNumber > for u8 {
286
- fn from ( n : InterfaceNumber ) -> u8 { n. 0 }
287
+ fn from ( n : InterfaceNumber ) -> u8 {
288
+ n. 0
289
+ }
287
290
}
288
291
289
292
/// A handle for a USB string descriptor that contains its index.
@@ -297,7 +300,9 @@ impl StringIndex {
297
300
}
298
301
299
302
impl From < StringIndex > for u8 {
300
- fn from ( i : StringIndex ) -> u8 { i. 0 }
303
+ fn from ( i : StringIndex ) -> u8 {
304
+ i. 0
305
+ }
301
306
}
302
307
303
308
/// Event and incoming packet information returned by [`UsbBus::poll`].
@@ -322,7 +327,7 @@ pub enum PollResult {
322
327
323
328
/// A SETUP packet has been received. This event should continue to be reported until the
324
329
/// packet is read. The corresponding bit in `ep_out` may also be set but is ignored.
325
- ep_setup : u16
330
+ ep_setup : u16 ,
326
331
} ,
327
332
328
333
/// A USB suspend request has been detected or, in the case of self-powered devices, the device
@@ -332,4 +337,4 @@ pub enum PollResult {
332
337
/// A USB resume request has been detected after being suspended or, in the case of self-powered
333
338
/// devices, the device has been connected to the USB bus.
334
339
Resume ,
335
- }
340
+ }
0 commit comments