Skip to content

Commit 447411f

Browse files
authored
Rework hal initialization (#1970)
* Rework hal initialization * Turn sw interrupt control into a virtual peripheral * Return a tuple instead of a named struct * Fix docs * Remove SystemClockControl * Move software interrupts under interrupt * Re-document what's left in system * Update time docs * Update sw int docs * Introduce Config * Fix tests * Remove redundant inits * Doc * Clean up examples&tests * Update tests * Add changelog entry * Start migration guide * Restore some convenience-imports * Remove Config from prelude
1 parent d60bafb commit 447411f

File tree

180 files changed

+1396
-2279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+1396
-2279
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ To help us review it efficiently, please ensure you've gone through the followin
77
- [ ] I have updated existing examples or added new ones (if applicable).
88
- [ ] I have used `cargo xtask fmt-packages` command to ensure that all changed code is formatted correctly.
99
- [ ] My changes were added to the [`CHANGELOG.md`](https://github.com/esp-rs/esp-hal/blob/main/esp-hal/CHANGELOG.md) in the **_proper_** section.
10+
- [ ] I have added necessary changes to user code to the [Migration Guide](https://github.com/esp-rs/esp-hal/blob/main/esp-hal/MIGRATING-0.21.md).
1011
- [ ] My changes are in accordance to the [esp-rs API guidelines](https://github.com/esp-rs/esp-hal/blob/main/documentation/API-GUIDELINES.md)
1112

1213
#### Extra:

documentation/CONTRIBUTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ By taking these extra steps to test your contributions, you help maintain the hi
8484

8585
Ensuring the quality and reliability of `esp-hal` is a shared responsibility, and testing plays a critical role in this process. Our GitHub CI automatically checks the buildability of all examples and drivers within the project. However, automated tests can't catch everything, especially when it comes to the nuanced behavior of hardware interactions. So make sure that the example affected by your change works as expected.
8686

87-
Further steps that can (or should) be taken in testing:
87+
Further steps that can (or should) be taken in testing:
8888

89-
* Using [xtask], build examples for the specified chip.
89+
* Using [xtask], build examples for the specified chip.
9090
* Build the documentation and run the doctests if they have been modified using the `build-documentation` and `run-doc-test` commands in [xtask].
91-
* Run the [HIL] tests locally if changes have been made to them.
91+
* Run the [HIL] tests locally if changes have been made to them.
9292

9393
[xtask]: https://github.com/esp-rs/esp-hal/tree/main/xtask
9494

@@ -122,13 +122,15 @@ This will use `rustfmt` to ensure that all source code is formatted correctly pr
122122
* [Link your PR] to any relevant issues it addresses.
123123
* [Allow edits from maintainers] so the branch can be updated for a merge. Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request additional information.
124124
* Make sure you add an entry with your changes to the [Changelog]. Also make sure that it is in the appropriate section of the document.
125+
* Make sure you add your changes to the current [migration guide].
125126
* We may ask for changes to be made before a PR can be merged, either using [suggested changes] or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch.
126127
* As you update your PR and apply changes, mark each conversation as [resolved].
127128
* Resolve merge conflicts if they arise, using resources like [this git tutorial] for help.
128129

129130
[Link your PR]: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
130131
[Allow edits from maintainers]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-forkmember
131132
[Changelog]: esp-hal/CHANGELOG.md
133+
[migration guide]: esp-hal/MIGRATING-0.20.md
132134
[suggested changes]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/incorporating-feedback-in-your-pull-request
133135
[resolved]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations
134136
[this git tutorial]: https://github.com/skills/resolve-merge-conflicts

esp-hal-embassy/src/executor/interrupt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit};
55
use embassy_executor::{raw, SendSpawner};
66
use esp_hal::{
77
get_core,
8-
interrupt::{self, InterruptHandler},
9-
system::SoftwareInterrupt,
8+
interrupt::{self, software::SoftwareInterrupt, InterruptHandler},
109
};
1110
use portable_atomic::{AtomicUsize, Ordering};
1211

esp-hal-embassy/src/executor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod thread;
55

66
#[export_name = "__pender"]
77
fn __pender(context: *mut ()) {
8-
use esp_hal::system::SoftwareInterrupt;
8+
use esp_hal::interrupt::software::SoftwareInterrupt;
99

1010
let context = (context as usize).to_le_bytes();
1111

esp-hal-embassy/src/executor/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa
7777
pub fn new() -> Self {
7878
#[cfg(multi_core)]
7979
unsafe {
80-
esp_hal::system::SoftwareInterrupt::<3>::steal()
80+
esp_hal::interrupt::software::SoftwareInterrupt::<3>::steal()
8181
.set_interrupt_handler(software3_interrupt)
8282
}
8383

esp-hal/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Added `esp_hal::init` to simplify HAL initialisation (#1970)
13+
1214
### Changed
1315

1416
### Fixed

esp-hal/MIGRATING-0.20.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Migration Guide from 0.20.x to vNext
2+
====================================
3+
4+
HAL initialsation
5+
-----------------
6+
7+
Instead of manually grabbing peripherals and setting up clocks, you should now call `esp_hal::init`.
8+
9+
```diff
10+
use esp_hal::{
11+
- clock::ClockControl,
12+
- peripherals::Peripherals,
13+
prelude::*,
14+
- system::SystemControl,
15+
};
16+
17+
#[entry]
18+
fn main() -> ! {
19+
- let peripherals = Peripherals::take();
20+
- let system = SystemControl::new(peripherals.SYSTEM);
21+
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
22+
+ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
23+
24+
// ...
25+
}
26+
```

esp-hal/src/aes/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,30 @@
2828
//! # let plaintext = b"message";
2929
//! # let mut keybuf = [0_u8; 16];
3030
//! # keybuf[..keytext.len()].copy_from_slice(keytext);
31-
//! let mut block_buf = [0_u8; 16];
32-
//! block_buf[..plaintext.len()].copy_from_slice(plaintext);
33-
//! let mut block = block_buf.clone();
31+
//! #
32+
//! let mut block = [0_u8; 16];
33+
//! block[..plaintext.len()].copy_from_slice(plaintext);
3434
//!
3535
//! let mut aes = Aes::new(peripherals.AES);
3636
//! aes.process(&mut block, Mode::Encryption128, keybuf);
37-
//! let hw_encrypted = block.clone();
37+
//!
38+
//! // The encryption happens in-place, so the ciphertext is in `block`
3839
//!
3940
//! aes.process(&mut block, Mode::Decryption128, keybuf);
40-
//! let hw_decrypted = block;
41+
//!
42+
//! // The decryption happens in-place, so the plaintext is in `block`
4143
//! # }
4244
//! ```
4345
//!
4446
//! ### AES-DMA
47+
//!
4548
//! Visit the [AES-DMA] test for a more advanced example of using AES-DMA
4649
//! mode.
4750
//!
4851
//! [AES-DMA]: https://github.com/esp-rs/esp-hal/blob/main/hil-test/tests/aes_dma.rs
4952
//!
5053
//! ## Implementation State
54+
//!
5155
//! * AES-DMA mode is currently not supported on ESP32 and ESP32S2
5256
//! * AES-DMA Initialization Vector (IV) is currently not supported
5357

esp-hal/src/analog/adc/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
//! # use esp_hal::analog::adc::Adc;
3333
//! # use esp_hal::delay::Delay;
3434
//! # use esp_hal::gpio::Io;
35-
//!
3635
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
3736
#![cfg_attr(esp32, doc = "let analog_pin = io.pins.gpio32;")]
3837
#![cfg_attr(any(esp32s2, esp32s3), doc = "let analog_pin = io.pins.gpio3;")]
@@ -41,8 +40,10 @@
4140
doc = "let analog_pin = io.pins.gpio2;"
4241
)]
4342
//! let mut adc1_config = AdcConfig::new();
44-
//! let mut pin = adc1_config.enable_pin(analog_pin,
45-
//! Attenuation::Attenuation11dB);
43+
//! let mut pin = adc1_config.enable_pin(
44+
//! analog_pin,
45+
//! Attenuation::Attenuation11dB,
46+
//! );
4647
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
4748
//!
4849
//! let mut delay = Delay::new(&clocks);
@@ -54,8 +55,10 @@
5455
//! }
5556
//! # }
5657
//! ```
58+
//!
5759
//! ## Implementation State
58-
//! - [ADC calibration is not implemented for all targets].
60+
//!
61+
//! - [ADC calibration is not implemented for all targets].
5962
//!
6063
//! [ADC calibration is not implemented for all targets]: https://github.com/esp-rs/esp-hal/issues/326
6164
use core::marker::PhantomData;

0 commit comments

Comments
 (0)