aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/i2c.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs
index 68cfc653e..d6742f6a6 100644
--- a/embassy-rp/src/i2c.rs
+++ b/embassy-rp/src/i2c.rs
@@ -70,8 +70,6 @@ impl<'d, T: Instance> I2c<'d, T, Blocking> {
70 } 70 }
71} 71}
72 72
73static I2C_WAKER: AtomicWaker = AtomicWaker::new();
74
75impl<'d, T: Instance> I2c<'d, T, Async> { 73impl<'d, T: Instance> I2c<'d, T, Async> {
76 pub fn new_async( 74 pub fn new_async(
77 peri: impl Peripheral<P = T> + 'd, 75 peri: impl Peripheral<P = T> + 'd,
@@ -109,7 +107,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> {
109 let r = f(self); 107 let r = f(self);
110 108
111 if r.is_pending() { 109 if r.is_pending() {
112 I2C_WAKER.register(cx.waker()); 110 T::waker().register(cx.waker());
113 g(self); 111 g(self);
114 } 112 }
115 r 113 r
@@ -122,7 +120,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> {
122 let i2c = T::regs(); 120 let i2c = T::regs();
123 i2c.ic_intr_mask().write_value(pac::i2c::regs::IcIntrMask::default()); 121 i2c.ic_intr_mask().write_value(pac::i2c::regs::IcIntrMask::default());
124 122
125 I2C_WAKER.wake(); 123 T::waker().wake();
126 } 124 }
127 125
128 async fn read_async_internal(&mut self, buffer: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> { 126 async fn read_async_internal(&mut self, buffer: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> {
@@ -809,6 +807,7 @@ fn i2c_reserved_addr(addr: u16) -> bool {
809 807
810mod sealed { 808mod sealed {
811 use embassy_cortex_m::interrupt::Interrupt; 809 use embassy_cortex_m::interrupt::Interrupt;
810 use embassy_sync::waitqueue::AtomicWaker;
812 811
813 pub trait Instance { 812 pub trait Instance {
814 const TX_DREQ: u8; 813 const TX_DREQ: u8;
@@ -818,6 +817,7 @@ mod sealed {
818 817
819 fn regs() -> crate::pac::i2c::I2c; 818 fn regs() -> crate::pac::i2c::I2c;
820 fn reset() -> crate::pac::resets::regs::Peripherals; 819 fn reset() -> crate::pac::resets::regs::Peripherals;
820 fn waker() -> &'static AtomicWaker;
821 } 821 }
822 822
823 pub trait Mode {} 823 pub trait Mode {}
@@ -862,6 +862,13 @@ macro_rules! impl_instance {
862 ret.$reset(true); 862 ret.$reset(true);
863 ret 863 ret
864 } 864 }
865
866 #[inline]
867 fn waker() -> &'static AtomicWaker {
868 static WAKER: AtomicWaker = AtomicWaker::new();
869
870 &WAKER
871 }
865 } 872 }
866 impl Instance for peripherals::$type {} 873 impl Instance for peripherals::$type {}
867 }; 874 };