3939//! p.USART1,
4040//! (pin_tx, pin_rx),
4141//! &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(),
4346//! clocks,
4447//! );
4548//!
@@ -153,10 +156,12 @@ impl<INMODE, OUTMODE> Pins<USART3> for (PD8<Alternate<OUTMODE>>, PD9<Input<INMOD
153156}
154157
155158pub 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 ,
160165}
161166
162167pub enum Parity {
@@ -209,13 +214,18 @@ impl Config {
209214 self
210215 }
211216
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 ;
214219 self
215220 }
216221
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;
219229 self
220230 }
221231
@@ -230,7 +240,7 @@ impl Default for Config {
230240 let baudrate = 115_200_u32 . bps ( ) ;
231241 Config {
232242 baudrate,
233- wordlength : WordLength :: DataBits8 ,
243+ wordlength : WordLength :: Bits8 ,
234244 parity : Parity :: ParityNone ,
235245 stopbits : StopBits :: STOP1 ,
236246 }
@@ -327,8 +337,8 @@ where
327337 } ;
328338 self . usart . cr1 . modify ( |_r, w| {
329339 w. m ( ) . bit ( match config. wordlength {
330- WordLength :: DataBits8 => false ,
331- WordLength :: DataBits9 => true ,
340+ WordLength :: Bits8 => false ,
341+ WordLength :: Bits9 => true ,
332342 } ) ;
333343 w. ps ( ) . bit ( parity_is_odd) ;
334344 w. pce ( ) . bit ( parity_is_used)
@@ -652,7 +662,7 @@ where
652662
653663/// Reads 9-bit words from the UART/USART
654664///
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
656666/// 9 received data bits and all other bits set to zero. Otherwise, the returned value will contain
657667/// 8 received data bits and all other bits set to zero.
658668impl < USART > crate :: hal:: serial:: Read < u16 > for Rx < USART , u16 >
@@ -733,7 +743,7 @@ where
733743
734744/// Writes 9-bit words to the UART/USART
735745///
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
737747/// be transmitted and the other 7 bits will be ignored. Otherwise, the 8 least significant bits
738748/// will be transmitted and the other 8 bits will be ignored.
739749impl < USART > crate :: hal:: serial:: Write < u16 > for Tx < USART , u16 >
0 commit comments