Skip to content

Commit

Permalink
Remove with_timeout constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 22, 2024
1 parent ea74722 commit 2b52500
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `AnySpi` and `AnySpiDmaChannel`. (#2334)
- Added `AnyI2s` and `AnyI2sDmaChannel`. (#2367)
- `Pins::steal()` to unsafely obtain GPIO. (#2335)
- `I2c::with_timeout` and `I2c::set_timeout` (#2361)

### Changed

Expand All @@ -32,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- The `i2s::{I2sWrite, I2sWriteDma, I2sRead, I2sReadDma, I2sWriteDmaAsync, I2sReadDmaAsync}` traits have been removed. (#2316)
- The `ledc::ChannelHW` trait is no longer generic. (#2387)
- The `I2c::new_with_timeout` constructors have been removed (#2361)

## [0.21.1]

Expand Down
9 changes: 9 additions & 0 deletions esp-hal/MIGRATING-0.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ the peripheral instance has been moved to the last generic parameter position.
```rust
let spi: Spi<'static, FullDuplexMode, SPI2> = Spi::new_typed(peripherals.SPI2, 1.MHz(), SpiMode::Mode0);
```

## I2C constructor changes

The `with_timeout` constructors have been removed in favour of `set_timeout` or `with_timeout`.

```diff
-let i2c = I2c::new_with_timeout(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz(), timeout);
+let i2c = I2c::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz()).with_timeout(timeout);
```
79 changes: 31 additions & 48 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,14 @@ where
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
timeout: Option<u32>,
) -> Self {
crate::into_ref!(i2c, sda, scl);

let i2c = I2c {
i2c,
phantom: PhantomData,
frequency,
timeout,
timeout: None,
};

PeripheralClockControl::reset(i2c.i2c.peripheral());
Expand All @@ -530,7 +529,7 @@ where
sda.connect_input_to_peripheral(i2c.i2c.sda_input_signal(), crate::private::Internal);
sda.connect_peripheral_to_output(i2c.i2c.sda_output_signal(), crate::private::Internal);

i2c.i2c.setup(frequency, timeout);
i2c.i2c.setup(frequency, None);
i2c
}

Expand All @@ -548,35 +547,34 @@ where

self.i2c.setup(self.frequency, self.timeout);
}

/// Set the I2C timeout.
// TODO: explain this function better - what's the unit, what happens on
// timeout, and just what exactly is a timeout in this context?
pub fn set_timeout(&mut self, timeout: Option<u32>) {
self.timeout = timeout;
self.i2c.setup(self.frequency, self.timeout);
}

/// Moving version of [`Self::set_timeout`] suitable for use during
/// peripheral initialization.
pub fn with_timeout(mut self, timeout: Option<u32>) -> Self {
self.set_timeout(timeout);
self
}
}

impl<'d> I2c<'d, Blocking> {
/// Create a new I2C instance
/// This will enable the peripheral but the peripheral won't get
/// automatically disabled when this gets dropped.
pub fn new<SDA: PeripheralOutput + PeripheralInput, SCL: PeripheralOutput + PeripheralInput>(
i2c: impl Peripheral<P = impl Into<AnyI2c>> + 'd,
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
) -> Self {
Self::new_with_timeout(i2c, sda, scl, frequency, None)
}

/// Create a new I2C instance with a custom timeout value.
/// This will enable the peripheral but the peripheral won't get
/// automatically disabled when this gets dropped.
pub fn new_with_timeout<
SDA: PeripheralOutput + PeripheralInput,
SCL: PeripheralOutput + PeripheralInput,
>(
i2c: impl Peripheral<P = impl Into<AnyI2c>> + 'd,
i2c: impl Peripheral<P = impl Instance> + 'd,
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
timeout: Option<u32>,
) -> Self {
Self::new_with_timeout_typed(i2c.map_into(), sda, scl, frequency, timeout)
Self::new_typed(i2c.map_into(), sda, scl, frequency)
}
}

Expand All @@ -596,23 +594,7 @@ where
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
) -> Self {
Self::new_with_timeout_typed(i2c, sda, scl, frequency, None)
}

/// Create a new I2C instance with a custom timeout value.
/// This will enable the peripheral but the peripheral won't get
/// automatically disabled when this gets dropped.
pub fn new_with_timeout_typed<
SDA: PeripheralOutput + PeripheralInput,
SCL: PeripheralOutput + PeripheralInput,
>(
i2c: impl Peripheral<P = T> + 'd,
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
timeout: Option<u32>,
) -> Self {
Self::new_internal(i2c, sda, scl, frequency, timeout)
Self::new_internal(i2c, sda, scl, frequency)
}
}

Expand All @@ -627,39 +609,40 @@ where
}
}

impl<'d, T> I2c<'d, Async, T>
where
T: Instance,
{
impl<'d> I2c<'d, Async> {
/// Create a new I2C instance
/// This will enable the peripheral but the peripheral won't get
/// automatically disabled when this gets dropped.
pub fn new_async<
SDA: PeripheralOutput + PeripheralInput,
SCL: PeripheralOutput + PeripheralInput,
>(
i2c: impl Peripheral<P = T> + 'd,
i2c: impl Peripheral<P = impl Instance> + 'd,
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
) -> Self {
Self::new_with_timeout_async(i2c, sda, scl, frequency, None)
Self::new_async_typed(i2c.map_into(), sda, scl, frequency)
}
}

/// Create a new I2C instance with a custom timeout value.
impl<'d, T> I2c<'d, Async, T>
where
T: Instance,
{
/// Create a new I2C instance
/// This will enable the peripheral but the peripheral won't get
/// automatically disabled when this gets dropped.
pub fn new_with_timeout_async<
pub fn new_async_typed<
SDA: PeripheralOutput + PeripheralInput,
SCL: PeripheralOutput + PeripheralInput,
>(
i2c: impl Peripheral<P = T> + 'd,
sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32,
timeout: Option<u32>,
) -> Self {
let mut this = Self::new_internal(i2c, sda, scl, frequency, timeout);
let mut this = Self::new_internal(i2c, sda, scl, frequency);

this.internal_set_interrupt_handler(this.i2c.async_handler());

Expand Down

0 comments on commit 2b52500

Please sign in to comment.