39
39
//! p.USART1,
40
40
//! (pin_tx, pin_rx),
41
41
//! &mut afio.mapr,
42
- //! Config::default().baudrate(9_600.bps()).wordlength_9(),
42
+ //! Config::default()
43
+ //! .baudrate(9_600.bps())
44
+ //! .wordlength_9bits()
45
+ //! .parity_none(),
43
46
//! clocks,
44
47
//! );
45
48
//!
@@ -153,10 +156,12 @@ impl<INMODE, OUTMODE> Pins<USART3> for (PD8<Alternate<OUTMODE>>, PD9<Input<INMOD
153
156
}
154
157
155
158
pub enum WordLength {
156
- /// When parity is enabled, a word has 7 data bits + 1 parity bit.
157
- DataBits8 ,
158
- /// When parity is enabled, a word has 8 data bits + 1 parity bit.
159
- DataBits9 ,
159
+ /// When parity is enabled, a word has 7 data bits + 1 parity bit,
160
+ /// otherwise 8 data bits.
161
+ Bits8 ,
162
+ /// When parity is enabled, a word has 8 data bits + 1 parity bit,
163
+ /// otherwise 9 data bits.
164
+ Bits9 ,
160
165
}
161
166
162
167
pub enum Parity {
@@ -209,13 +214,18 @@ impl Config {
209
214
self
210
215
}
211
216
212
- pub fn wordlength_8 ( mut self ) -> Self {
213
- self . wordlength = WordLength :: DataBits8 ;
217
+ pub fn wordlength_8bits ( mut self ) -> Self {
218
+ self . wordlength = WordLength :: Bits8 ;
214
219
self
215
220
}
216
221
217
- pub fn wordlength_9 ( mut self ) -> Self {
218
- self . wordlength = WordLength :: DataBits9 ;
222
+ pub fn wordlength_9bits ( mut self ) -> Self {
223
+ self . wordlength = WordLength :: Bits9 ;
224
+ self
225
+ }
226
+
227
+ pub fn wordlength ( mut self , wordlength : WordLength ) -> Self {
228
+ self . wordlength = wordlength;
219
229
self
220
230
}
221
231
@@ -230,7 +240,7 @@ impl Default for Config {
230
240
let baudrate = 115_200_u32 . bps ( ) ;
231
241
Config {
232
242
baudrate,
233
- wordlength : WordLength :: DataBits8 ,
243
+ wordlength : WordLength :: Bits8 ,
234
244
parity : Parity :: ParityNone ,
235
245
stopbits : StopBits :: STOP1 ,
236
246
}
@@ -327,8 +337,8 @@ where
327
337
} ;
328
338
self . usart . cr1 . modify ( |_r, w| {
329
339
w. m ( ) . bit ( match config. wordlength {
330
- WordLength :: DataBits8 => false ,
331
- WordLength :: DataBits9 => true ,
340
+ WordLength :: Bits8 => false ,
341
+ WordLength :: Bits9 => true ,
332
342
} ) ;
333
343
w. ps ( ) . bit ( parity_is_odd) ;
334
344
w. pce ( ) . bit ( parity_is_used)
@@ -652,7 +662,7 @@ where
652
662
653
663
/// Reads 9-bit words from the UART/USART
654
664
///
655
- /// If the UART/USART was configured with `WordLength::DataBits9 `, the returned value will contain
665
+ /// If the UART/USART was configured with `WordLength::Bits9 `, the returned value will contain
656
666
/// 9 received data bits and all other bits set to zero. Otherwise, the returned value will contain
657
667
/// 8 received data bits and all other bits set to zero.
658
668
impl < USART > crate :: hal:: serial:: Read < u16 > for Rx < USART , u16 >
@@ -733,7 +743,7 @@ where
733
743
734
744
/// Writes 9-bit words to the UART/USART
735
745
///
736
- /// If the UART/USART was configured with `WordLength::DataBits9 `, the 9 least significant bits will
746
+ /// If the UART/USART was configured with `WordLength::Bits9 `, the 9 least significant bits will
737
747
/// be transmitted and the other 7 bits will be ignored. Otherwise, the 8 least significant bits
738
748
/// will be transmitted and the other 8 bits will be ignored.
739
749
impl < USART > crate :: hal:: serial:: Write < u16 > for Tx < USART , u16 >
0 commit comments