add stopping state, handle dma drain, improve cli readability (state) by moving state to shared

This commit is contained in:
ktims committed 2026-08-25 12:51:52 -07:00
1 parent 31edf91933
commit bdd946ad11
7 files changed
+271 -121

No files matched your search

+70
View File
@@ -1,5 +1,16 @@
use core::cell::UnsafeCell;
use core::mem::MaybeUninit;
use crate::hal;
use crate::pac;
use defmt::{debug, info};
use hal::{
Enabled, Iocon, Pin,
drivers::pins,
traits::wg::digital::v2::{OutputPin, ToggleableOutputPin},
typestates::pin::{gpio::direction::Output, state::Gpio},
};
pub(crate) struct PllConstants {
pub m: u16, // 1-65535
@@ -184,3 +195,62 @@ pub(crate) fn init_audio_pll() {
}
info!("pll0 locked after {} loops", i);
}
pub struct SharedLed<T: OutputPin> {
inner: UnsafeCell<T>,
}
unsafe impl<T: OutputPin> Sync for SharedLed<T> {}
impl<T: OutputPin> SharedLed<T> {
pub fn new(inner: T) -> Self {
Self {
inner: UnsafeCell::new(inner),
}
}
pub fn on(&self) {
unsafe {
(*self.inner.get()).set_low().ok();
}
}
pub fn off(&self) {
unsafe {
(*self.inner.get()).set_high().ok();
}
}
}
impl<T: OutputPin + ToggleableOutputPin> SharedLed<T> {
pub fn toggle(&self) {
unsafe {
(*self.inner.get()).toggle().ok();
}
}
}
type Led1 = Pin<pins::Pio0_13, Gpio<Output>>;
type Led2 = Pin<pins::Pio0_14, Gpio<Output>>;
pub static LED1: MaybeUninit<SharedLed<Led1>> = MaybeUninit::uninit();
pub static LED2: MaybeUninit<SharedLed<Led2>> = MaybeUninit::uninit();
pub fn init_leds(iocon: &mut Iocon<Enabled>, gpio: &mut hal::Gpio<Enabled>) {
let led1 = SharedLed::new(
pins::Pio0_13::take()
.unwrap()
.into_gpio_pin(iocon, gpio)
.into_output_low(),
);
let led2 = SharedLed::new(
pins::Pio0_14::take()
.unwrap()
.into_gpio_pin(iocon, gpio)
.into_output_low(),
);
unsafe {
core::ptr::write(LED1.as_ptr() as *mut SharedLed<Led1>, led1);
core::ptr::write(LED2.as_ptr() as *mut SharedLed<Led2>, led2);
}
}
pub fn led1() -> &'static SharedLed<Led1> {
unsafe { &*LED1.as_ptr() }
}
pub fn led2() -> &'static SharedLed<Led2> {
unsafe { &*LED2.as_ptr() }
}