diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-18 08:29:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 08:29:43 +0000 |
commit | 18453ee64c7d1b397aa96cb322cedee6166b4602 (patch) | |
tree | d4e8492ba812ab18d953a630557fc0e25f0007bd | |
parent | b7d09442650d765562b25f9f27d654c2ef5e014a (diff) | |
parent | 02a3cdb507d535908bc0668a31526c05b5d01005 (diff) | |
download | embassy-18453ee64c7d1b397aa96cb322cedee6166b4602.zip |
Merge #1012
1012: rp i2c: have separate wakers for each i2c unit r=Dirbaio a=jsgf
If they both share one waker, there's the possibility that some wakeups could get lost.
Co-authored-by: Jeremy Fitzhardinge <jeremy@goop.org>
-rw-r--r-- | embassy-rp/src/i2c.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 68cfc653..d6742f6a 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> { } } -static I2C_WAKER: AtomicWaker = AtomicWaker::new(); - impl<'d, T: Instance> I2c<'d, T, Async> { pub fn new_async( peri: impl Peripheral<P = T> + 'd, @@ -109,7 +107,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> { let r = f(self); if r.is_pending() { - I2C_WAKER.register(cx.waker()); + T::waker().register(cx.waker()); g(self); } r @@ -122,7 +120,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> { let i2c = T::regs(); i2c.ic_intr_mask().write_value(pac::i2c::regs::IcIntrMask::default()); - I2C_WAKER.wake(); + T::waker().wake(); } 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 { mod sealed { use embassy_cortex_m::interrupt::Interrupt; + use embassy_sync::waitqueue::AtomicWaker; pub trait Instance { const TX_DREQ: u8; @@ -818,6 +817,7 @@ mod sealed { fn regs() -> crate::pac::i2c::I2c; fn reset() -> crate::pac::resets::regs::Peripherals; + fn waker() -> &'static AtomicWaker; } pub trait Mode {} @@ -862,6 +862,13 @@ macro_rules! impl_instance { ret.$reset(true); ret } + + #[inline] + fn waker() -> &'static AtomicWaker { + static WAKER: AtomicWaker = AtomicWaker::new(); + + &WAKER + } } impl Instance for peripherals::$type {} }; |