From ca76a4630cbf074e43b9478d9aeeba510c521243 Mon Sep 17 00:00:00 2001 From: AndreySmirnov81 <19325847+AndreySmirnov81@users.noreply.github.com> Date: Fri, 18 Feb 2022 13:08:42 +0300 Subject: [PATCH] Rename Serial items --- examples/serial_9bits.rs | 5 ++++- examples/serial_config.rs | 2 +- src/serial.rs | 38 ++++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/serial_9bits.rs b/examples/serial_9bits.rs index 0e9a32ee..55252003 100644 --- a/examples/serial_9bits.rs +++ b/examples/serial_9bits.rs @@ -121,7 +121,10 @@ fn main() -> ! { p.USART3, (tx_pin, rx_pin), &mut afio.mapr, - Config::default().baudrate(9600.bps()).wordlength_9(), + Config::default() + .baudrate(9600.bps()) + .wordlength_9bits() + .parity_none(), clocks, ) // Switching the 'Word' type parameter for the 'Read' and 'Write' traits from u8 to u16. diff --git a/examples/serial_config.rs b/examples/serial_config.rs index 0f6f7aae..57f58ba9 100644 --- a/examples/serial_config.rs +++ b/examples/serial_config.rs @@ -65,7 +65,7 @@ fn main() -> ! { serial::Config::default() .baudrate(9600.bps()) .stopbits(serial::StopBits::STOP2) - .wordlength_9() + .wordlength_9bits() .parity_odd(), clocks, ); diff --git a/src/serial.rs b/src/serial.rs index 62073ba2..afbda8df 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -39,7 +39,10 @@ //! p.USART1, //! (pin_tx, pin_rx), //! &mut afio.mapr, -//! Config::default().baudrate(9_600.bps()).wordlength_9(), +//! Config::default() +//! .baudrate(9_600.bps()) +//! .wordlength_9bits() +//! .parity_none(), //! clocks, //! ); //! @@ -153,10 +156,12 @@ impl Pins for (PD8>, PD9 Self { - self.wordlength = WordLength::DataBits8; + pub fn wordlength_8bits(mut self) -> Self { + self.wordlength = WordLength::Bits8; self } - pub fn wordlength_9(mut self) -> Self { - self.wordlength = WordLength::DataBits9; + pub fn wordlength_9bits(mut self) -> Self { + self.wordlength = WordLength::Bits9; + self + } + + pub fn wordlength(mut self, wordlength: WordLength) -> Self { + self.wordlength = wordlength; self } @@ -230,7 +240,7 @@ impl Default for Config { let baudrate = 115_200_u32.bps(); Config { baudrate, - wordlength: WordLength::DataBits8, + wordlength: WordLength::Bits8, parity: Parity::ParityNone, stopbits: StopBits::STOP1, } @@ -327,8 +337,8 @@ where }; self.usart.cr1.modify(|_r, w| { w.m().bit(match config.wordlength { - WordLength::DataBits8 => false, - WordLength::DataBits9 => true, + WordLength::Bits8 => false, + WordLength::Bits9 => true, }); w.ps().bit(parity_is_odd); w.pce().bit(parity_is_used) @@ -652,7 +662,7 @@ where /// Reads 9-bit words from the UART/USART /// -/// If the UART/USART was configured with `WordLength::DataBits9`, the returned value will contain +/// If the UART/USART was configured with `WordLength::Bits9`, the returned value will contain /// 9 received data bits and all other bits set to zero. Otherwise, the returned value will contain /// 8 received data bits and all other bits set to zero. impl crate::hal::serial::Read for Rx @@ -733,7 +743,7 @@ where /// Writes 9-bit words to the UART/USART /// -/// If the UART/USART was configured with `WordLength::DataBits9`, the 9 least significant bits will +/// If the UART/USART was configured with `WordLength::Bits9`, the 9 least significant bits will /// be transmitted and the other 7 bits will be ignored. Otherwise, the 8 least significant bits /// will be transmitted and the other 8 bits will be ignored. impl crate::hal::serial::Write for Tx