aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2022-07-03 16:54:01 -0500
committerDario Nieuwenhuis <[email protected]>2022-07-23 01:33:22 +0200
commitbff0ad9286ea219d0e19855b8ed8ba3e1a0f1bdf (patch)
tree46bd08d03a40fc4bd0828e95d62ad6e513298645
parent65a82d02d17fc491246eae219f416e565719c0ac (diff)
Update embassy-rp
-rw-r--r--embassy-nrf/src/gpio.rs2
-rw-r--r--embassy-rp/src/gpio.rs42
-rw-r--r--embassy-rp/src/spi.rs53
-rw-r--r--embassy-rp/src/uart.rs12
4 files changed, 50 insertions, 59 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index e5764f8a0..53ca15d3d 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -417,7 +417,7 @@ impl AnyPin {
417 Self { pin_port } 417 Self { pin_port }
418 } 418 }
419 419
420 pub fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> { 420 pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
421 Unborrowed::new(AnyPin { 421 Unborrowed::new(AnyPin {
422 pin_port: pin.unborrow().pin_port(), 422 pin_port: pin.unborrow().pin_port(),
423 }) 423 })
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index 53c26de1c..94d0f25c7 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -1,11 +1,11 @@
1#![macro_use]
1use core::future::Future; 2use core::future::Future;
2use core::marker::PhantomData;
3use core::pin::Pin as FuturePin; 3use core::pin::Pin as FuturePin;
4use core::task::{Context, Poll}; 4use core::task::{Context, Poll};
5 5
6use embassy::waitqueue::AtomicWaker; 6use embassy::waitqueue::AtomicWaker;
7use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; 7use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
8use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 8use embassy_hal_common::{unborrow, unsafe_impl_unborrow, Unborrowed};
9 9
10use crate::pac::common::{Reg, RW}; 10use crate::pac::common::{Reg, RW};
11use crate::pac::SIO; 11use crate::pac::SIO;
@@ -177,13 +177,13 @@ unsafe fn IO_IRQ_BANK0() {
177} 177}
178 178
179struct InputFuture<'a, T: Pin> { 179struct InputFuture<'a, T: Pin> {
180 pin: &'a mut T, 180 pin: Unborrowed<'a, T>,
181 level: InterruptTrigger, 181 level: InterruptTrigger,
182 phantom: PhantomData<&'a mut AnyPin>,
183} 182}
184 183
185impl<'d, T: Pin> InputFuture<'d, T> { 184impl<'d, T: Pin> InputFuture<'d, T> {
186 pub fn new(pin: &'d mut T, level: InterruptTrigger) -> Self { 185 pub fn new(pin: impl Unborrow<Target = T> + 'd, level: InterruptTrigger) -> Self {
186 unborrow!(pin);
187 unsafe { 187 unsafe {
188 let irq = interrupt::IO_IRQ_BANK0::steal(); 188 let irq = interrupt::IO_IRQ_BANK0::steal();
189 irq.disable(); 189 irq.disable();
@@ -215,11 +215,7 @@ impl<'d, T: Pin> InputFuture<'d, T> {
215 irq.enable(); 215 irq.enable();
216 } 216 }
217 217
218 Self { 218 Self { pin, level }
219 pin,
220 level,
221 phantom: PhantomData,
222 }
223 } 219 }
224} 220}
225 221
@@ -419,8 +415,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
419/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output 415/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
420/// mode. 416/// mode.
421pub struct Flex<'d, T: Pin> { 417pub struct Flex<'d, T: Pin> {
422 pin: T, 418 pin: Unborrowed<'d, T>,
423 phantom: PhantomData<&'d mut T>,
424} 419}
425 420
426impl<'d, T: Pin> Flex<'d, T> { 421impl<'d, T: Pin> Flex<'d, T> {
@@ -438,10 +433,7 @@ impl<'d, T: Pin> Flex<'d, T> {
438 }); 433 });
439 } 434 }
440 435
441 Self { 436 Self { pin }
442 pin,
443 phantom: PhantomData,
444 }
445 } 437 }
446 438
447 #[inline] 439 #[inline]
@@ -667,7 +659,25 @@ pub trait Pin: Unborrow<Target = Self> + sealed::Pin {
667pub struct AnyPin { 659pub struct AnyPin {
668 pin_bank: u8, 660 pin_bank: u8,
669} 661}
662
663impl AnyPin {
664 pub(crate) fn unborrow_and_degrade<'a>(pin: impl Unborrow<Target = impl Pin + 'a> + 'a) -> Unborrowed<'a, Self> {
665 Unborrowed::new(AnyPin {
666 pin_bank: pin.unborrow().pin_bank(),
667 })
668 }
669}
670
671macro_rules! unborrow_and_degrade {
672 ($($name:ident),*) => {
673 $(
674 let $name = $crate::gpio::AnyPin::unborrow_and_degrade($name);
675 )*
676 };
677}
678
670unsafe_impl_unborrow!(AnyPin); 679unsafe_impl_unborrow!(AnyPin);
680
671impl Pin for AnyPin {} 681impl Pin for AnyPin {}
672impl sealed::Pin for AnyPin { 682impl sealed::Pin for AnyPin {
673 fn pin_bank(&self) -> u8 { 683 fn pin_bank(&self) -> u8 {
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index 6b3f2238a..df030942e 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -1,7 +1,5 @@
1use core::marker::PhantomData;
2
3use embassy_embedded_hal::SetConfig; 1use embassy_embedded_hal::SetConfig;
4use embassy_hal_common::unborrow; 2use embassy_hal_common::{unborrow, Unborrowed};
5pub use embedded_hal_02::spi::{Phase, Polarity}; 3pub use embedded_hal_02::spi::{Phase, Polarity};
6 4
7use crate::gpio::sealed::Pin as _; 5use crate::gpio::sealed::Pin as _;
@@ -33,8 +31,7 @@ impl Default for Config {
33} 31}
34 32
35pub struct Spi<'d, T: Instance> { 33pub struct Spi<'d, T: Instance> {
36 inner: T, 34 inner: Unborrowed<'d, T>,
37 phantom: PhantomData<&'d mut T>,
38} 35}
39 36
40fn div_roundup(a: u32, b: u32) -> u32 { 37fn div_roundup(a: u32, b: u32) -> u32 {
@@ -63,48 +60,41 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
63impl<'d, T: Instance> Spi<'d, T> { 60impl<'d, T: Instance> Spi<'d, T> {
64 pub fn new( 61 pub fn new(
65 inner: impl Unborrow<Target = T> + 'd, 62 inner: impl Unborrow<Target = T> + 'd,
66 clk: impl Unborrow<Target = impl ClkPin<T>> + 'd, 63 clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
67 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, 64 mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
68 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, 65 miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
69 config: Config, 66 config: Config,
70 ) -> Self { 67 ) -> Self {
71 unborrow!(clk, mosi, miso); 68 unborrow_and_degrade!(clk, mosi, miso);
72 Self::new_inner( 69 Self::new_inner(inner, Some(clk), Some(mosi), Some(miso), None, config)
73 inner,
74 Some(clk.degrade()),
75 Some(mosi.degrade()),
76 Some(miso.degrade()),
77 None,
78 config,
79 )
80 } 70 }
81 71
82 pub fn new_txonly( 72 pub fn new_txonly(
83 inner: impl Unborrow<Target = T> + 'd, 73 inner: impl Unborrow<Target = T> + 'd,
84 clk: impl Unborrow<Target = impl ClkPin<T>> + 'd, 74 clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
85 mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd, 75 mosi: impl Unborrow<Target = impl MosiPin<T> + 'd> + 'd,
86 config: Config, 76 config: Config,
87 ) -> Self { 77 ) -> Self {
88 unborrow!(clk, mosi); 78 unborrow_and_degrade!(clk, mosi);
89 Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config) 79 Self::new_inner(inner, Some(clk), Some(mosi), None, None, config)
90 } 80 }
91 81
92 pub fn new_rxonly( 82 pub fn new_rxonly(
93 inner: impl Unborrow<Target = T> + 'd, 83 inner: impl Unborrow<Target = T> + 'd,
94 clk: impl Unborrow<Target = impl ClkPin<T>> + 'd, 84 clk: impl Unborrow<Target = impl ClkPin<T> + 'd> + 'd,
95 miso: impl Unborrow<Target = impl MisoPin<T>> + 'd, 85 miso: impl Unborrow<Target = impl MisoPin<T> + 'd> + 'd,
96 config: Config, 86 config: Config,
97 ) -> Self { 87 ) -> Self {
98 unborrow!(clk, miso); 88 unborrow_and_degrade!(clk, miso);
99 Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config) 89 Self::new_inner(inner, Some(clk), None, Some(miso), None, config)
100 } 90 }
101 91
102 fn new_inner( 92 fn new_inner(
103 inner: impl Unborrow<Target = T> + 'd, 93 inner: impl Unborrow<Target = T> + 'd,
104 clk: Option<AnyPin>, 94 clk: Option<Unborrowed<'d, AnyPin>>,
105 mosi: Option<AnyPin>, 95 mosi: Option<Unborrowed<'d, AnyPin>>,
106 miso: Option<AnyPin>, 96 miso: Option<Unborrowed<'d, AnyPin>>,
107 cs: Option<AnyPin>, 97 cs: Option<Unborrowed<'d, AnyPin>>,
108 config: Config, 98 config: Config,
109 ) -> Self { 99 ) -> Self {
110 unborrow!(inner); 100 unborrow!(inner);
@@ -137,10 +127,7 @@ impl<'d, T: Instance> Spi<'d, T> {
137 pin.io().ctrl().write(|w| w.set_funcsel(1)); 127 pin.io().ctrl().write(|w| w.set_funcsel(1));
138 } 128 }
139 } 129 }
140 Self { 130 Self { inner }
141 inner,
142 phantom: PhantomData,
143 }
144 } 131 }
145 132
146 pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error> { 133 pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error> {
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs
index c95407b6f..33119af6a 100644
--- a/embassy-rp/src/uart.rs
+++ b/embassy-rp/src/uart.rs
@@ -1,6 +1,4 @@
1use core::marker::PhantomData; 1use embassy_hal_common::{unborrow, Unborrowed};
2
3use embassy_hal_common::unborrow;
4use gpio::Pin; 2use gpio::Pin;
5 3
6use crate::{gpio, pac, peripherals, Unborrow}; 4use crate::{gpio, pac, peripherals, Unborrow};
@@ -23,8 +21,7 @@ impl Default for Config {
23} 21}
24 22
25pub struct Uart<'d, T: Instance> { 23pub struct Uart<'d, T: Instance> {
26 inner: T, 24 inner: Unborrowed<'d, T>,
27 phantom: PhantomData<&'d mut T>,
28} 25}
29 26
30impl<'d, T: Instance> Uart<'d, T> { 27impl<'d, T: Instance> Uart<'d, T> {
@@ -78,10 +75,7 @@ impl<'d, T: Instance> Uart<'d, T> {
78 cts.io().ctrl().write(|w| w.set_funcsel(2)); 75 cts.io().ctrl().write(|w| w.set_funcsel(2));
79 rts.io().ctrl().write(|w| w.set_funcsel(2)); 76 rts.io().ctrl().write(|w| w.set_funcsel(2));
80 } 77 }
81 Self { 78 Self { inner }
82 inner,
83 phantom: PhantomData,
84 }
85 } 79 }
86 80
87 pub fn send(&mut self, data: &[u8]) { 81 pub fn send(&mut self, data: &[u8]) {