stm32f1xx_hal/pacext/
adc.rs1use crate::Sealed;
2
3use super::*;
4use crate::pac::adc1;
5#[cfg(not(feature = "stm32f100"))]
6use crate::pac::adc2;
7#[cfg(not(feature = "stm32f100"))]
8use crate::pac::adc3;
9
10pub trait AdcRB: Sealed {
11 fn sr(&self) -> &adc1::SR;
12 type CR1rs: reg::Cr1R + reg::Cr1W;
13 fn cr1(&self) -> &Reg<Self::CR1rs>;
14 type CR2rs: reg::Cr2R + reg::Cr2W;
15 fn cr2(&self) -> &Reg<Self::CR2rs>;
16 fn htr(&self) -> &adc1::HTR;
17 fn jdr(&self, n: usize) -> &adc1::JDR;
18 fn jdr1(&self) -> &adc1::JDR {
19 self.jdr(0)
20 }
21 fn jdr2(&self) -> &adc1::JDR {
22 self.jdr(1)
23 }
24 fn jdr3(&self) -> &adc1::JDR {
25 self.jdr(2)
26 }
27 fn jdr4(&self) -> &adc1::JDR {
28 self.jdr(3)
29 }
30 fn jofr(&self, n: usize) -> &adc1::JOFR;
31 fn jofr1(&self) -> &adc1::JOFR {
32 self.jofr(0)
33 }
34 fn jofr2(&self) -> &adc1::JOFR {
35 self.jofr(1)
36 }
37 fn jofr3(&self) -> &adc1::JOFR {
38 self.jofr(2)
39 }
40 fn jofr4(&self) -> &adc1::JOFR {
41 self.jofr(3)
42 }
43 fn jsqr(&self) -> &adc1::JSQR;
44 fn ltr(&self) -> &adc1::LTR;
45 fn smpr1(&self) -> &adc1::SMPR1;
46 fn smpr2(&self) -> &adc1::SMPR2;
47 fn sqr1(&self) -> &adc1::SQR1;
48 fn sqr2(&self) -> &adc1::SQR2;
49 fn sqr3(&self) -> &adc1::SQR3;
50 type DRrs: reg::Dr;
51 fn dr(&self) -> &Reg<Self::DRrs>;
52}
53
54wrap_r! {
55 pub trait Cr1R {
56 fn awdch(&self) -> adc1::cr1::AWDCH_R;
57 fn eocie(&self) -> adc1::cr1::EOCIE_R;
58 fn awdie(&self) -> adc1::cr1::AWDIE_R;
59 fn jeocie(&self) -> adc1::cr1::JEOCIE_R;
60 fn scan(&self) -> adc1::cr1::SCAN_R;
61 fn awdsgl(&self) -> adc1::cr1::AWDSGL_R;
62 fn jauto(&self) -> adc1::cr1::JAUTO_R;
63 fn discen(&self) -> adc1::cr1::DISCEN_R;
64 fn jdiscen(&self) -> adc1::cr1::JDISCEN_R;
65 fn discnum(&self) -> adc1::cr1::DISCNUM_R;
66 fn jawden(&self) -> adc1::cr1::JAWDEN_R;
67 fn awden(&self) -> adc1::cr1::AWDEN_R;
68 }
69}
70
71wrap_w! {
72 pub trait Cr1W {
73 fn awdch(&mut self) -> adc1::cr1::AWDCH_W<'_, REG>;
74 fn eocie(&mut self) -> adc1::cr1::EOCIE_W<'_, REG>;
75 fn awdie(&mut self) -> adc1::cr1::AWDIE_W<'_, REG>;
76 fn jeocie(&mut self) -> adc1::cr1::JEOCIE_W<'_, REG>;
77 fn scan(&mut self) -> adc1::cr1::SCAN_W<'_, REG>;
78 fn awdsgl(&mut self) -> adc1::cr1::AWDSGL_W<'_, REG>;
79 fn jauto(&mut self) -> adc1::cr1::JAUTO_W<'_, REG>;
80 fn discen(&mut self) -> adc1::cr1::DISCEN_W<'_, REG>;
81 fn jdiscen(&mut self) -> adc1::cr1::JDISCEN_W<'_, REG>;
82 fn discnum(&mut self) -> adc1::cr1::DISCNUM_W<'_, REG>;
83 fn jawden(&mut self) -> adc1::cr1::JAWDEN_W<'_, REG>;
84 fn awden(&mut self) -> adc1::cr1::AWDEN_W<'_, REG>;
85 }
86}
87
88wrap_r! {
89 pub trait Cr2R {
90 fn adon(&self) -> adc1::cr2::ADON_R;
91 fn cont(&self) -> adc1::cr2::CONT_R;
92 fn cal(&self) -> adc1::cr2::CAL_R;
93 fn rstcal(&self) -> adc1::cr2::RSTCAL_R;
94 fn dma(&self) -> adc1::cr2::DMA_R;
95 fn align(&self) -> adc1::cr2::ALIGN_R;
96 fn jexttrig(&self) -> adc1::cr2::JEXTTRIG_R;
97 fn exttrig(&self) -> adc1::cr2::EXTTRIG_R;
98 fn jswstart(&self) -> adc1::cr2::JSWSTART_R;
99 fn swstart(&self) -> adc1::cr2::SWSTART_R;
100 fn tsvrefe(&self) -> adc1::cr2::TSVREFE_R;
101 }
102}
103
104wrap_w! {
105 pub trait Cr2W {
106 fn adon(&mut self) -> adc1::cr2::ADON_W<'_, REG>;
107 fn cont(&mut self) -> adc1::cr2::CONT_W<'_, REG>;
108 fn cal(&mut self) -> adc1::cr2::CAL_W<'_, REG>;
109 fn rstcal(&mut self) -> adc1::cr2::RSTCAL_W<'_, REG>;
110 fn dma(&mut self) -> adc1::cr2::DMA_W<'_, REG>;
111 fn align(&mut self) -> adc1::cr2::ALIGN_W<'_, REG>;
112 fn jexttrig(&mut self) -> adc1::cr2::JEXTTRIG_W<'_, REG>;
113 fn exttrig(&mut self) -> adc1::cr2::EXTTRIG_W<'_, REG>;
114 fn jswstart(&mut self) -> adc1::cr2::JSWSTART_W<'_, REG>;
115 fn swstart(&mut self) -> adc1::cr2::SWSTART_W<'_, REG>;
116 fn tsvrefe(&mut self) -> adc1::cr2::TSVREFE_W<'_, REG>;
117 }
118}
119
120pub trait ExtSelW {
121 fn select_swstart(&mut self) -> &mut Self;
122}
123
124impl<REG: reg::ExtSelW> ExtSelW for W<REG> {
125 fn select_swstart(&mut self) -> &mut Self {
126 REG::select_swstart(self)
127 }
128}
129
130wrap_r! {
131 pub trait Dr {
132 fn data(&self) -> adc1::dr::DATA_R;
133 }
134}
135
136mod reg {
137 use super::*;
138
139 pub trait Cr1R: RegisterSpec<Ux = u32> + Readable + Sized {
140 fn awdch(r: &R<Self>) -> adc1::cr1::AWDCH_R;
141 fn eocie(r: &R<Self>) -> adc1::cr1::EOCIE_R;
142 fn awdie(r: &R<Self>) -> adc1::cr1::AWDIE_R;
143 fn jeocie(r: &R<Self>) -> adc1::cr1::JEOCIE_R;
144 fn scan(r: &R<Self>) -> adc1::cr1::SCAN_R;
145 fn awdsgl(r: &R<Self>) -> adc1::cr1::AWDSGL_R;
146 fn jauto(r: &R<Self>) -> adc1::cr1::JAUTO_R;
147 fn discen(r: &R<Self>) -> adc1::cr1::DISCEN_R;
148 fn jdiscen(r: &R<Self>) -> adc1::cr1::JDISCEN_R;
149 fn discnum(r: &R<Self>) -> adc1::cr1::DISCNUM_R;
150 fn jawden(r: &R<Self>) -> adc1::cr1::JAWDEN_R;
151 fn awden(r: &R<Self>) -> adc1::cr1::AWDEN_R;
152 }
153
154 pub trait Cr1W: RegisterSpec<Ux = u32> + Writable + Resettable + Sized {
155 fn awdch(w: &mut W<Self>) -> adc1::cr1::AWDCH_W<'_, Self>;
156 fn eocie(w: &mut W<Self>) -> adc1::cr1::EOCIE_W<'_, Self>;
157 fn awdie(w: &mut W<Self>) -> adc1::cr1::AWDIE_W<'_, Self>;
158 fn jeocie(w: &mut W<Self>) -> adc1::cr1::JEOCIE_W<'_, Self>;
159 fn scan(w: &mut W<Self>) -> adc1::cr1::SCAN_W<'_, Self>;
160 fn awdsgl(w: &mut W<Self>) -> adc1::cr1::AWDSGL_W<'_, Self>;
161 fn jauto(w: &mut W<Self>) -> adc1::cr1::JAUTO_W<'_, Self>;
162 fn discen(w: &mut W<Self>) -> adc1::cr1::DISCEN_W<'_, Self>;
163 fn jdiscen(w: &mut W<Self>) -> adc1::cr1::JDISCEN_W<'_, Self>;
164 fn discnum(w: &mut W<Self>) -> adc1::cr1::DISCNUM_W<'_, Self>;
165 fn jawden(w: &mut W<Self>) -> adc1::cr1::JAWDEN_W<'_, Self>;
166 fn awden(w: &mut W<Self>) -> adc1::cr1::AWDEN_W<'_, Self>;
167 }
168
169 pub trait Cr2R: RegisterSpec<Ux = u32> + Readable + Sized {
170 fn adon(r: &R<Self>) -> adc1::cr2::ADON_R;
171 fn cont(r: &R<Self>) -> adc1::cr2::CONT_R;
172 fn cal(r: &R<Self>) -> adc1::cr2::CAL_R;
173 fn rstcal(r: &R<Self>) -> adc1::cr2::RSTCAL_R;
174 fn dma(r: &R<Self>) -> adc1::cr2::DMA_R;
175 fn align(r: &R<Self>) -> adc1::cr2::ALIGN_R;
176 fn jexttrig(r: &R<Self>) -> adc1::cr2::JEXTTRIG_R;
177 fn exttrig(r: &R<Self>) -> adc1::cr2::EXTTRIG_R;
178 fn jswstart(r: &R<Self>) -> adc1::cr2::JSWSTART_R;
179 fn swstart(r: &R<Self>) -> adc1::cr2::SWSTART_R;
180 fn tsvrefe(r: &R<Self>) -> adc1::cr2::TSVREFE_R;
181 }
182 pub trait Cr2W: RegisterSpec<Ux = u32> + Writable + Resettable + Sized + ExtSelW {
183 fn adon(w: &mut W<Self>) -> adc1::cr2::ADON_W<'_, Self>;
184 fn cont(w: &mut W<Self>) -> adc1::cr2::CONT_W<'_, Self>;
185 fn cal(w: &mut W<Self>) -> adc1::cr2::CAL_W<'_, Self>;
186 fn rstcal(w: &mut W<Self>) -> adc1::cr2::RSTCAL_W<'_, Self>;
187 fn dma(w: &mut W<Self>) -> adc1::cr2::DMA_W<'_, Self>;
188 fn align(w: &mut W<Self>) -> adc1::cr2::ALIGN_W<'_, Self>;
189 fn jexttrig(w: &mut W<Self>) -> adc1::cr2::JEXTTRIG_W<'_, Self>;
190 fn exttrig(w: &mut W<Self>) -> adc1::cr2::EXTTRIG_W<'_, Self>;
191 fn jswstart(w: &mut W<Self>) -> adc1::cr2::JSWSTART_W<'_, Self>;
192 fn swstart(w: &mut W<Self>) -> adc1::cr2::SWSTART_W<'_, Self>;
193 fn tsvrefe(w: &mut W<Self>) -> adc1::cr2::TSVREFE_W<'_, Self>;
194 }
195 pub trait Dr: RegisterSpec<Ux = u32> + Readable + Sized {
196 fn data(r: &R<Self>) -> adc1::dr::DATA_R;
197 }
198
199 pub trait ExtSelW: RegisterSpec<Ux = u32> + Sized {
200 fn select_swstart(w: &mut W<Self>) -> &mut W<Self>;
201 }
202}
203
204macro_rules! impl_ext {
205 ($adc:ident) => {
206 impl Sealed for $adc::RegisterBlock {}
207 impl AdcRB for $adc::RegisterBlock {
208 type CR1rs = $adc::cr1::CR1rs;
209 type CR2rs = $adc::cr2::CR2rs;
210 type DRrs = $adc::dr::DRrs;
211 impl_reg! {
212 sr -> &adc1::SR;
213 cr1 -> &Reg<Self::CR1rs>;
214 cr2 -> &Reg<Self::CR2rs>;
215 htr -> &adc1::HTR;
216 jdr: n -> &adc1::JDR;
217 jofr: n -> &adc1::JOFR;
218 jsqr -> &adc1::JSQR;
219 ltr -> &adc1::LTR;
220 smpr1 -> &adc1::SMPR1;
221 smpr2 -> &adc1::SMPR2;
222 sqr1 -> &adc1::SQR1;
223 sqr2 -> &adc1::SQR2;
224 sqr3 -> &adc1::SQR3;
225 dr -> &Reg<Self::DRrs>;
226 }
227 }
228
229 impl reg::Cr1R for $adc::cr1::CR1rs {
230 impl_read! {
231 awdch -> adc1::cr1::AWDCH_R;
232 eocie -> adc1::cr1::EOCIE_R;
233 awdie -> adc1::cr1::AWDIE_R;
234 jeocie -> adc1::cr1::JEOCIE_R;
235 scan -> adc1::cr1::SCAN_R;
236 awdsgl -> adc1::cr1::AWDSGL_R;
237 jauto -> adc1::cr1::JAUTO_R;
238 discen -> adc1::cr1::DISCEN_R;
239 jdiscen -> adc1::cr1::JDISCEN_R;
240 discnum -> adc1::cr1::DISCNUM_R;
241 jawden -> adc1::cr1::JAWDEN_R;
242 awden -> adc1::cr1::AWDEN_R;
243 }
244 }
245 impl reg::Cr1W for $adc::cr1::CR1rs {
246 impl_write! {
247 awdch -> adc1::cr1::AWDCH_W<'_, Self>;
248 eocie -> adc1::cr1::EOCIE_W<'_, Self>;
249 awdie -> adc1::cr1::AWDIE_W<'_, Self>;
250 jeocie -> adc1::cr1::JEOCIE_W<'_, Self>;
251 scan -> adc1::cr1::SCAN_W<'_, Self>;
252 awdsgl -> adc1::cr1::AWDSGL_W<'_, Self>;
253 jauto -> adc1::cr1::JAUTO_W<'_, Self>;
254 discen -> adc1::cr1::DISCEN_W<'_, Self>;
255 jdiscen -> adc1::cr1::JDISCEN_W<'_, Self>;
256 discnum -> adc1::cr1::DISCNUM_W<'_, Self>;
257 jawden -> adc1::cr1::JAWDEN_W<'_, Self>;
258 awden -> adc1::cr1::AWDEN_W<'_, Self>;
259 }
260 }
261 impl reg::Dr for $adc::dr::DRrs {
262 impl_read! {
263 data -> adc1::dr::DATA_R;
264 }
265 }
266 };
267}
268
269macro_rules! impl_cr2 {
270 ($adc:ident) => {
271 impl reg::Cr2R for $adc::cr2::CR2rs {
272 impl_read! {
273 adon -> adc1::cr2::ADON_R;
274 cont -> adc1::cr2::CONT_R;
275 cal -> adc1::cr2::CAL_R;
276 rstcal -> adc1::cr2::RSTCAL_R;
277 dma -> adc1::cr2::DMA_R;
278 align -> adc1::cr2::ALIGN_R;
279 jexttrig -> adc1::cr2::JEXTTRIG_R;
280 exttrig -> adc1::cr2::EXTTRIG_R;
281 jswstart -> adc1::cr2::JSWSTART_R;
282 swstart -> adc1::cr2::SWSTART_R;
283 tsvrefe -> adc1::cr2::TSVREFE_R;
284 }
285 }
286 impl reg::Cr2W for $adc::cr2::CR2rs {
287 impl_write! {
288 adon -> adc1::cr2::ADON_W<'_, Self>;
289 cont -> adc1::cr2::CONT_W<'_, Self>;
290 cal -> adc1::cr2::CAL_W<'_, Self>;
291 rstcal -> adc1::cr2::RSTCAL_W<'_, Self>;
292 dma -> adc1::cr2::DMA_W<'_, Self>;
293 align -> adc1::cr2::ALIGN_W<'_, Self>;
294 jexttrig -> adc1::cr2::JEXTTRIG_W<'_, Self>;
295 exttrig -> adc1::cr2::EXTTRIG_W<'_, Self>;
296 jswstart -> adc1::cr2::JSWSTART_W<'_, Self>;
297 swstart -> adc1::cr2::SWSTART_W<'_, Self>;
298 tsvrefe -> adc1::cr2::TSVREFE_W<'_, Self>;
299 }
300 }
301 impl reg::ExtSelW for $adc::cr2::CR2rs {
302 fn select_swstart(w: &mut W<Self>) -> &mut W<Self> {
303 w.extsel().swstart()
304 }
305 }
306 };
307}
308
309impl_ext!(adc1);
310impl_cr2!(adc1);
311
312#[cfg(not(feature = "stm32f100"))]
313impl_ext!(adc2);
314#[cfg(not(feature = "stm32f100"))]
315impl_ext!(adc3);
316#[cfg(not(feature = "stm32f100"))]
317impl_cr2!(adc3);