aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32f4/src/exti.rs412
-rw-r--r--embassy-stm32f4/src/serial.rs89
2 files changed, 247 insertions, 254 deletions
diff --git a/embassy-stm32f4/src/exti.rs b/embassy-stm32f4/src/exti.rs
index 7ec2197ef..52cf5a294 100644
--- a/embassy-stm32f4/src/exti.rs
+++ b/embassy-stm32f4/src/exti.rs
@@ -22,10 +22,9 @@ impl<'a> ExtiManager {
22 Self { syscfg } 22 Self { syscfg }
23 } 23 }
24 24
25 pub fn new_pin<T, I>(&'static mut self, mut pin: T, interrupt: I) -> ExtiPin<T, I> 25 pub fn new_pin<T>(&'static mut self, mut pin: T, interrupt: T::Interrupt) -> ExtiPin<T>
26 where 26 where
27 T: HalExtiPin + WithInterrupt<Instance = I>, 27 T: HalExtiPin + WithInterrupt,
28 I: Interrupt,
29 { 28 {
30 pin.make_interrupt_source(&mut self.syscfg); 29 pin.make_interrupt_source(&mut self.syscfg);
31 30
@@ -37,9 +36,9 @@ impl<'a> ExtiManager {
37 } 36 }
38} 37}
39 38
40pub struct ExtiPin<T: HalExtiPin, I: Interrupt> { 39pub struct ExtiPin<T: HalExtiPin + WithInterrupt> {
41 pin: T, 40 pin: T,
42 interrupt: I, 41 interrupt: T::Interrupt,
43 _mgr: &'static ExtiManager, 42 _mgr: &'static ExtiManager,
44} 43}
45 44
@@ -54,7 +53,7 @@ pub struct ExtiPin<T: HalExtiPin, I: Interrupt> {
54 EXTI15_10_IRQn EXTI15_10_IRQHandler Handler for pins connected to line 10 to 15 53 EXTI15_10_IRQn EXTI15_10_IRQHandler Handler for pins connected to line 10 to 15
55*/ 54*/
56 55
57impl<T: HalExtiPin + 'static, I: Interrupt + 'static> WaitForRisingEdge for ExtiPin<T, I> { 56impl<T: HalExtiPin + WithInterrupt + 'static> WaitForRisingEdge for ExtiPin<T> {
58 type Future<'a> = impl Future<Output = ()> + 'a; 57 type Future<'a> = impl Future<Output = ()> + 'a;
59 58
60 fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 59 fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> {
@@ -74,7 +73,7 @@ impl<T: HalExtiPin + 'static, I: Interrupt + 'static> WaitForRisingEdge for Exti
74 } 73 }
75} 74}
76 75
77impl<T: HalExtiPin + 'static, I: Interrupt + 'static> WaitForFallingEdge for ExtiPin<T, I> { 76impl<T: HalExtiPin + WithInterrupt + 'static> WaitForFallingEdge for ExtiPin<T> {
78 type Future<'a> = impl Future<Output = ()> + 'a; 77 type Future<'a> = impl Future<Output = ()> + 'a;
79 78
80 fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 79 fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> {
@@ -99,18 +98,21 @@ mod private {
99} 98}
100 99
101pub trait WithInterrupt: private::Sealed { 100pub trait WithInterrupt: private::Sealed {
102 type Instance; 101 type Interrupt: interrupt::Interrupt;
103} 102}
104 103
105macro_rules! exti { 104macro_rules! exti {
106 ($($PER:ident => ($set:ident, $pin:ident),)+) => { 105 ($set:ident, [
106 $($INT:ident => $pin:ident,)+
107 ]) => {
107 $( 108 $(
108 impl<T> private::Sealed for gpio::$set::$pin<T> {} 109 impl<T> private::Sealed for gpio::$set::$pin<T> {}
109 impl<T> WithInterrupt for gpio::$set::$pin<T> { 110 impl<T> WithInterrupt for gpio::$set::$pin<T> {
110 type Instance = interrupt::$PER; 111 type Interrupt = interrupt::$INT;
111 } 112 }
112 )+ 113 )+
113 } 114
115 };
114} 116}
115 117
116#[cfg(any( 118#[cfg(any(
@@ -132,24 +134,24 @@ macro_rules! exti {
132 feature = "stm32f469", 134 feature = "stm32f469",
133 feature = "stm32f479" 135 feature = "stm32f479"
134))] 136))]
135exti! { 137exti!(gpioa, [
136 EXTI0 => (gpioa, PA0), 138 EXTI0 => PA0,
137 EXTI1 => (gpioa, PA1), 139 EXTI1 => PA1,
138 EXTI2 => (gpioa, PA2), 140 EXTI2 => PA2,
139 EXTI3 => (gpioa, PA3), 141 EXTI3 => PA3,
140 EXTI4 => (gpioa, PA4), 142 EXTI4 => PA4,
141 EXTI9_5 => (gpioa, PA5), 143 EXTI9_5 => PA5,
142 EXTI9_5 => (gpioa, PA6), 144 EXTI9_5 => PA6,
143 EXTI9_5 => (gpioa, PA7), 145 EXTI9_5 => PA7,
144 EXTI9_5 => (gpioa, PA8), 146 EXTI9_5 => PA8,
145 EXTI9_5 => (gpioa, PA9), 147 EXTI9_5 => PA9,
146 EXTI15_10 => (gpioa, PA10), 148 EXTI15_10 => PA10,
147 EXTI15_10 => (gpioa, PA11), 149 EXTI15_10 => PA11,
148 EXTI15_10 => (gpioa, PA12), 150 EXTI15_10 => PA12,
149 EXTI15_10 => (gpioa, PA13), 151 EXTI15_10 => PA13,
150 EXTI15_10 => (gpioa, PA14), 152 EXTI15_10 => PA14,
151 EXTI15_10 => (gpioa, PA15), 153 EXTI15_10 => PA15,
152} 154]);
153 155
154#[cfg(any( 156#[cfg(any(
155 feature = "stm32f401", 157 feature = "stm32f401",
@@ -170,24 +172,24 @@ exti! {
170 feature = "stm32f469", 172 feature = "stm32f469",
171 feature = "stm32f479" 173 feature = "stm32f479"
172))] 174))]
173exti! { 175exti!(gpiob, [
174 EXTI0 => (gpiob, PB0), 176 EXTI0 => PB0,
175 EXTI1 => (gpiob, PB1), 177 EXTI1 => PB1,
176 EXTI2 => (gpiob, PB2), 178 EXTI2 => PB2,
177 EXTI3 => (gpiob, PB3), 179 EXTI3 => PB3,
178 EXTI4 => (gpiob, PB4), 180 EXTI4 => PB4,
179 EXTI9_5 => (gpiob, PB5), 181 EXTI9_5 => PB5,
180 EXTI9_5 => (gpiob, PB6), 182 EXTI9_5 => PB6,
181 EXTI9_5 => (gpiob, PB7), 183 EXTI9_5 => PB7,
182 EXTI9_5 => (gpiob, PB8), 184 EXTI9_5 => PB8,
183 EXTI9_5 => (gpiob, PB9), 185 EXTI9_5 => PB9,
184 EXTI15_10 => (gpiob, PB10), 186 EXTI15_10 => PB10,
185 EXTI15_10 => (gpiob, PB11), 187 EXTI15_10 => PB11,
186 EXTI15_10 => (gpiob, PB12), 188 EXTI15_10 => PB12,
187 EXTI15_10 => (gpiob, PB13), 189 EXTI15_10 => PB13,
188 EXTI15_10 => (gpiob, PB14), 190 EXTI15_10 => PB14,
189 EXTI15_10 => (gpiob, PB15), 191 EXTI15_10 => PB15,
190} 192]);
191 193
192#[cfg(any( 194#[cfg(any(
193 feature = "stm32f401", 195 feature = "stm32f401",
@@ -208,24 +210,24 @@ exti! {
208 feature = "stm32f469", 210 feature = "stm32f469",
209 feature = "stm32f479" 211 feature = "stm32f479"
210))] 212))]
211exti! { 213exti!(gpioc, [
212 EXTI0 => (gpioc, PC0), 214 EXTI0 => PC0,
213 EXTI1 => (gpioc, PC1), 215 EXTI1 => PC1,
214 EXTI2 => (gpioc, PC2), 216 EXTI2 => PC2,
215 EXTI3 => (gpioc, PC3), 217 EXTI3 => PC3,
216 EXTI4 => (gpioc, PC4), 218 EXTI4 => PC4,
217 EXTI9_5 => (gpioc, PC5), 219 EXTI9_5 => PC5,
218 EXTI9_5 => (gpioc, PC6), 220 EXTI9_5 => PC6,
219 EXTI9_5 => (gpioc, PC7), 221 EXTI9_5 => PC7,
220 EXTI9_5 => (gpioc, PC8), 222 EXTI9_5 => PC8,
221 EXTI9_5 => (gpioc, PC9), 223 EXTI9_5 => PC9,
222 EXTI15_10 => (gpioc, PC10), 224 EXTI15_10 => PC10,
223 EXTI15_10 => (gpioc, PC11), 225 EXTI15_10 => PC11,
224 EXTI15_10 => (gpioc, PC12), 226 EXTI15_10 => PC12,
225 EXTI15_10 => (gpioc, PC13), 227 EXTI15_10 => PC13,
226 EXTI15_10 => (gpioc, PC14), 228 EXTI15_10 => PC14,
227 EXTI15_10 => (gpioc, PC15), 229 EXTI15_10 => PC15,
228} 230]);
229 231
230#[cfg(any( 232#[cfg(any(
231 feature = "stm32f401", 233 feature = "stm32f401",
@@ -245,24 +247,24 @@ exti! {
245 feature = "stm32f469", 247 feature = "stm32f469",
246 feature = "stm32f479" 248 feature = "stm32f479"
247))] 249))]
248exti! { 250exti!(gpiod, [
249 EXTI0 => (gpiod, PD0), 251 EXTI0 => PD0,
250 EXTI1 => (gpiod, PD1), 252 EXTI1 => PD1,
251 EXTI2 => (gpiod, PD2), 253 EXTI2 => PD2,
252 EXTI3 => (gpiod, PD3), 254 EXTI3 => PD3,
253 EXTI4 => (gpiod, PD4), 255 EXTI4 => PD4,
254 EXTI9_5 => (gpiod, PD5), 256 EXTI9_5 => PD5,
255 EXTI9_5 => (gpiod, PD6), 257 EXTI9_5 => PD6,
256 EXTI9_5 => (gpiod, PD7), 258 EXTI9_5 => PD7,
257 EXTI9_5 => (gpiod, PD8), 259 EXTI9_5 => PD8,
258 EXTI9_5 => (gpiod, PD9), 260 EXTI9_5 => PD9,
259 EXTI15_10 => (gpiod, PD10), 261 EXTI15_10 => PD10,
260 EXTI15_10 => (gpiod, PD11), 262 EXTI15_10 => PD11,
261 EXTI15_10 => (gpiod, PD12), 263 EXTI15_10 => PD12,
262 EXTI15_10 => (gpiod, PD13), 264 EXTI15_10 => PD13,
263 EXTI15_10 => (gpiod, PD14), 265 EXTI15_10 => PD14,
264 EXTI15_10 => (gpiod, PD15), 266 EXTI15_10 => PD15,
265} 267]);
266 268
267#[cfg(any( 269#[cfg(any(
268 feature = "stm32f401", 270 feature = "stm32f401",
@@ -282,24 +284,24 @@ exti! {
282 feature = "stm32f469", 284 feature = "stm32f469",
283 feature = "stm32f479" 285 feature = "stm32f479"
284))] 286))]
285exti! { 287exti!(gpioe, [
286 EXTI0 => (gpioe, PE0), 288 EXTI0 => PE0,
287 EXTI1 => (gpioe, PE1), 289 EXTI1 => PE1,
288 EXTI2 => (gpioe, PE2), 290 EXTI2 => PE2,
289 EXTI3 => (gpioe, PE3), 291 EXTI3 => PE3,
290 EXTI4 => (gpioe, PE4), 292 EXTI4 => PE4,
291 EXTI9_5 => (gpioe, PE5), 293 EXTI9_5 => PE5,
292 EXTI9_5 => (gpioe, PE6), 294 EXTI9_5 => PE6,
293 EXTI9_5 => (gpioe, PE7), 295 EXTI9_5 => PE7,
294 EXTI9_5 => (gpioe, PE8), 296 EXTI9_5 => PE8,
295 EXTI9_5 => (gpioe, PE9), 297 EXTI9_5 => PE9,
296 EXTI15_10 => (gpioe, PE10), 298 EXTI15_10 => PE10,
297 EXTI15_10 => (gpioe, PE11), 299 EXTI15_10 => PE11,
298 EXTI15_10 => (gpioe, PE12), 300 EXTI15_10 => PE12,
299 EXTI15_10 => (gpioe, PE13), 301 EXTI15_10 => PE13,
300 EXTI15_10 => (gpioe, PE14), 302 EXTI15_10 => PE14,
301 EXTI15_10 => (gpioe, PE15), 303 EXTI15_10 => PE15,
302} 304]);
303 305
304#[cfg(any( 306#[cfg(any(
305 feature = "stm32f405", 307 feature = "stm32f405",
@@ -317,24 +319,24 @@ exti! {
317 feature = "stm32f469", 319 feature = "stm32f469",
318 feature = "stm32f479" 320 feature = "stm32f479"
319))] 321))]
320exti! { 322exti!(gpiof, [
321 EXTI0 => (gpiof, PF0), 323 EXTI0 => PF0,
322 EXTI1 => (gpiof, PF1), 324 EXTI1 => PF1,
323 EXTI2 => (gpiof, PF2), 325 EXTI2 => PF2,
324 EXTI3 => (gpiof, PF3), 326 EXTI3 => PF3,
325 EXTI4 => (gpiof, PF4), 327 EXTI4 => PF4,
326 EXTI9_5 => (gpiof, PF5), 328 EXTI9_5 => PF5,
327 EXTI9_5 => (gpiof, PF6), 329 EXTI9_5 => PF6,
328 EXTI9_5 => (gpiof, PF7), 330 EXTI9_5 => PF7,
329 EXTI9_5 => (gpiof, PF8), 331 EXTI9_5 => PF8,
330 EXTI9_5 => (gpiof, PF9), 332 EXTI9_5 => PF9,
331 EXTI15_10 => (gpiof, PF10), 333 EXTI15_10 => PF10,
332 EXTI15_10 => (gpiof, PF11), 334 EXTI15_10 => PF11,
333 EXTI15_10 => (gpiof, PF12), 335 EXTI15_10 => PF12,
334 EXTI15_10 => (gpiof, PF13), 336 EXTI15_10 => PF13,
335 EXTI15_10 => (gpiof, PF14), 337 EXTI15_10 => PF14,
336 EXTI15_10 => (gpiof, PF15), 338 EXTI15_10 => PF15,
337} 339]);
338 340
339#[cfg(any( 341#[cfg(any(
340 feature = "stm32f405", 342 feature = "stm32f405",
@@ -352,24 +354,24 @@ exti! {
352 feature = "stm32f469", 354 feature = "stm32f469",
353 feature = "stm32f479" 355 feature = "stm32f479"
354))] 356))]
355exti! { 357exti!(gpiog, [
356 EXTI0 => (gpiog, PG0), 358 EXTI0 => PG0,
357 EXTI1 => (gpiog, PG1), 359 EXTI1 => PG1,
358 EXTI2 => (gpiog, PG2), 360 EXTI2 => PG2,
359 EXTI3 => (gpiog, PG3), 361 EXTI3 => PG3,
360 EXTI4 => (gpiog, PG4), 362 EXTI4 => PG4,
361 EXTI9_5 => (gpiog, PG5), 363 EXTI9_5 => PG5,
362 EXTI9_5 => (gpiog, PG6), 364 EXTI9_5 => PG6,
363 EXTI9_5 => (gpiog, PG7), 365 EXTI9_5 => PG7,
364 EXTI9_5 => (gpiog, PG8), 366 EXTI9_5 => PG8,
365 EXTI9_5 => (gpiog, PG9), 367 EXTI9_5 => PG9,
366 EXTI15_10 => (gpiog, PG10), 368 EXTI15_10 => PG10,
367 EXTI15_10 => (gpiog, PG11), 369 EXTI15_10 => PG11,
368 EXTI15_10 => (gpiog, PG12), 370 EXTI15_10 => PG12,
369 EXTI15_10 => (gpiog, PG13), 371 EXTI15_10 => PG13,
370 EXTI15_10 => (gpiog, PG14), 372 EXTI15_10 => PG14,
371 EXTI15_10 => (gpiog, PG15), 373 EXTI15_10 => PG15,
372} 374]);
373 375
374#[cfg(any( 376#[cfg(any(
375 feature = "stm32f405", 377 feature = "stm32f405",
@@ -389,30 +391,30 @@ exti! {
389 feature = "stm32f469", 391 feature = "stm32f469",
390 feature = "stm32f479" 392 feature = "stm32f479"
391))] 393))]
392exti! { 394exti!(gpioh, [
393 EXTI0 => (gpioh, PH0), 395 EXTI0 => PH0,
394 EXTI1 => (gpioh, PH1), 396 EXTI1 => PH1,
395 EXTI2 => (gpioh, PH2), 397 EXTI2 => PH2,
396 EXTI3 => (gpioh, PH3), 398 EXTI3 => PH3,
397 EXTI4 => (gpioh, PH4), 399 EXTI4 => PH4,
398 EXTI9_5 => (gpioh, PH5), 400 EXTI9_5 => PH5,
399 EXTI9_5 => (gpioh, PH6), 401 EXTI9_5 => PH6,
400 EXTI9_5 => (gpioh, PH7), 402 EXTI9_5 => PH7,
401 EXTI9_5 => (gpioh, PH8), 403 EXTI9_5 => PH8,
402 EXTI9_5 => (gpioh, PH9), 404 EXTI9_5 => PH9,
403 EXTI15_10 => (gpioh, PH10), 405 EXTI15_10 => PH10,
404 EXTI15_10 => (gpioh, PH11), 406 EXTI15_10 => PH11,
405 EXTI15_10 => (gpioh, PH12), 407 EXTI15_10 => PH12,
406 EXTI15_10 => (gpioh, PH13), 408 EXTI15_10 => PH13,
407 EXTI15_10 => (gpioh, PH14), 409 EXTI15_10 => PH14,
408 EXTI15_10 => (gpioh, PH15), 410 EXTI15_10 => PH15,
409} 411]);
410 412
411#[cfg(any(feature = "stm32f401"))] 413#[cfg(any(feature = "stm32f401"))]
412exti! { 414exti!(gpioh, [
413 EXTI0 => (gpioh, PH0), 415 EXTI0 => PH0,
414 EXTI1 => (gpioh, PH1), 416 EXTI1 => PH1,
415} 417]);
416 418
417#[cfg(any( 419#[cfg(any(
418 feature = "stm32f405", 420 feature = "stm32f405",
@@ -426,24 +428,24 @@ exti! {
426 feature = "stm32f469", 428 feature = "stm32f469",
427 feature = "stm32f479" 429 feature = "stm32f479"
428))] 430))]
429exti! { 431exti!(gpioi, [
430 EXTI0 => (gpioi, PI0), 432 EXTI0 => PI0,
431 EXTI1 => (gpioi, PI1), 433 EXTI1 => PI1,
432 EXTI2 => (gpioi, PI2), 434 EXTI2 => PI2,
433 EXTI3 => (gpioi, PI3), 435 EXTI3 => PI3,
434 EXTI4 => (gpioi, PI4), 436 EXTI4 => PI4,
435 EXTI9_5 => (gpioi, PI5), 437 EXTI9_5 => PI5,
436 EXTI9_5 => (gpioi, PI6), 438 EXTI9_5 => PI6,
437 EXTI9_5 => (gpioi, PI7), 439 EXTI9_5 => PI7,
438 EXTI9_5 => (gpioi, PI8), 440 EXTI9_5 => PI8,
439 EXTI9_5 => (gpioi, PI9), 441 EXTI9_5 => PI9,
440 EXTI15_10 => (gpioi, PI10), 442 EXTI15_10 => PI10,
441 EXTI15_10 => (gpioi, PI11), 443 EXTI15_10 => PI11,
442 EXTI15_10 => (gpioi, PI12), 444 EXTI15_10 => PI12,
443 EXTI15_10 => (gpioi, PI13), 445 EXTI15_10 => PI13,
444 EXTI15_10 => (gpioi, PI14), 446 EXTI15_10 => PI14,
445 EXTI15_10 => (gpioi, PI15), 447 EXTI15_10 => PI15,
446} 448]);
447 449
448#[cfg(any( 450#[cfg(any(
449 feature = "stm32f427", 451 feature = "stm32f427",
@@ -453,24 +455,24 @@ exti! {
453 feature = "stm32f469", 455 feature = "stm32f469",
454 feature = "stm32f479" 456 feature = "stm32f479"
455))] 457))]
456exti! { 458exti!(gpioj, [
457 EXTI0 => (gpioj, PJ0), 459 EXTI0 => PJ0,
458 EXTI1 => (gpioj, PJ1), 460 EXTI1 => PJ1,
459 EXTI2 => (gpioj, PJ2), 461 EXTI2 => PJ2,
460 EXTI3 => (gpioj, PJ3), 462 EXTI3 => PJ3,
461 EXTI4 => (gpioj, PJ4), 463 EXTI4 => PJ4,
462 EXTI9_5 => (gpioj, PJ5), 464 EXTI9_5 => PJ5,
463 EXTI9_5 => (gpioj, PJ6), 465 EXTI9_5 => PJ6,
464 EXTI9_5 => (gpioj, PJ7), 466 EXTI9_5 => PJ7,
465 EXTI9_5 => (gpioj, PJ8), 467 EXTI9_5 => PJ8,
466 EXTI9_5 => (gpioj, PJ9), 468 EXTI9_5 => PJ9,
467 EXTI15_10 => (gpioj, PJ10), 469 EXTI15_10 => PJ10,
468 EXTI15_10 => (gpioj, PJ11), 470 EXTI15_10 => PJ11,
469 EXTI15_10 => (gpioj, PJ12), 471 EXTI15_10 => PJ12,
470 EXTI15_10 => (gpioj, PJ13), 472 EXTI15_10 => PJ13,
471 EXTI15_10 => (gpioj, PJ14), 473 EXTI15_10 => PJ14,
472 EXTI15_10 => (gpioj, PJ15), 474 EXTI15_10 => PJ15,
473} 475]);
474 476
475#[cfg(any( 477#[cfg(any(
476 feature = "stm32f427", 478 feature = "stm32f427",
@@ -480,13 +482,13 @@ exti! {
480 feature = "stm32f469", 482 feature = "stm32f469",
481 feature = "stm32f479" 483 feature = "stm32f479"
482))] 484))]
483exti! { 485exti!(gpioj, [
484 EXTI0 => (gpiok, PK0), 486 EXTI0 => PK0,
485 EXTI1 => (gpiok, PK1), 487 EXTI1 => PK1,
486 EXTI2 => (gpiok, PK2), 488 EXTI2 => PK2,
487 EXTI3 => (gpiok, PK3), 489 EXTI3 => PK3,
488 EXTI4 => (gpiok, PK4), 490 EXTI4 => PK4,
489 EXTI9_5 => (gpiok, PK5), 491 EXTI9_5 => PK5,
490 EXTI9_5 => (gpiok, PK6), 492 EXTI9_5 => PK6,
491 EXTI9_5 => (gpiok, PK7), 493 EXTI9_5 => PK7,
492} 494]);
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs
index 36ca5af56..2ca82ac50 100644
--- a/embassy-stm32f4/src/serial.rs
+++ b/embassy-stm32f4/src/serial.rs
@@ -5,6 +5,7 @@
5//! are dropped correctly (e.g. not using `mem::forget()`). 5//! are dropped correctly (e.g. not using `mem::forget()`).
6 6
7use core::future::Future; 7use core::future::Future;
8use core::marker::PhantomData;
8use core::ptr; 9use core::ptr;
9use core::sync::atomic::{self, Ordering}; 10use core::sync::atomic::{self, Ordering};
10 11
@@ -12,62 +13,56 @@ use embassy::interrupt::{Interrupt, InterruptExt};
12use embassy::traits::uart::{Error, Uart}; 13use embassy::traits::uart::{Error, Uart};
13use embassy::util::InterruptFuture; 14use embassy::util::InterruptFuture;
14 15
15use crate::hal::dma; 16use crate::hal::{
16use crate::hal::dma::config::DmaConfig; 17 dma,
17use crate::hal::dma::traits::{PeriAddress, Stream}; 18 dma::config::DmaConfig,
18use crate::hal::dma::{MemoryToPeripheral, PeripheralToMemory, Transfer}; 19 dma::traits::{Channel, DMASet, PeriAddress, Stream},
19use crate::hal::rcc::Clocks; 20 dma::{MemoryToPeripheral, PeripheralToMemory, Transfer},
20use crate::hal::serial; 21 rcc::Clocks,
21use crate::hal::serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}; 22 serial,
22use crate::hal::serial::Pins; 23 serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig},
23use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; 24 serial::{Event as SerialEvent, Pins, Serial as HalSerial},
25};
24use crate::interrupt; 26use crate::interrupt;
25use crate::pac; 27use crate::pac;
26 28
27/// Interface to the Serial peripheral 29/// Interface to the Serial peripheral
28pub struct Serial< 30pub struct Serial<
29 USART: PeriAddress<MemSize = u8>, 31 USART: PeriAddress<MemSize = u8> + WithInterrupt,
30 TSTREAM: Stream, 32 TSTREAM: Stream + WithInterrupt,
31 RSTREAM: Stream, 33 RSTREAM: Stream + WithInterrupt,
32 CHANNEL: dma::traits::Channel, 34 CHANNEL: dma::traits::Channel,
33 TINT: Interrupt,
34 RINT: Interrupt,
35 UINT: Interrupt,
36> { 35> {
37 tx_stream: Option<TSTREAM>, 36 tx_stream: Option<TSTREAM>,
38 rx_stream: Option<RSTREAM>, 37 rx_stream: Option<RSTREAM>,
39 usart: Option<USART>, 38 usart: Option<USART>,
40 tx_int: TINT, 39 tx_int: TSTREAM::Interrupt,
41 rx_int: RINT, 40 rx_int: RSTREAM::Interrupt,
42 usart_int: UINT, 41 usart_int: USART::Interrupt,
43 channel: core::marker::PhantomData<CHANNEL>, 42 channel: PhantomData<CHANNEL>,
44} 43}
45 44
46// static mut INSTANCE: *const Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> = ptr::null_mut(); 45// static mut INSTANCE: *const Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> = ptr::null_mut();
47 46
48impl<USART, TSTREAM, RSTREAM, CHANNEL, TINT, RINT, UINT> 47impl<USART, TSTREAM, RSTREAM, CHANNEL> Serial<USART, TSTREAM, RSTREAM, CHANNEL>
49 Serial<USART, TSTREAM, RSTREAM, CHANNEL, TINT, RINT, UINT>
50where 48where
51 USART: serial::Instance 49 USART: serial::Instance
52 + dma::traits::PeriAddress<MemSize = u8> 50 + PeriAddress<MemSize = u8>
53 + dma::traits::DMASet<TSTREAM, CHANNEL, MemoryToPeripheral> 51 + DMASet<TSTREAM, CHANNEL, MemoryToPeripheral>
54 + dma::traits::DMASet<RSTREAM, CHANNEL, PeripheralToMemory> 52 + DMASet<RSTREAM, CHANNEL, PeripheralToMemory>
55 + WithInterrupt<Instance = UINT>, 53 + WithInterrupt,
56 TSTREAM: Stream + WithInterrupt<Instance = TINT>, 54 TSTREAM: Stream + WithInterrupt,
57 RSTREAM: Stream + WithInterrupt<Instance = RINT>, 55 RSTREAM: Stream + WithInterrupt,
58 CHANNEL: dma::traits::Channel, 56 CHANNEL: Channel,
59 TINT: Interrupt,
60 RINT: Interrupt,
61 UINT: Interrupt,
62{ 57{
63 // Leaking futures is forbidden! 58 // Leaking futures is forbidden!
64 pub unsafe fn new<PINS>( 59 pub unsafe fn new<PINS>(
65 usart: USART, 60 usart: USART,
66 streams: (TSTREAM, RSTREAM), 61 streams: (TSTREAM, RSTREAM),
67 pins: PINS, 62 pins: PINS,
68 tx_int: TINT, 63 tx_int: TSTREAM::Interrupt,
69 rx_int: RINT, 64 rx_int: RSTREAM::Interrupt,
70 usart_int: UINT, 65 usart_int: USART::Interrupt,
71 mut config: SerialConfig, 66 mut config: SerialConfig,
72 clocks: Clocks, 67 clocks: Clocks,
73 ) -> Self 68 ) -> Self
@@ -96,21 +91,17 @@ where
96 } 91 }
97} 92}
98 93
99impl<USART, TSTREAM, RSTREAM, CHANNEL, TINT, RINT, UINT> Uart 94impl<USART, TSTREAM, RSTREAM, CHANNEL> Uart for Serial<USART, TSTREAM, RSTREAM, CHANNEL>
100 for Serial<USART, TSTREAM, RSTREAM, CHANNEL, TINT, RINT, UINT>
101where 95where
102 USART: serial::Instance 96 USART: serial::Instance
103 + dma::traits::PeriAddress<MemSize = u8> 97 + PeriAddress<MemSize = u8>
104 + dma::traits::DMASet<TSTREAM, CHANNEL, MemoryToPeripheral> 98 + DMASet<TSTREAM, CHANNEL, MemoryToPeripheral>
105 + dma::traits::DMASet<RSTREAM, CHANNEL, PeripheralToMemory> 99 + DMASet<RSTREAM, CHANNEL, PeripheralToMemory>
106 + WithInterrupt<Instance = UINT> 100 + WithInterrupt
107 + 'static, 101 + 'static,
108 TSTREAM: Stream + WithInterrupt<Instance = TINT> + 'static, 102 TSTREAM: Stream + WithInterrupt + 'static,
109 RSTREAM: Stream + WithInterrupt<Instance = RINT> + 'static, 103 RSTREAM: Stream + WithInterrupt + 'static,
110 CHANNEL: dma::traits::Channel + 'static, 104 CHANNEL: Channel + 'static,
111 TINT: Interrupt + 'static,
112 RINT: Interrupt + 'static,
113 UINT: Interrupt + 'static,
114{ 105{
115 type SendFuture<'a> = impl Future<Output = Result<(), Error>> + 'a; 106 type SendFuture<'a> = impl Future<Output = Result<(), Error>> + 'a;
116 type ReceiveFuture<'a> = impl Future<Output = Result<(), Error>> + 'a; 107 type ReceiveFuture<'a> = impl Future<Output = Result<(), Error>> + 'a;
@@ -192,7 +183,7 @@ mod private {
192} 183}
193 184
194pub trait WithInterrupt: private::Sealed { 185pub trait WithInterrupt: private::Sealed {
195 type Instance; 186 type Interrupt: Interrupt;
196} 187}
197 188
198macro_rules! dma { 189macro_rules! dma {
@@ -200,7 +191,7 @@ macro_rules! dma {
200 $( 191 $(
201 impl private::Sealed for dma::$stream<pac::$dma> {} 192 impl private::Sealed for dma::$stream<pac::$dma> {}
202 impl WithInterrupt for dma::$stream<pac::$dma> { 193 impl WithInterrupt for dma::$stream<pac::$dma> {
203 type Instance = interrupt::$PER; 194 type Interrupt = interrupt::$PER;
204 } 195 }
205 )+ 196 )+
206 } 197 }
@@ -211,7 +202,7 @@ macro_rules! usart {
211 $( 202 $(
212 impl private::Sealed for pac::$usart {} 203 impl private::Sealed for pac::$usart {}
213 impl WithInterrupt for pac::$usart { 204 impl WithInterrupt for pac::$usart {
214 type Instance = interrupt::$PER; 205 type Interrupt = interrupt::$PER;
215 } 206 }
216 )+ 207 )+
217 } 208 }