|
|
|
@ -6,11 +6,10 @@ use embedded_hal::prelude::*;
|
|
|
|
|
use nb::block; |
|
|
|
|
use void::Void; |
|
|
|
|
|
|
|
|
|
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))] |
|
|
|
|
use crate::stm32::{RCC, USART1, USART2}; |
|
|
|
|
|
|
|
|
|
use crate::gpio::gpioa::{PA10, PA14, PA15, PA2, PA3, PA9}; |
|
|
|
|
use crate::gpio::gpiob::{PB6, PB7}; |
|
|
|
|
use crate::gpio::{Alternate, AF0, AF1}; |
|
|
|
|
use crate::gpio::*; |
|
|
|
|
use crate::rcc::Clocks; |
|
|
|
|
use crate::time::Bps; |
|
|
|
|
|
|
|
|
@ -40,41 +39,41 @@ pub enum Error {
|
|
|
|
|
pub trait Pins<USART> {} |
|
|
|
|
|
|
|
|
|
#[cfg(any(feature = "stm32f030", feature = "stm32f042"))] |
|
|
|
|
impl Pins<USART1> for (PA9<Alternate<AF1>>, PA10<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART1> for (gpioa::PA9<Alternate<AF1>>, gpioa::PA10<Alternate<AF1>>) {} |
|
|
|
|
#[cfg(any(feature = "stm32f030", feature = "stm32f042"))] |
|
|
|
|
impl Pins<USART1> for (PB6<Alternate<AF0>>, PB7<Alternate<AF0>>) {} |
|
|
|
|
impl Pins<USART1> for (gpiob::PB6<Alternate<AF0>>, gpiob::PB7<Alternate<AF0>>) {} |
|
|
|
|
#[cfg(any(feature = "stm32f030", feature = "stm32f042"))] |
|
|
|
|
impl Pins<USART1> for (PA9<Alternate<AF1>>, PB7<Alternate<AF0>>) {} |
|
|
|
|
impl Pins<USART1> for (gpioa::PA9<Alternate<AF1>>, gpiob::PB7<Alternate<AF0>>) {} |
|
|
|
|
#[cfg(any(feature = "stm32f030", feature = "stm32f042"))] |
|
|
|
|
impl Pins<USART1> for (PB6<Alternate<AF0>>, PA10<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART1> for (gpiob::PB6<Alternate<AF0>>, gpioa::PA10<Alternate<AF1>>) {} |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "stm32f030x6")] |
|
|
|
|
impl Pins<USART1> for (PA2<Alternate<AF1>>, PA3<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART1> for (gpioa::PA2<Alternate<AF1>>, gpioa::PA3<Alternate<AF1>>) {} |
|
|
|
|
|
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030xc", |
|
|
|
|
))] |
|
|
|
|
impl Pins<USART2> for (PA2<Alternate<AF1>>, PA3<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART2> for (gpioa::PA2<Alternate<AF1>>, gpioa::PA3<Alternate<AF1>>) {} |
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030xc", |
|
|
|
|
))] |
|
|
|
|
impl Pins<USART2> for (PA2<Alternate<AF1>>, PA15<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART2> for (gpioa::PA2<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>) {} |
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030xc", |
|
|
|
|
))] |
|
|
|
|
impl Pins<USART2> for (PA14<Alternate<AF1>>, PA15<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART2> for (gpioa::PA14<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>) {} |
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030xc", |
|
|
|
|
))] |
|
|
|
|
impl Pins<USART2> for (PA14<Alternate<AF1>>, PA3<Alternate<AF1>>) {} |
|
|
|
|
impl Pins<USART2> for (gpioa::PA14<Alternate<AF1>>, gpioa::PA3<Alternate<AF1>>) {} |
|
|
|
|
|
|
|
|
|
/// Serial abstraction
|
|
|
|
|
pub struct Serial<USART, PINS> { |
|
|
|
@ -93,6 +92,7 @@ pub struct Tx<USART> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// USART1
|
|
|
|
|
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))] |
|
|
|
|
impl<PINS> Serial<USART1, PINS> { |
|
|
|
|
pub fn usart1(usart: USART1, pins: PINS, baud_rate: Bps, clocks: Clocks) -> Self |
|
|
|
|
where |
|
|
|
@ -133,6 +133,7 @@ impl<PINS> Serial<USART1, PINS> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))] |
|
|
|
|
impl embedded_hal::serial::Read<u8> for Rx<USART1> { |
|
|
|
|
type Error = Error; |
|
|
|
|
|
|
|
|
@ -157,6 +158,7 @@ impl embedded_hal::serial::Read<u8> for Rx<USART1> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))] |
|
|
|
|
impl embedded_hal::serial::Write<u8> for Tx<USART1> { |
|
|
|
|
type Error = Void; |
|
|
|
|
|
|
|
|
@ -187,6 +189,11 @@ impl embedded_hal::serial::Write<u8> for Tx<USART1> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// USART2
|
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030x8" |
|
|
|
|
))] |
|
|
|
|
impl<PINS> Serial<USART2, PINS> { |
|
|
|
|
pub fn usart2(usart: USART2, pins: PINS, baud_rate: Bps, clocks: Clocks) -> Self |
|
|
|
|
where |
|
|
|
@ -227,6 +234,11 @@ impl<PINS> Serial<USART2, PINS> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030x8" |
|
|
|
|
))] |
|
|
|
|
impl embedded_hal::serial::Read<u8> for Rx<USART2> { |
|
|
|
|
type Error = Error; |
|
|
|
|
|
|
|
|
@ -251,6 +263,11 @@ impl embedded_hal::serial::Read<u8> for Rx<USART2> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(any(
|
|
|
|
|
feature = "stm32f042", |
|
|
|
|
feature = "stm32f030x8", |
|
|
|
|
feature = "stm32f030x8" |
|
|
|
|
))] |
|
|
|
|
impl embedded_hal::serial::Write<u8> for Tx<USART2> { |
|
|
|
|
type Error = Void; |
|
|
|
|
|
|
|
|
|