Only read value types from efuses (#2259)
* Only read value types from efuses * Changelog * Clean up remaining bool reads
This commit is contained in:
parent
f1bedbe3dc
commit
ed51cd8c35
@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Make `DmaDescriptor` methods public (#2237)
|
- Make `DmaDescriptor` methods public (#2237)
|
||||||
- Added a way to configure watchdogs in `esp_hal::init` (#2180)
|
- Added a way to configure watchdogs in `esp_hal::init` (#2180)
|
||||||
- Implement `embedded_hal_async::delay::DelayNs` for `TIMGx` timers (#2084)
|
- Implement `embedded_hal_async::delay::DelayNs` for `TIMGx` timers (#2084)
|
||||||
|
- Added `Efuse::read_bit` (#2259)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- TWAI on ESP32 (#2207)
|
- TWAI on ESP32 (#2207)
|
||||||
- TWAI should no longer panic when receiving a non-compliant frame (#2255)
|
- TWAI should no longer panic when receiving a non-compliant frame (#2255)
|
||||||
- OneShotTimer: fixed `delay_nanos` behaviour (#2256)
|
- OneShotTimer: fixed `delay_nanos` behaviour (#2256)
|
||||||
|
- Fixed unsoundness around `Efuse` (#2259)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
@ -255,3 +255,7 @@ Diff of the `psram_quad.rs` example
|
|||||||
...
|
...
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## eFuse
|
||||||
|
|
||||||
|
Calling `Efuse::read_field_le::<bool>()` no longer compiles. Use `Efuse::read_bit()` instead.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use bytemuck::AnyBitPattern;
|
||||||
|
|
||||||
use crate::soc::efuse::{Efuse, EfuseBlock};
|
use crate::soc::efuse::{Efuse, EfuseBlock};
|
||||||
|
|
||||||
/// The bit field for get access to efuse data
|
/// The bit field for get access to efuse data
|
||||||
@ -21,7 +23,7 @@ impl EfuseField {
|
|||||||
impl Efuse {
|
impl Efuse {
|
||||||
/// Read field value in a little-endian order
|
/// Read field value in a little-endian order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn read_field_le<T: Sized + 'static>(field: EfuseField) -> T {
|
pub fn read_field_le<T: AnyBitPattern>(field: EfuseField) -> T {
|
||||||
let mut output = core::mem::MaybeUninit::<T>::uninit();
|
let mut output = core::mem::MaybeUninit::<T>::uninit();
|
||||||
// represent output value as a bytes slice
|
// represent output value as a bytes slice
|
||||||
let mut bytes = unsafe {
|
let mut bytes = unsafe {
|
||||||
@ -89,7 +91,7 @@ impl Efuse {
|
|||||||
|
|
||||||
/// Read field value in a big-endian order
|
/// Read field value in a big-endian order
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn read_field_be<T: Sized + 'static>(field: EfuseField) -> T {
|
pub fn read_field_be<T: AnyBitPattern>(field: EfuseField) -> T {
|
||||||
// read value in a little-endian order
|
// read value in a little-endian order
|
||||||
let mut output = Self::read_field_le::<T>(field);
|
let mut output = Self::read_field_le::<T>(field);
|
||||||
// represent output value as a byte slice
|
// represent output value as a byte slice
|
||||||
@ -103,4 +105,13 @@ impl Efuse {
|
|||||||
bytes.reverse();
|
bytes.reverse();
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read bit value.
|
||||||
|
///
|
||||||
|
/// This function panics if the field's bit length is not equal to 1.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn read_bit(field: EfuseField) -> bool {
|
||||||
|
assert_eq!(field.bit_len, 1);
|
||||||
|
Self::read_field_le::<u8>(field) != 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ impl Efuse {
|
|||||||
/// CPU and application CPU), the application CPU is unavailable on
|
/// CPU and application CPU), the application CPU is unavailable on
|
||||||
/// some.
|
/// some.
|
||||||
pub fn get_core_count() -> u32 {
|
pub fn get_core_count() -> u32 {
|
||||||
if Self::read_field_le::<bool>(DISABLE_APP_CPU) {
|
if Self::read_bit(DISABLE_APP_CPU) {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
2
|
2
|
||||||
@ -97,8 +97,8 @@ impl Efuse {
|
|||||||
/// Note that the actual clock may be lower, depending on the current power
|
/// Note that the actual clock may be lower, depending on the current power
|
||||||
/// configuration of the chip, clock source, and other settings.
|
/// configuration of the chip, clock source, and other settings.
|
||||||
pub fn get_max_cpu_frequency() -> HertzU32 {
|
pub fn get_max_cpu_frequency() -> HertzU32 {
|
||||||
let has_rating = Self::read_field_le::<bool>(CHIP_CPU_FREQ_RATED);
|
let has_rating = Self::read_bit(CHIP_CPU_FREQ_RATED);
|
||||||
let has_low_rating = Self::read_field_le::<bool>(CHIP_CPU_FREQ_LOW);
|
let has_low_rating = Self::read_bit(CHIP_CPU_FREQ_LOW);
|
||||||
|
|
||||||
if has_rating && has_low_rating {
|
if has_rating && has_low_rating {
|
||||||
160.MHz()
|
160.MHz()
|
||||||
@ -109,7 +109,7 @@ impl Efuse {
|
|||||||
|
|
||||||
/// Returns the CHIP_VER_DIS_BT eFuse value.
|
/// Returns the CHIP_VER_DIS_BT eFuse value.
|
||||||
pub fn is_bluetooth_enabled() -> bool {
|
pub fn is_bluetooth_enabled() -> bool {
|
||||||
!Self::read_field_le::<bool>(DISABLE_BT)
|
!Self::read_bit(DISABLE_BT)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the CHIP_VER_PKG eFuse value.
|
/// Returns the CHIP_VER_PKG eFuse value.
|
||||||
|
|||||||
@ -291,7 +291,7 @@ where
|
|||||||
|
|
||||||
// On the esp32c3, and esp32s3 the USB_EXCHG_PINS efuse is bugged and
|
// On the esp32c3, and esp32s3 the USB_EXCHG_PINS efuse is bugged and
|
||||||
// doesn't swap the pullups too, this works around that.
|
// doesn't swap the pullups too, this works around that.
|
||||||
if Efuse::read_field_le(USB_EXCHG_PINS) {
|
if Efuse::read_bit(USB_EXCHG_PINS) {
|
||||||
USB_DEVICE::register_block().conf0().modify(|_, w| {
|
USB_DEVICE::register_block().conf0().modify(|_, w| {
|
||||||
w.pad_pull_override()
|
w.pad_pull_override()
|
||||||
.set_bit()
|
.set_bit()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user