From 75002d4bdca5b49f0ae42e4e2de7ab663b0ccaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 21 Mar 2024 23:35:46 +0000 Subject: [PATCH] remove DMXIdle struct --- bluepill-rs/src/dmx.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/bluepill-rs/src/dmx.rs b/bluepill-rs/src/dmx.rs index a394e51..515230a 100644 --- a/bluepill-rs/src/dmx.rs +++ b/bluepill-rs/src/dmx.rs @@ -5,13 +5,8 @@ type _TxDma = dma::TxDma, dma::dma1::C4>; type _DMXUniverse = &'static mut [u8; DMX_LEN]; type _DMXTransfer = dma::Transfer, _TxDma>; -pub struct DMXIdle { - tx: Option<_TxDma>, - txbuffer: Option<_DMXUniverse>, -} - pub enum DMX { - Idle(DMXIdle), + Idle(Option<_TxDma>, Option<_DMXUniverse>), Busy(Option<_DMXTransfer>), } @@ -26,10 +21,7 @@ impl DMX { { 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 DMX { 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 DMX { 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)); } }