9
9
#![ no_main]
10
10
#![ no_std]
11
11
12
- use core:: convert:: Infallible ;
13
12
use cortex_m_rt:: entry;
14
13
use nb:: block;
15
14
use panic_halt as _;
16
15
use stm32f1xx_hal:: {
17
16
pac,
18
17
prelude:: * ,
19
- serial:: { self , Config , Serial } ,
18
+ serial:: { self , Config , Error , Serial } ,
20
19
} ;
21
- use unwrap_infallible:: UnwrapInfallible ;
22
20
23
21
// The address of the slave device.
24
22
const SLAVE_ADDR : u8 = 123 ;
@@ -29,7 +27,7 @@ const MSG_MAX_LEN: usize = u8::MAX as usize;
29
27
// Receives a message addressed to the slave device. Returns the size of the received message.
30
28
fn receive_msg < RX > ( serial_rx : & mut RX , buf : & mut [ u8 ; MSG_MAX_LEN ] ) -> usize
31
29
where
32
- RX : embedded_hal :: serial:: Read < u16 , Error = serial:: Error > ,
30
+ RX : embedded_hal_02 :: serial:: Read < u16 , Error = serial:: Error > ,
33
31
{
34
32
enum RxPhase {
35
33
Start ,
@@ -79,19 +77,19 @@ where
79
77
// Send message.
80
78
fn send_msg < TX > ( serial_tx : & mut TX , msg : & [ u8 ] )
81
79
where
82
- TX : embedded_hal :: serial:: Write < u8 , Error = Infallible >
83
- + embedded_hal :: serial:: Write < u16 , Error = Infallible > ,
80
+ TX : embedded_hal_02 :: serial:: Write < u8 , Error = Error >
81
+ + embedded_hal_02 :: serial:: Write < u16 , Error = Error > ,
84
82
{
85
83
// Send address.
86
- block ! ( serial_tx. write( SLAVE_ADDR as u16 | 0x100 ) ) . unwrap_infallible ( ) ;
84
+ block ! ( serial_tx. write( SLAVE_ADDR as u16 | 0x100 ) ) . unwrap ( ) ;
87
85
88
86
// Send message len.
89
87
assert ! ( msg. len( ) <= MSG_MAX_LEN ) ;
90
- block ! ( serial_tx. write( msg. len( ) as u8 ) ) . unwrap_infallible ( ) ;
88
+ block ! ( serial_tx. write( msg. len( ) as u8 ) ) . unwrap ( ) ;
91
89
92
90
// Send message.
93
91
for & b in msg {
94
- block ! ( serial_tx. write( b) ) . unwrap_infallible ( ) ;
92
+ block ! ( serial_tx. write( b) ) . unwrap ( ) ;
95
93
}
96
94
}
97
95
0 commit comments