lpc55_hal/drivers/serial/
config.rs1use crate::time::Hertz;
2
3#[derive(Clone, Copy, Debug)]
4pub enum WordLength {
5 DataBits7,
6 DataBits8,
7 DataBits9,
8}
9
10#[derive(Clone, Copy, Debug)]
11pub enum Parity {
12 ParityNone,
13 ParityEven,
14 ParityOdd,
15}
16
17#[derive(Clone, Copy, Debug)]
18pub enum StopBits {
19 #[doc = "1 stop bit"]
20 STOP1,
21 #[doc = "2 stop bits"]
24 STOP2,
25 }
28
29#[derive(Clone, Copy, Debug)]
30pub struct Config {
31 pub speed: Hertz,
32 pub wordlength: WordLength,
33 pub parity: Parity,
34 pub stopbits: StopBits,
35}
36
37impl Config {
38 pub fn speed<Speed: Into<Hertz>>(mut self, speed: Speed) -> Self {
39 self.speed = speed.into();
40 self
41 }
42
43 pub fn parity_none(mut self) -> Self {
44 self.parity = Parity::ParityNone;
45 self
46 }
47
48 pub fn parity_even(mut self) -> Self {
49 self.parity = Parity::ParityEven;
50 self
51 }
52
53 pub fn parity_odd(mut self) -> Self {
54 self.parity = Parity::ParityOdd;
55 self
56 }
57
58 pub fn wordlength_8(mut self) -> Self {
59 self.wordlength = WordLength::DataBits8;
60 self
61 }
62
63 pub fn wordlength_9(mut self) -> Self {
64 self.wordlength = WordLength::DataBits9;
65 self
66 }
67
68 pub fn stopbits(mut self, stopbits: StopBits) -> Self {
69 self.stopbits = stopbits;
70 self
71 }
72}
73
74#[derive(Debug)]
75pub struct InvalidConfig;
76
77impl Default for Config {
78 fn default() -> Config {
80 Config {
81 speed: Hertz(9_600),
83 wordlength: WordLength::DataBits8,
84 parity: Parity::ParityNone,
85 stopbits: StopBits::STOP1,
86 }
87 }
88}