@@ -444,6 +444,16 @@ mod split {
444
444
Tx { usart, pin }
445
445
}
446
446
447
+ /// Destruct [`Tx`] to regain access to underlying USART and pin.
448
+ pub ( crate ) fn free ( self ) -> ( Usart , Pin ) {
449
+ ( self . usart , self . pin )
450
+ }
451
+ }
452
+
453
+ impl < Usart , Pin > Tx < Usart , Pin >
454
+ where
455
+ Usart : Instance ,
456
+ {
447
457
/// Get a reference to internal usart peripheral
448
458
///
449
459
/// # Safety
@@ -472,11 +482,6 @@ mod split {
472
482
pub ( crate ) unsafe fn usart_mut ( & mut self ) -> & mut Usart {
473
483
& mut self . usart
474
484
}
475
-
476
- /// Destruct [`Tx`] to regain access to underlying USART and pin.
477
- pub ( crate ) fn free ( self ) -> ( Usart , Pin ) {
478
- ( self . usart , self . pin )
479
- }
480
485
}
481
486
482
487
impl < Usart , Pin > Rx < Usart , Pin >
@@ -488,6 +493,20 @@ mod split {
488
493
Rx { usart, pin }
489
494
}
490
495
496
+ /// Destruct [`Rx`] to regain access to the underlying pin.
497
+ ///
498
+ /// The USART is omitted, as it is returnend from Tx already to avoid
499
+ /// beeing able to crate a duplicate reference to the same underlying
500
+ /// peripheral.
501
+ pub ( crate ) fn free ( self ) -> Pin {
502
+ self . pin
503
+ }
504
+ }
505
+
506
+ impl < Usart , Pin > Rx < Usart , Pin >
507
+ where
508
+ Usart : Instance ,
509
+ {
491
510
/// Get a reference to internal usart peripheral
492
511
///
493
512
/// # Safety
@@ -515,15 +534,6 @@ mod split {
515
534
pub ( crate ) unsafe fn usart_mut ( & mut self ) -> & mut Usart {
516
535
& mut self . usart
517
536
}
518
-
519
- /// Destruct [`Rx`] to regain access to the underlying pin.
520
- ///
521
- /// The USART is omitted, as it is returnend from Tx already to avoid
522
- /// beeing able to crate a duplicate reference to the same underlying
523
- /// peripheral.
524
- pub ( crate ) fn free ( self ) -> Pin {
525
- self . pin
526
- }
527
537
}
528
538
}
529
539
@@ -586,6 +596,48 @@ where
586
596
Self { usart, pins }
587
597
}
588
598
599
+ /// Releases the USART peripheral and associated pins
600
+ pub fn free ( self ) -> ( Usart , ( Tx , Rx ) ) {
601
+ self . usart
602
+ . cr1
603
+ . modify ( |_, w| w. ue ( ) . disabled ( ) . re ( ) . disabled ( ) . te ( ) . disabled ( ) ) ;
604
+ ( self . usart , self . pins )
605
+ }
606
+
607
+ /// Joins previously [`Serial::split()`] serial.
608
+ ///
609
+ /// This is often needed to access methods only implemented for [`Serial`]
610
+ /// but not for [`Tx`] nor [`Rx`].
611
+ ///
612
+ /// # Example
613
+ ///
614
+ /// ```
615
+ /// let dp = pac::Peripherals::take().unwrap();
616
+ ///
617
+ /// (tx, rx) = Serial::new(dp.USART1, ...).split();
618
+ ///
619
+ /// // Do something with tx and rx
620
+ ///
621
+ /// serial = Serial::join(tx, rx);
622
+ /// ```
623
+ pub fn join ( tx : split:: Tx < Usart , Tx > , rx : split:: Rx < Usart , Rx > ) -> Self
624
+ where
625
+ Tx : TxPin < Usart > ,
626
+ Rx : RxPin < Usart > ,
627
+ {
628
+ let ( usart, tx_pin) = tx. free ( ) ;
629
+ let rx_pin = rx. free ( ) ;
630
+ Self {
631
+ usart,
632
+ pins : ( tx_pin, rx_pin) ,
633
+ }
634
+ }
635
+ }
636
+
637
+ impl < Usart , Pins > Serial < Usart , Pins >
638
+ where
639
+ Usart : Instance ,
640
+ {
589
641
/// Serial read out of the read register
590
642
///
591
643
/// No error handling and no additional side-effects, besides the implied
@@ -806,43 +858,6 @@ where
806
858
pub fn match_character ( & self ) -> u8 {
807
859
self . usart . cr2 . read ( ) . add ( ) . bits ( )
808
860
}
809
-
810
- /// Releases the USART peripheral and associated pins
811
- pub fn free ( self ) -> ( Usart , ( Tx , Rx ) ) {
812
- self . usart
813
- . cr1
814
- . modify ( |_, w| w. ue ( ) . disabled ( ) . re ( ) . disabled ( ) . te ( ) . disabled ( ) ) ;
815
- ( self . usart , self . pins )
816
- }
817
-
818
- /// Joins previously [`Serial::split()`] serial.
819
- ///
820
- /// This is often needed to access methods only implemented for [`Serial`]
821
- /// but not for [`Tx`] nor [`Rx`].
822
- ///
823
- /// # Example
824
- ///
825
- /// ```
826
- /// let dp = pac::Peripherals::take().unwrap();
827
- ///
828
- /// (tx, rx) = Serial::new(dp.USART1, ...).split();
829
- ///
830
- /// // Do something with tx and rx
831
- ///
832
- /// serial = Serial::join(tx, rx);
833
- /// ```
834
- pub fn join ( tx : split:: Tx < Usart , Tx > , rx : split:: Rx < Usart , Rx > ) -> Self
835
- where
836
- Tx : TxPin < Usart > ,
837
- Rx : RxPin < Usart > ,
838
- {
839
- let ( usart, tx_pin) = tx. free ( ) ;
840
- let rx_pin = rx. free ( ) ;
841
- Self {
842
- usart,
843
- pins : ( tx_pin, rx_pin) ,
844
- }
845
- }
846
861
}
847
862
848
863
impl < Usart , Tx , Rx > Serial < Usart , ( Tx , Rx ) >
@@ -1057,7 +1072,6 @@ where
1057
1072
impl < Usart , Pin > Rx < Usart , Pin >
1058
1073
where
1059
1074
Usart : Instance + Dma ,
1060
- Pin : RxPin < Usart > ,
1061
1075
{
1062
1076
/// Fill the buffer with received data using DMA.
1063
1077
pub fn read_exact < B , C > ( self , buffer : B , mut channel : C ) -> dma:: Transfer < B , C , Self >
@@ -1112,7 +1126,6 @@ where
1112
1126
impl < Usart , Pin > dma:: Target for Rx < Usart , Pin >
1113
1127
where
1114
1128
Usart : Instance + Dma ,
1115
- Pin : RxPin < Usart > ,
1116
1129
{
1117
1130
fn enable_dma ( & mut self ) {
1118
1131
// NOTE(unsafe) critical section prevents races
@@ -1149,11 +1162,9 @@ where
1149
1162
}
1150
1163
}
1151
1164
1152
- impl < Usart , Tx , Rx > Serial < Usart , ( Tx , Rx ) >
1165
+ impl < Usart , Pins > Serial < Usart , Pins >
1153
1166
where
1154
1167
Usart : Instance + Dma ,
1155
- Rx : RxPin < Usart > ,
1156
- Tx : TxPin < Usart > ,
1157
1168
{
1158
1169
/// Fill the buffer with received data using DMA.
1159
1170
pub fn read_exact < B , C > ( self , buffer : B , mut channel : C ) -> dma:: Transfer < B , C , Self >
@@ -1188,7 +1199,7 @@ where
1188
1199
}
1189
1200
}
1190
1201
1191
- impl < Usart , Tx , Rx > dma:: Target for Serial < Usart , ( Tx , Rx ) >
1202
+ impl < Usart , Pins > dma:: Target for Serial < Usart , Pins >
1192
1203
where
1193
1204
Usart : Instance + Dma ,
1194
1205
{
0 commit comments