1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::clock::EicClock;
use crate::pac;
pub mod pin;
pub struct ConfigurableEIC {
eic: pac::EIC,
}
impl ConfigurableEIC {
fn new(eic: pac::EIC) -> Self {
Self { eic }
}
pub fn button_debounce_pins(&mut self, debounce_pins: &[pin::ExternalInterruptID]) {
self.eic.dprescaler.modify(|_, w| {
w.tickon().set_bit() .states0().set_bit() .states1().set_bit() .prescaler0().div16()
.prescaler1().div16()
});
let mut debounceen: u32 = 0;
for pin in debounce_pins {
debounceen |= 1 << *pin as u32;
}
self.eic.debouncen.write(|w| unsafe { w.bits(debounceen) });
}
pub fn finalize(self) -> EIC {
self.into()
}
}
pub fn init_with_ulp32k(mclk: &mut pac::MCLK, _clock: EicClock, eic: pac::EIC) -> ConfigurableEIC {
mclk.apbamask.modify(|_, w| w.eic_().set_bit());
eic.ctrla.modify(|_, w| w.swrst().set_bit());
while eic.syncbusy.read().swrst().bit_is_set() {
cortex_m::asm::nop();
}
eic.ctrla.modify(|_, w| w.cksel().set_bit());
ConfigurableEIC::new(eic)
}
pub struct EIC {
_eic: pac::EIC,
}
impl From<ConfigurableEIC> for EIC {
fn from(eic: ConfigurableEIC) -> Self {
eic.eic.ctrla.modify(|_, w| w.enable().set_bit());
while eic.eic.syncbusy.read().enable().bit_is_set() {
cortex_m::asm::nop();
}
Self { _eic: eic.eic }
}
}