stm32f1xx_hal/pacext/
uart.rs1#![allow(unused)]
2
3use crate::{sealed, Sealed};
4
5use super::*;
6use crate::pac::uart4;
7use crate::pac::usart1;
8
9pub trait UartRB: Sealed {
10 fn cr1(&self) -> &usart1::CR1;
11 fn dr(&self) -> &usart1::DR;
12 fn brr(&self) -> &usart1::BRR;
13 type SRrs: reg::SrR + reg::SrW;
14 fn sr(&self) -> &Reg<Self::SRrs>;
15 type CR2rs: reg::Cr2R + reg::Cr2W;
16 fn cr2(&self) -> &Reg<Self::CR2rs>;
17 type CR3rs: reg::Cr3R + reg::Cr3W;
18 fn cr3(&self) -> &Reg<Self::CR3rs>;
19 type GTPRrs: reg::GtprR + reg::GtprW;
20 fn gtpr(&self) -> &Reg<Self::GTPRrs>;
21}
22
23wrap_r! {
24 pub trait SrR {
25 fn pe(&self) -> usart1::sr::PE_R;
26 fn fe(&self) -> usart1::sr::FE_R;
27 fn nf(&self) -> usart1::sr::NE_R;
28 fn ore(&self) -> usart1::sr::ORE_R;
29 fn idle(&self) -> usart1::sr::IDLE_R;
30 fn rxne(&self) -> usart1::sr::RXNE_R;
31 fn tc(&self) -> usart1::sr::TC_R;
32 fn txe(&self) -> usart1::sr::TXE_R;
33 fn lbd(&self) -> usart1::sr::LBD_R;
34 }
35}
36wrap_w! {
37 pub trait SrW {
38 fn rxne(&mut self) -> usart1::sr::RXNE_W<'_, REG>;
39 fn tc(&mut self) -> usart1::sr::TC_W<'_, REG>;
40 fn lbd(&mut self) -> usart1::sr::LBD_W<'_, REG>;
41 }
42}
43
44wrap_r! {
45 pub trait Cr2R {
46 fn add(&self) -> usart1::cr2::ADD_R;
47 fn lbdl(&self) -> usart1::cr2::LBDL_R;
48 fn lbdie(&self) -> usart1::cr2::LBDIE_R;
49 fn linen(&self) -> usart1::cr2::LINEN_R;
50 }
51}
52wrap_w! {
53 pub trait Cr2W {
54 fn add(&mut self) -> usart1::cr2::ADD_W<'_, REG>;
55 fn lbdl(&mut self) -> usart1::cr2::LBDL_W<'_, REG>;
56 fn lbdie(&mut self) -> usart1::cr2::LBDIE_W<'_, REG>;
57 fn linen(&mut self) -> usart1::cr2::LINEN_W<'_, REG>;
58 }
59}
60
61wrap_r! {
62 pub trait Cr3R {
63 fn eie(&self) -> usart1::cr3::EIE_R;
64 fn iren(&self) -> usart1::cr3::IREN_R;
65 fn irlp(&self) -> usart1::cr3::IRLP_R;
66 fn hdsel(&self) -> usart1::cr3::HDSEL_R;
67 fn dmar(&self) -> usart1::cr3::DMAR_R;
68 fn dmat(&self) -> usart1::cr3::DMAT_R;
69 }
70}
71wrap_w! {
72 pub trait Cr3W {
73 fn eie(&mut self) -> usart1::cr3::EIE_W<'_, REG>;
74 fn iren(&mut self) -> usart1::cr3::IREN_W<'_, REG>;
75 fn irlp(&mut self) -> usart1::cr3::IRLP_W<'_, REG>;
76 fn hdsel(&mut self) -> usart1::cr3::HDSEL_W<'_, REG>;
77 fn dmar(&mut self) -> usart1::cr3::DMAR_W<'_, REG>;
78 fn dmat(&mut self) -> usart1::cr3::DMAT_W<'_, REG>;
79 }
80}
81
82wrap_r! {
83 pub trait GtprR {
84 fn psc(&self) -> usart1::gtpr::PSC_R;
85 }
86}
87wrap_w! {
88 pub trait GtprW {
89 fn psc(&mut self) -> usart1::gtpr::PSC_W<'_, REG>;
90 }
91}
92
93mod reg {
94 use super::*;
95
96 pub trait SrR: RegisterSpec<Ux = u16> + Readable + Sized {
97 fn pe(r: &R<Self>) -> usart1::sr::PE_R;
98 fn fe(r: &R<Self>) -> usart1::sr::FE_R;
99 fn nf(r: &R<Self>) -> usart1::sr::NE_R;
100 fn ore(r: &R<Self>) -> usart1::sr::ORE_R;
101 fn idle(r: &R<Self>) -> usart1::sr::IDLE_R;
102 fn rxne(r: &R<Self>) -> usart1::sr::RXNE_R;
103 fn tc(r: &R<Self>) -> usart1::sr::TC_R;
104 fn txe(r: &R<Self>) -> usart1::sr::TXE_R;
105 fn lbd(r: &R<Self>) -> usart1::sr::LBD_R;
106 }
107 pub trait SrW: RegisterSpec<Ux = u16> + Writable + Resettable + Sized {
108 fn rxne(w: &mut W<Self>) -> usart1::sr::RXNE_W<'_, Self>;
109 fn tc(w: &mut W<Self>) -> usart1::sr::TC_W<'_, Self>;
110 fn lbd(w: &mut W<Self>) -> usart1::sr::LBD_W<'_, Self>;
111 }
112
113 pub trait Cr2R: RegisterSpec<Ux = u16> + Readable + Sized {
114 fn add(r: &R<Self>) -> usart1::cr2::ADD_R;
115 fn lbdl(r: &R<Self>) -> usart1::cr2::LBDL_R;
116 fn lbdie(r: &R<Self>) -> usart1::cr2::LBDIE_R;
117 fn linen(r: &R<Self>) -> usart1::cr2::LINEN_R;
118 }
119 pub trait Cr2W: RegisterSpec<Ux = u16> + Writable + Resettable + Sized {
120 fn add(w: &mut W<Self>) -> usart1::cr2::ADD_W<'_, Self>;
121 fn lbdl(w: &mut W<Self>) -> usart1::cr2::LBDL_W<'_, Self>;
122 fn lbdie(w: &mut W<Self>) -> usart1::cr2::LBDIE_W<'_, Self>;
123 fn linen(w: &mut W<Self>) -> usart1::cr2::LINEN_W<'_, Self>;
124 }
125
126 pub trait Cr3R: RegisterSpec<Ux = u16> + Readable + Sized {
127 fn eie(r: &R<Self>) -> usart1::cr3::EIE_R;
128 fn iren(r: &R<Self>) -> usart1::cr3::IREN_R;
129 fn irlp(r: &R<Self>) -> usart1::cr3::IRLP_R;
130 fn hdsel(r: &R<Self>) -> usart1::cr3::HDSEL_R;
131 fn dmar(r: &R<Self>) -> usart1::cr3::DMAR_R;
132 fn dmat(r: &R<Self>) -> usart1::cr3::DMAT_R;
133 }
134 pub trait Cr3W: RegisterSpec<Ux = u16> + Writable + Resettable + Sized {
135 fn eie(w: &mut W<Self>) -> usart1::cr3::EIE_W<'_, Self>;
136 fn iren(w: &mut W<Self>) -> usart1::cr3::IREN_W<'_, Self>;
137 fn irlp(w: &mut W<Self>) -> usart1::cr3::IRLP_W<'_, Self>;
138 fn hdsel(w: &mut W<Self>) -> usart1::cr3::HDSEL_W<'_, Self>;
139 fn dmar(w: &mut W<Self>) -> usart1::cr3::DMAR_W<'_, Self>;
140 fn dmat(w: &mut W<Self>) -> usart1::cr3::DMAT_W<'_, Self>;
141 }
142
143 pub trait GtprR: RegisterSpec<Ux = u16> + Readable + Sized {
144 fn psc(r: &R<Self>) -> usart1::gtpr::PSC_R;
145 }
146 pub trait GtprW: RegisterSpec<Ux = u16> + Writable + Resettable + Sized {
147 fn psc(w: &mut W<Self>) -> usart1::gtpr::PSC_W<'_, Self>;
148 }
149}
150
151macro_rules! impl_ext {
152 ($(#[$attr:meta])* $uart:ident) => {
153 impl Sealed for $uart::RegisterBlock {}
154 impl UartRB for $uart::RegisterBlock {
155 type SRrs = $uart::sr::SRrs;
156 type CR2rs = $uart::cr2::CR2rs;
157 type CR3rs = $uart::cr3::CR3rs;
158 type GTPRrs = $uart::gtpr::GTPRrs;
159 impl_reg! {
160 cr1 -> &usart1::CR1;
161 dr -> &usart1::DR;
162 brr -> &usart1::BRR;
163 sr -> &Reg<Self::SRrs>;
164 cr2 -> &Reg<Self::CR2rs>;
165 cr3 -> &Reg<Self::CR3rs>;
166 gtpr -> &Reg<Self::GTPRrs>;
167 }
168 }
169
170 impl reg::SrR for $uart::sr::SRrs {
171 #[inline(always)]
172 fn nf(r: &R<Self>) -> usart1::sr::NE_R {
173 r.ne()
174 }
175 impl_read! {
176 pe -> usart1::sr::PE_R;
177 fe -> usart1::sr::FE_R;
178 ore -> usart1::sr::ORE_R;
179 idle -> usart1::sr::IDLE_R;
180 rxne -> usart1::sr::RXNE_R;
181 tc -> usart1::sr::TC_R;
182 txe -> usart1::sr::TXE_R;
183 lbd -> usart1::sr::LBD_R;
184 }
185 }
186 impl reg::SrW for $uart::sr::SRrs {
187 impl_write! {
188 rxne -> usart1::sr::RXNE_W<'_, Self>;
189 tc -> usart1::sr::TC_W<'_, Self>;
190 lbd -> usart1::sr::LBD_W<'_, Self>;
191 }
192 }
193
194 impl reg::Cr2R for $uart::cr2::CR2rs {
195 impl_read! {
196 add -> usart1::cr2::ADD_R;
197 lbdl -> usart1::cr2::LBDL_R;
198 lbdie -> usart1::cr2::LBDIE_R;
199 linen -> usart1::cr2::LINEN_R;
200 }
201 }
202 impl reg::Cr2W for $uart::cr2::CR2rs {
203 impl_write! {
204 add -> usart1::cr2::ADD_W<'_, Self>;
205 lbdl -> usart1::cr2::LBDL_W<'_, Self>;
206 lbdie -> usart1::cr2::LBDIE_W<'_, Self>;
207 linen -> usart1::cr2::LINEN_W<'_, Self>;
208 }
209 }
210
211 $(#[$attr])*
212 impl reg::Cr3R for $uart::cr3::CR3rs {
213 impl_read! {
214 eie -> usart1::cr3::EIE_R;
215 iren -> usart1::cr3::IREN_R;
216 irlp -> usart1::cr3::IRLP_R;
217 hdsel -> usart1::cr3::HDSEL_R;
218 dmar -> usart1::cr3::DMAR_R;
219 dmat -> usart1::cr3::DMAT_R;
220 }
221 }
222 $(#[$attr])*
223 impl reg::Cr3W for $uart::cr3::CR3rs {
224 impl_write! {
225 eie -> usart1::cr3::EIE_W<'_, Self>;
226 iren -> usart1::cr3::IREN_W<'_, Self>;
227 irlp -> usart1::cr3::IRLP_W<'_, Self>;
228 hdsel -> usart1::cr3::HDSEL_W<'_, Self>;
229 dmar -> usart1::cr3::DMAR_W<'_, Self>;
230 dmat -> usart1::cr3::DMAT_W<'_, Self>;
231 }
232 }
233
234 impl reg::GtprR for $uart::gtpr::GTPRrs {
235 impl_read! {
236 psc -> usart1::gtpr::PSC_R;
237 }
238 }
239 impl reg::GtprW for $uart::gtpr::GTPRrs {
240 impl_write! {
241 psc -> usart1::gtpr::PSC_W<'_, Self>;
242 }
243 }
244 };
245}
246
247impl_ext!(usart1);
248#[cfg(any(all(feature = "stm32f103", feature = "high"), feature = "connectivity"))]
249impl_ext!(uart4);