Compare commits

..

2 commits

Author SHA1 Message Date
91139c792c streamlining 2024-03-21 21:04:51 +00:00
df790fcc74 main.rs task "foo" 2024-03-21 19:23:06 +00:00
2 changed files with 23 additions and 17 deletions

View file

@ -22,7 +22,7 @@ impl DMX {
where where
PINS: serial::Pins<pac::USART1>, PINS: serial::Pins<pac::USART1>,
{ {
let _ = serial.reconfigure(250_000.bps(), &clocks); serial.reconfigure(250_000.bps(), &clocks).unwrap();
Self::Idle(DMXIdle { Self::Idle(DMXIdle {
tx: Some(serial.tx.with_dma(channel)), tx: Some(serial.tx.with_dma(channel)),

View file

@ -9,7 +9,7 @@ mod dmx;
// extern crate panic_halt; // extern crate panic_halt;
extern crate panic_semihosting; extern crate panic_semihosting;
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [DMA1_CHANNEL4])] #[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [PVD])]
mod app { mod app {
use cortex_m::singleton; use cortex_m::singleton;
use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer}; use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer};
@ -24,12 +24,12 @@ mod app {
#[shared] #[shared]
struct Shared { struct Shared {
buffer: &'static mut [u8; 512], buffer: &'static mut [u8; 512],
delay_us: timer::DelayUs<pac::TIM2>,
} }
#[local] #[local]
struct Local { struct Local {
dmx: DMX, dmx: DMX,
delay_us: timer::DelayUs<pac::TIM2>,
led: gpio::gpioc::PC13<gpio::Output>, led: gpio::gpioc::PC13<gpio::Output>,
} }
@ -72,15 +72,18 @@ mod app {
&clocks, &clocks,
); );
// rtic::pend(pac::Interrupt::DMA1_CHANNEL4); // ???
foo::spawn().unwrap();
( (
Shared { Shared {
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(), buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
},
Local {
dmx: DMX::new(serial, dma1.4, &clocks),
// Configure timer // Configure timer
delay_us: cx.device.TIM2.delay_us(&clocks), delay_us: cx.device.TIM2.delay_us(&clocks),
},
Local {
dmx: DMX::new(serial, dma1.4, &clocks),
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function // Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
// in order to configure the port. For pins 0-7, crl should be passed instead. // in order to configure the port. For pins 0-7, crl should be passed instead.
@ -90,18 +93,21 @@ mod app {
) )
} }
#[idle(local = [dmx, delay_us, led], shared = [&buffer])] #[idle]
fn idle(cx: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
loop { loop {
cx.local.dmx.send(cx.shared.buffer); rtic::export::wfi();
cx.local.delay_us.delay(1.secs());
cx.local.led.set_high();
cx.local.delay_us.delay(1.secs());
cx.local.led.set_low();
cx.local.dmx.wait();
} }
} }
#[task(local = [dmx, led], shared = [&buffer, delay_us])]
fn foo(mut cx: foo::Context) {
cx.local.dmx.send(cx.shared.buffer);
cx.local.led.toggle();
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
cx.local.dmx.wait();
foo::spawn().unwrap();
}
} }