aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/spi/mod.rs23
-rw-r--r--embassy-stm32/src/spi/spi_v1.rs6
-rw-r--r--embassy-stm32/src/usart.rs47
3 files changed, 25 insertions, 51 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index 3e00fdd4e..79dce3306 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -6,6 +6,8 @@ mod spi;
6 6
7pub use spi::*; 7pub use spi::*;
8 8
9use crate::gpio::Pin;
10
9pub enum Error { 11pub enum Error {
10 Framing, 12 Framing,
11 Crc, 13 Crc,
@@ -41,32 +43,21 @@ impl Default for Config {
41 43
42pub(crate) mod sealed { 44pub(crate) mod sealed {
43 use super::*; 45 use super::*;
44 use crate::gpio::Pin;
45 use embassy::util::AtomicWaker;
46 46
47 pub trait Instance { 47 pub trait Instance {
48 fn regs() -> &'static crate::pac::spi::Spi; 48 fn regs() -> &'static crate::pac::spi::Spi;
49 } 49 }
50 50
51 pub trait SckPin<T: Instance>: Pin { 51 pub trait SckPin<T: Instance>: Pin {
52 const AF: u8; 52 fn af_num(&self) -> u8;
53 fn af(&self) -> u8 {
54 Self::AF
55 }
56 } 53 }
57 54
58 pub trait MosiPin<T: Instance>: Pin { 55 pub trait MosiPin<T: Instance>: Pin {
59 const AF: u8; 56 fn af_num(&self) -> u8;
60 fn af(&self) -> u8 {
61 Self::AF
62 }
63 } 57 }
64 58
65 pub trait MisoPin<T: Instance>: Pin { 59 pub trait MisoPin<T: Instance>: Pin {
66 const AF: u8; 60 fn af_num(&self) -> u8;
67 fn af(&self) -> u8 {
68 Self::AF
69 }
70 } 61 }
71} 62}
72 63
@@ -95,7 +86,9 @@ macro_rules! impl_spi_pin {
95 impl crate::spi::$pin_func<peripherals::$inst> for peripherals::$pin {} 86 impl crate::spi::$pin_func<peripherals::$inst> for peripherals::$pin {}
96 87
97 impl crate::spi::sealed::$pin_func<peripherals::$inst> for peripherals::$pin { 88 impl crate::spi::sealed::$pin_func<peripherals::$inst> for peripherals::$pin {
98 const AF: u8 = $af; 89 fn af_num(&self) -> u8 {
90 $af
91 }
99 } 92 }
100 }; 93 };
101} 94}
diff --git a/embassy-stm32/src/spi/spi_v1.rs b/embassy-stm32/src/spi/spi_v1.rs
index 90515727f..a464c4275 100644
--- a/embassy-stm32/src/spi/spi_v1.rs
+++ b/embassy-stm32/src/spi/spi_v1.rs
@@ -43,9 +43,9 @@ impl<'d, T: Instance> Spi<'d, T> {
43 unborrow!(peri, sck, mosi, miso); 43 unborrow!(peri, sck, mosi, miso);
44 44
45 unsafe { 45 unsafe {
46 sck.set_as_af(sck.af()); 46 sck.set_as_af(sck.af_num());
47 mosi.set_as_af(mosi.af()); 47 mosi.set_as_af(mosi.af_num());
48 miso.set_as_af(miso.af()); 48 miso.set_as_af(miso.af_num());
49 } 49 }
50 50
51 let sck = sck.degrade(); 51 let sck = sck.degrade();
diff --git a/embassy-stm32/src/usart.rs b/embassy-stm32/src/usart.rs
index a49383bc9..e4f77398f 100644
--- a/embassy-stm32/src/usart.rs
+++ b/embassy-stm32/src/usart.rs
@@ -56,20 +56,20 @@ pub(crate) mod sealed {
56 pub trait Instance { 56 pub trait Instance {
57 fn regs(&self) -> Usart; 57 fn regs(&self) -> Usart;
58 } 58 }
59 pub trait RxPin<T: Instance>: OptionalPin { 59 pub trait RxPin<T: Instance>: Pin {
60 const AF_NUM: u8; 60 fn af_num(&self) -> u8;
61 } 61 }
62 pub trait TxPin<T: Instance>: OptionalPin { 62 pub trait TxPin<T: Instance>: Pin {
63 const AF_NUM: u8; 63 fn af_num(&self) -> u8;
64 } 64 }
65 pub trait CtsPin<T: Instance>: OptionalPin { 65 pub trait CtsPin<T: Instance>: Pin {
66 const AF_NUM: u8; 66 fn af_num(&self) -> u8;
67 } 67 }
68 pub trait RtsPin<T: Instance>: OptionalPin { 68 pub trait RtsPin<T: Instance>: Pin {
69 const AF_NUM: u8; 69 fn af_num(&self) -> u8;
70 } 70 }
71 pub trait CkPin<T: Instance>: OptionalPin { 71 pub trait CkPin<T: Instance>: Pin {
72 const AF_NUM: u8; 72 fn af_num(&self) -> u8;
73 } 73 }
74} 74}
75pub trait Instance: sealed::Instance {} 75pub trait Instance: sealed::Instance {}
@@ -79,27 +79,6 @@ pub trait CtsPin<T: Instance>: sealed::CtsPin<T> {}
79pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {} 79pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {}
80pub trait CkPin<T: Instance>: sealed::CkPin<T> {} 80pub trait CkPin<T: Instance>: sealed::CkPin<T> {}
81 81
82impl<T: Instance> sealed::RxPin<T> for NoPin {
83 const AF_NUM: u8 = 0;
84}
85impl<T: Instance> RxPin<T> for NoPin {}
86impl<T: Instance> sealed::TxPin<T> for NoPin {
87 const AF_NUM: u8 = 0;
88}
89impl<T: Instance> TxPin<T> for NoPin {}
90impl<T: Instance> sealed::CtsPin<T> for NoPin {
91 const AF_NUM: u8 = 0;
92}
93impl<T: Instance> CtsPin<T> for NoPin {}
94impl<T: Instance> sealed::RtsPin<T> for NoPin {
95 const AF_NUM: u8 = 0;
96}
97impl<T: Instance> RtsPin<T> for NoPin {}
98impl<T: Instance> sealed::CkPin<T> for NoPin {
99 const AF_NUM: u8 = 0;
100}
101impl<T: Instance> CkPin<T> for NoPin {}
102
103macro_rules! impl_usart { 82macro_rules! impl_usart {
104 ($inst:ident) => { 83 ($inst:ident) => {
105 impl crate::usart::sealed::Instance for peripherals::$inst { 84 impl crate::usart::sealed::Instance for peripherals::$inst {
@@ -112,9 +91,11 @@ macro_rules! impl_usart {
112} 91}
113 92
114macro_rules! impl_usart_pin { 93macro_rules! impl_usart_pin {
115 ($inst:ident, $func:ident, $pin:ident, $num:expr) => { 94 ($inst:ident, $func:ident, $pin:ident, $af:expr) => {
116 impl crate::usart::sealed::$func<peripherals::$inst> for peripherals::$pin { 95 impl crate::usart::sealed::$func<peripherals::$inst> for peripherals::$pin {
117 const AF_NUM: u8 = $num; 96 fn af_num(&self) -> u8 {
97 $af
98 }
118 } 99 }
119 impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {} 100 impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {}
120 }; 101 };