Skip to content

Commit ab84c43

Browse files
committed
serial: document parity and word length configuration
1 parent 6ce89df commit ab84c43

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/serial.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ 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.
7982
#[derive(Copy, Clone, PartialEq)]
8083
pub enum WordLength {
8184
DataBits8,
8285
DataBits9,
8386
}
87+
/// The parity bits appended to each serial data word
88+
///
89+
/// When enabled parity bits will be automatically added by hardware on transmit, and automatically checked by
90+
/// hardware on receive. For example, `read()` would return [`Error::Parity`](super::Error::Parity).
91+
///
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`].
8494
#[derive(Copy, Clone, PartialEq)]
8595
pub enum Parity {
8696
ParityNone,
@@ -162,11 +172,19 @@ pub mod config {
162172
self
163173
}
164174

175+
/// Enables Even Parity
176+
///
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`].
165179
pub fn parity_even(mut self) -> Self {
166180
self.parity = Parity::ParityEven;
167181
self
168182
}
169183

184+
/// Enables Odd Parity
185+
///
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`].
170188
pub fn parity_odd(mut self) -> Self {
171189
self.parity = Parity::ParityOdd;
172190
self
@@ -177,6 +195,10 @@ pub mod config {
177195
self
178196
}
179197

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.
180202
pub fn wordlength_9(mut self) -> Self {
181203
self.wordlength = WordLength::DataBits9;
182204
self

0 commit comments

Comments
 (0)