creation from serial
This commit is contained in:
parent
7c6328f9fc
commit
a82f68d546
2 changed files with 8 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
use cortex_m::singleton;
|
use cortex_m::singleton;
|
||||||
use stm32f1xx_hal::{afio, dma, pac, prelude::*, rcc, serial};
|
use stm32f1xx_hal::{dma, pac, prelude::*, rcc, serial};
|
||||||
|
|
||||||
type _TxDma = dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>;
|
type _TxDma = dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>;
|
||||||
|
|
||||||
|
@ -15,17 +15,14 @@ pub enum DMX {
|
||||||
|
|
||||||
impl DMX {
|
impl DMX {
|
||||||
pub fn new<PINS>(
|
pub fn new<PINS>(
|
||||||
usart: pac::USART1,
|
mut serial: serial::Serial<pac::USART1, PINS>,
|
||||||
pins: PINS,
|
|
||||||
mapr: &mut afio::MAPR,
|
|
||||||
channel: dma::dma1::C4,
|
channel: dma::dma1::C4,
|
||||||
clocks: &rcc::Clocks,
|
clocks: &rcc::Clocks,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
PINS: serial::Pins<pac::USART1>,
|
PINS: serial::Pins<pac::USART1>,
|
||||||
{
|
{
|
||||||
// Serial config
|
let _ = serial.reconfigure(250_000.bps(), &clocks);
|
||||||
let serial = serial::Serial::new(usart, pins, mapr, 250_000.bps(), &clocks);
|
|
||||||
|
|
||||||
Self::Idle(DMXIdle {
|
Self::Idle(DMXIdle {
|
||||||
tx: Some(serial.tx.with_dma(channel)),
|
tx: Some(serial.tx.with_dma(channel)),
|
||||||
|
@ -42,7 +39,7 @@ impl DMX {
|
||||||
let tx = idle.tx.take().unwrap();
|
let tx = idle.tx.take().unwrap();
|
||||||
|
|
||||||
txbuffer.copy_from_slice(data);
|
txbuffer.copy_from_slice(data);
|
||||||
*self = Self::Busy(Some(tx.write(txbuffer)))
|
*self = Self::Busy(Some(tx.write(txbuffer)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ extern crate panic_semihosting;
|
||||||
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [DMA1_CHANNEL4])]
|
#[rtic::app(device = stm32f1xx_hal::pac, dispatchers = [DMA1_CHANNEL4])]
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m::singleton;
|
use cortex_m::singleton;
|
||||||
use stm32f1xx_hal::{gpio, pac, prelude::*, timer};
|
use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer};
|
||||||
use systick_monotonic::Systick;
|
use systick_monotonic::Systick;
|
||||||
|
|
||||||
use crate::dmx::DMX;
|
use crate::dmx::DMX;
|
||||||
|
@ -61,14 +61,14 @@ mod app {
|
||||||
let dma1 = cx.device.DMA1.split();
|
let dma1 = cx.device.DMA1.split();
|
||||||
|
|
||||||
// Serial config
|
// Serial config
|
||||||
let dmx = DMX::new(
|
let serial = serial::Serial::new(
|
||||||
cx.device.USART1,
|
cx.device.USART1,
|
||||||
(
|
(
|
||||||
gpioa.pa9.into_alternate_open_drain(&mut gpioa.crh),
|
gpioa.pa9.into_alternate_open_drain(&mut gpioa.crh),
|
||||||
gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh),
|
gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh),
|
||||||
),
|
),
|
||||||
&mut afio.mapr,
|
&mut afio.mapr,
|
||||||
dma1.4,
|
serial::Config::default(),
|
||||||
&clocks,
|
&clocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ mod app {
|
||||||
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
|
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
|
||||||
},
|
},
|
||||||
Local {
|
Local {
|
||||||
dmx: dmx,
|
dmx: DMX::new(serial, dma1.4, &clocks),
|
||||||
|
|
||||||
// Configure timer
|
// Configure timer
|
||||||
delay_us: cx.device.TIM2.delay_us(&clocks),
|
delay_us: cx.device.TIM2.delay_us(&clocks),
|
||||||
|
|
Loading…
Reference in a new issue