Skip to content

Serial: Replace Pins trait with TxPin / RxPin #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ opt-level = "s"

[[example]]
name = "adc_cont"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "adc_multi"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "adc_trig"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "aes_ecb"
Expand Down Expand Up @@ -312,15 +312,19 @@ required-features = ["rt","stm32l0x2"]

[[example]]
name = "rtc"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "serial"
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "serial_dma"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "serial_dma_async"
required-features = ["stm32l0x2"]
required-features = ["stm32l0x2", "io-STM32L071"]

[[example]]
name = "timer"
Expand Down
3 changes: 2 additions & 1 deletion examples/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn main() -> ! {

let serial = dp.USART2
.usart(
(gpioa.pa2, gpioa.pa3),
gpioa.pa2,
gpioa.pa3,
serial::Config::default()
.baudrate(115_200.bps()),
&mut rcc,
Expand Down
14 changes: 4 additions & 10 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ fn main() -> ! {
// the RCC register.
let gpioa = dp.GPIOA.split(&mut rcc);

#[cfg(feature = "stm32l0x1")]
let tx_pin = gpioa.pa9;
#[cfg(feature = "stm32l0x1")]
let rx_pin = gpioa.pa10;

#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
let tx_pin = gpioa.pa14;
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
let rx_pin = gpioa.pa15;
// Choose TX / RX pins
let tx_pin = gpioa.pa2;
let rx_pin = gpioa.pa3;

// Configure the serial peripheral.
let serial = dp
.USART2
.usart((tx_pin, rx_pin), serial::Config::default(), &mut rcc)
.usart(tx_pin, rx_pin, serial::Config::default(), &mut rcc)
.unwrap();

let (mut tx, mut rx) = serial.split();
Expand Down
3 changes: 2 additions & 1 deletion examples/serial_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn main() -> ! {
let (mut tx, mut rx) = dp
.USART2
.usart(
(gpioa.pa2, gpioa.pa3),
gpioa.pa2,
gpioa.pa3,
serial::Config::default().baudrate(115_200.bps()),
&mut rcc,
)
Expand Down
17 changes: 9 additions & 8 deletions examples/serial_dma_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);

let (tx, rx) = dp
.USART2
.usart(
(gpioa.pa2, gpioa.pa3),
serial::Config::default().baudrate(115_200.bps()),
&mut rcc,
)
.unwrap()
.split();
.USART2
.usart(
gpioa.pa2,
gpioa.pa3,
serial::Config::default().baudrate(115_200.bps()),
&mut rcc,
)
.unwrap()
.split();

// we only have two elements for each queue, so U2 is fine (size is max 2)
let mut rx_buffers: Queue<Pin<DmaBuffer>, U2> = Queue::new();
Expand Down
33 changes: 30 additions & 3 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,29 @@ use crate::{
I2C1,
I2C2,
I2C3,
USART1,
USART2,
},
rcc::Rcc,
serial,
};

#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
use crate::pac::USART1;

#[cfg(any(
feature = "io-STM32L021",
feature = "io-STM32L031",
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
use crate::pac::USART2;

#[cfg(any(
feature = "io-STM32L021",
feature = "io-STM32L031",
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
use crate::serial;

#[cfg(feature = "stm32l082")]
use crate::aes;

Expand Down Expand Up @@ -521,13 +537,24 @@ impl_target!(
// ADC
adc::DmaToken, Channel1, 0;
adc::DmaToken, Channel2, 0;
);

#[cfg(any(feature = "io-STM32L051", feature = "io-STM32L071"))]
impl_target!(
// USART1
serial::Tx<USART1>, Channel2, 3;
serial::Tx<USART1>, Channel4, 3;
serial::Rx<USART1>, Channel3, 3;
serial::Rx<USART1>, Channel5, 3;
);

#[cfg(any(
feature = "io-STM32L021",
feature = "io-STM32L031",
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
impl_target!(
// USART2
serial::Tx<USART2>, Channel4, 4;
serial::Tx<USART2>, Channel7, 4;
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub mod rcc;
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
pub mod rng;
pub mod rtc;
#[cfg(any(
feature = "io-STM32L021",
feature = "io-STM32L031",
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
pub mod serial;
pub mod spi;
pub mod syscfg;
Expand Down
27 changes: 23 additions & 4 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pub use crate::{
i2c::I2cExt as _,
pwr::PowerMode as _,
rcc::RccExt as _,
serial::{
Serial1Ext as _,
Serial2Ext as _,
},
spi::SpiExt as _,
time::U32Ext as _,
timer::TimerExt as _,
Expand All @@ -28,3 +24,26 @@ pub use crate::{
WindowWatchdogExt as _,
},
};

#[cfg(any(
feature = "io-STM32L021",
feature = "io-STM32L031",
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
pub use crate::serial::{
Serial1LpExt as _,
Serial2Ext as _,
};
#[cfg(any(
feature = "io-STM32L051",
feature = "io-STM32L071",
))]
pub use crate::serial::Serial1LpExt as _;
#[cfg(any(
feature = "io-STM32L071",
))]
pub use crate::serial::{
Serial4Ext as _,
Serial5Ext as _,
};
Loading