aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/usart/mod.rs77
1 files changed, 16 insertions, 61 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 0c5bbf491..4f2ff8b2a 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -14,7 +14,7 @@ use embassy_sync::waitqueue::AtomicWaker;
14use futures_util::future::{select, Either}; 14use futures_util::future::{select, Either};
15 15
16use crate::dma::ChannelAndRequest; 16use crate::dma::ChannelAndRequest;
17use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 17use crate::gpio::{self, AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
18use crate::interrupt::typelevel::Interrupt as _; 18use crate::interrupt::typelevel::Interrupt as _;
19use crate::interrupt::{self, Interrupt, InterruptExt}; 19use crate::interrupt::{self, Interrupt, InterruptExt};
20use crate::mode::{Async, Blocking, Mode}; 20use crate::mode::{Async, Blocking, Mode};
@@ -224,6 +224,17 @@ pub enum HalfDuplexConfig {
224 OpenDrainInternal, 224 OpenDrainInternal,
225} 225}
226 226
227impl HalfDuplexConfig {
228 pub fn af_type(self) -> gpio::AfType {
229 match self {
230 HalfDuplexConfig::PushPull => AfType::output(OutputType::PushPull, Speed::Medium),
231 HalfDuplexConfig::OpenDrainExternal => AfType::output(OutputType::OpenDrain, Speed::Medium),
232 #[cfg(not(gpio_v1))]
233 HalfDuplexConfig::OpenDrainInternal => AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up),
234 }
235 }
236}
237
227/// Serial error 238/// Serial error
228#[derive(Debug, Eq, PartialEq, Copy, Clone)] 239#[derive(Debug, Eq, PartialEq, Copy, Clone)]
229#[cfg_attr(feature = "defmt", derive(defmt::Format))] 240#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -1066,21 +1077,7 @@ impl<'d> Uart<'d, Async> {
1066 Self::new_inner( 1077 Self::new_inner(
1067 peri, 1078 peri,
1068 None, 1079 None,
1069 new_pin!( 1080 new_pin!(tx, half_duplex.af_type()),
1070 tx,
1071 match half_duplex {
1072 HalfDuplexConfig::PushPull => {
1073 AfType::output(OutputType::PushPull, Speed::Medium)
1074 }
1075 HalfDuplexConfig::OpenDrainExternal => {
1076 AfType::output(OutputType::OpenDrain, Speed::Medium)
1077 }
1078 #[cfg(not(gpio_v1))]
1079 HalfDuplexConfig::OpenDrainInternal => {
1080 AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up)
1081 }
1082 }
1083 ),
1084 None, 1081 None,
1085 None, 1082 None,
1086 None, 1083 None,
@@ -1117,21 +1114,7 @@ impl<'d> Uart<'d, Async> {
1117 peri, 1114 peri,
1118 None, 1115 None,
1119 None, 1116 None,
1120 new_pin!( 1117 new_pin!(rx, half_duplex.af_type()),
1121 rx,
1122 match half_duplex {
1123 HalfDuplexConfig::PushPull => {
1124 AfType::output(OutputType::PushPull, Speed::Medium)
1125 }
1126 HalfDuplexConfig::OpenDrainExternal => {
1127 AfType::output(OutputType::OpenDrain, Speed::Medium)
1128 }
1129 #[cfg(not(gpio_v1))]
1130 HalfDuplexConfig::OpenDrainInternal => {
1131 AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up)
1132 }
1133 }
1134 ),
1135 None, 1118 None,
1136 None, 1119 None,
1137 new_dma!(tx_dma), 1120 new_dma!(tx_dma),
@@ -1247,21 +1230,7 @@ impl<'d> Uart<'d, Blocking> {
1247 Self::new_inner( 1230 Self::new_inner(
1248 peri, 1231 peri,
1249 None, 1232 None,
1250 new_pin!( 1233 new_pin!(tx, half_duplex.af_type()),
1251 tx,
1252 match half_duplex {
1253 HalfDuplexConfig::PushPull => {
1254 AfType::output(OutputType::PushPull, Speed::Medium)
1255 }
1256 HalfDuplexConfig::OpenDrainExternal => {
1257 AfType::output(OutputType::OpenDrain, Speed::Medium)
1258 }
1259 #[cfg(not(gpio_v1))]
1260 HalfDuplexConfig::OpenDrainInternal => {
1261 AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up)
1262 }
1263 }
1264 ),
1265 None, 1234 None,
1266 None, 1235 None,
1267 None, 1236 None,
@@ -1295,21 +1264,7 @@ impl<'d> Uart<'d, Blocking> {
1295 peri, 1264 peri,
1296 None, 1265 None,
1297 None, 1266 None,
1298 new_pin!( 1267 new_pin!(rx, half_duplex.af_type()),
1299 rx,
1300 match half_duplex {
1301 HalfDuplexConfig::PushPull => {
1302 AfType::output(OutputType::PushPull, Speed::Medium)
1303 }
1304 HalfDuplexConfig::OpenDrainExternal => {
1305 AfType::output(OutputType::OpenDrain, Speed::Medium)
1306 }
1307 #[cfg(not(gpio_v1))]
1308 HalfDuplexConfig::OpenDrainInternal => {
1309 AfType::output_pull(OutputType::OpenDrain, Speed::Medium, Pull::Up)
1310 }
1311 }
1312 ),
1313 None, 1268 None,
1314 None, 1269 None,
1315 None, 1270 None,