remove DMXIdle struct
This commit is contained in:
parent
dd8dfeacd6
commit
75002d4bdc
1 changed files with 6 additions and 17 deletions
|
@ -5,13 +5,8 @@ type _TxDma = dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>;
|
|||
type _DMXUniverse<const DMX_LEN: usize> = &'static mut [u8; DMX_LEN];
|
||||
type _DMXTransfer<const DMX_LEN: usize> = dma::Transfer<dma::R, _DMXUniverse<DMX_LEN>, _TxDma>;
|
||||
|
||||
pub struct DMXIdle<const DMX_LEN: usize> {
|
||||
tx: Option<_TxDma>,
|
||||
txbuffer: Option<_DMXUniverse<DMX_LEN>>,
|
||||
}
|
||||
|
||||
pub enum DMX<const DMX_LEN: usize = 512> {
|
||||
Idle(DMXIdle<DMX_LEN>),
|
||||
Idle(Option<_TxDma>, Option<_DMXUniverse<DMX_LEN>>),
|
||||
Busy(Option<_DMXTransfer<DMX_LEN>>),
|
||||
}
|
||||
|
||||
|
@ -26,10 +21,7 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
|||
{
|
||||
serial.reconfigure(250_000.bps(), &clocks).unwrap();
|
||||
|
||||
Self::Idle(DMXIdle {
|
||||
tx: Some(serial.tx.with_dma(channel)),
|
||||
txbuffer: None,
|
||||
})
|
||||
Self::Idle(Some(serial.tx.with_dma(channel)), None)
|
||||
}
|
||||
|
||||
pub fn send(&mut self, data: &[u8; DMX_LEN]) {
|
||||
|
@ -37,15 +29,15 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
|||
self.wait();
|
||||
}
|
||||
|
||||
let Self::Idle(idle) = self else {
|
||||
let Self::Idle(tx, txbuffer) = self else {
|
||||
panic!("Broken DMX State!")
|
||||
};
|
||||
|
||||
let txbuffer = idle.txbuffer.take().unwrap_or_else(|| {
|
||||
let txbuffer = txbuffer.take().unwrap_or_else(|| {
|
||||
let foo = singleton!(: [u8; 512] = [0u8; 512]).unwrap();
|
||||
(&mut foo[..DMX_LEN]).try_into().unwrap()
|
||||
});
|
||||
let tx = idle.tx.take().unwrap();
|
||||
let tx = tx.take().unwrap();
|
||||
|
||||
txbuffer.copy_from_slice(data);
|
||||
*self = Self::Busy(Some(tx.write(txbuffer)));
|
||||
|
@ -57,9 +49,6 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
|||
let xfer = xfer.take().unwrap();
|
||||
let (txbuffer, tx) = xfer.wait();
|
||||
|
||||
*self = Self::Idle(DMXIdle {
|
||||
tx: Some(tx),
|
||||
txbuffer: Some(txbuffer),
|
||||
});
|
||||
*self = Self::Idle(Some(tx), Some(txbuffer));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue