From a82f68d546ad9224e2773c8139cb497b4adfbf6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:52:04 +0000 Subject: [PATCH] creation from serial --- bluepill-rs/src/dmx.rs | 11 ++++------- bluepill-rs/src/main.rs | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/bluepill-rs/src/dmx.rs b/bluepill-rs/src/dmx.rs index 3b1ce54..c1784c8 100644 --- a/bluepill-rs/src/dmx.rs +++ b/bluepill-rs/src/dmx.rs @@ -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, dma::dma1::C4>; @@ -15,17 +15,14 @@ pub enum DMX { impl DMX { pub fn new( - usart: pac::USART1, - pins: PINS, - mapr: &mut afio::MAPR, + mut serial: serial::Serial, channel: dma::dma1::C4, clocks: &rcc::Clocks, ) -> Self where PINS: serial::Pins, { - // 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))); } } diff --git a/bluepill-rs/src/main.rs b/bluepill-rs/src/main.rs index 6dc0c4d..5b21814 100644 --- a/bluepill-rs/src/main.rs +++ b/bluepill-rs/src/main.rs @@ -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),