Skip to content

Instantly share code, notes, and snippets.

@keithduncan
Last active January 17, 2020 01:20
Show Gist options
  • Save keithduncan/c77b55e37ce87c39e2e0a8aa44fef658 to your computer and use it in GitHub Desktop.
Save keithduncan/c77b55e37ce87c39e2e0a8aa44fef658 to your computer and use it in GitHub Desktop.
mod mcu {
extern crate atsamd_hal as hal;
pub use hal::target_device::*;
pub use hal::*;
}
pub fn configure_eic(pm: &mut mcu::PM, clocks: &mut mcu::clock::GenericClockController, eic: &mut mcu::EIC) {
pm.apbamask.modify(|_, w| w.eic_().set_bit());
let gclk0 = clocks.gclk1();
clocks.eic(&gclk0).expect("eic clock");
eic.evctrl.modify(|_, w| w.extinteo2().set_bit());
eic.config[0].modify(|_, w| {
w.sense2().fall();
w.filten2().set_bit()
});
eic.ctrl.modify(|_, w| w.enable().set_bit());
while eic.status.read().syncbusy().bit_is_set() {}
}
pub fn configure_tc(pm: &mut mcu::PM, clocks: &mut mcu::clock::GenericClockController, tc: &mut mcu::TC3) {
// Power on tc3
pm.apbcmask.modify(|_, w| w.tc3_().set_bit());
let gclk0 = clocks.gclk0();
clocks.tcc2_tc3(&gclk0).expect("tc3 clock");
let counter = tc.count_16();
counter.evctrl.modify(|_, w| {
w.tcei().set_bit();
w.evact().count()
});
counter.ctrla.modify(|_, w| w.enable().set_bit());
while counter.status.read().syncbusy().bit_is_set() {}
}
pub fn configure_evsys(pm: &mut mcu::PM, evsys: &mut mcu::EVSYS) {
// Power on event system
pm.apbcmask.modify(|_, w| w.evsys_().set_bit());
let channel: u8 = 0; // u4
evsys.user.write(|w| {
unsafe {
// 0x01 == channel 0
w.channel().bits(channel + 1);
// TC3
w.user().bits(0x12)
}
});
evsys.channel.write(|w| {
w.path().asynchronous();
unsafe {
// EXTINT[2]
w.evgen().bits(0x0E);
}
unsafe {
w.channel().bits(channel)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment