1+ use crate :: endpoint:: { Endpoint , EndpointAddress , EndpointDirection , EndpointType } ;
2+ use crate :: { Result , UsbDirection , UsbError } ;
13use core:: cell:: RefCell ;
2- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
34use core:: mem;
45use core:: ptr;
5- use crate :: { Result , UsbDirection , UsbError } ;
6- use crate :: endpoint:: { Endpoint , EndpointDirection , EndpointType , EndpointAddress } ;
6+ use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
77
88/// A trait for device-specific USB peripherals. Implement this to add support for a new hardware
99/// platform.
@@ -41,7 +41,8 @@ pub trait UsbBus: Sync + Sized {
4141 ep_addr : Option < EndpointAddress > ,
4242 ep_type : EndpointType ,
4343 max_packet_size : u16 ,
44- interval : u8 ) -> Result < EndpointAddress > ;
44+ interval : u8 ,
45+ ) -> Result < EndpointAddress > ;
4546
4647 /// Enables and initializes the USB peripheral. Soon after enabling the device will be reset, so
4748 /// there is no need to perform a USB reset in this method.
@@ -215,14 +216,11 @@ impl<B: UsbBus> UsbBusAllocator<B> {
215216 ep_addr : Option < EndpointAddress > ,
216217 ep_type : EndpointType ,
217218 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)
226224 . map ( |a| Endpoint :: new ( & self . bus_ptr , a, ep_type, max_packet_size, interval) )
227225 }
228226
@@ -242,7 +240,8 @@ impl<B: UsbBus> UsbBusAllocator<B> {
242240 /// feasibly recoverable.
243241 #[ inline]
244242 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" )
246245 }
247246
248247 /// Allocates a bulk endpoint.
@@ -257,7 +256,8 @@ impl<B: UsbBus> UsbBusAllocator<B> {
257256 /// feasibly recoverable.
258257 #[ inline]
259258 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" )
261261 }
262262
263263 /// Allocates an interrupt endpoint.
@@ -269,11 +269,12 @@ impl<B: UsbBus> UsbBusAllocator<B> {
269269 /// Panics if endpoint allocation fails, because running out of endpoints or memory is not
270270 /// feasibly recoverable.
271271 #[ 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)
277278 . expect ( "alloc_ep failed" )
278279 }
279280}
@@ -283,7 +284,9 @@ impl<B: UsbBus> UsbBusAllocator<B> {
283284pub struct InterfaceNumber ( u8 ) ;
284285
285286impl From < InterfaceNumber > for u8 {
286- fn from ( n : InterfaceNumber ) -> u8 { n. 0 }
287+ fn from ( n : InterfaceNumber ) -> u8 {
288+ n. 0
289+ }
287290}
288291
289292/// A handle for a USB string descriptor that contains its index.
@@ -297,7 +300,9 @@ impl StringIndex {
297300}
298301
299302impl From < StringIndex > for u8 {
300- fn from ( i : StringIndex ) -> u8 { i. 0 }
303+ fn from ( i : StringIndex ) -> u8 {
304+ i. 0
305+ }
301306}
302307
303308/// Event and incoming packet information returned by [`UsbBus::poll`].
@@ -322,7 +327,7 @@ pub enum PollResult {
322327
323328 /// A SETUP packet has been received. This event should continue to be reported until the
324329 /// packet is read. The corresponding bit in `ep_out` may also be set but is ignored.
325- ep_setup : u16
330+ ep_setup : u16 ,
326331 } ,
327332
328333 /// A USB suspend request has been detected or, in the case of self-powered devices, the device
@@ -332,4 +337,4 @@ pub enum PollResult {
332337 /// A USB resume request has been detected after being suspended or, in the case of self-powered
333338 /// devices, the device has been connected to the USB bus.
334339 Resume ,
335- }
340+ }
0 commit comments