steal just a bit

This commit is contained in:
Jörn-Michael Miehe 2024-03-25 00:28:37 +00:00
parent 57a49d0021
commit f3151add3a
2 changed files with 24 additions and 17 deletions

View file

@ -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<serial::Tx<pac::USART1>, dma::dma1::C4>;
type DMXUniverse<const DMX_LEN: usize> = &'static mut [u8; DMX_LEN];
@ -79,18 +79,15 @@ pub struct DMX<const DMX_LEN: usize> {
}
impl<const DMX_LEN: usize> DMX<DMX_LEN> {
pub fn new<PINS>(
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<pac::USART1>,
{
) -> Self {
// use provided memory region
assert!(mem.len() >= DMX_LEN * 2);
@ -106,10 +103,23 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
// 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,

View file

@ -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,
),