implicit wait()
This commit is contained in:
parent
91139c792c
commit
c27c980097
2 changed files with 28 additions and 20 deletions
|
@ -31,27 +31,33 @@ impl DMX {
|
|||
}
|
||||
|
||||
pub fn send(&mut self, data: &[u8; 512]) {
|
||||
if let Self::Idle(idle) = self {
|
||||
let txbuffer = idle
|
||||
.txbuffer
|
||||
.take()
|
||||
.unwrap_or_else(|| singleton!(: [u8; 512] = [0; 512]).unwrap());
|
||||
let tx = idle.tx.take().unwrap();
|
||||
|
||||
txbuffer.copy_from_slice(data);
|
||||
*self = Self::Busy(Some(tx.write(txbuffer)));
|
||||
if let Self::Busy(_) = self {
|
||||
self.wait();
|
||||
}
|
||||
|
||||
let Self::Idle(idle) = self else {
|
||||
panic!("Broken DMX State!")
|
||||
};
|
||||
|
||||
let txbuffer = idle
|
||||
.txbuffer
|
||||
.take()
|
||||
.unwrap_or_else(|| singleton!(: [u8; 512] = [0; 512]).unwrap());
|
||||
let tx = idle.tx.take().unwrap();
|
||||
|
||||
txbuffer.copy_from_slice(data);
|
||||
*self = Self::Busy(Some(tx.write(txbuffer)));
|
||||
}
|
||||
|
||||
pub fn wait(&mut self) {
|
||||
if let Self::Busy(xfer) = self {
|
||||
let xfer = xfer.take().unwrap();
|
||||
let (txbuffer, tx) = xfer.wait();
|
||||
let Self::Busy(xfer) = self else { return };
|
||||
|
||||
*self = Self::Idle(DMXIdle {
|
||||
tx: Some(tx),
|
||||
txbuffer: Some(txbuffer),
|
||||
});
|
||||
}
|
||||
let xfer = xfer.take().unwrap();
|
||||
let (txbuffer, tx) = xfer.wait();
|
||||
|
||||
*self = Self::Idle(DMXIdle {
|
||||
tx: Some(tx),
|
||||
txbuffer: Some(txbuffer),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ mod dmx;
|
|||
// extern crate panic_halt;
|
||||
extern crate panic_semihosting;
|
||||
|
||||
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [PVD])]
|
||||
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [SPI1, SPI2, SPI3])]
|
||||
mod app {
|
||||
use cortex_m::singleton;
|
||||
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
|
||||
// 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),
|
||||
)
|
||||
|
@ -107,7 +109,7 @@ mod app {
|
|||
cx.local.led.toggle();
|
||||
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
|
||||
|
||||
cx.local.dmx.wait();
|
||||
// cx.local.dmx.wait();
|
||||
foo::spawn().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue