diff --git a/bluepill-rs/src/dmx.rs b/bluepill-rs/src/dmx.rs index 8458e6c..a394e51 100644 --- a/bluepill-rs/src/dmx.rs +++ b/bluepill-rs/src/dmx.rs @@ -2,18 +2,20 @@ use cortex_m::singleton; use stm32f1xx_hal::{dma, pac, prelude::*, rcc, serial}; type _TxDma = dma::TxDma, dma::dma1::C4>; +type _DMXUniverse = &'static mut [u8; DMX_LEN]; +type _DMXTransfer = dma::Transfer, _TxDma>; -pub struct DMXIdle { +pub struct DMXIdle { tx: Option<_TxDma>, - txbuffer: Option<&'static mut [u8; 512]>, + txbuffer: Option<_DMXUniverse>, } -pub enum DMX { - Idle(DMXIdle), - Busy(Option>), +pub enum DMX { + Idle(DMXIdle), + Busy(Option<_DMXTransfer>), } -impl DMX { +impl DMX { pub fn new( mut serial: serial::Serial, channel: dma::dma1::C4, @@ -30,7 +32,7 @@ impl DMX { }) } - pub fn send(&mut self, data: &[u8; 512]) { + pub fn send(&mut self, data: &[u8; DMX_LEN]) { if let Self::Busy(_) = self { self.wait(); } @@ -39,10 +41,10 @@ impl DMX { panic!("Broken DMX State!") }; - let txbuffer = idle - .txbuffer - .take() - .unwrap_or_else(|| singleton!(: [u8; 512] = [0; 512]).unwrap()); + let txbuffer = idle.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(); txbuffer.copy_from_slice(data); diff --git a/bluepill-rs/src/main.rs b/bluepill-rs/src/main.rs index 37f29f3..427d323 100644 --- a/bluepill-rs/src/main.rs +++ b/bluepill-rs/src/main.rs @@ -29,7 +29,7 @@ mod app { #[local] struct Local { - dmx: DMX, + dmx: DMX<512>, led: gpio::gpioc::PC13, }