diff --git a/bluepill-rs/src/dmx.rs b/bluepill-rs/src/dmx.rs index 515230a..01d8400 100644 --- a/bluepill-rs/src/dmx.rs +++ b/bluepill-rs/src/dmx.rs @@ -1,13 +1,14 @@ 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>; +const DMX_LEN_MAX: usize = 512; +type TxDma = dma::TxDma, dma::dma1::C4>; +type DMXUniverse = &'static mut [u8; DMX_LEN]; +type DMXTransfer = dma::Transfer, TxDma>; pub enum DMX { - Idle(Option<_TxDma>, Option<_DMXUniverse>), - Busy(Option<_DMXTransfer>), + Idle(Option, Option>), + Busy(Option>), } impl DMX { @@ -24,7 +25,7 @@ impl DMX { Self::Idle(Some(serial.tx.with_dma(channel)), None) } - pub fn send(&mut self, data: &[u8; DMX_LEN]) { + pub fn send(&mut self, data: &[u8]) { if let Self::Busy(_) = self { self.wait(); } @@ -34,12 +35,12 @@ impl DMX { }; let txbuffer = txbuffer.take().unwrap_or_else(|| { - let foo = singleton!(: [u8; 512] = [0u8; 512]).unwrap(); + let foo = singleton!(: [u8; DMX_LEN_MAX] = [0u8; DMX_LEN_MAX]).unwrap(); (&mut foo[..DMX_LEN]).try_into().unwrap() }); let tx = tx.take().unwrap(); - txbuffer.copy_from_slice(data); + txbuffer.copy_from_slice(&data[..DMX_LEN]); *self = Self::Busy(Some(tx.write(txbuffer))); } diff --git a/bluepill-rs/src/main.rs b/bluepill-rs/src/main.rs index 427d323..6bc79c0 100644 --- a/bluepill-rs/src/main.rs +++ b/bluepill-rs/src/main.rs @@ -11,11 +11,12 @@ extern crate panic_semihosting; #[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [SPI1, SPI2, SPI3])] mod app { + use crate::dmx::DMX; use cortex_m::singleton; use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer}; use systick_monotonic::Systick; - use crate::dmx::DMX; + const DMX_LEN: usize = 512; // A monotonic timer to enable scheduling in RTIC #[monotonic(binds = SysTick, default = true)] @@ -23,13 +24,13 @@ mod app { #[shared] struct Shared { - buffer: &'static mut [u8; 512], + buffer: &'static mut [u8], delay_us: timer::DelayUs, } #[local] struct Local { - dmx: DMX<512>, + dmx: DMX, led: gpio::gpioc::PC13, } @@ -77,7 +78,7 @@ mod app { ( Shared { - buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(), + buffer: singleton!(: [u8; DMX_LEN] = [0b01010101; DMX_LEN]).unwrap(), // Configure timer delay_us: cx.device.TIM2.delay_us(&clocks),