diff options
| author | Jeremy Fitzhardinge <[email protected]> | 2022-10-16 18:00:23 -0700 |
|---|---|---|
| committer | Jeremy Fitzhardinge <[email protected]> | 2022-10-16 18:00:23 -0700 |
| commit | e4c2b2aa9a61e5135d2e129705c9bdc3b4cb73ae (patch) | |
| tree | 6e1036a519ee5facbbd973e5708c61eff14766cf | |
| parent | b7d09442650d765562b25f9f27d654c2ef5e014a (diff) | |
rp i2c: have separate wakers for each i2c unit
If they both share one waker, there's the possibility that some wakeups
could get lost.
| -rw-r--r-- | embassy-rp/src/i2c.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 68cfc653e..b9e4382c7 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -70,7 +70,7 @@ impl<'d, T: Instance> I2c<'d, T, Blocking> { | |||
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | static I2C_WAKER: AtomicWaker = AtomicWaker::new(); | 73 | static I2C_WAKER: [AtomicWaker; 2] = [AtomicWaker::new(), AtomicWaker::new()]; |
| 74 | 74 | ||
| 75 | impl<'d, T: Instance> I2c<'d, T, Async> { | 75 | impl<'d, T: Instance> I2c<'d, T, Async> { |
| 76 | pub fn new_async( | 76 | pub fn new_async( |
| @@ -109,7 +109,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> { | |||
| 109 | let r = f(self); | 109 | let r = f(self); |
| 110 | 110 | ||
| 111 | if r.is_pending() { | 111 | if r.is_pending() { |
| 112 | I2C_WAKER.register(cx.waker()); | 112 | I2C_WAKER[T::IDX].register(cx.waker()); |
| 113 | g(self); | 113 | g(self); |
| 114 | } | 114 | } |
| 115 | r | 115 | r |
| @@ -122,7 +122,7 @@ impl<'d, T: Instance> I2c<'d, T, Async> { | |||
| 122 | let i2c = T::regs(); | 122 | let i2c = T::regs(); |
| 123 | i2c.ic_intr_mask().write_value(pac::i2c::regs::IcIntrMask::default()); | 123 | i2c.ic_intr_mask().write_value(pac::i2c::regs::IcIntrMask::default()); |
| 124 | 124 | ||
| 125 | I2C_WAKER.wake(); | 125 | I2C_WAKER[T::IDX].wake(); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | async fn read_async_internal(&mut self, buffer: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> { | 128 | async fn read_async_internal(&mut self, buffer: &mut [u8], restart: bool, send_stop: bool) -> Result<(), Error> { |
| @@ -813,6 +813,7 @@ mod sealed { | |||
| 813 | pub trait Instance { | 813 | pub trait Instance { |
| 814 | const TX_DREQ: u8; | 814 | const TX_DREQ: u8; |
| 815 | const RX_DREQ: u8; | 815 | const RX_DREQ: u8; |
| 816 | const IDX: usize; | ||
| 816 | 817 | ||
| 817 | type Interrupt: Interrupt; | 818 | type Interrupt: Interrupt; |
| 818 | 819 | ||
| @@ -844,10 +845,11 @@ impl_mode!(Async); | |||
| 844 | pub trait Instance: sealed::Instance {} | 845 | pub trait Instance: sealed::Instance {} |
| 845 | 846 | ||
| 846 | macro_rules! impl_instance { | 847 | macro_rules! impl_instance { |
| 847 | ($type:ident, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { | 848 | ($type:ident, $idx:expr, $irq:ident, $reset:ident, $tx_dreq:expr, $rx_dreq:expr) => { |
| 848 | impl sealed::Instance for peripherals::$type { | 849 | impl sealed::Instance for peripherals::$type { |
| 849 | const TX_DREQ: u8 = $tx_dreq; | 850 | const TX_DREQ: u8 = $tx_dreq; |
| 850 | const RX_DREQ: u8 = $rx_dreq; | 851 | const RX_DREQ: u8 = $rx_dreq; |
| 852 | const IDX: usize = $idx; | ||
| 851 | 853 | ||
| 852 | type Interrupt = crate::interrupt::$irq; | 854 | type Interrupt = crate::interrupt::$irq; |
| 853 | 855 | ||
| @@ -867,8 +869,8 @@ macro_rules! impl_instance { | |||
| 867 | }; | 869 | }; |
| 868 | } | 870 | } |
| 869 | 871 | ||
| 870 | impl_instance!(I2C0, I2C0_IRQ, set_i2c0, 32, 33); | 872 | impl_instance!(I2C0, 0, I2C0_IRQ, set_i2c0, 32, 33); |
| 871 | impl_instance!(I2C1, I2C1_IRQ, set_i2c1, 34, 35); | 873 | impl_instance!(I2C1, 1, I2C1_IRQ, set_i2c1, 34, 35); |
| 872 | 874 | ||
| 873 | pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + crate::gpio::Pin {} | 875 | pub trait SdaPin<T: Instance>: sealed::SdaPin<T> + crate::gpio::Pin {} |
| 874 | pub trait SclPin<T: Instance>: sealed::SclPin<T> + crate::gpio::Pin {} | 876 | pub trait SclPin<T: Instance>: sealed::SclPin<T> + crate::gpio::Pin {} |
