Skip to content

Commit ca76a46

Browse files
Rename Serial items
1 parent ab33c09 commit ca76a46

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

examples/serial_9bits.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ fn main() -> ! {
121121
p.USART3,
122122
(tx_pin, rx_pin),
123123
&mut afio.mapr,
124-
Config::default().baudrate(9600.bps()).wordlength_9(),
124+
Config::default()
125+
.baudrate(9600.bps())
126+
.wordlength_9bits()
127+
.parity_none(),
125128
clocks,
126129
)
127130
// Switching the 'Word' type parameter for the 'Read' and 'Write' traits from u8 to u16.

examples/serial_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn main() -> ! {
6565
serial::Config::default()
6666
.baudrate(9600.bps())
6767
.stopbits(serial::StopBits::STOP2)
68-
.wordlength_9()
68+
.wordlength_9bits()
6969
.parity_odd(),
7070
clocks,
7171
);

src/serial.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
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

155158
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,
160165
}
161166

162167
pub 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.
658668
impl<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.
739749
impl<USART> crate::hal::serial::Write<u16> for Tx<USART, u16>

0 commit comments

Comments
 (0)