Skip to content

Commit

Permalink
Remove all instance type params
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jan 8, 2025
1 parent 5a64d9b commit 42dd0b7
Show file tree
Hide file tree
Showing 18 changed files with 439 additions and 1,119 deletions.
6 changes: 2 additions & 4 deletions documentation/API-GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ In general, the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines
- Drivers must take peripherals via the `PeripheralRef` pattern - they don't consume peripherals directly.
- If a driver requires pins, those pins should be configured using `fn with_signal_name(self, pin: impl Peripheral<P = impl PeripheralInput> + 'd) -> Self` or `fn with_signal_name(self, pin: impl Peripheral<P = impl PeripheralOutput> + 'd) -> Self`
- If a driver supports multiple peripheral instances (for example, I2C0 is one such instance):
- The peripheral instance type must be positioned as the last type parameter of the driver type.
- The peripheral instance type must default to a type that supports any of the peripheral instances.
- The driver should not be generic over the peripheral instance.
- The author must to use `crate::any_peripheral` to define the "any" peripheral instance type.
- The driver must implement a `new` constructor that automatically converts the peripheral instance into the any type, and a `new_typed` that preserves the peripheral type.
- The driver must implement a `new` constructor that automatically converts the peripheral instance into the any type.
- If a driver is configurable, configuration options should be implemented as a `Config` struct in the same module where the driver is located.
- The driver's constructor should take the config struct by value, and it should return `Result<Self, ConfigError>`.
- The `ConfigError` enum should be separate from other `Error` enums used by the driver.
- The driver should implement `fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>`.
- In case the driver's configuration is infallible (all possible combinations of options are supported by the hardware), the `ConfigError` should be implemented as an empty `enum`.
- Configuration structs should derive `procmacros::BuilderLite` in order to automatically implement the Builder Lite pattern for them.
- If a driver only supports a single peripheral instance, no instance type parameter is necessary.
- If a driver implements both blocking and async operations, or only implements blocking operations, but may support asynchronous ones in the future, the driver's type signature must include a `crate::Mode` type parameter.
- By default, constructors must configure the driver for blocking mode. The driver must implement `into_async` (and a matching `into_blocking`) function that reconfigures the driver.
- `into_async` must configure the driver and/or the associated DMA channels. This most often means enabling an interrupt handler.
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use esp_hal::{
interrupt::{InterruptHandler, Priority},
sync::Locked,
time::{now, ExtU64},
timer::{AnyTimer, OneShotTimer},
timer::OneShotTimer,
Blocking,
};

pub type Timer = OneShotTimer<'static, Blocking, AnyTimer>;
pub type Timer = OneShotTimer<'static, Blocking>;

enum AlarmState {
Created(extern "C" fn()),
Expand Down
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- The `prelude` module has been removed (#2845)

- Removed all peripheral instance type parameters and `new_typed` constructors (#2907)

## [0.22.0] - 2024-11-20

### Added
Expand Down
9 changes: 9 additions & 0 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ is not compatible with the hardware.
+.unwrap();
```

## Peripheral instance type parameters and `new_typed` constructors have been removed

Call `new` instead and remove the type parameters if you've used them.

```diff
-let mut spi: Spi<'lt, SPI2> = Spi::new_typed(..).unwrap();
+let mut spi: Spi<'lt> = Spi::new(..).unwrap();
```

## LCD_CAM configuration changes

- `cam` now has a `Config` strurct that contains frequency, bit/byte order, VSync filter options.
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,18 +1668,18 @@ impl<DEG: DmaChannel> DmaChannelConvert<DEG> for DEG {
///
/// ```rust,no_run
#[doc = crate::before_snippet!()]
/// use esp_hal::spi::AnySpi;
/// use esp_hal::spi::master::{Spi, SpiDma, Config, Instance as SpiInstance};
/// use esp_hal::dma::DmaChannelFor;
/// use esp_hal::peripheral::Peripheral;
/// use esp_hal::Blocking;
///
/// fn configures_spi_dma<'d, S, CH>(
/// spi: Spi<'d, Blocking, S>,
/// fn configures_spi_dma<'d, CH>(
/// spi: Spi<'d, Blocking>,
/// channel: impl Peripheral<P = CH> + 'd,
/// ) -> SpiDma<'d, Blocking, S>
/// ) -> SpiDma<'d, Blocking>
/// where
/// S: SpiInstance,
/// CH: DmaChannelFor<S> + 'd,
/// CH: DmaChannelFor<AnySpi> + 'd,
/// {
/// spi.with_dma(channel)
/// }
Expand Down
32 changes: 10 additions & 22 deletions esp-hal/src/gpio/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl<P: InputPin> PeripheralInput for P {}
impl<P: OutputPin> PeripheralOutput for P {}

// Pin drivers
impl<P: InputPin> PeripheralInput for Flex<'static, P> {}
impl<P: OutputPin> PeripheralOutput for Flex<'static, P> {}
impl PeripheralInput for Flex<'static> {}
impl PeripheralOutput for Flex<'static> {}

// Placeholders
impl PeripheralInput for NoPin {}
Expand Down Expand Up @@ -226,11 +226,8 @@ where
}
}

impl<P> From<Flex<'static, P>> for InputSignal
where
P: InputPin,
{
fn from(input: Flex<'static, P>) -> Self {
impl From<Flex<'static>> for InputSignal {
fn from(input: Flex<'static>) -> Self {
Self::new(input.degrade())
}
}
Expand Down Expand Up @@ -364,11 +361,8 @@ where
}
}

impl<P> From<Flex<'static, P>> for OutputSignal
where
P: OutputPin,
{
fn from(input: Flex<'static, P>) -> Self {
impl From<Flex<'static>> for OutputSignal {
fn from(input: Flex<'static>) -> Self {
Self::new(input.degrade())
}
}
Expand Down Expand Up @@ -576,11 +570,8 @@ impl From<OutputConnection> for InputConnection {
}
}

impl<P> From<Flex<'static, P>> for InputConnection
where
P: InputPin,
{
fn from(pin: Flex<'static, P>) -> Self {
impl From<Flex<'static>> for InputConnection {
fn from(pin: Flex<'static>) -> Self {
pin.peripheral_input().into()
}
}
Expand Down Expand Up @@ -668,11 +659,8 @@ impl From<OutputSignal> for OutputConnection {
}
}

impl<P> From<Flex<'static, P>> for OutputConnection
where
P: OutputPin,
{
fn from(pin: Flex<'static, P>) -> Self {
impl From<Flex<'static>> for OutputConnection {
fn from(pin: Flex<'static>) -> Self {
pin.into_peripheral_output().into()
}
}
Expand Down
Loading

0 comments on commit 42dd0b7

Please sign in to comment.