From f3151add3a99d58c104d7dc218b5c91dd5bbc558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael?= <40151420+ldericher@users.noreply.github.com> Date: Mon, 25 Mar 2024 00:28:37 +0000 Subject: [PATCH] steal just a bit --- bluepill-rs/src/dmx2.rs | 32 +++++++++++++++++++++----------- bluepill-rs/src/main.rs | 9 +++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/bluepill-rs/src/dmx2.rs b/bluepill-rs/src/dmx2.rs index 595759d..47bbf4f 100644 --- a/bluepill-rs/src/dmx2.rs +++ b/bluepill-rs/src/dmx2.rs @@ -1,4 +1,4 @@ -use stm32f1xx_hal::{afio, dma, pac, prelude::*, rcc, serial}; +use stm32f1xx_hal::{afio, dma, gpio, pac, prelude::*, rcc, serial}; type TxDma = dma::TxDma, dma::dma1::C4>; type DMXUniverse = &'static mut [u8; DMX_LEN]; @@ -79,18 +79,15 @@ pub struct DMX { } impl DMX { - pub fn new( + pub fn new( mem: &'static mut [u8], mut dma_channel: dma::dma1::C4, - nvic: &mut pac::NVIC, - usart: pac::USART1, - pins: PINS, + pa9: gpio::PA9, + pa10: gpio::PA10, + acrh: &mut gpio::Cr<'A', true>, mapr: &mut afio::MAPR, clocks: &rcc::Clocks, - ) -> Self - where - PINS: serial::Pins, - { + ) -> Self { // use provided memory region assert!(mem.len() >= DMX_LEN * 2); @@ -106,10 +103,23 @@ impl DMX { // setup DMA1_CHANNEL4 interrupt on TransferComplete dma_channel.listen(dma::Event::TransferComplete); - unsafe { nvic.set_priority(pac::Interrupt::DMA1_CHANNEL4, 1) }; + unsafe { + pac::CorePeripherals::steal() + .NVIC + .set_priority(pac::Interrupt::DMA1_CHANNEL4, 1) + }; // Serial config - let serial = serial::Serial::new(usart, pins, mapr, 250_000.bps(), &clocks); + let serial = serial::Serial::new( + unsafe { pac::Peripherals::steal() }.USART1, + ( + pa9.into_alternate_open_drain(acrh), + pa10, //.into_pull_up_input(acrh), + ), + mapr, + 250_000.bps(), + &clocks, + ); Self { tx_universe, diff --git a/bluepill-rs/src/main.rs b/bluepill-rs/src/main.rs index 7980488..0867908 100644 --- a/bluepill-rs/src/main.rs +++ b/bluepill-rs/src/main.rs @@ -82,12 +82,9 @@ mod app { dmx: DMX::new( cx.local.buffer, dma1.4, - &mut cx.core.NVIC, - cx.device.USART1, - ( - gpioa.pa9.into_alternate_open_drain(&mut gpioa.crh), - gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh), - ), + gpioa.pa9, + gpioa.pa10, + &mut gpioa.crh, &mut afio.mapr, &clocks, ),