@@ -128,8 +128,9 @@ where
128
128
129
129
usart. brr . write ( |w| unsafe { w. bits ( brr) } ) ;
130
130
131
- // Reset other registers to disable advanced USART features
132
- usart. cr2 . reset ( ) ;
131
+ // Set character match and reset other registers to disable advanced USART features
132
+ let ch = config. character_match . unwrap_or ( 0 ) ;
133
+ usart. cr2 . write ( |w| w. add ( ) . bits ( ch) ) ;
133
134
134
135
// Enable transmission and receiving
135
136
usart
@@ -147,6 +148,8 @@ where
147
148
match event {
148
149
Event :: Rxne => self . usart . cr1 . modify ( |_, w| w. rxneie ( ) . set_bit ( ) ) ,
149
150
Event :: Txe => self . usart . cr1 . modify ( |_, w| w. txeie ( ) . set_bit ( ) ) ,
151
+ Event :: CharacterMatch => self . usart . cr1 . modify ( |_, w| w. cmie ( ) . set_bit ( ) ) ,
152
+ Event :: Error => self . usart . cr3 . modify ( |_, w| w. eie ( ) . set_bit ( ) ) ,
150
153
}
151
154
}
152
155
@@ -155,6 +158,8 @@ where
155
158
match event {
156
159
Event :: Rxne => self . usart . cr1 . modify ( |_, w| w. rxneie ( ) . clear_bit ( ) ) ,
157
160
Event :: Txe => self . usart . cr1 . modify ( |_, w| w. txeie ( ) . clear_bit ( ) ) ,
161
+ Event :: CharacterMatch => self . usart . cr1 . modify ( |_, w| w. cmie ( ) . clear_bit ( ) ) ,
162
+ Event :: Error => self . usart . cr3 . modify ( |_, w| w. eie ( ) . clear_bit ( ) ) ,
158
163
}
159
164
}
160
165
@@ -377,6 +382,7 @@ where
377
382
pub struct Config {
378
383
pub baud_rate : Bps ,
379
384
pub oversampling : Oversampling ,
385
+ pub character_match : Option < u8 > ,
380
386
}
381
387
382
388
pub enum Oversampling {
@@ -389,6 +395,7 @@ impl Default for Config {
389
395
Self {
390
396
baud_rate : 115_200 . bps ( ) ,
391
397
oversampling : Oversampling :: By16 ,
398
+ character_match : None ,
392
399
}
393
400
}
394
401
}
@@ -400,6 +407,10 @@ pub enum Event {
400
407
Rxne ,
401
408
/// New data can be sent
402
409
Txe ,
410
+ /// Character match interrupt
411
+ CharacterMatch ,
412
+ /// Error interrupt
413
+ Error ,
403
414
}
404
415
405
416
/// Implemented by all USART instances
0 commit comments