use const declarations
This commit is contained in:
parent
75002d4bdc
commit
e3b9f7ceb0
2 changed files with 14 additions and 12 deletions
|
@ -1,13 +1,14 @@
|
|||
use cortex_m::singleton;
|
||||
use stm32f1xx_hal::{dma, pac, prelude::*, rcc, serial};
|
||||
|
||||
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>;
|
||||
const DMX_LEN_MAX: usize = 512;
|
||||
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 enum DMX<const DMX_LEN: usize = 512> {
|
||||
Idle(Option<_TxDma>, Option<_DMXUniverse<DMX_LEN>>),
|
||||
Busy(Option<_DMXTransfer<DMX_LEN>>),
|
||||
Idle(Option<TxDma>, Option<DMXUniverse<DMX_LEN>>),
|
||||
Busy(Option<DMXTransfer<DMX_LEN>>),
|
||||
}
|
||||
|
||||
impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
||||
|
@ -24,7 +25,7 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
|||
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<const DMX_LEN: usize> DMX<DMX_LEN> {
|
|||
};
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<pac::TIM2>,
|
||||
}
|
||||
|
||||
#[local]
|
||||
struct Local {
|
||||
dmx: DMX<512>,
|
||||
dmx: DMX<DMX_LEN>,
|
||||
led: gpio::gpioc::PC13<gpio::Output>,
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue