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
PINS: serial::Pins<pac::USART1>,
{
let _ = serial.reconfigure(250_000.bps(), &clocks);
serial.reconfigure(250_000.bps(), &clocks).unwrap();
Self::Idle(DMXIdle {
tx: Some(serial.tx.with_dma(channel)),

View file

@ -9,7 +9,7 @@ mod dmx;
// extern crate panic_halt;
extern crate panic_semihosting;
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [DMA1_CHANNEL4])]
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [PVD])]
mod app {
use cortex_m::singleton;
use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer};
@ -24,12 +24,12 @@ mod app {
#[shared]
struct Shared {
buffer: &'static mut [u8; 512],
delay_us: timer::DelayUs<pac::TIM2>,
}
#[local]
struct Local {
dmx: DMX,
delay_us: timer::DelayUs<pac::TIM2>,
led: gpio::gpioc::PC13<gpio::Output>,
}
@ -72,15 +72,18 @@ mod app {
&clocks,
);
// rtic::pend(pac::Interrupt::DMA1_CHANNEL4); // ???
foo::spawn().unwrap();
(
Shared {
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
},
Local {
dmx: DMX::new(serial, dma1.4, &clocks),
// Configure timer
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
// 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])]
fn idle(cx: idle::Context) -> ! {
#[idle]
fn idle(_: idle::Context) -> ! {
loop {
rtic::export::wfi();
}
}
#[task(local = [dmx, led], shared = [&buffer, delay_us])]
fn foo(mut cx: foo::Context) {
cx.local.dmx.send(cx.shared.buffer);
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.led.toggle();
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
cx.local.dmx.wait();
}
foo::spawn().unwrap();
}
}