implicit wait()
This commit is contained in:
parent
91139c792c
commit
c27c980097
2 changed files with 28 additions and 20 deletions
|
@ -31,7 +31,14 @@ impl DMX {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, data: &[u8; 512]) {
|
pub fn send(&mut self, data: &[u8; 512]) {
|
||||||
if let Self::Idle(idle) = self {
|
if let Self::Busy(_) = self {
|
||||||
|
self.wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
let Self::Idle(idle) = self else {
|
||||||
|
panic!("Broken DMX State!")
|
||||||
|
};
|
||||||
|
|
||||||
let txbuffer = idle
|
let txbuffer = idle
|
||||||
.txbuffer
|
.txbuffer
|
||||||
.take()
|
.take()
|
||||||
|
@ -41,10 +48,10 @@ impl DMX {
|
||||||
txbuffer.copy_from_slice(data);
|
txbuffer.copy_from_slice(data);
|
||||||
*self = Self::Busy(Some(tx.write(txbuffer)));
|
*self = Self::Busy(Some(tx.write(txbuffer)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn wait(&mut self) {
|
pub fn wait(&mut self) {
|
||||||
if let Self::Busy(xfer) = self {
|
let Self::Busy(xfer) = self else { return };
|
||||||
|
|
||||||
let xfer = xfer.take().unwrap();
|
let xfer = xfer.take().unwrap();
|
||||||
let (txbuffer, tx) = xfer.wait();
|
let (txbuffer, tx) = xfer.wait();
|
||||||
|
|
||||||
|
@ -53,5 +60,4 @@ impl DMX {
|
||||||
txbuffer: Some(txbuffer),
|
txbuffer: Some(txbuffer),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = [PVD])]
|
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [SPI1, SPI2, SPI3])]
|
||||||
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};
|
||||||
|
@ -87,7 +87,9 @@ mod app {
|
||||||
|
|
||||||
// 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.
|
||||||
led: gpioc.pc13.into_push_pull_output(&mut gpioc.crh),
|
led: gpioc
|
||||||
|
.pc13
|
||||||
|
.into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High),
|
||||||
},
|
},
|
||||||
init::Monotonics(mono),
|
init::Monotonics(mono),
|
||||||
)
|
)
|
||||||
|
@ -107,7 +109,7 @@ mod app {
|
||||||
cx.local.led.toggle();
|
cx.local.led.toggle();
|
||||||
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
|
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
|
||||||
|
|
||||||
cx.local.dmx.wait();
|
// cx.local.dmx.wait();
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue