Removed global static signal and added signal to interrupt state. Nice: signaling can be done in immutable environment. Added extra pin to test to be able to measure with logic scope
This commit is contained in:
@ -2,12 +2,24 @@ pub mod complementary_pwm;
|
||||
pub mod qei;
|
||||
pub mod simple_pwm;
|
||||
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::signal::Signal;
|
||||
use stm32_metapac::timer::vals;
|
||||
|
||||
use crate::interrupt;
|
||||
use crate::rcc::RccPeripheral;
|
||||
use crate::time::Hertz;
|
||||
|
||||
pub struct State {
|
||||
signal: Signal<CriticalSectionRawMutex, usize>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub(crate) const fn new() -> Self {
|
||||
Self { signal: Signal::new() }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-pac")]
|
||||
pub mod low_level {
|
||||
pub use super::sealed::*;
|
||||
@ -91,6 +103,7 @@ pub(crate) mod sealed {
|
||||
|
||||
pub trait GeneralPurpose16bitInstance: Basic16bitInstance {
|
||||
fn regs_gp16() -> crate::pac::timer::TimGp16;
|
||||
fn state() -> &'static State;
|
||||
|
||||
fn set_counting_mode(&mut self, mode: CountingMode) {
|
||||
let (cms, dir) = mode.into();
|
||||
@ -510,6 +523,11 @@ foreach_interrupt! {
|
||||
fn regs_gp16() -> crate::pac::timer::TimGp16 {
|
||||
crate::pac::$inst
|
||||
}
|
||||
fn state() -> &'static State {
|
||||
static STATE: State = State::new();
|
||||
&STATE
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -528,6 +546,11 @@ foreach_interrupt! {
|
||||
fn regs_gp16() -> crate::pac::timer::TimGp16 {
|
||||
unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) }
|
||||
}
|
||||
fn state() -> &'static State {
|
||||
static STATE: State = State::new();
|
||||
&STATE
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -551,6 +574,10 @@ foreach_interrupt! {
|
||||
fn regs_gp16() -> crate::pac::timer::TimGp16 {
|
||||
unsafe { crate::pac::timer::TimGp16::from_ptr(crate::pac::$inst.as_ptr()) }
|
||||
}
|
||||
fn state() -> &'static State {
|
||||
static STATE: State = State::new();
|
||||
&STATE
|
||||
}
|
||||
}
|
||||
|
||||
impl sealed::AdvancedControlInstance for crate::peripherals::$inst {
|
||||
|
@ -1,8 +1,7 @@
|
||||
use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use embassy_hal_internal::{into_ref, PeripheralRef};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::signal::Signal;
|
||||
|
||||
use super::*;
|
||||
#[allow(unused_imports)]
|
||||
@ -12,9 +11,6 @@ use crate::time::Hertz;
|
||||
use crate::Peripheral;
|
||||
use crate::_generated::interrupt::typelevel::Interrupt;
|
||||
|
||||
// Declare a signal to awake user code for signaling the update interrupt id happen
|
||||
static SIGNAL_UPDATE: Signal<CriticalSectionRawMutex, usize> = Signal::new();
|
||||
|
||||
pub struct InterruptHandler<T: CaptureCompare16bitInstance> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
@ -24,7 +20,7 @@ impl<T: CaptureCompare16bitInstance> interrupt::typelevel::Handler<T::Interrupt>
|
||||
let regs = T::regs();
|
||||
let sr = regs.sr().read();
|
||||
if sr.uif() {
|
||||
SIGNAL_UPDATE.signal(0);
|
||||
T::state().signal.signal(0);
|
||||
// clear the flag
|
||||
critical_section::with(|_| {
|
||||
regs.sr().modify(|w| w.set_uif(false));
|
||||
@ -137,8 +133,8 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
|
||||
self.inner.enable_update_interrupt(enable);
|
||||
}
|
||||
|
||||
pub async fn wait_update_interrupt(&self) {
|
||||
_ = SIGNAL_UPDATE.wait().await;
|
||||
pub fn wait_update_interrupt(&self) -> impl Future<Output = usize> {
|
||||
T::state().signal.wait()
|
||||
}
|
||||
|
||||
pub fn set_duty(&mut self, channel: Channel, duty: u16) {
|
||||
|
Reference in New Issue
Block a user