Skip to content

Commit f8e9688

Browse files
committed
Remove with_timeout constructors
1 parent 25a67e3 commit f8e9688

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

esp-hal/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Added `AnySpi` and `AnySpiDmaChannel`. (#2334)
1717
- Added `AnyI2s` and `AnyI2sDmaChannel`. (#2367)
1818
- `Pins::steal()` to unsafely obtain GPIO. (#2335)
19+
- `I2c::with_timeout` and `I2c::set_timeout` (#2361)
1920

2021
### Changed
2122

@@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2829
### Removed
2930

3031
- The `i2s::{I2sWrite, I2sWriteDma, I2sRead, I2sReadDma, I2sWriteDmaAsync, I2sReadDmaAsync}` traits have been removed. (#2316)
32+
- The `I2c::new_with_timeout` constructors have been removed (#2361)
3133

3234
## [0.21.1]
3335

esp-hal/MIGRATING-0.21.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ the peripheral instance has been moved to the last generic parameter position.
5050
```rust
5151
let spi: Spi<'static, FullDuplexMode, SPI2> = Spi::new_typed(peripherals.SPI2, 1.MHz(), SpiMode::Mode0);
5252
```
53+
54+
## I2C constructor changes
55+
56+
The `with_timeout` constructors have been removed in favour of `set_timeout` or `with_timeout`.
57+
58+
```diff
59+
-let i2c = I2c::new_with_timeout(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz(), timeout);
60+
+let i2c = I2c::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz()).with_timeout(timeout);
61+
```

esp-hal/src/i2c.rs

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,14 @@ where
497497
sda: impl Peripheral<P = SDA> + 'd,
498498
scl: impl Peripheral<P = SCL> + 'd,
499499
frequency: HertzU32,
500-
timeout: Option<u32>,
501500
) -> Self {
502501
crate::into_ref!(i2c, sda, scl);
503502

504503
let i2c = I2c {
505504
i2c,
506505
phantom: PhantomData,
507506
frequency,
508-
timeout,
507+
timeout: None,
509508
};
510509

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

533-
i2c.i2c.setup(frequency, timeout);
532+
i2c.i2c.setup(frequency, None);
534533
i2c
535534
}
536535

@@ -548,35 +547,34 @@ where
548547

549548
self.i2c.setup(self.frequency, self.timeout);
550549
}
550+
551+
/// Set the I2C timeout.
552+
// TODO: explain this function better - what's the unit, what happens on
553+
// timeout, and just what exactly is a timeout in this context?
554+
pub fn set_timeout(&mut self, timeout: Option<u32>) {
555+
self.timeout = timeout;
556+
self.i2c.setup(self.frequency, self.timeout);
557+
}
558+
559+
/// Moving version of [`Self::set_timeout`] suitable for use during
560+
/// peripheral initialization.
561+
pub fn with_timeout(mut self, timeout: Option<u32>) -> Self {
562+
self.set_timeout(timeout);
563+
self
564+
}
551565
}
552566

553567
impl<'d> I2c<'d, Blocking> {
554568
/// Create a new I2C instance
555569
/// This will enable the peripheral but the peripheral won't get
556570
/// automatically disabled when this gets dropped.
557571
pub fn new<SDA: PeripheralOutput + PeripheralInput, SCL: PeripheralOutput + PeripheralInput>(
558-
i2c: impl Peripheral<P = impl Into<AnyI2c>> + 'd,
559-
sda: impl Peripheral<P = SDA> + 'd,
560-
scl: impl Peripheral<P = SCL> + 'd,
561-
frequency: HertzU32,
562-
) -> Self {
563-
Self::new_with_timeout(i2c, sda, scl, frequency, None)
564-
}
565-
566-
/// Create a new I2C instance with a custom timeout value.
567-
/// This will enable the peripheral but the peripheral won't get
568-
/// automatically disabled when this gets dropped.
569-
pub fn new_with_timeout<
570-
SDA: PeripheralOutput + PeripheralInput,
571-
SCL: PeripheralOutput + PeripheralInput,
572-
>(
573-
i2c: impl Peripheral<P = impl Into<AnyI2c>> + 'd,
572+
i2c: impl Peripheral<P = impl Instance> + 'd,
574573
sda: impl Peripheral<P = SDA> + 'd,
575574
scl: impl Peripheral<P = SCL> + 'd,
576575
frequency: HertzU32,
577-
timeout: Option<u32>,
578576
) -> Self {
579-
Self::new_with_timeout_typed(i2c.map_into(), sda, scl, frequency, timeout)
577+
Self::new_typed(i2c.map_into(), sda, scl, frequency)
580578
}
581579
}
582580

@@ -596,23 +594,7 @@ where
596594
scl: impl Peripheral<P = SCL> + 'd,
597595
frequency: HertzU32,
598596
) -> Self {
599-
Self::new_with_timeout_typed(i2c, sda, scl, frequency, None)
600-
}
601-
602-
/// Create a new I2C instance with a custom timeout value.
603-
/// This will enable the peripheral but the peripheral won't get
604-
/// automatically disabled when this gets dropped.
605-
pub fn new_with_timeout_typed<
606-
SDA: PeripheralOutput + PeripheralInput,
607-
SCL: PeripheralOutput + PeripheralInput,
608-
>(
609-
i2c: impl Peripheral<P = T> + 'd,
610-
sda: impl Peripheral<P = SDA> + 'd,
611-
scl: impl Peripheral<P = SCL> + 'd,
612-
frequency: HertzU32,
613-
timeout: Option<u32>,
614-
) -> Self {
615-
Self::new_internal(i2c, sda, scl, frequency, timeout)
597+
Self::new_internal(i2c, sda, scl, frequency)
616598
}
617599
}
618600

@@ -627,39 +609,40 @@ where
627609
}
628610
}
629611

630-
impl<'d, T> I2c<'d, Async, T>
631-
where
632-
T: Instance,
633-
{
612+
impl<'d> I2c<'d, Async> {
634613
/// Create a new I2C instance
635614
/// This will enable the peripheral but the peripheral won't get
636615
/// automatically disabled when this gets dropped.
637616
pub fn new_async<
638617
SDA: PeripheralOutput + PeripheralInput,
639618
SCL: PeripheralOutput + PeripheralInput,
640619
>(
641-
i2c: impl Peripheral<P = T> + 'd,
620+
i2c: impl Peripheral<P = impl Instance> + 'd,
642621
sda: impl Peripheral<P = SDA> + 'd,
643622
scl: impl Peripheral<P = SCL> + 'd,
644623
frequency: HertzU32,
645624
) -> Self {
646-
Self::new_with_timeout_async(i2c, sda, scl, frequency, None)
625+
Self::new_async_typed(i2c.map_into(), sda, scl, frequency)
647626
}
627+
}
648628

649-
/// Create a new I2C instance with a custom timeout value.
629+
impl<'d, T> I2c<'d, Async, T>
630+
where
631+
T: Instance,
632+
{
633+
/// Create a new I2C instance
650634
/// This will enable the peripheral but the peripheral won't get
651635
/// automatically disabled when this gets dropped.
652-
pub fn new_with_timeout_async<
636+
pub fn new_async_typed<
653637
SDA: PeripheralOutput + PeripheralInput,
654638
SCL: PeripheralOutput + PeripheralInput,
655639
>(
656640
i2c: impl Peripheral<P = T> + 'd,
657641
sda: impl Peripheral<P = SDA> + 'd,
658642
scl: impl Peripheral<P = SCL> + 'd,
659643
frequency: HertzU32,
660-
timeout: Option<u32>,
661644
) -> Self {
662-
let mut this = Self::new_internal(i2c, sda, scl, frequency, timeout);
645+
let mut this = Self::new_internal(i2c, sda, scl, frequency);
663646

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

0 commit comments

Comments
 (0)