Skip to content
Snippets Groups Projects
Commit 8e0b5333 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

add listen/unlisten to Capture

parent 76636afe
Branches
No related tags found
No related merge requests found
...@@ -52,6 +52,18 @@ pub enum Error { ...@@ -52,6 +52,18 @@ pub enum Error {
_Extensible, _Extensible,
} }
/// Interrupt event
pub enum Event {
/// Capture on channel 1
Capture1,
/// Capture on channel 2
Capture2,
/// Capture on channel 3
Capture3,
/// Capture on channel 4
Capture4,
}
/// Input capture interface /// Input capture interface
pub struct Capture<'a, T>(pub &'a T) pub struct Capture<'a, T>(pub &'a T)
where where
...@@ -149,6 +161,30 @@ impl<'a> Capture<'a, TIM1> { ...@@ -149,6 +161,30 @@ impl<'a> Capture<'a, TIM1> {
); );
} }
/// Starts listening for an interrupt `event`
pub fn listen(&self, event: Event) {
let tim1 = self.0;
match event {
Event::Capture1 => tim1.dier.modify(|_, w| w.cc1ie().set()),
Event::Capture2 => tim1.dier.modify(|_, w| w.cc2ie().set()),
Event::Capture3 => tim1.dier.modify(|_, w| w.cc3ie().set()),
Event::Capture4 => tim1.dier.modify(|_, w| w.cc4ie().set()),
}
}
/// Stops listening for an interrupt `event`
pub fn unlisten(&self, event: Event) {
let tim1 = self.0;
match event {
Event::Capture1 => tim1.dier.modify(|_, w| w.cc1ie().clear()),
Event::Capture2 => tim1.dier.modify(|_, w| w.cc2ie().clear()),
Event::Capture3 => tim1.dier.modify(|_, w| w.cc3ie().clear()),
Event::Capture4 => tim1.dier.modify(|_, w| w.cc4ie().clear()),
}
}
fn _set_resolution(&self, resolution: ::apb2::Ticks) { fn _set_resolution(&self, resolution: ::apb2::Ticks) {
let psc = u16( let psc = u16(
resolution.0.checked_sub(1).expect("impossible resolution"), resolution.0.checked_sub(1).expect("impossible resolution"),
...@@ -420,6 +456,30 @@ where ...@@ -420,6 +456,30 @@ where
); );
} }
/// Starts listening for an interrupt `event`
pub fn listen(&self, event: Event) {
let tim = self.0;
match event {
Event::Capture1 => tim.dier.modify(|_, w| w.cc1ie().set()),
Event::Capture2 => tim.dier.modify(|_, w| w.cc2ie().set()),
Event::Capture3 => tim.dier.modify(|_, w| w.cc3ie().set()),
Event::Capture4 => tim.dier.modify(|_, w| w.cc4ie().set()),
}
}
/// Stops listening for an interrupt `event`
pub fn unlisten(&self, event: Event) {
let tim = self.0;
match event {
Event::Capture1 => tim.dier.modify(|_, w| w.cc1ie().clear()),
Event::Capture2 => tim.dier.modify(|_, w| w.cc2ie().clear()),
Event::Capture3 => tim.dier.modify(|_, w| w.cc3ie().clear()),
Event::Capture4 => tim.dier.modify(|_, w| w.cc4ie().clear()),
}
}
fn _set_resolution(&self, resolution: ::apb1::Ticks) { fn _set_resolution(&self, resolution: ::apb1::Ticks) {
let psc = u16( let psc = u16(
resolution.0.checked_sub(1).expect("impossible resolution"), resolution.0.checked_sub(1).expect("impossible resolution"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment