Merge pull request #22 from xoviat/cleanup

minor cleanup to interface
This commit is contained in:
Dario Nieuwenhuis 2021-01-14 19:02:00 +01:00 committed by GitHub
commit 28fe29fff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 27 deletions

View File

@ -14,6 +14,7 @@ use embassy::uart::Uart;
use embassy::util::Forever; use embassy::util::Forever;
use embassy_stm32f4::interrupt; use embassy_stm32f4::interrupt;
use embassy_stm32f4::serial; use embassy_stm32f4::serial;
use stm32f4xx_hal::serial::config::Config;
use stm32f4xx_hal::stm32; use stm32f4xx_hal::stm32;
use stm32f4xx_hal::{prelude::*, serial::config}; use stm32f4xx_hal::{prelude::*, serial::config};
@ -32,15 +33,16 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
let mut serial = unsafe { let mut serial = unsafe {
serial::Serial::new( serial::Serial::new(
gpioa.pa9.into_alternate_af7(), dp.USART1,
gpioa.pa10.into_alternate_af7(), dp.DMA2,
(
gpioa.pa9.into_alternate_af7(),
gpioa.pa10.into_alternate_af7(),
),
interrupt::take!(DMA2_STREAM7), interrupt::take!(DMA2_STREAM7),
interrupt::take!(DMA2_STREAM2), interrupt::take!(DMA2_STREAM2),
interrupt::take!(USART1), interrupt::take!(USART1),
dp.DMA2, Config::default().baudrate(9600.bps()),
dp.USART1,
config::Parity::ParityNone,
9600.bps(),
clocks, clocks,
) )
}; };

View File

@ -26,6 +26,7 @@ use crate::hal::rcc::Clocks;
use crate::hal::serial::config::{ use crate::hal::serial::config::{
Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength, Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength,
}; };
use crate::hal::serial::Pins;
use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial};
use crate::hal::time::Bps; use crate::hal::time::Bps;
@ -58,31 +59,21 @@ static mut INSTANCE: *const Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> = ptr::
impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> {
// Leaking futures is forbidden! // Leaking futures is forbidden!
pub unsafe fn new( pub unsafe fn new<PINS>(
txd: PA9<Alternate<AF7>>, usart: USART1,
rxd: PA10<Alternate<AF7>>, dma: DMA2,
pins: PINS,
tx_int: interrupt::DMA2_STREAM7Interrupt, tx_int: interrupt::DMA2_STREAM7Interrupt,
rx_int: interrupt::DMA2_STREAM2Interrupt, rx_int: interrupt::DMA2_STREAM2Interrupt,
usart_int: interrupt::USART1Interrupt, usart_int: interrupt::USART1Interrupt,
dma: DMA2, mut config: SerialConfig,
usart: USART1,
parity: Parity,
baudrate: Bps,
clocks: Clocks, clocks: Clocks,
) -> Self { ) -> Self
let mut serial = HalSerial::usart1( where
usart, PINS: Pins<USART1>,
(txd, rxd), {
SerialConfig { config.dma = SerialDmaConfig::TxRx;
baudrate: baudrate, let mut serial = HalSerial::usart1(usart, pins, config, clocks).unwrap();
wordlength: WordLength::DataBits8,
parity: Parity::ParityNone,
stopbits: StopBits::STOP1,
dma: SerialDmaConfig::TxRx,
},
clocks,
)
.unwrap();
serial.listen(SerialEvent::Idle); serial.listen(SerialEvent::Idle);
// serial.listen(SerialEvent::Txe); // serial.listen(SerialEvent::Txe);