Skip to content

Commit 35c6b23

Browse files
committed
serial: remove WordLength configuration but set it automatically based on parity
1 parent ab84c43 commit 35c6b23

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
constants to specify how many transmit / receive buffers to include in
2222
`ethernet::DesRing`. To replicate the previous behaviour, use `DesRing<4, 4>`
2323
* spi: Utilise FIFO in `Transfer` and `Write` implementations
24+
* **Breaking**: manual control over serial data length removed, now set automatically based on parity
2425

2526
## [v0.10.0] 2021-07-xx
2627

src/serial.rs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,12 @@ pub enum Event {
7676
pub mod config {
7777
use crate::time::Hertz;
7878

79-
/// The number of bits in a serial data word
80-
///
81-
/// Note that the length includes the data bits and any parity bits, but not start or stop bits.
82-
#[derive(Copy, Clone, PartialEq)]
83-
pub enum WordLength {
84-
DataBits8,
85-
DataBits9,
86-
}
8779
/// The parity bits appended to each serial data word
8880
///
8981
/// When enabled parity bits will be automatically added by hardware on transmit, and automatically checked by
9082
/// hardware on receive. For example, `read()` would return [`Error::Parity`](super::Error::Parity).
9183
///
92-
/// Note that parity bits are included in the serial word length, so if parity is used word length should be set to
93-
/// [`WordLength::DataBits9`].
84+
/// Note that parity bits are included in the serial word length, so if parity is used word length will be set to 9.
9485
#[derive(Copy, Clone, PartialEq)]
9586
pub enum Parity {
9687
ParityNone,
@@ -135,7 +126,6 @@ pub mod config {
135126
#[derive(Copy, Clone)]
136127
pub struct Config {
137128
pub baudrate: Hertz,
138-
pub wordlength: WordLength,
139129
pub parity: Parity,
140130
pub stopbits: StopBits,
141131
pub bitorder: BitOrder,
@@ -152,7 +142,6 @@ pub mod config {
152142
pub fn new<T: Into<Hertz>>(frequency: T) -> Self {
153143
Config {
154144
baudrate: frequency.into(),
155-
wordlength: WordLength::DataBits8,
156145
parity: Parity::ParityNone,
157146
stopbits: StopBits::STOP1,
158147
bitorder: BitOrder::LsbFirst,
@@ -174,36 +163,22 @@ pub mod config {
174163

175164
/// Enables Even Parity
176165
///
177-
/// Note that parity bits are included in the serial word length, so if parity is used word length should be set
178-
/// to [`WordLength::DataBits9`].
166+
/// Note that parity bits are included in the serial word length, so if parity is used word length will be set
167+
/// to 9.
179168
pub fn parity_even(mut self) -> Self {
180169
self.parity = Parity::ParityEven;
181170
self
182171
}
183172

184173
/// Enables Odd Parity
185174
///
186-
/// Note that parity bits are included in the serial word length, so if parity is used word length should be set
187-
/// to [`WordLength::DataBits9`].
175+
/// Note that parity bits are included in the serial word length, so if parity is used word length will be set
176+
/// to 9.
188177
pub fn parity_odd(mut self) -> Self {
189178
self.parity = Parity::ParityOdd;
190179
self
191180
}
192181

193-
pub fn wordlength_8(mut self) -> Self {
194-
self.wordlength = WordLength::DataBits8;
195-
self
196-
}
197-
198-
/// Set the serial word length to 9
199-
///
200-
/// Note that the HAL currently only supports transmitting 8-bit serial data, so the 9th bit will always be zero
201-
/// except when it is a parity bit.
202-
pub fn wordlength_9(mut self) -> Self {
203-
self.wordlength = WordLength::DataBits9;
204-
self
205-
}
206-
207182
/// Specify the number of stop bits
208183
pub fn stopbits(mut self, stopbits: StopBits) -> Self {
209184
self.stopbits = stopbits;
@@ -617,9 +592,9 @@ macro_rules! usart {
617592
.m1()
618593
.clear_bit()
619594
.m0()
620-
.variant(match config.wordlength {
621-
WordLength::DataBits8 => M0::BIT8,
622-
WordLength::DataBits9 => M0::BIT9,
595+
.variant(match config.parity {
596+
Parity::ParityNone => M0::BIT8,
597+
_ => M0::BIT9,
623598
}).pce()
624599
.variant(match config.parity {
625600
Parity::ParityNone => PCE::DISABLED,

0 commit comments

Comments
 (0)