lpc8xx_hal/usart/
settings.rs1use core::marker::PhantomData;
2
3use crate::pac::usart0::cfg::{
4 self, CLKPOL_A, DATALEN_A, PARITYSEL_A, RXPOL_A, STOPLEN_A, TXPOL_A,
5};
6
7pub struct Settings<Word = u8> {
13 pub(super) data_len: DATALEN_A,
14 pub(super) parity: PARITYSEL_A,
15 pub(super) stop_len: STOPLEN_A,
16 pub(super) clock_pol: CLKPOL_A,
17 pub(super) rx_pol: RXPOL_A,
18 pub(super) tx_pol: TXPOL_A,
19
20 _word: PhantomData<Word>,
21}
22
23impl<Word> Settings<Word> {
24 pub fn data_len_7(mut self) -> Settings<u8> {
28 self.data_len = DATALEN_A::BIT_7;
29 self.transmute()
30 }
31
32 pub fn data_len_8(mut self) -> Settings<u8> {
36 self.data_len = DATALEN_A::BIT_8;
37 self.transmute()
38 }
39
40 pub fn data_len_9(mut self) -> Settings<u16> {
44 self.data_len = DATALEN_A::BIT_9;
45 self.transmute()
46 }
47
48 pub fn parity_none(mut self) -> Self {
52 self.parity = PARITYSEL_A::NO_PARITY;
53 self
54 }
55
56 pub fn parity_even(mut self) -> Self {
60 self.parity = PARITYSEL_A::EVEN_PARITY;
61 self
62 }
63
64 pub fn parity_odd(mut self) -> Self {
68 self.parity = PARITYSEL_A::ODD_PARITY;
69 self
70 }
71
72 pub fn stop_len_1(mut self) -> Self {
76 self.stop_len = STOPLEN_A::BIT_1;
77 self
78 }
79
80 pub fn stop_len_2(mut self) -> Self {
84 self.stop_len = STOPLEN_A::BITS_2;
85 self
86 }
87
88 pub fn clock_pol_falling(mut self) -> Self {
94 self.clock_pol = CLKPOL_A::FALLING_EDGE;
95 self
96 }
97
98 pub fn clock_pol_rising(mut self) -> Self {
104 self.clock_pol = CLKPOL_A::RISING_EDGE;
105 self
106 }
107
108 pub fn rx_pol_standard(mut self) -> Self {
112 self.rx_pol = RXPOL_A::STANDARD;
113 self
114 }
115
116 pub fn rx_pol_inverted(mut self) -> Self {
120 self.rx_pol = RXPOL_A::INVERTED;
121 self
122 }
123
124 pub fn tx_pol_standard(mut self) -> Self {
128 self.tx_pol = TXPOL_A::STANDARD;
129 self
130 }
131
132 pub fn tx_pol_inverted(mut self) -> Self {
136 self.tx_pol = TXPOL_A::INVERTED;
137 self
138 }
139
140 fn transmute<NewW>(self) -> Settings<NewW> {
141 Settings {
142 data_len: self.data_len,
143 parity: self.parity,
144 stop_len: self.stop_len,
145 clock_pol: self.clock_pol,
146 rx_pol: self.rx_pol,
147 tx_pol: self.tx_pol,
148 _word: PhantomData,
149 }
150 }
151
152 pub(super) fn apply(&self, w: &mut cfg::W) {
153 w.datalen().variant(self.data_len);
154 w.paritysel().variant(self.parity);
155 w.stoplen().variant(self.stop_len);
156 w.clkpol().variant(self.clock_pol);
157 w.rxpol().variant(self.rx_pol);
158 w.txpol().variant(self.tx_pol);
159 }
160}
161
162impl Default for Settings {
163 fn default() -> Self {
164 Settings {
165 data_len: DATALEN_A::BIT_8,
166 parity: PARITYSEL_A::NO_PARITY,
167 stop_len: STOPLEN_A::BIT_1,
168 clock_pol: CLKPOL_A::FALLING_EDGE,
169 rx_pol: RXPOL_A::STANDARD,
170 tx_pol: TXPOL_A::STANDARD,
171 _word: PhantomData,
172 }
173 }
174}