Write bits directly to intenset/clr + shorts
This commit is contained in:
parent
87ca902e44
commit
e6d0dba5ca
@ -197,27 +197,8 @@ impl<'d, T: Instance> Timer<'d, T> {
|
|||||||
if regs.events_compare[n].read().bits() != 0 {
|
if regs.events_compare[n].read().bits() != 0 {
|
||||||
// Clear the interrupt, otherwise the interrupt will be repeatedly raised as soon as the interrupt handler exits.
|
// Clear the interrupt, otherwise the interrupt will be repeatedly raised as soon as the interrupt handler exits.
|
||||||
// We can't clear the event, because it's used to poll whether the future is done or still pending.
|
// We can't clear the event, because it's used to poll whether the future is done or still pending.
|
||||||
regs.intenclr.write(|w| match n {
|
regs.intenclr
|
||||||
0 => w.compare0().clear(),
|
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + n))) });
|
||||||
1 => w.compare1().clear(),
|
|
||||||
2 => w.compare2().clear(),
|
|
||||||
3 => w.compare3().clear(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4().clear(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5().clear(),
|
|
||||||
_ => unreachable!("No timers have more than 6 CC registers"),
|
|
||||||
});
|
|
||||||
T::waker(n).wake();
|
T::waker(n).wake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,52 +275,16 @@ impl<'a, T: Instance> Cc<'a, T> {
|
|||||||
///
|
///
|
||||||
/// So, when the timer's counter reaches the value stored in this register, the timer's counter will be reset to 0.
|
/// So, when the timer's counter reaches the value stored in this register, the timer's counter will be reset to 0.
|
||||||
pub fn short_compare_clear(&self) {
|
pub fn short_compare_clear(&self) {
|
||||||
T::regs().shorts.write(|w| match self.n {
|
T::regs()
|
||||||
0 => w.compare0_clear().enabled(),
|
.shorts
|
||||||
1 => w.compare1_clear().enabled(),
|
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << self.n)) })
|
||||||
2 => w.compare2_clear().enabled(),
|
|
||||||
3 => w.compare3_clear().enabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4_clear().enabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5_clear().enabled(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable the shortcut between this CC register's COMPARE event and the timer's CLEAR task.
|
/// Disable the shortcut between this CC register's COMPARE event and the timer's CLEAR task.
|
||||||
pub fn unshort_compare_clear(&self) {
|
pub fn unshort_compare_clear(&self) {
|
||||||
T::regs().shorts.write(|w| match self.n {
|
T::regs()
|
||||||
0 => w.compare0_clear().disabled(),
|
.shorts
|
||||||
1 => w.compare1_clear().disabled(),
|
.modify(|r, w| unsafe { w.bits(r.bits() & (0 << self.n)) })
|
||||||
2 => w.compare2_clear().disabled(),
|
|
||||||
3 => w.compare3_clear().disabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4_clear().disabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5_clear().disabled(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable the shortcut between this CC register's COMPARE event and the timer's STOP task.
|
/// Enable the shortcut between this CC register's COMPARE event and the timer's STOP task.
|
||||||
@ -348,52 +293,16 @@ impl<'a, T: Instance> Cc<'a, T> {
|
|||||||
///
|
///
|
||||||
/// So, when the timer's counter reaches the value stored in this register, the timer will stop counting up.
|
/// So, when the timer's counter reaches the value stored in this register, the timer will stop counting up.
|
||||||
pub fn short_compare_stop(&self) {
|
pub fn short_compare_stop(&self) {
|
||||||
T::regs().shorts.write(|w| match self.n {
|
T::regs()
|
||||||
0 => w.compare0_stop().enabled(),
|
.shorts
|
||||||
1 => w.compare1_stop().enabled(),
|
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << (8 + self.n))) })
|
||||||
2 => w.compare2_stop().enabled(),
|
|
||||||
3 => w.compare3_stop().enabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4_stop().enabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5_stop().enabled(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable the shortcut between this CC register's COMPARE event and the timer's STOP task.
|
/// Disable the shortcut between this CC register's COMPARE event and the timer's STOP task.
|
||||||
pub fn unshort_compare_stop(&self) {
|
pub fn unshort_compare_stop(&self) {
|
||||||
T::regs().shorts.write(|w| match self.n {
|
T::regs()
|
||||||
0 => w.compare0_stop().disabled(),
|
.shorts
|
||||||
1 => w.compare1_stop().disabled(),
|
.modify(|r, w| unsafe { w.bits(r.bits() & (0 << (8 + self.n))) })
|
||||||
2 => w.compare2_stop().disabled(),
|
|
||||||
3 => w.compare3_stop().disabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4_stop().disabled(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5_stop().disabled(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait until the timer's counter reaches the value stored in this register.
|
/// Wait until the timer's counter reaches the value stored in this register.
|
||||||
@ -403,51 +312,13 @@ impl<'a, T: Instance> Cc<'a, T> {
|
|||||||
let regs = T::regs();
|
let regs = T::regs();
|
||||||
|
|
||||||
// Enable the interrupt for this CC's COMPARE event.
|
// Enable the interrupt for this CC's COMPARE event.
|
||||||
regs.intenset.write(|w| match self.n {
|
regs.intenset
|
||||||
0 => w.compare0().set(),
|
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + self.n))) });
|
||||||
1 => w.compare1().set(),
|
|
||||||
2 => w.compare2().set(),
|
|
||||||
3 => w.compare3().set(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4().set(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5().set(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Disable the interrupt if the future is dropped.
|
// Disable the interrupt if the future is dropped.
|
||||||
let on_drop = OnDrop::new(|| {
|
let on_drop = OnDrop::new(|| {
|
||||||
regs.intenclr.write(|w| match self.n {
|
regs.intenclr
|
||||||
0 => w.compare0().clear(),
|
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + self.n))) });
|
||||||
1 => w.compare1().clear(),
|
|
||||||
2 => w.compare2().clear(),
|
|
||||||
3 => w.compare3().clear(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
4 => w.compare4().clear(),
|
|
||||||
#[cfg(any(
|
|
||||||
feature = "nrf52805",
|
|
||||||
feature = "nrf52811",
|
|
||||||
feature = "nrf52820",
|
|
||||||
feature = "nrf52833",
|
|
||||||
))]
|
|
||||||
5 => w.compare5().clear(),
|
|
||||||
_ => unreachable!("a `Cc` cannot be created with `n > 5`"),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
poll_fn(|cx| {
|
poll_fn(|cx| {
|
||||||
|
Loading…
Reference in New Issue
Block a user