Skip to content

Commit

Permalink
Minor documentation updates & mask interrupts on cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
ithinuel committed Jan 7, 2024
1 parent 1662f53 commit 643d281
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion rp2040-hal/examples/i2c_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This application demonstrates how to talk to I²C devices with an RP2040.
//! in an Async environment.
//!
//! This example does not set a `waker_setter` and defaults to polling.
//! This example does not set `on_pending` and defaults to polling.
//!
//! It may need to be adapted to your particular board layout and/or pin assignment.
//!
Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/examples/i2c_async_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! This application demonstrates how to talk to I²C devices with an RP2040.
//! in an Async environment.
//!
//! This example sets a `waker_setter` and is able to sleep when the task is pending on i2c
//! updates..
//! This example sets `on_pending` and `on_cancel`. It is able to sleep when the task is pending on
//! i2c updates and clear a saved waker when the future is dropped before completion.
//!
//! It may need to be adapted to your particular board layout and/or pin assignment.
//!
Expand Down
6 changes: 3 additions & 3 deletions rp2040-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ valid_pins! {
}
}

/// Operational mode of the I2C Block.
/// Operational mode of the I2C peripheral.
pub trait I2CMode: Sealed {
/// Indicates whether this mode is Controller or Peripheral.
const IS_CONTROLLER: bool;
}
/// Operational mode of the I2C block running as Controller.
/// Operational mode of the I2C peripheral running as Controller.
pub trait I2CControllerMode: Sealed {}

/// Marker for an I2C block operating as a controller.
/// Marker for an I2C peripheral operating as a controller.
pub struct Controller<Mode: I2CControllerMode> {
#[cfg_attr(not(feature = "eh1_0_alpha"), allow(dead_code))]
m: Mode,
Expand Down
23 changes: 15 additions & 8 deletions rp2040-hal/src/i2c/controller/eh1_0_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@ where

#[inline]
fn check_tx_ready(&mut self) -> Poll<Result<(), u32>> {
{
if let Some(abort_reason) = self.read_and_clear_abort_reason() {
Poll::Ready(Err(abort_reason))
} else if !self.tx_fifo_full() {
Poll::Ready(Ok(()))
} else {
Poll::Pending
}
if let Some(abort_reason) = self.read_and_clear_abort_reason() {
Poll::Ready(Err(abort_reason))
} else if !self.tx_fifo_full() {
Poll::Ready(Ok(()))
} else {
Poll::Pending
}
}

Expand All @@ -188,6 +186,15 @@ where
if let Some(on_cancel) = self.mode.m.on_cancel {
(on_cancel)();
}
self.i2c.ic_intr_mask.modify(|_, w| {
w.m_rx_full()
.enabled()
.m_tx_empty()
.enabled()
.m_tx_abrt()
.enabled()
});

self.i2c.ic_enable.modify(|_, w| w.abort().set_bit());
while self.i2c.ic_enable.read().abort().bit_is_set() {
cortex_m::asm::nop()
Expand Down

0 comments on commit 643d281

Please sign in to comment.