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 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>;
|
||||
|
||||
|
@ -15,17 +15,14 @@ pub enum DMX {
|
|||
|
||||
impl DMX {
|
||||
pub fn new<PINS>(
|
||||
usart: pac::USART1,
|
||||
pins: PINS,
|
||||
mapr: &mut afio::MAPR,
|
||||
mut serial: serial::Serial<pac::USART1, PINS>,
|
||||
channel: dma::dma1::C4,
|
||||
clocks: &rcc::Clocks,
|
||||
) -> Self
|
||||
where
|
||||
PINS: serial::Pins<pac::USART1>,
|
||||
{
|
||||
// Serial config
|
||||
let serial = serial::Serial::new(usart, pins, mapr, 250_000.bps(), &clocks);
|
||||
let _ = serial.reconfigure(250_000.bps(), &clocks);
|
||||
|
||||
Self::Idle(DMXIdle {
|
||||
tx: Some(serial.tx.with_dma(channel)),
|
||||
|
@ -42,7 +39,7 @@ impl DMX {
|
|||
let tx = idle.tx.take().unwrap();
|
||||
|
||||
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])]
|
||||
mod app {
|
||||
use cortex_m::singleton;
|
||||
use stm32f1xx_hal::{gpio, pac, prelude::*, timer};
|
||||
use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer};
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
use crate::dmx::DMX;
|
||||
|
@ -61,14 +61,14 @@ mod app {
|
|||
let dma1 = cx.device.DMA1.split();
|
||||
|
||||
// Serial config
|
||||
let dmx = DMX::new(
|
||||
let serial = serial::Serial::new(
|
||||
cx.device.USART1,
|
||||
(
|
||||
gpioa.pa9.into_alternate_open_drain(&mut gpioa.crh),
|
||||
gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh),
|
||||
),
|
||||
&mut afio.mapr,
|
||||
dma1.4,
|
||||
serial::Config::default(),
|
||||
&clocks,
|
||||
);
|
||||
|
||||
|
@ -77,7 +77,7 @@ mod app {
|
|||
buffer: singleton!(: [u8; 512] = [0b01010101; 512]).unwrap(),
|
||||
},
|
||||
Local {
|
||||
dmx: dmx,
|
||||
dmx: DMX::new(serial, dma1.4, &clocks),
|
||||
|
||||
// Configure timer
|
||||
delay_us: cx.device.TIM2.delay_us(&clocks),
|
||||
|
|
Loading…
Reference in a new issue