@@ -362,118 +362,118 @@ where
362
362
}
363
363
364
364
macro_rules! hal {
365
- ( $ (
365
+ (
366
366
$( #[ $meta: meta] ) *
367
367
$USARTX: ident: (
368
368
$usartX: ident,
369
369
$usartX_remap: ident,
370
370
$bit: ident,
371
371
$closure: expr,
372
372
) ,
373
- ) +) => {
374
- $(
375
- $( #[ $meta] ) *
376
- /// The behaviour of the functions is equal for all three USARTs.
377
- /// Except that they are using the corresponding USART hardware and pins.
378
- impl <PINS > Serial <$USARTX, PINS > {
379
-
380
- /// Configures the serial interface and creates the interface
381
- /// struct.
382
- ///
383
- /// `Bps` is the baud rate of the interface.
384
- ///
385
- /// `Clocks` passes information about the current frequencies of
386
- /// the clocks. The existence of the struct ensures that the
387
- /// clock settings are fixed.
388
- ///
389
- /// The `serial` struct takes ownership over the `USARTX` device
390
- /// registers and the specified `PINS`
391
- ///
392
- /// `MAPR` and `APBX` are register handles which are passed for
393
- /// configuration. (`MAPR` is used to map the USART to the
394
- /// corresponding pins. `APBX` is used to reset the USART.)
395
- pub fn $usartX(
396
- usart: $USARTX,
397
- pins: PINS ,
398
- mapr: & mut MAPR ,
399
- config: Config ,
400
- clocks: Clocks ,
401
- ) -> Self
402
- where
403
- PINS : Pins <$USARTX>,
404
- {
405
- #[ allow( unused_unsafe) ]
406
- Serial { usart, pins } . init(
407
- config,
408
- clocks,
409
- || mapr. modify_mapr( |_, w| unsafe {
410
- #[ allow( clippy:: redundant_closure_call) ]
411
- w. $usartX_remap( ) . $bit( ( $closure) ( PINS :: REMAP ) )
412
- } ) )
413
- }
414
-
373
+ ) => {
374
+ $( #[ $meta] ) *
375
+ /// The behaviour of the functions is equal for all three USARTs.
376
+ /// Except that they are using the corresponding USART hardware and pins.
377
+ impl <PINS > Serial <$USARTX, PINS > {
378
+ /// Configures the serial interface and creates the interface
379
+ /// struct.
380
+ ///
381
+ /// `Bps` is the baud rate of the interface.
382
+ ///
383
+ /// `Clocks` passes information about the current frequencies of
384
+ /// the clocks. The existence of the struct ensures that the
385
+ /// clock settings are fixed.
386
+ ///
387
+ /// The `serial` struct takes ownership over the `USARTX` device
388
+ /// registers and the specified `PINS`
389
+ ///
390
+ /// `MAPR` and `APBX` are register handles which are passed for
391
+ /// configuration. (`MAPR` is used to map the USART to the
392
+ /// corresponding pins. `APBX` is used to reset the USART.)
393
+ pub fn $usartX(
394
+ usart: $USARTX,
395
+ pins: PINS ,
396
+ mapr: & mut MAPR ,
397
+ config: Config ,
398
+ clocks: Clocks ,
399
+ ) -> Self
400
+ where
401
+ PINS : Pins <$USARTX>,
402
+ {
403
+ #[ allow( unused_unsafe) ]
404
+ Serial { usart, pins } . init( config, clocks, || {
405
+ mapr. modify_mapr( |_, w| unsafe {
406
+ #[ allow( clippy:: redundant_closure_call) ]
407
+ w. $usartX_remap( ) . $bit( ( $closure) ( PINS :: REMAP ) )
408
+ } )
409
+ } )
415
410
}
411
+ }
416
412
417
- impl Tx <$USARTX> {
418
- pub fn listen( & mut self ) {
419
- unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. txeie( ) . set_bit( ) ) } ;
420
- }
421
-
422
- pub fn unlisten( & mut self ) {
423
- unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. txeie( ) . clear_bit( ) ) } ;
424
- }
413
+ impl Tx <$USARTX> {
414
+ pub fn listen( & mut self ) {
415
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. txeie( ) . set_bit( ) ) } ;
425
416
}
426
417
427
- impl Rx <$USARTX> {
428
- pub fn listen( & mut self ) {
429
- unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. rxneie( ) . set_bit( ) ) } ;
430
- }
431
-
432
- pub fn unlisten( & mut self ) {
433
- unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. rxneie( ) . clear_bit( ) ) } ;
434
- }
418
+ pub fn unlisten( & mut self ) {
419
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. txeie( ) . clear_bit( ) ) } ;
435
420
}
421
+ }
436
422
437
- impl crate :: hal:: serial:: Read <u8 > for Rx <$USARTX> {
438
- type Error = Error ;
423
+ impl Rx <$USARTX> {
424
+ pub fn listen( & mut self ) {
425
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. rxneie( ) . set_bit( ) ) } ;
426
+ }
439
427
440
- fn read( & mut self ) -> nb:: Result <u8 , Error > {
441
- unsafe { & * $USARTX:: ptr( ) } . read( )
442
- }
428
+ pub fn unlisten( & mut self ) {
429
+ unsafe { ( * $USARTX:: ptr( ) ) . cr1. modify( |_, w| w. rxneie( ) . clear_bit( ) ) } ;
443
430
}
431
+ }
444
432
445
- impl crate :: hal:: serial:: Write <u8 > for Tx <$USARTX> {
446
- type Error = Infallible ;
433
+ impl crate :: hal:: serial:: Read <u8 > for Rx <$USARTX> {
434
+ type Error = Error ;
447
435
448
- fn flush( & mut self ) -> nb:: Result <( ) , Self :: Error > {
449
- unsafe { & * $USARTX:: ptr( ) } . flush( )
450
- }
451
- fn write( & mut self , byte: u8 ) -> nb:: Result <( ) , Self :: Error > {
452
- unsafe { & * $USARTX:: ptr( ) } . write( byte)
453
- }
436
+ fn read( & mut self ) -> nb:: Result <u8 , Error > {
437
+ unsafe { & * $USARTX:: ptr( ) } . read( )
454
438
}
439
+ }
455
440
456
- impl < PINS > crate :: hal:: serial:: Read <u8 > for Serial <$USARTX, PINS > {
457
- type Error = Error ;
441
+ impl crate :: hal:: serial:: Write <u8 > for Tx <$USARTX> {
442
+ type Error = Infallible ;
458
443
459
- fn read( & mut self ) -> nb:: Result <u8 , Error > {
460
- self . usart. deref( ) . read( )
461
- }
444
+ fn flush( & mut self ) -> nb:: Result <( ) , Self :: Error > {
445
+ unsafe { & * $USARTX:: ptr( ) } . flush( )
446
+ }
447
+ fn write( & mut self , byte: u8 ) -> nb:: Result <( ) , Self :: Error > {
448
+ unsafe { & * $USARTX:: ptr( ) } . write( byte)
462
449
}
450
+ }
451
+ } ;
452
+ }
463
453
464
- impl <PINS > crate :: hal:: serial:: Write <u8 > for Serial <$USARTX, PINS > {
465
- type Error = Infallible ;
454
+ impl < USART , PINS > crate :: hal:: serial:: Read < u8 > for Serial < USART , PINS >
455
+ where
456
+ USART : Instance ,
457
+ {
458
+ type Error = Error ;
466
459
467
- fn flush( & mut self ) -> nb:: Result <( ) , Self :: Error > {
468
- self . usart. deref( ) . flush( )
469
- }
460
+ fn read ( & mut self ) -> nb:: Result < u8 , Error > {
461
+ self . usart . deref ( ) . read ( )
462
+ }
463
+ }
470
464
471
- fn write( & mut self , byte: u8 ) -> nb:: Result <( ) , Self :: Error > {
472
- self . usart. deref( ) . write( byte)
473
- }
474
- }
465
+ impl < USART , PINS > crate :: hal:: serial:: Write < u8 > for Serial < USART , PINS >
466
+ where
467
+ USART : Instance ,
468
+ {
469
+ type Error = Infallible ;
475
470
476
- ) +
471
+ fn flush ( & mut self ) -> nb:: Result < ( ) , Self :: Error > {
472
+ self . usart . deref ( ) . flush ( )
473
+ }
474
+
475
+ fn write ( & mut self , byte : u8 ) -> nb:: Result < ( ) , Self :: Error > {
476
+ self . usart . deref ( ) . write ( byte)
477
477
}
478
478
}
479
479
@@ -497,13 +497,17 @@ hal! {
497
497
bit,
498
498
|remap| remap == 1 ,
499
499
) ,
500
+ }
501
+ hal ! {
500
502
/// # USART2 functions
501
503
USART2 : (
502
504
usart2,
503
505
usart2_remap,
504
506
bit,
505
507
|remap| remap == 1 ,
506
508
) ,
509
+ }
510
+ hal ! {
507
511
/// # USART3 functions
508
512
USART3 : (
509
513
usart3,
0 commit comments