aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-04-14 16:01:43 +0200
committerDario Nieuwenhuis <[email protected]>2021-04-14 17:04:40 +0200
commit59ccc45f280e05a9d2a0ece2bb1e01debadb2f7e (patch)
tree14e39ffbab69238fb330fb21bd9d5894486d0d0b /embassy-stm32
parentb34b74de9de38e4bee9a4c8d95246bf9d138f86f (diff)
Remove pin from Uart
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/f4/serial.rs45
1 files changed, 19 insertions, 26 deletions
diff --git a/embassy-stm32/src/f4/serial.rs b/embassy-stm32/src/f4/serial.rs
index 7539abf51..78aaa8944 100644
--- a/embassy-stm32/src/f4/serial.rs
+++ b/embassy-stm32/src/f4/serial.rs
@@ -2,7 +2,6 @@
2 2
3use core::future::Future; 3use core::future::Future;
4use core::marker::PhantomData; 4use core::marker::PhantomData;
5use core::pin::Pin;
6use embassy::interrupt::Interrupt; 5use embassy::interrupt::Interrupt;
7use embassy::traits::uart::{Error, Read, ReadUntilIdle, Write}; 6use embassy::traits::uart::{Error, Read, ReadUntilIdle, Write};
8use embassy::util::InterruptFuture; 7use embassy::util::InterruptFuture;
@@ -101,13 +100,12 @@ where
101 /// Receives serial data. 100 /// Receives serial data.
102 /// 101 ///
103 /// The future is pending until the buffer is completely filled. 102 /// The future is pending until the buffer is completely filled.
104 fn read<'a>(self: Pin<&'a mut Self>, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { 103 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
105 let this = unsafe { self.get_unchecked_mut() };
106 let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; 104 let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) };
107 105
108 async move { 106 async move {
109 let rx_stream = this.rx_stream.take().unwrap(); 107 let rx_stream = self.rx_stream.take().unwrap();
110 let usart = this.usart.take().unwrap(); 108 let usart = self.usart.take().unwrap();
111 109
112 let mut rx_transfer = Transfer::init( 110 let mut rx_transfer = Transfer::init(
113 rx_stream, 111 rx_stream,
@@ -120,13 +118,13 @@ where
120 .double_buffer(false), 118 .double_buffer(false),
121 ); 119 );
122 120
123 let fut = InterruptFuture::new(&mut this.rx_int); 121 let fut = InterruptFuture::new(&mut self.rx_int);
124 rx_transfer.start(|_usart| {}); 122 rx_transfer.start(|_usart| {});
125 fut.await; 123 fut.await;
126 124
127 let (rx_stream, usart, _, _) = rx_transfer.free(); 125 let (rx_stream, usart, _, _) = rx_transfer.free();
128 this.rx_stream.replace(rx_stream); 126 self.rx_stream.replace(rx_stream);
129 this.usart.replace(usart); 127 self.usart.replace(usart);
130 128
131 Ok(()) 129 Ok(())
132 } 130 }
@@ -148,14 +146,13 @@ where
148 type WriteFuture<'a> = impl Future<Output = Result<(), Error>> + 'a; 146 type WriteFuture<'a> = impl Future<Output = Result<(), Error>> + 'a;
149 147
150 /// Sends serial data. 148 /// Sends serial data.
151 fn write<'a>(self: Pin<&'a mut Self>, buf: &'a [u8]) -> Self::WriteFuture<'a> { 149 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
152 let this = unsafe { self.get_unchecked_mut() };
153 #[allow(mutable_transmutes)] 150 #[allow(mutable_transmutes)]
154 let static_buf = unsafe { core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf) }; 151 let static_buf = unsafe { core::mem::transmute::<&'a [u8], &'static mut [u8]>(buf) };
155 152
156 async move { 153 async move {
157 let tx_stream = this.tx_stream.take().unwrap(); 154 let tx_stream = self.tx_stream.take().unwrap();
158 let usart = this.usart.take().unwrap(); 155 let usart = self.usart.take().unwrap();
159 156
160 let mut tx_transfer = Transfer::init( 157 let mut tx_transfer = Transfer::init(
161 tx_stream, 158 tx_stream,
@@ -168,15 +165,15 @@ where
168 .double_buffer(false), 165 .double_buffer(false),
169 ); 166 );
170 167
171 let fut = InterruptFuture::new(&mut this.tx_int); 168 let fut = InterruptFuture::new(&mut self.tx_int);
172 169
173 tx_transfer.start(|_usart| {}); 170 tx_transfer.start(|_usart| {});
174 fut.await; 171 fut.await;
175 172
176 let (tx_stream, usart, _buf, _) = tx_transfer.free(); 173 let (tx_stream, usart, _buf, _) = tx_transfer.free();
177 174
178 this.tx_stream.replace(tx_stream); 175 self.tx_stream.replace(tx_stream);
179 this.usart.replace(usart); 176 self.usart.replace(usart);
180 177
181 Ok(()) 178 Ok(())
182 } 179 }
@@ -202,16 +199,12 @@ where
202 /// The future is pending until either the buffer is completely full, or the RX line falls idle after receiving some data. 199 /// The future is pending until either the buffer is completely full, or the RX line falls idle after receiving some data.
203 /// 200 ///
204 /// Returns the number of bytes read. 201 /// Returns the number of bytes read.
205 fn read_until_idle<'a>( 202 fn read_until_idle<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadUntilIdleFuture<'a> {
206 self: Pin<&'a mut Self>,
207 buf: &'a mut [u8],
208 ) -> Self::ReadUntilIdleFuture<'a> {
209 let this = unsafe { self.get_unchecked_mut() };
210 let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) }; 203 let static_buf = unsafe { core::mem::transmute::<&'a mut [u8], &'static mut [u8]>(buf) };
211 204
212 async move { 205 async move {
213 let rx_stream = this.rx_stream.take().unwrap(); 206 let rx_stream = self.rx_stream.take().unwrap();
214 let usart = this.usart.take().unwrap(); 207 let usart = self.usart.take().unwrap();
215 208
216 unsafe { 209 unsafe {
217 /* __HAL_UART_ENABLE_IT(&uart->UartHandle, UART_IT_IDLE); */ 210 /* __HAL_UART_ENABLE_IT(&uart->UartHandle, UART_IT_IDLE); */
@@ -235,8 +228,8 @@ where
235 228
236 let total_bytes = RSTREAM::get_number_of_transfers() as usize; 229 let total_bytes = RSTREAM::get_number_of_transfers() as usize;
237 230
238 let fut = InterruptFuture::new(&mut this.rx_int); 231 let fut = InterruptFuture::new(&mut self.rx_int);
239 let fut_idle = InterruptFuture::new(&mut this.usart_int); 232 let fut_idle = InterruptFuture::new(&mut self.usart_int);
240 233
241 rx_transfer.start(|_usart| {}); 234 rx_transfer.start(|_usart| {});
242 235
@@ -249,8 +242,8 @@ where
249 unsafe { 242 unsafe {
250 (*USART::ptr()).cr1.modify(|_, w| w.idleie().clear_bit()); 243 (*USART::ptr()).cr1.modify(|_, w| w.idleie().clear_bit());
251 } 244 }
252 this.rx_stream.replace(rx_stream); 245 self.rx_stream.replace(rx_stream);
253 this.usart.replace(usart); 246 self.usart.replace(usart);
254 247
255 Ok(total_bytes - remaining_bytes) 248 Ok(total_bytes - remaining_bytes)
256 } 249 }