aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/uarte.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 14:00:19 +0200
commit4901c34d9c4cd326ab9bca02dd099a663da2567f (patch)
tree8225afebb595fb10c1d67148c0d19b7b732853da /embassy-nrf/src/uarte.rs
parent8a9d2f59af004902d3978a2922843833b98bcce0 (diff)
Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
-rw-r--r--embassy-nrf/src/uarte.rs156
1 files changed, 78 insertions, 78 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index d5ffb3159..a556d6b9c 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -18,7 +18,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
18use core::task::Poll; 18use core::task::Poll;
19 19
20use embassy_hal_common::drop::OnDrop; 20use embassy_hal_common::drop::OnDrop;
21use embassy_hal_common::{unborrow, Unborrowed}; 21use embassy_hal_common::{into_ref, PeripheralRef};
22use futures::future::poll_fn; 22use futures::future::poll_fn;
23use pac::uarte0::RegisterBlock; 23use pac::uarte0::RegisterBlock;
24// Re-export SVD variants to allow user to directly set values. 24// Re-export SVD variants to allow user to directly set values.
@@ -31,7 +31,7 @@ use crate::interrupt::{Interrupt, InterruptExt};
31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 31use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
32use crate::timer::{Frequency, Instance as TimerInstance, Timer}; 32use crate::timer::{Frequency, Instance as TimerInstance, Timer};
33use crate::util::slice_in_ram_or; 33use crate::util::slice_in_ram_or;
34use crate::{pac, Unborrow}; 34use crate::{pac, Peripheral};
35 35
36#[derive(Clone)] 36#[derive(Clone)]
37#[non_exhaustive] 37#[non_exhaustive]
@@ -83,40 +83,40 @@ pub struct UarteRx<'d, T: Instance> {
83impl<'d, T: Instance> Uarte<'d, T> { 83impl<'d, T: Instance> Uarte<'d, T> {
84 /// Create a new UARTE without hardware flow control 84 /// Create a new UARTE without hardware flow control
85 pub fn new( 85 pub fn new(
86 uarte: impl Unborrow<Target = T> + 'd, 86 uarte: impl Peripheral<P = T> + 'd,
87 irq: impl Unborrow<Target = T::Interrupt> + 'd, 87 irq: impl Peripheral<P = T::Interrupt> + 'd,
88 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 88 rxd: impl Peripheral<P = impl GpioPin> + 'd,
89 txd: impl Unborrow<Target = impl GpioPin> + 'd, 89 txd: impl Peripheral<P = impl GpioPin> + 'd,
90 config: Config, 90 config: Config,
91 ) -> Self { 91 ) -> Self {
92 unborrow_and_degrade!(rxd, txd); 92 into_degraded_ref!(rxd, txd);
93 Self::new_inner(uarte, irq, rxd, txd, None, None, config) 93 Self::new_inner(uarte, irq, rxd, txd, None, None, config)
94 } 94 }
95 95
96 /// Create a new UARTE with hardware flow control (RTS/CTS) 96 /// Create a new UARTE with hardware flow control (RTS/CTS)
97 pub fn new_with_rtscts( 97 pub fn new_with_rtscts(
98 uarte: impl Unborrow<Target = T> + 'd, 98 uarte: impl Peripheral<P = T> + 'd,
99 irq: impl Unborrow<Target = T::Interrupt> + 'd, 99 irq: impl Peripheral<P = T::Interrupt> + 'd,
100 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 100 rxd: impl Peripheral<P = impl GpioPin> + 'd,
101 txd: impl Unborrow<Target = impl GpioPin> + 'd, 101 txd: impl Peripheral<P = impl GpioPin> + 'd,
102 cts: impl Unborrow<Target = impl GpioPin> + 'd, 102 cts: impl Peripheral<P = impl GpioPin> + 'd,
103 rts: impl Unborrow<Target = impl GpioPin> + 'd, 103 rts: impl Peripheral<P = impl GpioPin> + 'd,
104 config: Config, 104 config: Config,
105 ) -> Self { 105 ) -> Self {
106 unborrow_and_degrade!(rxd, txd, cts, rts); 106 into_degraded_ref!(rxd, txd, cts, rts);
107 Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config) 107 Self::new_inner(uarte, irq, rxd, txd, Some(cts), Some(rts), config)
108 } 108 }
109 109
110 fn new_inner( 110 fn new_inner(
111 _uarte: impl Unborrow<Target = T> + 'd, 111 _uarte: impl Peripheral<P = T> + 'd,
112 irq: impl Unborrow<Target = T::Interrupt> + 'd, 112 irq: impl Peripheral<P = T::Interrupt> + 'd,
113 rxd: Unborrowed<'d, AnyPin>, 113 rxd: PeripheralRef<'d, AnyPin>,
114 txd: Unborrowed<'d, AnyPin>, 114 txd: PeripheralRef<'d, AnyPin>,
115 cts: Option<Unborrowed<'d, AnyPin>>, 115 cts: Option<PeripheralRef<'d, AnyPin>>,
116 rts: Option<Unborrowed<'d, AnyPin>>, 116 rts: Option<PeripheralRef<'d, AnyPin>>,
117 config: Config, 117 config: Config,
118 ) -> Self { 118 ) -> Self {
119 unborrow!(irq); 119 into_ref!(irq);
120 120
121 let r = T::regs(); 121 let r = T::regs();
122 122
@@ -237,35 +237,35 @@ fn configure(r: &RegisterBlock, config: Config, hardware_flow_control: bool) {
237impl<'d, T: Instance> UarteTx<'d, T> { 237impl<'d, T: Instance> UarteTx<'d, T> {
238 /// Create a new tx-only UARTE without hardware flow control 238 /// Create a new tx-only UARTE without hardware flow control
239 pub fn new( 239 pub fn new(
240 uarte: impl Unborrow<Target = T> + 'd, 240 uarte: impl Peripheral<P = T> + 'd,
241 irq: impl Unborrow<Target = T::Interrupt> + 'd, 241 irq: impl Peripheral<P = T::Interrupt> + 'd,
242 txd: impl Unborrow<Target = impl GpioPin> + 'd, 242 txd: impl Peripheral<P = impl GpioPin> + 'd,
243 config: Config, 243 config: Config,
244 ) -> Self { 244 ) -> Self {
245 unborrow_and_degrade!(txd); 245 into_degraded_ref!(txd);
246 Self::new_inner(uarte, irq, txd, None, config) 246 Self::new_inner(uarte, irq, txd, None, config)
247 } 247 }
248 248
249 /// Create a new tx-only UARTE with hardware flow control (RTS/CTS) 249 /// Create a new tx-only UARTE with hardware flow control (RTS/CTS)
250 pub fn new_with_rtscts( 250 pub fn new_with_rtscts(
251 uarte: impl Unborrow<Target = T> + 'd, 251 uarte: impl Peripheral<P = T> + 'd,
252 irq: impl Unborrow<Target = T::Interrupt> + 'd, 252 irq: impl Peripheral<P = T::Interrupt> + 'd,
253 txd: impl Unborrow<Target = impl GpioPin> + 'd, 253 txd: impl Peripheral<P = impl GpioPin> + 'd,
254 cts: impl Unborrow<Target = impl GpioPin> + 'd, 254 cts: impl Peripheral<P = impl GpioPin> + 'd,
255 config: Config, 255 config: Config,
256 ) -> Self { 256 ) -> Self {
257 unborrow_and_degrade!(txd, cts); 257 into_degraded_ref!(txd, cts);
258 Self::new_inner(uarte, irq, txd, Some(cts), config) 258 Self::new_inner(uarte, irq, txd, Some(cts), config)
259 } 259 }
260 260
261 fn new_inner( 261 fn new_inner(
262 _uarte: impl Unborrow<Target = T> + 'd, 262 _uarte: impl Peripheral<P = T> + 'd,
263 irq: impl Unborrow<Target = T::Interrupt> + 'd, 263 irq: impl Peripheral<P = T::Interrupt> + 'd,
264 txd: Unborrowed<'d, AnyPin>, 264 txd: PeripheralRef<'d, AnyPin>,
265 cts: Option<Unborrowed<'d, AnyPin>>, 265 cts: Option<PeripheralRef<'d, AnyPin>>,
266 config: Config, 266 config: Config,
267 ) -> Self { 267 ) -> Self {
268 unborrow!(irq); 268 into_ref!(irq);
269 269
270 let r = T::regs(); 270 let r = T::regs();
271 271
@@ -429,35 +429,35 @@ impl<'a, T: Instance> Drop for UarteTx<'a, T> {
429impl<'d, T: Instance> UarteRx<'d, T> { 429impl<'d, T: Instance> UarteRx<'d, T> {
430 /// Create a new rx-only UARTE without hardware flow control 430 /// Create a new rx-only UARTE without hardware flow control
431 pub fn new( 431 pub fn new(
432 uarte: impl Unborrow<Target = T> + 'd, 432 uarte: impl Peripheral<P = T> + 'd,
433 irq: impl Unborrow<Target = T::Interrupt> + 'd, 433 irq: impl Peripheral<P = T::Interrupt> + 'd,
434 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 434 rxd: impl Peripheral<P = impl GpioPin> + 'd,
435 config: Config, 435 config: Config,
436 ) -> Self { 436 ) -> Self {
437 unborrow_and_degrade!(rxd); 437 into_degraded_ref!(rxd);
438 Self::new_inner(uarte, irq, rxd, None, config) 438 Self::new_inner(uarte, irq, rxd, None, config)
439 } 439 }
440 440
441 /// Create a new rx-only UARTE with hardware flow control (RTS/CTS) 441 /// Create a new rx-only UARTE with hardware flow control (RTS/CTS)
442 pub fn new_with_rtscts( 442 pub fn new_with_rtscts(
443 uarte: impl Unborrow<Target = T> + 'd, 443 uarte: impl Peripheral<P = T> + 'd,
444 irq: impl Unborrow<Target = T::Interrupt> + 'd, 444 irq: impl Peripheral<P = T::Interrupt> + 'd,
445 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 445 rxd: impl Peripheral<P = impl GpioPin> + 'd,
446 rts: impl Unborrow<Target = impl GpioPin> + 'd, 446 rts: impl Peripheral<P = impl GpioPin> + 'd,
447 config: Config, 447 config: Config,
448 ) -> Self { 448 ) -> Self {
449 unborrow_and_degrade!(rxd, rts); 449 into_degraded_ref!(rxd, rts);
450 Self::new_inner(uarte, irq, rxd, Some(rts), config) 450 Self::new_inner(uarte, irq, rxd, Some(rts), config)
451 } 451 }
452 452
453 fn new_inner( 453 fn new_inner(
454 _uarte: impl Unborrow<Target = T> + 'd, 454 _uarte: impl Peripheral<P = T> + 'd,
455 irq: impl Unborrow<Target = T::Interrupt> + 'd, 455 irq: impl Peripheral<P = T::Interrupt> + 'd,
456 rxd: Unborrowed<'d, AnyPin>, 456 rxd: PeripheralRef<'d, AnyPin>,
457 rts: Option<Unborrowed<'d, AnyPin>>, 457 rts: Option<PeripheralRef<'d, AnyPin>>,
458 config: Config, 458 config: Config,
459 ) -> Self { 459 ) -> Self {
460 unborrow!(irq); 460 into_ref!(irq);
461 461
462 let r = T::regs(); 462 let r = T::regs();
463 463
@@ -668,33 +668,33 @@ pub struct UarteWithIdle<'d, U: Instance, T: TimerInstance> {
668impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> { 668impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
669 /// Create a new UARTE without hardware flow control 669 /// Create a new UARTE without hardware flow control
670 pub fn new( 670 pub fn new(
671 uarte: impl Unborrow<Target = U> + 'd, 671 uarte: impl Peripheral<P = U> + 'd,
672 timer: impl Unborrow<Target = T> + 'd, 672 timer: impl Peripheral<P = T> + 'd,
673 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 673 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
674 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 674 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
675 irq: impl Unborrow<Target = U::Interrupt> + 'd, 675 irq: impl Peripheral<P = U::Interrupt> + 'd,
676 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 676 rxd: impl Peripheral<P = impl GpioPin> + 'd,
677 txd: impl Unborrow<Target = impl GpioPin> + 'd, 677 txd: impl Peripheral<P = impl GpioPin> + 'd,
678 config: Config, 678 config: Config,
679 ) -> Self { 679 ) -> Self {
680 unborrow_and_degrade!(rxd, txd); 680 into_degraded_ref!(rxd, txd);
681 Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config) 681 Self::new_inner(uarte, timer, ppi_ch1, ppi_ch2, irq, rxd, txd, None, None, config)
682 } 682 }
683 683
684 /// Create a new UARTE with hardware flow control (RTS/CTS) 684 /// Create a new UARTE with hardware flow control (RTS/CTS)
685 pub fn new_with_rtscts( 685 pub fn new_with_rtscts(
686 uarte: impl Unborrow<Target = U> + 'd, 686 uarte: impl Peripheral<P = U> + 'd,
687 timer: impl Unborrow<Target = T> + 'd, 687 timer: impl Peripheral<P = T> + 'd,
688 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 688 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
689 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 689 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
690 irq: impl Unborrow<Target = U::Interrupt> + 'd, 690 irq: impl Peripheral<P = U::Interrupt> + 'd,
691 rxd: impl Unborrow<Target = impl GpioPin> + 'd, 691 rxd: impl Peripheral<P = impl GpioPin> + 'd,
692 txd: impl Unborrow<Target = impl GpioPin> + 'd, 692 txd: impl Peripheral<P = impl GpioPin> + 'd,
693 cts: impl Unborrow<Target = impl GpioPin> + 'd, 693 cts: impl Peripheral<P = impl GpioPin> + 'd,
694 rts: impl Unborrow<Target = impl GpioPin> + 'd, 694 rts: impl Peripheral<P = impl GpioPin> + 'd,
695 config: Config, 695 config: Config,
696 ) -> Self { 696 ) -> Self {
697 unborrow_and_degrade!(rxd, txd, cts, rts); 697 into_degraded_ref!(rxd, txd, cts, rts);
698 Self::new_inner( 698 Self::new_inner(
699 uarte, 699 uarte,
700 timer, 700 timer,
@@ -710,15 +710,15 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
710 } 710 }
711 711
712 fn new_inner( 712 fn new_inner(
713 uarte: impl Unborrow<Target = U> + 'd, 713 uarte: impl Peripheral<P = U> + 'd,
714 timer: impl Unborrow<Target = T> + 'd, 714 timer: impl Peripheral<P = T> + 'd,
715 ppi_ch1: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 715 ppi_ch1: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
716 ppi_ch2: impl Unborrow<Target = impl ConfigurableChannel + 'd> + 'd, 716 ppi_ch2: impl Peripheral<P = impl ConfigurableChannel + 'd> + 'd,
717 irq: impl Unborrow<Target = U::Interrupt> + 'd, 717 irq: impl Peripheral<P = U::Interrupt> + 'd,
718 rxd: Unborrowed<'d, AnyPin>, 718 rxd: PeripheralRef<'d, AnyPin>,
719 txd: Unborrowed<'d, AnyPin>, 719 txd: PeripheralRef<'d, AnyPin>,
720 cts: Option<Unborrowed<'d, AnyPin>>, 720 cts: Option<PeripheralRef<'d, AnyPin>>,
721 rts: Option<Unborrowed<'d, AnyPin>>, 721 rts: Option<PeripheralRef<'d, AnyPin>>,
722 config: Config, 722 config: Config,
723 ) -> Self { 723 ) -> Self {
724 let baudrate = config.baudrate; 724 let baudrate = config.baudrate;
@@ -726,7 +726,7 @@ impl<'d, U: Instance, T: TimerInstance> UarteWithIdle<'d, U, T> {
726 726
727 let mut timer = Timer::new(timer); 727 let mut timer = Timer::new(timer);
728 728
729 unborrow!(ppi_ch1, ppi_ch2); 729 into_ref!(ppi_ch1, ppi_ch2);
730 730
731 let r = U::regs(); 731 let r = U::regs();
732 732
@@ -939,7 +939,7 @@ pub(crate) mod sealed {
939 } 939 }
940} 940}
941 941
942pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { 942pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
943 type Interrupt: Interrupt; 943 type Interrupt: Interrupt;
944} 944}
945 945