|
| 1 | +use crate::Sealed; |
| 2 | + |
| 3 | +use super::*; |
| 4 | +use crate::pac::adc1; |
| 5 | +#[cfg(not(feature = "stm32f100"))] |
| 6 | +use crate::pac::adc2; |
| 7 | +#[cfg(not(feature = "stm32f100"))] |
| 8 | +use crate::pac::adc3; |
| 9 | + |
| 10 | +pub trait AdcExt: 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 | + |
| 54 | +wrap_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 | + |
| 71 | +wrap_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 | + |
| 88 | +wrap_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 | + |
| 104 | +wrap_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 | + |
| 120 | +wrap_r! { |
| 121 | + pub trait Dr { |
| 122 | + fn data(&self) -> adc1::dr::DATA_R; |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +mod reg { |
| 127 | + use super::*; |
| 128 | + |
| 129 | + pub trait Cr1R: RegisterSpec<Ux = u32> + Readable + Sized { |
| 130 | + fn awdch(r: &R<Self>) -> adc1::cr1::AWDCH_R; |
| 131 | + fn eocie(r: &R<Self>) -> adc1::cr1::EOCIE_R; |
| 132 | + fn awdie(r: &R<Self>) -> adc1::cr1::AWDIE_R; |
| 133 | + fn jeocie(r: &R<Self>) -> adc1::cr1::JEOCIE_R; |
| 134 | + fn scan(r: &R<Self>) -> adc1::cr1::SCAN_R; |
| 135 | + fn awdsgl(r: &R<Self>) -> adc1::cr1::AWDSGL_R; |
| 136 | + fn jauto(r: &R<Self>) -> adc1::cr1::JAUTO_R; |
| 137 | + fn discen(r: &R<Self>) -> adc1::cr1::DISCEN_R; |
| 138 | + fn jdiscen(r: &R<Self>) -> adc1::cr1::JDISCEN_R; |
| 139 | + fn discnum(r: &R<Self>) -> adc1::cr1::DISCNUM_R; |
| 140 | + fn jawden(r: &R<Self>) -> adc1::cr1::JAWDEN_R; |
| 141 | + fn awden(r: &R<Self>) -> adc1::cr1::AWDEN_R; |
| 142 | + } |
| 143 | + |
| 144 | + pub trait Cr1W: RegisterSpec<Ux = u32> + Writable + Resettable + Sized { |
| 145 | + fn awdch(w: &mut W<Self>) -> adc1::cr1::AWDCH_W<Self>; |
| 146 | + fn eocie(w: &mut W<Self>) -> adc1::cr1::EOCIE_W<Self>; |
| 147 | + fn awdie(w: &mut W<Self>) -> adc1::cr1::AWDIE_W<Self>; |
| 148 | + fn jeocie(w: &mut W<Self>) -> adc1::cr1::JEOCIE_W<Self>; |
| 149 | + fn scan(w: &mut W<Self>) -> adc1::cr1::SCAN_W<Self>; |
| 150 | + fn awdsgl(w: &mut W<Self>) -> adc1::cr1::AWDSGL_W<Self>; |
| 151 | + fn jauto(w: &mut W<Self>) -> adc1::cr1::JAUTO_W<Self>; |
| 152 | + fn discen(w: &mut W<Self>) -> adc1::cr1::DISCEN_W<Self>; |
| 153 | + fn jdiscen(w: &mut W<Self>) -> adc1::cr1::JDISCEN_W<Self>; |
| 154 | + fn discnum(w: &mut W<Self>) -> adc1::cr1::DISCNUM_W<Self>; |
| 155 | + fn jawden(w: &mut W<Self>) -> adc1::cr1::JAWDEN_W<Self>; |
| 156 | + fn awden(w: &mut W<Self>) -> adc1::cr1::AWDEN_W<Self>; |
| 157 | + } |
| 158 | + |
| 159 | + pub trait Cr2R: RegisterSpec<Ux = u32> + Readable + Sized { |
| 160 | + fn adon(r: &R<Self>) -> adc1::cr2::ADON_R; |
| 161 | + fn cont(r: &R<Self>) -> adc1::cr2::CONT_R; |
| 162 | + fn cal(r: &R<Self>) -> adc1::cr2::CAL_R; |
| 163 | + fn rstcal(r: &R<Self>) -> adc1::cr2::RSTCAL_R; |
| 164 | + fn dma(r: &R<Self>) -> adc1::cr2::DMA_R; |
| 165 | + fn align(r: &R<Self>) -> adc1::cr2::ALIGN_R; |
| 166 | + fn jexttrig(r: &R<Self>) -> adc1::cr2::JEXTTRIG_R; |
| 167 | + fn exttrig(r: &R<Self>) -> adc1::cr2::EXTTRIG_R; |
| 168 | + fn jswstart(r: &R<Self>) -> adc1::cr2::JSWSTART_R; |
| 169 | + fn swstart(r: &R<Self>) -> adc1::cr2::SWSTART_R; |
| 170 | + fn tsvrefe(r: &R<Self>) -> adc1::cr2::TSVREFE_R; |
| 171 | + } |
| 172 | + pub trait Cr2W: RegisterSpec<Ux = u32> + Writable + Resettable + Sized { |
| 173 | + fn adon(w: &mut W<Self>) -> adc1::cr2::ADON_W<Self>; |
| 174 | + fn cont(w: &mut W<Self>) -> adc1::cr2::CONT_W<Self>; |
| 175 | + fn cal(w: &mut W<Self>) -> adc1::cr2::CAL_W<Self>; |
| 176 | + fn rstcal(w: &mut W<Self>) -> adc1::cr2::RSTCAL_W<Self>; |
| 177 | + fn dma(w: &mut W<Self>) -> adc1::cr2::DMA_W<Self>; |
| 178 | + fn align(w: &mut W<Self>) -> adc1::cr2::ALIGN_W<Self>; |
| 179 | + fn jexttrig(w: &mut W<Self>) -> adc1::cr2::JEXTTRIG_W<Self>; |
| 180 | + fn exttrig(w: &mut W<Self>) -> adc1::cr2::EXTTRIG_W<Self>; |
| 181 | + fn jswstart(w: &mut W<Self>) -> adc1::cr2::JSWSTART_W<Self>; |
| 182 | + fn swstart(w: &mut W<Self>) -> adc1::cr2::SWSTART_W<Self>; |
| 183 | + fn tsvrefe(w: &mut W<Self>) -> adc1::cr2::TSVREFE_W<Self>; |
| 184 | + } |
| 185 | + pub trait Dr: RegisterSpec<Ux = u32> + Readable + Sized { |
| 186 | + fn data(r: &R<Self>) -> adc1::dr::DATA_R; |
| 187 | + } |
| 188 | +} |
| 189 | + |
| 190 | +macro_rules! impl_ext { |
| 191 | + ($adc:ident) => { |
| 192 | + impl Sealed for $adc::RegisterBlock {} |
| 193 | + impl AdcExt for $adc::RegisterBlock { |
| 194 | + type CR1rs = $adc::cr1::CR1rs; |
| 195 | + type CR2rs = $adc::cr2::CR2rs; |
| 196 | + type DRrs = $adc::dr::DRrs; |
| 197 | + impl_reg! { |
| 198 | + sr -> &adc1::SR; |
| 199 | + cr1 -> &Reg<Self::CR1rs>; |
| 200 | + cr2 -> &Reg<Self::CR2rs>; |
| 201 | + htr -> &adc1::HTR; |
| 202 | + jdr: n -> &adc1::JDR; |
| 203 | + jofr: n -> &adc1::JOFR; |
| 204 | + jsqr -> &adc1::JSQR; |
| 205 | + ltr -> &adc1::LTR; |
| 206 | + smpr1 -> &adc1::SMPR1; |
| 207 | + smpr2 -> &adc1::SMPR2; |
| 208 | + sqr1 -> &adc1::SQR1; |
| 209 | + sqr2 -> &adc1::SQR2; |
| 210 | + sqr3 -> &adc1::SQR3; |
| 211 | + dr -> &Reg<Self::DRrs>; |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + impl reg::Cr1R for $adc::cr1::CR1rs { |
| 216 | + impl_read! { |
| 217 | + awdch -> adc1::cr1::AWDCH_R; |
| 218 | + eocie -> adc1::cr1::EOCIE_R; |
| 219 | + awdie -> adc1::cr1::AWDIE_R; |
| 220 | + jeocie -> adc1::cr1::JEOCIE_R; |
| 221 | + scan -> adc1::cr1::SCAN_R; |
| 222 | + awdsgl -> adc1::cr1::AWDSGL_R; |
| 223 | + jauto -> adc1::cr1::JAUTO_R; |
| 224 | + discen -> adc1::cr1::DISCEN_R; |
| 225 | + jdiscen -> adc1::cr1::JDISCEN_R; |
| 226 | + discnum -> adc1::cr1::DISCNUM_R; |
| 227 | + jawden -> adc1::cr1::JAWDEN_R; |
| 228 | + awden -> adc1::cr1::AWDEN_R; |
| 229 | + } |
| 230 | + } |
| 231 | + impl reg::Cr1W for $adc::cr1::CR1rs { |
| 232 | + impl_write! { |
| 233 | + awdch -> adc1::cr1::AWDCH_W<Self>; |
| 234 | + eocie -> adc1::cr1::EOCIE_W<Self>; |
| 235 | + awdie -> adc1::cr1::AWDIE_W<Self>; |
| 236 | + jeocie -> adc1::cr1::JEOCIE_W<Self>; |
| 237 | + scan -> adc1::cr1::SCAN_W<Self>; |
| 238 | + awdsgl -> adc1::cr1::AWDSGL_W<Self>; |
| 239 | + jauto -> adc1::cr1::JAUTO_W<Self>; |
| 240 | + discen -> adc1::cr1::DISCEN_W<Self>; |
| 241 | + jdiscen -> adc1::cr1::JDISCEN_W<Self>; |
| 242 | + discnum -> adc1::cr1::DISCNUM_W<Self>; |
| 243 | + jawden -> adc1::cr1::JAWDEN_W<Self>; |
| 244 | + awden -> adc1::cr1::AWDEN_W<Self>; |
| 245 | + } |
| 246 | + } |
| 247 | + impl reg::Dr for $adc::dr::DRrs { |
| 248 | + impl_read! { |
| 249 | + data -> adc1::dr::DATA_R; |
| 250 | + } |
| 251 | + } |
| 252 | + }; |
| 253 | +} |
| 254 | + |
| 255 | +macro_rules! impl_cr2 { |
| 256 | + ($adc:ident) => { |
| 257 | + impl reg::Cr2R for $adc::cr2::CR2rs { |
| 258 | + impl_read! { |
| 259 | + adon -> adc1::cr2::ADON_R; |
| 260 | + cont -> adc1::cr2::CONT_R; |
| 261 | + cal -> adc1::cr2::CAL_R; |
| 262 | + rstcal -> adc1::cr2::RSTCAL_R; |
| 263 | + dma -> adc1::cr2::DMA_R; |
| 264 | + align -> adc1::cr2::ALIGN_R; |
| 265 | + jexttrig -> adc1::cr2::JEXTTRIG_R; |
| 266 | + exttrig -> adc1::cr2::EXTTRIG_R; |
| 267 | + jswstart -> adc1::cr2::JSWSTART_R; |
| 268 | + swstart -> adc1::cr2::SWSTART_R; |
| 269 | + tsvrefe -> adc1::cr2::TSVREFE_R; |
| 270 | + } |
| 271 | + } |
| 272 | + impl reg::Cr2W for $adc::cr2::CR2rs { |
| 273 | + impl_write! { |
| 274 | + adon -> adc1::cr2::ADON_W<Self>; |
| 275 | + cont -> adc1::cr2::CONT_W<Self>; |
| 276 | + cal -> adc1::cr2::CAL_W<Self>; |
| 277 | + rstcal -> adc1::cr2::RSTCAL_W<Self>; |
| 278 | + dma -> adc1::cr2::DMA_W<Self>; |
| 279 | + align -> adc1::cr2::ALIGN_W<Self>; |
| 280 | + jexttrig -> adc1::cr2::JEXTTRIG_W<Self>; |
| 281 | + exttrig -> adc1::cr2::EXTTRIG_W<Self>; |
| 282 | + jswstart -> adc1::cr2::JSWSTART_W<Self>; |
| 283 | + swstart -> adc1::cr2::SWSTART_W<Self>; |
| 284 | + tsvrefe -> adc1::cr2::TSVREFE_W<Self>; |
| 285 | + } |
| 286 | + } |
| 287 | + }; |
| 288 | +} |
| 289 | + |
| 290 | +impl_ext!(adc1); |
| 291 | +impl_cr2!(adc1); |
| 292 | + |
| 293 | +#[cfg(not(feature = "stm32f100"))] |
| 294 | +impl_ext!(adc2); |
| 295 | +#[cfg(not(feature = "stm32f100"))] |
| 296 | +impl_ext!(adc3); |
| 297 | +#[cfg(not(feature = "stm32f100"))] |
| 298 | +impl_cr2!(adc3); |
0 commit comments