Skip to content

Commit 4c9c96f

Browse files
authored
Added settings for onebit and overrun for serial (#166)
* Added settings for onebit and overrun for serial * Removed the error checking function that came with another PR
1 parent 552a8c7 commit 4c9c96f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/serial.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct Config {
8989
oversampling: Oversampling,
9090
character_match: Option<u8>,
9191
receiver_timeout: Option<u32>,
92+
disable_overrun: bool,
93+
onebit_sampling: bool,
9294
}
9395

9496
impl Config {
@@ -142,6 +144,18 @@ impl Config {
142144
self.receiver_timeout = Some(receiver_timeout);
143145
self
144146
}
147+
148+
/// Disable overrun detection
149+
pub fn with_overrun_disabled(mut self) -> Self {
150+
self.disable_overrun = true;
151+
self
152+
}
153+
154+
/// Change to onebit sampling
155+
pub fn with_onebit_sampling(mut self) -> Self {
156+
self.onebit_sampling = true;
157+
self
158+
}
145159
}
146160

147161
impl Default for Config {
@@ -154,6 +168,8 @@ impl Default for Config {
154168
oversampling: Oversampling::Over16,
155169
character_match: None,
156170
receiver_timeout: None,
171+
disable_overrun: false,
172+
onebit_sampling: false,
157173
}
158174
}
159175
}
@@ -264,7 +280,17 @@ macro_rules! hal {
264280
}
265281

266282
// Enable One bit sampling method
267-
usart.cr3.modify(|_, w| w.onebit().set_bit());
283+
usart.cr3.modify(|_, w| {
284+
if config.onebit_sampling {
285+
w.onebit().set_bit();
286+
}
287+
288+
if config.disable_overrun {
289+
w.ovrdis().set_bit();
290+
}
291+
292+
w
293+
});
268294

269295
// Configure parity and word length
270296
// Unlike most uart devices, the "word length" of this usart device refers to

0 commit comments

Comments
 (0)