Skip to content

Commit

Permalink
0.22 migration document additions/fixes (#2986)
Browse files Browse the repository at this point in the history
* fix small typo

* Adjust `new_with_config` removal example

Remove the `config` parameter construction as it has changed and is not
relevant to this example.

* Mention builder lite

* Mention `Spi` enum prefix removal

* Remove `new_with_config` from unrelated examples

* Code block fix `dif` -> `diff` typo
  • Loading branch information
EliteTK authored Jan 17, 2025
1 parent 5d0145e commit 48b52e0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ by `esp_hal::init()`. The channels themselves have been renamed to match other p
- GDMA devices provide `set_priority` to change DMA in/out channel priority

```diff
let mut spi = Spi::new_with_config(
peripherals.SPI2,
Config::default(),
)
let mut spi = spi
// other setup
-.with_dma(dma_channel.configure(false, DmaPriority::Priority0));
+.with_dma(dma_channel);
```

```diff
+dma_channel.set_priority(DmaPriority::Priority1);
let mut spi = Spi::new_with_config(
peripherals.SPI2,
Config::default(),
)
let mut spi = spi
// other setup
-.with_dma(dma_channel.configure(false, DmaPriority::Priority1));
+.with_dma(dma_channel);
Expand Down Expand Up @@ -235,19 +229,15 @@ https://github.com/rust-embedded/embedded-hal/blob/master/docs/migrating-from-0.

## Driver constructors now take a configuration and are fallible

The old `new_with_config` constructor have been removed, and `new` constructors now always take
The old `new_with_config` constructors have been removed, and `new` constructors now always take
a configuration structure. They have also been updated to return a `ConfigError` if the configuration
is not compatible with the hardware.

```diff
-let mut spi = Spi::new_with_config(
+let mut spi = Spi::new(
peripherals.SPI2,
Config {
frequency: 100.kHz(),
mode: SpiMode::_0,
..Config::default()
},
config,
-);
+)
+.unwrap();
Expand All @@ -262,6 +252,17 @@ is not compatible with the hardware.
+.unwrap();
```

Additionally, the configuration structs now implement the Builder Lite pattern.

```diff
-let config = Config {
- frequency: 100.kHz(),
- mode: Mode::_0,
- ..Config::default()
-}
+let config = Config::default().with_frequency(100.kHz()).with_mode(Mode::_0);
```

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

Call `new` instead and remove the type parameters if you've used them.
Expand Down Expand Up @@ -453,7 +454,7 @@ e.g.

e.g.

```dif
```diff
- while let nb::Result::Ok(_c) = serial.read_byte() {
- cnt += 1;
- }
Expand Down Expand Up @@ -482,10 +483,11 @@ Additionally the enum is marked as non-exhaustive.

## SPI Changes

The SPI mode variants are renamed from e.g. `Mode0` to `_0`.
A number of enums have had their `Spi` prefix dropped and the SPI mode variants
are renamed from e.g. `Mode0` to `_0`.

```diff
- Mode::Mode0
- SpiMode::Mode0
+ Mode::_0
```

Expand Down

0 comments on commit 48b52e0

Please sign in to comment.