steal just a bit
This commit is contained in:
parent
57a49d0021
commit
f3151add3a
2 changed files with 24 additions and 17 deletions
|
@ -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 TxDma = dma::TxDma<serial::Tx<pac::USART1>, dma::dma1::C4>;
|
||||||
type DMXUniverse<const DMX_LEN: usize> = &'static mut [u8; DMX_LEN];
|
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> {
|
impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
||||||
pub fn new<PINS>(
|
pub fn new(
|
||||||
mem: &'static mut [u8],
|
mem: &'static mut [u8],
|
||||||
mut dma_channel: dma::dma1::C4,
|
mut dma_channel: dma::dma1::C4,
|
||||||
nvic: &mut pac::NVIC,
|
pa9: gpio::PA9,
|
||||||
usart: pac::USART1,
|
pa10: gpio::PA10,
|
||||||
pins: PINS,
|
acrh: &mut gpio::Cr<'A', true>,
|
||||||
mapr: &mut afio::MAPR,
|
mapr: &mut afio::MAPR,
|
||||||
clocks: &rcc::Clocks,
|
clocks: &rcc::Clocks,
|
||||||
) -> Self
|
) -> Self {
|
||||||
where
|
|
||||||
PINS: serial::Pins<pac::USART1>,
|
|
||||||
{
|
|
||||||
// use provided memory region
|
// use provided memory region
|
||||||
assert!(mem.len() >= DMX_LEN * 2);
|
assert!(mem.len() >= DMX_LEN * 2);
|
||||||
|
|
||||||
|
@ -106,10 +103,23 @@ impl<const DMX_LEN: usize> DMX<DMX_LEN> {
|
||||||
|
|
||||||
// setup DMA1_CHANNEL4 interrupt on TransferComplete
|
// setup DMA1_CHANNEL4 interrupt on TransferComplete
|
||||||
dma_channel.listen(dma::Event::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
|
// 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 {
|
Self {
|
||||||
tx_universe,
|
tx_universe,
|
||||||
|
|
|
@ -82,12 +82,9 @@ mod app {
|
||||||
dmx: DMX::new(
|
dmx: DMX::new(
|
||||||
cx.local.buffer,
|
cx.local.buffer,
|
||||||
dma1.4,
|
dma1.4,
|
||||||
&mut cx.core.NVIC,
|
gpioa.pa9,
|
||||||
cx.device.USART1,
|
gpioa.pa10,
|
||||||
(
|
&mut gpioa.crh,
|
||||||
gpioa.pa9.into_alternate_open_drain(&mut gpioa.crh),
|
|
||||||
gpioa.pa10, //.into_pull_up_input(&mut gpioa.crh),
|
|
||||||
),
|
|
||||||
&mut afio.mapr,
|
&mut afio.mapr,
|
||||||
&clocks,
|
&clocks,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue