aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/Cargo.toml8
-rw-r--r--embassy-nrf/src/buffered_uarte.rs14
-rw-r--r--embassy-nrf/src/gpio.rs229
-rw-r--r--embassy-nrf/src/gpiote.rs147
-rw-r--r--embassy-nrf/src/spim.rs264
-rw-r--r--embassy-nrf/src/twim.rs297
-rw-r--r--embassy-nrf/src/uarte.rs203
-rw-r--r--examples/nrf/Cargo.toml1
8 files changed, 910 insertions, 253 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index 3d0c171f3..c9bd2bc14 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -12,6 +12,9 @@ edition = "2018"
12# There are no plans to make this stable. 12# There are no plans to make this stable.
13unstable-pac = [] 13unstable-pac = []
14 14
15# Implement embedded-hal 1.0 alpha and embedded-hal-async traits.
16unstable-traits = ["embedded-hal-1", "embedded-hal-async"]
17
15nrf52805 = ["nrf52805-pac", "_ppi"] 18nrf52805 = ["nrf52805-pac", "_ppi"]
16nrf52810 = ["nrf52810-pac", "_ppi"] 19nrf52810 = ["nrf52810-pac", "_ppi"]
17nrf52811 = ["nrf52811-pac", "_ppi"] 20nrf52811 = ["nrf52811-pac", "_ppi"]
@@ -47,11 +50,14 @@ embassy = { version = "0.1.0", path = "../embassy" }
47embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} 50embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]}
48embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 51embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
49 52
53embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
54embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true}
55embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true}
56
50defmt = { version = "0.3", optional = true } 57defmt = { version = "0.3", optional = true }
51log = { version = "0.4.14", optional = true } 58log = { version = "0.4.14", optional = true }
52cortex-m-rt = ">=0.6.15,<0.8" 59cortex-m-rt = ">=0.6.15,<0.8"
53cortex-m = "0.7.3" 60cortex-m = "0.7.3"
54embedded-hal = "0.2.6"
55embedded-dma = "0.1.2" 61embedded-dma = "0.1.2"
56futures = { version = "0.3.17", default-features = false } 62futures = { version = "0.3.17", default-features = false }
57critical-section = "0.2.5" 63critical-section = "0.2.5"
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 45e8afc4b..2880c84f6 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -213,9 +213,6 @@ impl<'d, U: UarteInstance, T: TimerInstance> AsyncBufRead for BufferedUarte<'d,
213 cx: &mut Context<'_>, 213 cx: &mut Context<'_>,
214 ) -> Poll<embassy::io::Result<&[u8]>> { 214 ) -> Poll<embassy::io::Result<&[u8]>> {
215 self.inner.with(|state| { 215 self.inner.with(|state| {
216 // Conservative compiler fence to prevent optimizations that do not
217 // take in to account actions by DMA. The fence has been placed here,
218 // before any DMA action has started
219 compiler_fence(Ordering::SeqCst); 216 compiler_fence(Ordering::SeqCst);
220 trace!("poll_read"); 217 trace!("poll_read");
221 218
@@ -265,9 +262,6 @@ impl<'d, U: UarteInstance, T: TimerInstance> AsyncWrite for BufferedUarte<'d, U,
265 262
266 trace!("poll_write: queued {:?}", n); 263 trace!("poll_write: queued {:?}", n);
267 264
268 // Conservative compiler fence to prevent optimizations that do not
269 // take in to account actions by DMA. The fence has been placed here,
270 // before any DMA action has started
271 compiler_fence(Ordering::SeqCst); 265 compiler_fence(Ordering::SeqCst);
272 266
273 Poll::Ready(Ok(n)) 267 Poll::Ready(Ok(n))
@@ -347,9 +341,7 @@ impl<'a, U: UarteInstance, T: TimerInstance> PeripheralState for StateInner<'a,
347 trace!(" irq_rx: buf {:?} {:?}", buf.as_ptr() as u32, buf.len()); 341 trace!(" irq_rx: buf {:?} {:?}", buf.as_ptr() as u32, buf.len());
348 342
349 // Start UARTE Receive transaction 343 // Start UARTE Receive transaction
350 r.tasks_startrx.write(|w| 344 r.tasks_startrx.write(|w| unsafe { w.bits(1) });
351 // `1` is a valid value to write to task registers.
352 unsafe { w.bits(1) });
353 } 345 }
354 break; 346 break;
355 } 347 }
@@ -397,9 +389,7 @@ impl<'a, U: UarteInstance, T: TimerInstance> PeripheralState for StateInner<'a,
397 unsafe { w.maxcnt().bits(buf.len() as _) }); 389 unsafe { w.maxcnt().bits(buf.len() as _) });
398 390
399 // Start UARTE Transmit transaction 391 // Start UARTE Transmit transaction
400 r.tasks_starttx.write(|w| 392 r.tasks_starttx.write(|w| unsafe { w.bits(1) });
401 // `1` is a valid value to write to task registers.
402 unsafe { w.bits(1) });
403 } 393 }
404 break; 394 break;
405 } 395 }
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index abda909f0..3f204d564 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -7,7 +7,6 @@ use core::marker::PhantomData;
7use cfg_if::cfg_if; 7use cfg_if::cfg_if;
8use embassy::util::Unborrow; 8use embassy::util::Unborrow;
9use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 9use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
10use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
11use gpio::pin_cnf::DRIVE_A; 10use gpio::pin_cnf::DRIVE_A;
12 11
13use crate::pac; 12use crate::pac;
@@ -57,18 +56,6 @@ impl<'d, T: Pin> Input<'d, T> {
57 } 56 }
58} 57}
59 58
60impl<'d, T: Pin> InputPin for Input<'d, T> {
61 type Error = Infallible;
62
63 fn is_high(&self) -> Result<bool, Self::Error> {
64 Ok(self.is_high())
65 }
66
67 fn is_low(&self) -> Result<bool, Self::Error> {
68 Ok(self.is_low())
69 }
70}
71
72/// Digital input or output level. 59/// Digital input or output level.
73#[derive(Debug, Eq, PartialEq)] 60#[derive(Debug, Eq, PartialEq)]
74#[cfg_attr(feature = "defmt", derive(defmt::Format))] 61#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -142,28 +129,6 @@ impl<'d, T: Pin> Output<'d, T> {
142 } 129 }
143} 130}
144 131
145impl<'d, T: Pin> OutputPin for Output<'d, T> {
146 type Error = Infallible;
147
148 fn set_high(&mut self) -> Result<(), Self::Error> {
149 Ok(self.set_high())
150 }
151
152 fn set_low(&mut self) -> Result<(), Self::Error> {
153 Ok(self.set_low())
154 }
155}
156
157impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
158 fn is_set_high(&self) -> Result<bool, Self::Error> {
159 Ok(self.is_set_high())
160 }
161
162 fn is_set_low(&self) -> Result<bool, Self::Error> {
163 Ok(self.is_set_low())
164 }
165}
166
167/// GPIO flexible pin. 132/// GPIO flexible pin.
168/// 133///
169/// This pin can either be a disconnected, input, or output pin. The level register bit will remain 134/// This pin can either be a disconnected, input, or output pin. The level register bit will remain
@@ -276,43 +241,6 @@ impl<'d, T: Pin> Drop for Flex<'d, T> {
276 } 241 }
277} 242}
278 243
279/// Implement [`InputPin`] for [`Flex`];
280///
281/// If the pin is not in input mode the result is unspecified.
282impl<'d, T: Pin> InputPin for Flex<'d, T> {
283 type Error = Infallible;
284
285 fn is_high(&self) -> Result<bool, Self::Error> {
286 Ok(self.is_high())
287 }
288
289 fn is_low(&self) -> Result<bool, Self::Error> {
290 Ok(self.is_low())
291 }
292}
293
294impl<'d, T: Pin> OutputPin for Flex<'d, T> {
295 type Error = Infallible;
296
297 fn set_high(&mut self) -> Result<(), Self::Error> {
298 Ok(self.set_high())
299 }
300
301 fn set_low(&mut self) -> Result<(), Self::Error> {
302 Ok(self.set_low())
303 }
304}
305
306impl<'d, T: Pin> StatefulOutputPin for Flex<'d, T> {
307 fn is_set_high(&self) -> Result<bool, Self::Error> {
308 Ok(self.is_set_high())
309 }
310
311 fn is_set_low(&self) -> Result<bool, Self::Error> {
312 Ok(self.is_set_low())
313 }
314}
315
316pub(crate) mod sealed { 244pub(crate) mod sealed {
317 use super::*; 245 use super::*;
318 246
@@ -491,3 +419,160 @@ macro_rules! impl_pin {
491 } 419 }
492 }; 420 };
493} 421}
422
423// ====================
424
425mod eh02 {
426 use super::*;
427
428 impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> {
429 type Error = Infallible;
430
431 fn is_high(&self) -> Result<bool, Self::Error> {
432 Ok(self.is_high())
433 }
434
435 fn is_low(&self) -> Result<bool, Self::Error> {
436 Ok(self.is_low())
437 }
438 }
439
440 impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> {
441 type Error = Infallible;
442
443 fn set_high(&mut self) -> Result<(), Self::Error> {
444 Ok(self.set_high())
445 }
446
447 fn set_low(&mut self) -> Result<(), Self::Error> {
448 Ok(self.set_low())
449 }
450 }
451
452 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> {
453 fn is_set_high(&self) -> Result<bool, Self::Error> {
454 Ok(self.is_set_high())
455 }
456
457 fn is_set_low(&self) -> Result<bool, Self::Error> {
458 Ok(self.is_set_low())
459 }
460 }
461
462 /// Implement [`InputPin`] for [`Flex`];
463 ///
464 /// If the pin is not in input mode the result is unspecified.
465 impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> {
466 type Error = Infallible;
467
468 fn is_high(&self) -> Result<bool, Self::Error> {
469 Ok(self.is_high())
470 }
471
472 fn is_low(&self) -> Result<bool, Self::Error> {
473 Ok(self.is_low())
474 }
475 }
476
477 impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> {
478 type Error = Infallible;
479
480 fn set_high(&mut self) -> Result<(), Self::Error> {
481 Ok(self.set_high())
482 }
483
484 fn set_low(&mut self) -> Result<(), Self::Error> {
485 Ok(self.set_low())
486 }
487 }
488
489 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> {
490 fn is_set_high(&self) -> Result<bool, Self::Error> {
491 Ok(self.is_set_high())
492 }
493
494 fn is_set_low(&self) -> Result<bool, Self::Error> {
495 Ok(self.is_set_low())
496 }
497 }
498}
499
500#[cfg(feature = "unstable-traits")]
501mod eh1 {
502 use super::*;
503
504 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
505 type Error = Infallible;
506 }
507
508 impl<'d, T: Pin> embedded_hal_1::digital::blocking::InputPin for Input<'d, T> {
509 fn is_high(&self) -> Result<bool, Self::Error> {
510 Ok(self.is_high())
511 }
512
513 fn is_low(&self) -> Result<bool, Self::Error> {
514 Ok(self.is_low())
515 }
516 }
517
518 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> {
519 type Error = Infallible;
520 }
521
522 impl<'d, T: Pin> embedded_hal_1::digital::blocking::OutputPin for Output<'d, T> {
523 fn set_high(&mut self) -> Result<(), Self::Error> {
524 Ok(self.set_high())
525 }
526
527 fn set_low(&mut self) -> Result<(), Self::Error> {
528 Ok(self.set_low())
529 }
530 }
531
532 impl<'d, T: Pin> embedded_hal_1::digital::blocking::StatefulOutputPin for Output<'d, T> {
533 fn is_set_high(&self) -> Result<bool, Self::Error> {
534 Ok(self.is_set_high())
535 }
536
537 fn is_set_low(&self) -> Result<bool, Self::Error> {
538 Ok(self.is_set_low())
539 }
540 }
541
542 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
543 type Error = Infallible;
544 }
545
546 /// Implement [`InputPin`] for [`Flex`];
547 ///
548 /// If the pin is not in input mode the result is unspecified.
549 impl<'d, T: Pin> embedded_hal_1::digital::blocking::InputPin for Flex<'d, T> {
550 fn is_high(&self) -> Result<bool, Self::Error> {
551 Ok(self.is_high())
552 }
553
554 fn is_low(&self) -> Result<bool, Self::Error> {
555 Ok(self.is_low())
556 }
557 }
558
559 impl<'d, T: Pin> embedded_hal_1::digital::blocking::OutputPin for Flex<'d, T> {
560 fn set_high(&mut self) -> Result<(), Self::Error> {
561 Ok(self.set_high())
562 }
563
564 fn set_low(&mut self) -> Result<(), Self::Error> {
565 Ok(self.set_low())
566 }
567 }
568
569 impl<'d, T: Pin> embedded_hal_1::digital::blocking::StatefulOutputPin for Flex<'d, T> {
570 fn is_set_high(&self) -> Result<bool, Self::Error> {
571 Ok(self.is_set_high())
572 }
573
574 fn is_set_low(&self) -> Result<bool, Self::Error> {
575 Ok(self.is_set_low())
576 }
577 }
578}
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index f1104904b..a4c24058c 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -5,7 +5,6 @@ use core::task::{Context, Poll};
5use embassy::interrupt::{Interrupt, InterruptExt}; 5use embassy::interrupt::{Interrupt, InterruptExt};
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_hal_common::unsafe_impl_unborrow; 7use embassy_hal_common::unsafe_impl_unborrow;
8use embedded_hal::digital::v2::InputPin;
9use futures::future::poll_fn; 8use futures::future::poll_fn;
10 9
11use crate::gpio::sealed::Pin as _; 10use crate::gpio::sealed::Pin as _;
@@ -216,18 +215,6 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
216 } 215 }
217} 216}
218 217
219impl<'d, C: Channel, T: GpioPin> InputPin for InputChannel<'d, C, T> {
220 type Error = Infallible;
221
222 fn is_high(&self) -> Result<bool, Self::Error> {
223 self.pin.is_high()
224 }
225
226 fn is_low(&self) -> Result<bool, Self::Error> {
227 self.pin.is_low()
228 }
229}
230
231/// GPIOTE channel driver in output mode 218/// GPIOTE channel driver in output mode
232pub struct OutputChannel<'d, C: Channel, T: GpioPin> { 219pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
233 ch: C, 220 ch: C,
@@ -454,3 +441,137 @@ impl_channel!(GPIOTE_CH4, 4);
454impl_channel!(GPIOTE_CH5, 5); 441impl_channel!(GPIOTE_CH5, 5);
455impl_channel!(GPIOTE_CH6, 6); 442impl_channel!(GPIOTE_CH6, 6);
456impl_channel!(GPIOTE_CH7, 7); 443impl_channel!(GPIOTE_CH7, 7);
444
445// ====================
446
447mod eh02 {
448 use super::*;
449
450 impl<'d, C: Channel, T: GpioPin> embedded_hal_02::digital::v2::InputPin for InputChannel<'d, C, T> {
451 type Error = Infallible;
452
453 fn is_high(&self) -> Result<bool, Self::Error> {
454 self.pin.is_high()
455 }
456
457 fn is_low(&self) -> Result<bool, Self::Error> {
458 self.pin.is_low()
459 }
460 }
461}
462
463#[cfg(feature = "unstable-traits")]
464mod eh1 {
465 use super::*;
466 use futures::FutureExt;
467
468 impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::ErrorType for InputChannel<'d, C, T> {
469 type Error = Infallible;
470 }
471
472 impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin
473 for InputChannel<'d, C, T>
474 {
475 fn is_high(&self) -> Result<bool, Self::Error> {
476 self.pin.is_high()
477 }
478
479 fn is_low(&self) -> Result<bool, Self::Error> {
480 self.pin.is_low()
481 }
482 }
483
484 impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Input<'d, T> {
485 type WaitForHighFuture<'a>
486 where
487 Self: 'a,
488 = impl Future<Output = Result<(), Self::Error>> + 'a;
489
490 fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
491 self.wait_for_high().map(Ok)
492 }
493
494 type WaitForLowFuture<'a>
495 where
496 Self: 'a,
497 = impl Future<Output = Result<(), Self::Error>> + 'a;
498
499 fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
500 self.wait_for_low().map(Ok)
501 }
502
503 type WaitForRisingEdgeFuture<'a>
504 where
505 Self: 'a,
506 = impl Future<Output = Result<(), Self::Error>> + 'a;
507
508 fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
509 self.wait_for_rising_edge().map(Ok)
510 }
511
512 type WaitForFallingEdgeFuture<'a>
513 where
514 Self: 'a,
515 = impl Future<Output = Result<(), Self::Error>> + 'a;
516
517 fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
518 self.wait_for_falling_edge().map(Ok)
519 }
520
521 type WaitForAnyEdgeFuture<'a>
522 where
523 Self: 'a,
524 = impl Future<Output = Result<(), Self::Error>> + 'a;
525
526 fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
527 self.wait_for_any_edge().map(Ok)
528 }
529 }
530
531 impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Flex<'d, T> {
532 type WaitForHighFuture<'a>
533 where
534 Self: 'a,
535 = impl Future<Output = Result<(), Self::Error>> + 'a;
536
537 fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
538 self.wait_for_high().map(Ok)
539 }
540
541 type WaitForLowFuture<'a>
542 where
543 Self: 'a,
544 = impl Future<Output = Result<(), Self::Error>> + 'a;
545
546 fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
547 self.wait_for_low().map(Ok)
548 }
549
550 type WaitForRisingEdgeFuture<'a>
551 where
552 Self: 'a,
553 = impl Future<Output = Result<(), Self::Error>> + 'a;
554
555 fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
556 self.wait_for_rising_edge().map(Ok)
557 }
558
559 type WaitForFallingEdgeFuture<'a>
560 where
561 Self: 'a,
562 = impl Future<Output = Result<(), Self::Error>> + 'a;
563
564 fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
565 self.wait_for_falling_edge().map(Ok)
566 }
567
568 type WaitForAnyEdgeFuture<'a>
569 where
570 Self: 'a,
571 = impl Future<Output = Result<(), Self::Error>> + 'a;
572
573 fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
574 self.wait_for_any_edge().map(Ok)
575 }
576 }
577}
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index e767bc703..cd43b26e6 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -1,15 +1,12 @@
1#![macro_use] 1#![macro_use]
2 2
3use core::future::Future;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
5use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{compiler_fence, Ordering};
6use core::task::Poll; 5use core::task::Poll;
7use embassy::interrupt::InterruptExt; 6use embassy::interrupt::InterruptExt;
8use embassy::traits;
9use embassy::util::Unborrow; 7use embassy::util::Unborrow;
10use embassy_hal_common::unborrow; 8use embassy_hal_common::unborrow;
11use futures::future::poll_fn; 9use futures::future::poll_fn;
12use traits::spi::{FullDuplex, Read, Spi, Write};
13 10
14use crate::gpio; 11use crate::gpio;
15use crate::gpio::sealed::Pin as _; 12use crate::gpio::sealed::Pin as _;
@@ -18,7 +15,7 @@ use crate::interrupt::Interrupt;
18use crate::util::{slice_ptr_parts, slice_ptr_parts_mut}; 15use crate::util::{slice_ptr_parts, slice_ptr_parts_mut};
19use crate::{pac, util::slice_in_ram_or}; 16use crate::{pac, util::slice_in_ram_or};
20 17
21pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 18pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
22pub use pac::spim0::frequency::FREQUENCY_A as Frequency; 19pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
23 20
24#[derive(Debug, Clone, Copy, PartialEq, Eq)] 21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -267,59 +264,6 @@ impl<'d, T: Instance> Drop for Spim<'d, T> {
267 } 264 }
268} 265}
269 266
270impl<'d, T: Instance> Spi<u8> for Spim<'d, T> {
271 type Error = Error;
272}
273
274impl<'d, T: Instance> Read<u8> for Spim<'d, T> {
275 type ReadFuture<'a>
276 where
277 Self: 'a,
278 = impl Future<Output = Result<(), Self::Error>> + 'a;
279
280 fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> {
281 self.read(data)
282 }
283}
284
285impl<'d, T: Instance> Write<u8> for Spim<'d, T> {
286 type WriteFuture<'a>
287 where
288 Self: 'a,
289 = impl Future<Output = Result<(), Self::Error>> + 'a;
290
291 fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
292 self.write(data)
293 }
294}
295
296impl<'d, T: Instance> FullDuplex<u8> for Spim<'d, T> {
297 type WriteReadFuture<'a>
298 where
299 Self: 'a,
300 = impl Future<Output = Result<(), Self::Error>> + 'a;
301
302 fn read_write<'a>(&'a mut self, rx: &'a mut [u8], tx: &'a [u8]) -> Self::WriteReadFuture<'a> {
303 self.transfer(rx, tx)
304 }
305}
306
307impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u8> for Spim<'d, T> {
308 type Error = Error;
309 fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
310 self.blocking_transfer_in_place(words)?;
311 Ok(words)
312 }
313}
314
315impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spim<'d, T> {
316 type Error = Error;
317
318 fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
319 self.blocking_write(words)
320 }
321}
322
323pub(crate) mod sealed { 267pub(crate) mod sealed {
324 use embassy::waitqueue::AtomicWaker; 268 use embassy::waitqueue::AtomicWaker;
325 269
@@ -363,3 +307,209 @@ macro_rules! impl_spim {
363 } 307 }
364 }; 308 };
365} 309}
310
311// ====================
312
313mod eh02 {
314 use super::*;
315
316 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<u8> for Spim<'d, T> {
317 type Error = Error;
318 fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
319 self.blocking_transfer_in_place(words)?;
320 Ok(words)
321 }
322 }
323
324 impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<u8> for Spim<'d, T> {
325 type Error = Error;
326
327 fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
328 self.blocking_write(words)
329 }
330 }
331}
332
333#[cfg(feature = "unstable-traits")]
334mod eh1 {
335 use super::*;
336 use core::future::Future;
337
338 impl embedded_hal_1::spi::Error for Error {
339 fn kind(&self) -> embedded_hal_1::spi::ErrorKind {
340 match *self {
341 Self::TxBufferTooLong => embedded_hal_1::spi::ErrorKind::Other,
342 Self::RxBufferTooLong => embedded_hal_1::spi::ErrorKind::Other,
343 Self::DMABufferNotInDataMemory => embedded_hal_1::spi::ErrorKind::Other,
344 }
345 }
346 }
347
348 impl<'d, T: Instance> embedded_hal_1::spi::ErrorType for Spim<'d, T> {
349 type Error = Error;
350 }
351
352 impl<'d, T: Instance> embedded_hal_1::spi::blocking::Read<u8> for Spim<'d, T> {
353 fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
354 self.blocking_transfer(words, &[])
355 }
356
357 fn read_transaction(&mut self, words: &mut [&mut [u8]]) -> Result<(), Self::Error> {
358 for buf in words {
359 self.blocking_read(buf)?
360 }
361 Ok(())
362 }
363 }
364
365 impl<'d, T: Instance> embedded_hal_1::spi::blocking::Write<u8> for Spim<'d, T> {
366 fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
367 self.blocking_write(words)
368 }
369
370 fn write_transaction(&mut self, words: &[&[u8]]) -> Result<(), Self::Error> {
371 for buf in words {
372 self.blocking_write(buf)?
373 }
374 Ok(())
375 }
376
377 fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
378 where
379 WI: IntoIterator<Item = u8>,
380 {
381 for w in words {
382 self.blocking_write(&[w])?;
383 }
384 Ok(())
385 }
386 }
387
388 impl<'d, T: Instance> embedded_hal_1::spi::blocking::ReadWrite<u8> for Spim<'d, T> {
389 fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> {
390 self.blocking_transfer(read, write)
391 }
392
393 fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
394 self.blocking_transfer_in_place(words)
395 }
396
397 fn transaction<'a>(
398 &mut self,
399 operations: &mut [embedded_hal_async::spi::Operation<'a, u8>],
400 ) -> Result<(), Self::Error> {
401 use embedded_hal_1::spi::blocking::Operation;
402 for o in operations {
403 match o {
404 Operation::Read(b) => self.blocking_read(b)?,
405 Operation::Write(b) => self.blocking_write(b)?,
406 Operation::Transfer(r, w) => self.blocking_transfer(r, w)?,
407 Operation::TransferInPlace(b) => self.blocking_transfer_in_place(b)?,
408 }
409 }
410 Ok(())
411 }
412 }
413
414 impl<'d, T: Instance> embedded_hal_async::spi::Read<u8> for Spim<'d, T> {
415 type ReadFuture<'a>
416 where
417 Self: 'a,
418 = impl Future<Output = Result<(), Self::Error>> + 'a;
419
420 fn read<'a>(&'a mut self, words: &'a mut [u8]) -> Self::ReadFuture<'a> {
421 self.read(words)
422 }
423
424 type ReadTransactionFuture<'a>
425 where
426 Self: 'a,
427 = impl Future<Output = Result<(), Self::Error>> + 'a;
428
429 fn read_transaction<'a>(
430 &'a mut self,
431 words: &'a mut [&'a mut [u8]],
432 ) -> Self::ReadTransactionFuture<'a> {
433 async move {
434 for buf in words {
435 self.read(buf).await?
436 }
437 Ok(())
438 }
439 }
440 }
441
442 impl<'d, T: Instance> embedded_hal_async::spi::Write<u8> for Spim<'d, T> {
443 type WriteFuture<'a>
444 where
445 Self: 'a,
446 = impl Future<Output = Result<(), Self::Error>> + 'a;
447
448 fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
449 self.write(data)
450 }
451
452 type WriteTransactionFuture<'a>
453 where
454 Self: 'a,
455 = impl Future<Output = Result<(), Self::Error>> + 'a;
456
457 fn write_transaction<'a>(
458 &'a mut self,
459 words: &'a [&'a [u8]],
460 ) -> Self::WriteTransactionFuture<'a> {
461 async move {
462 for buf in words {
463 self.write(buf).await?
464 }
465 Ok(())
466 }
467 }
468 }
469
470 impl<'d, T: Instance> embedded_hal_async::spi::ReadWrite<u8> for Spim<'d, T> {
471 type TransferFuture<'a>
472 where
473 Self: 'a,
474 = impl Future<Output = Result<(), Self::Error>> + 'a;
475
476 fn transfer<'a>(&'a mut self, rx: &'a mut [u8], tx: &'a [u8]) -> Self::TransferFuture<'a> {
477 self.transfer(rx, tx)
478 }
479
480 type TransferInPlaceFuture<'a>
481 where
482 Self: 'a,
483 = impl Future<Output = Result<(), Self::Error>> + 'a;
484
485 fn transfer_in_place<'a>(
486 &'a mut self,
487 words: &'a mut [u8],
488 ) -> Self::TransferInPlaceFuture<'a> {
489 self.transfer_in_place(words)
490 }
491
492 type TransactionFuture<'a>
493 where
494 Self: 'a,
495 = impl Future<Output = Result<(), Self::Error>> + 'a;
496
497 fn transaction<'a>(
498 &'a mut self,
499 operations: &'a mut [embedded_hal_async::spi::Operation<'a, u8>],
500 ) -> Self::TransactionFuture<'a> {
501 use embedded_hal_1::spi::blocking::Operation;
502 async move {
503 for o in operations {
504 match o {
505 Operation::Read(b) => self.read(b).await?,
506 Operation::Write(b) => self.write(b).await?,
507 Operation::Transfer(r, w) => self.transfer(r, w).await?,
508 Operation::TransferInPlace(b) => self.transfer_in_place(b).await?,
509 }
510 }
511 Ok(())
512 }
513 }
514 }
515}
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index ab649c470..4cd47c897 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -11,12 +11,10 @@ use core::marker::PhantomData;
11use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; 11use core::sync::atomic::{compiler_fence, Ordering::SeqCst};
12use core::task::Poll; 12use core::task::Poll;
13use embassy::interrupt::{Interrupt, InterruptExt}; 13use embassy::interrupt::{Interrupt, InterruptExt};
14use embassy::traits;
15use embassy::util::Unborrow; 14use embassy::util::Unborrow;
16use embassy::waitqueue::AtomicWaker; 15use embassy::waitqueue::AtomicWaker;
17use embassy_hal_common::unborrow; 16use embassy_hal_common::unborrow;
18use futures::future::poll_fn; 17use futures::future::poll_fn;
19use traits::i2c::I2c;
20 18
21use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 19use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
22use crate::gpio; 20use crate::gpio;
@@ -50,6 +48,22 @@ impl Default for Config {
50 } 48 }
51} 49}
52 50
51#[derive(Debug, Copy, Clone, Eq, PartialEq)]
52#[cfg_attr(feature = "defmt", derive(defmt::Format))]
53#[non_exhaustive]
54pub enum Error {
55 TxBufferTooLong,
56 RxBufferTooLong,
57 TxBufferZeroLength,
58 RxBufferZeroLength,
59 Transmit,
60 Receive,
61 DMABufferNotInDataMemory,
62 AddressNack,
63 DataNack,
64 Overrun,
65}
66
53/// Interface to a TWIM instance. 67/// Interface to a TWIM instance.
54pub struct Twim<'d, T: Instance> { 68pub struct Twim<'d, T: Instance> {
55 phantom: PhantomData<&'d mut T>, 69 phantom: PhantomData<&'d mut T>,
@@ -506,101 +520,6 @@ impl<'a, T: Instance> Drop for Twim<'a, T> {
506 } 520 }
507} 521}
508 522
509impl<'d, T> I2c for Twim<'d, T>
510where
511 T: Instance,
512{
513 type Error = Error;
514
515 type WriteFuture<'a>
516 where
517 Self: 'a,
518 = impl Future<Output = Result<(), Self::Error>> + 'a;
519 type ReadFuture<'a>
520 where
521 Self: 'a,
522 = impl Future<Output = Result<(), Self::Error>> + 'a;
523 type WriteReadFuture<'a>
524 where
525 Self: 'a,
526 = impl Future<Output = Result<(), Self::Error>> + 'a;
527
528 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
529 self.read(address, buffer)
530 }
531
532 fn write<'a>(&'a mut self, address: u8, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
533 self.write(address, buffer)
534 }
535
536 fn write_read<'a>(
537 &'a mut self,
538 address: u8,
539 wr_buffer: &'a [u8],
540 rd_buffer: &'a mut [u8],
541 ) -> Self::WriteReadFuture<'a> {
542 self.write_read(address, wr_buffer, rd_buffer)
543 }
544}
545
546impl<'a, T: Instance> embedded_hal::blocking::i2c::Write for Twim<'a, T> {
547 type Error = Error;
548
549 fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Error> {
550 if slice_in_ram(bytes) {
551 self.blocking_write(addr, bytes)
552 } else {
553 let buf = &mut [0; FORCE_COPY_BUFFER_SIZE][..];
554 for chunk in bytes.chunks(FORCE_COPY_BUFFER_SIZE) {
555 buf[..chunk.len()].copy_from_slice(chunk);
556 self.blocking_write(addr, &buf[..chunk.len()])?;
557 }
558 Ok(())
559 }
560 }
561}
562
563impl<'a, T: Instance> embedded_hal::blocking::i2c::Read for Twim<'a, T> {
564 type Error = Error;
565
566 fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Error> {
567 self.blocking_read(addr, bytes)
568 }
569}
570
571impl<'a, T: Instance> embedded_hal::blocking::i2c::WriteRead for Twim<'a, T> {
572 type Error = Error;
573
574 fn write_read<'w>(
575 &mut self,
576 addr: u8,
577 bytes: &'w [u8],
578 buffer: &'w mut [u8],
579 ) -> Result<(), Error> {
580 if slice_in_ram(bytes) {
581 self.blocking_write_read(addr, bytes, buffer)
582 } else {
583 self.blocking_copy_write_read(addr, bytes, buffer)
584 }
585 }
586}
587
588#[derive(Debug, Copy, Clone, Eq, PartialEq)]
589#[cfg_attr(feature = "defmt", derive(defmt::Format))]
590#[non_exhaustive]
591pub enum Error {
592 TxBufferTooLong,
593 RxBufferTooLong,
594 TxBufferZeroLength,
595 RxBufferZeroLength,
596 Transmit,
597 Receive,
598 DMABufferNotInDataMemory,
599 AddressNack,
600 DataNack,
601 Overrun,
602}
603
604pub(crate) mod sealed { 523pub(crate) mod sealed {
605 use super::*; 524 use super::*;
606 525
@@ -642,3 +561,187 @@ macro_rules! impl_twim {
642 } 561 }
643 }; 562 };
644} 563}
564
565// ====================
566
567mod eh02 {
568 use super::*;
569
570 impl<'a, T: Instance> embedded_hal_02::blocking::i2c::Write for Twim<'a, T> {
571 type Error = Error;
572
573 fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Error> {
574 if slice_in_ram(bytes) {
575 self.blocking_write(addr, bytes)
576 } else {
577 let buf = &mut [0; FORCE_COPY_BUFFER_SIZE][..];
578 for chunk in bytes.chunks(FORCE_COPY_BUFFER_SIZE) {
579 buf[..chunk.len()].copy_from_slice(chunk);
580 self.blocking_write(addr, &buf[..chunk.len()])?;
581 }
582 Ok(())
583 }
584 }
585 }
586
587 impl<'a, T: Instance> embedded_hal_02::blocking::i2c::Read for Twim<'a, T> {
588 type Error = Error;
589
590 fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Error> {
591 self.blocking_read(addr, bytes)
592 }
593 }
594
595 impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> {
596 type Error = Error;
597
598 fn write_read<'w>(
599 &mut self,
600 addr: u8,
601 bytes: &'w [u8],
602 buffer: &'w mut [u8],
603 ) -> Result<(), Error> {
604 if slice_in_ram(bytes) {
605 self.blocking_write_read(addr, bytes, buffer)
606 } else {
607 self.blocking_copy_write_read(addr, bytes, buffer)
608 }
609 }
610 }
611}
612
613#[cfg(feature = "unstable-traits")]
614mod eh1 {
615 use super::*;
616
617 impl embedded_hal_1::i2c::Error for Error {
618 fn kind(&self) -> embedded_hal_1::i2c::ErrorKind {
619 match *self {
620 Self::TxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other,
621 Self::RxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other,
622 Self::TxBufferZeroLength => embedded_hal_1::i2c::ErrorKind::Other,
623 Self::RxBufferZeroLength => embedded_hal_1::i2c::ErrorKind::Other,
624 Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other,
625 Self::Receive => embedded_hal_1::i2c::ErrorKind::Other,
626 Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other,
627 Self::AddressNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(
628 embedded_hal_1::i2c::NoAcknowledgeSource::Address,
629 ),
630 Self::DataNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(
631 embedded_hal_1::i2c::NoAcknowledgeSource::Data,
632 ),
633 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun,
634 }
635 }
636 }
637
638 impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for Twim<'d, T> {
639 type Error = Error;
640 }
641
642 impl<'d, T: Instance> embedded_hal_1::i2c::blocking::I2c for Twim<'d, T> {
643 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
644 self.blocking_read(address, buffer)
645 }
646
647 fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> {
648 self.blocking_write(address, buffer)
649 }
650
651 fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error>
652 where
653 B: IntoIterator<Item = u8>,
654 {
655 todo!();
656 }
657
658 fn write_iter_read<B>(
659 &mut self,
660 _address: u8,
661 _bytes: B,
662 _buffer: &mut [u8],
663 ) -> Result<(), Self::Error>
664 where
665 B: IntoIterator<Item = u8>,
666 {
667 todo!();
668 }
669
670 fn write_read(
671 &mut self,
672 address: u8,
673 wr_buffer: &[u8],
674 rd_buffer: &mut [u8],
675 ) -> Result<(), Self::Error> {
676 self.blocking_write_read(address, wr_buffer, rd_buffer)
677 }
678
679 fn transaction<'a>(
680 &mut self,
681 _address: u8,
682 _operations: &mut [embedded_hal_async::i2c::Operation<'a>],
683 ) -> Result<(), Self::Error> {
684 todo!();
685 }
686
687 fn transaction_iter<'a, O>(
688 &mut self,
689 _address: u8,
690 _operations: O,
691 ) -> Result<(), Self::Error>
692 where
693 O: IntoIterator<Item = embedded_hal_async::i2c::Operation<'a>>,
694 {
695 todo!();
696 }
697 }
698
699 impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> {
700 type ReadFuture<'a>
701 where
702 Self: 'a,
703 = impl Future<Output = Result<(), Self::Error>> + 'a;
704
705 fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
706 self.read(address, buffer)
707 }
708
709 type WriteFuture<'a>
710 where
711 Self: 'a,
712 = impl Future<Output = Result<(), Self::Error>> + 'a;
713
714 fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
715 self.write(address, bytes)
716 }
717
718 type WriteReadFuture<'a>
719 where
720 Self: 'a,
721 = impl Future<Output = Result<(), Self::Error>> + 'a;
722
723 fn write_read<'a>(
724 &'a mut self,
725 address: u8,
726 wr_buffer: &'a [u8],
727 rd_buffer: &'a mut [u8],
728 ) -> Self::WriteReadFuture<'a> {
729 self.write_read(address, wr_buffer, rd_buffer)
730 }
731
732 type TransactionFuture<'a>
733 where
734 Self: 'a,
735 = impl Future<Output = Result<(), Self::Error>> + 'a;
736
737 fn transaction<'a>(
738 &'a mut self,
739 address: u8,
740 operations: &mut [embedded_hal_async::i2c::Operation<'a>],
741 ) -> Self::TransactionFuture<'a> {
742 let _ = address;
743 let _ = operations;
744 async move { todo!() }
745 }
746 }
747}
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 07cec5d6b..b10e55a05 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -712,3 +712,206 @@ macro_rules! impl_uarte {
712 } 712 }
713 }; 713 };
714} 714}
715
716// ====================
717
718mod eh02 {
719 use super::*;
720
721 impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for Uarte<'d, T> {
722 type Error = Error;
723
724 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
725 self.blocking_write(buffer)
726 }
727
728 fn bflush(&mut self) -> Result<(), Self::Error> {
729 Ok(())
730 }
731 }
732
733 impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for UarteTx<'d, T> {
734 type Error = Error;
735
736 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
737 self.blocking_write(buffer)
738 }
739
740 fn bflush(&mut self) -> Result<(), Self::Error> {
741 Ok(())
742 }
743 }
744
745 impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8>
746 for UarteWithIdle<'d, U, T>
747 {
748 type Error = Error;
749
750 fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
751 self.blocking_write(buffer)
752 }
753
754 fn bflush(&mut self) -> Result<(), Self::Error> {
755 Ok(())
756 }
757 }
758}
759
760#[cfg(feature = "unstable-traits")]
761mod eh1 {
762 use super::*;
763 use core::future::Future;
764
765 impl embedded_hal_1::serial::Error for Error {
766 fn kind(&self) -> embedded_hal_1::serial::ErrorKind {
767 match *self {
768 Self::BufferTooLong => embedded_hal_1::serial::ErrorKind::Other,
769 Self::BufferZeroLength => embedded_hal_1::serial::ErrorKind::Other,
770 Self::DMABufferNotInDataMemory => embedded_hal_1::serial::ErrorKind::Other,
771 }
772 }
773 }
774
775 // =====================
776
777 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for Uarte<'d, T> {
778 type Error = Error;
779 }
780
781 impl<'d, T: Instance> embedded_hal_1::serial::blocking::Write for Uarte<'d, T> {
782 fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
783 self.blocking_write(buffer)
784 }
785
786 fn flush(&mut self) -> Result<(), Self::Error> {
787 Ok(())
788 }
789 }
790
791 impl<'d, T: Instance> embedded_hal_async::serial::Read for Uarte<'d, T> {
792 type ReadFuture<'a>
793 where
794 Self: 'a,
795 = impl Future<Output = Result<(), Self::Error>> + 'a;
796
797 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
798 self.read(buffer)
799 }
800 }
801
802 impl<'d, T: Instance> embedded_hal_async::serial::Write for Uarte<'d, T> {
803 type WriteFuture<'a>
804 where
805 Self: 'a,
806 = impl Future<Output = Result<(), Self::Error>> + 'a;
807
808 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
809 self.write(buffer)
810 }
811
812 type FlushFuture<'a>
813 where
814 Self: 'a,
815 = impl Future<Output = Result<(), Self::Error>> + 'a;
816
817 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
818 async move { Ok(()) }
819 }
820 }
821
822 // =====================
823
824 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UarteTx<'d, T> {
825 type Error = Error;
826 }
827
828 impl<'d, T: Instance> embedded_hal_1::serial::blocking::Write for UarteTx<'d, T> {
829 fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
830 self.blocking_write(buffer)
831 }
832
833 fn flush(&mut self) -> Result<(), Self::Error> {
834 Ok(())
835 }
836 }
837
838 impl<'d, T: Instance> embedded_hal_async::serial::Write for UarteTx<'d, T> {
839 type WriteFuture<'a>
840 where
841 Self: 'a,
842 = impl Future<Output = Result<(), Self::Error>> + 'a;
843
844 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
845 self.write(buffer)
846 }
847
848 type FlushFuture<'a>
849 where
850 Self: 'a,
851 = impl Future<Output = Result<(), Self::Error>> + 'a;
852
853 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
854 async move { Ok(()) }
855 }
856 }
857
858 // =====================
859
860 impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UarteRx<'d, T> {
861 type Error = Error;
862 }
863
864 impl<'d, T: Instance> embedded_hal_async::serial::Read for UarteRx<'d, T> {
865 type ReadFuture<'a>
866 where
867 Self: 'a,
868 = impl Future<Output = Result<(), Self::Error>> + 'a;
869
870 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
871 self.read(buffer)
872 }
873 }
874
875 // =====================
876
877 impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType
878 for UarteWithIdle<'d, U, T>
879 {
880 type Error = Error;
881 }
882
883 impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read
884 for UarteWithIdle<'d, U, T>
885 {
886 type ReadFuture<'a>
887 where
888 Self: 'a,
889 = impl Future<Output = Result<(), Self::Error>> + 'a;
890
891 fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
892 self.read(buffer)
893 }
894 }
895
896 impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write
897 for UarteWithIdle<'d, U, T>
898 {
899 type WriteFuture<'a>
900 where
901 Self: 'a,
902 = impl Future<Output = Result<(), Self::Error>> + 'a;
903
904 fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
905 self.write(buffer)
906 }
907
908 type FlushFuture<'a>
909 where
910 Self: 'a,
911 = impl Future<Output = Result<(), Self::Error>> + 'a;
912
913 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
914 async move { Ok(()) }
915 }
916 }
917}
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index ca013f8b7..fa7286923 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -15,7 +15,6 @@ defmt-rtt = "0.3"
15 15
16cortex-m = "0.7.3" 16cortex-m = "0.7.3"
17cortex-m-rt = "0.7.0" 17cortex-m-rt = "0.7.0"
18embedded-hal = "0.2.6"
19panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
20futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 19futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
21rand = { version = "0.8.4", default-features = false } 20rand = { version = "0.8.4", default-features = false }