Skip to content

Commit

Permalink
Remove more enum prefixes (#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored Jan 9, 2025
1 parent 848029b commit 021676e
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 63 deletions.
3 changes: 3 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `gpio::{Input, Flex}::wakeup_enable` now returns an error instead of panicking. (#2916)

- Removed the `I` prefix from `DriveStrength` enum variants. (#2922)
- Removed the `Attenuation` prefix from `Attenuation` enum variants. (#2922)

### Fixed

- Xtensa devices now correctly enable the `esp-hal-procmacros/rtc-slow` feature (#2594)
Expand Down
18 changes: 18 additions & 0 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,21 @@ The Address and Command enums have similarly had their variants changed from e.g
- Command::Command1
+ Command::_1Bit
```

## GPIO Changes

The GPIO drive strength variants are renamed from e.g. `I5mA` to `_5mA`.

```diff
-DriveStrength::I5mA
+DriveStrength::_5mA
```

## ADC Changes

The ADC attenuation variants are renamed from e.g. `Attenuation0dB` to `_0dB`.

```diff
-Attenuation::Attenuation0dB
+Attenuation::_0dB
```
32 changes: 16 additions & 16 deletions esp-hal/src/analog/adc/calibration/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ mod impls {
/// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32c3/curve_fitting_coefficients.c>
#[cfg(esp32c3)]
CURVES_COEFFS1 [
Attenuation0dB => [
_0dB => [
-0.225966470500043,
-0.0007265418501948,
0.0000109410402681,
],
Attenuation2p5dB => [
_2p5dB => [
0.4229623392600516,
-0.0000731527490903,
0.0000088166562521,
],
Attenuation6dB => [
_6dB => [
-1.017859239236435,
-0.0097159265299153,
0.0000149794028038,
],
Attenuation11dB => [
_11dB => [
-1.4912262772850453,
-0.0228549975564099,
0.0000356391935717,
Expand All @@ -173,22 +173,22 @@ mod impls {
/// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32c6/curve_fitting_coefficients.c>
#[cfg(esp32c6)]
CURVES_COEFFS1 [
Attenuation0dB => [
_0dB => [
-0.0487166399931449,
0.0006436483033201,
0.0000030410131806,
],
Attenuation2p5dB => [
_2p5dB => [
-0.8665498165817785,
0.0015239070452946,
0.0000013818878844,
],
Attenuation6dB => [
_6dB => [
-1.2277821756674387,
0.0022275554717885,
0.0000005924302667,
],
Attenuation11dB => [
_11dB => [
-0.3801417550380255,
-0.0006020352420772,
0.0000012442478488,
Expand All @@ -198,22 +198,22 @@ mod impls {
/// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32s3/curve_fitting_coefficients.c>
#[cfg(esp32s3)]
CURVES_COEFFS1 [
Attenuation0dB => [
_0dB => [
-2.7856531419538344,
-0.0050871540569528,
0.0000097982495890,
],
Attenuation2p5dB => [
_2p5dB => [
-2.9831022915028695,
-0.0049393185868806,
0.0000101379430548,
],
Attenuation6dB => [
_6dB => [
-2.3285545746296417,
-0.0147640181047414,
0.0000208385525314,
],
Attenuation11dB => [
_11dB => [
-0.644403418269478,
-0.0644334888647536,
0.0001297891447611,
Expand All @@ -225,22 +225,22 @@ mod impls {
/// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32s3/curve_fitting_coefficients.c>
#[cfg(esp32s3)]
CURVES_COEFFS2 [
Attenuation0dB => [
_0dB => [
-2.5668651654328927,
0.0001353548869615,
0.0000036615265189,
],
Attenuation2p5dB => [
_2p5dB => [
-2.3690184690298404,
-0.0066319894226185,
0.0000118964995959,
],
Attenuation6dB => [
_6dB => [
-0.9452499397020617,
-0.0200996773954387,
0.00000259011467956,
],
Attenuation11dB => [
_11dB => [
1.2247719764336924,
-0.0755717904943462,
0.0001478791187119,
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! let mut adc1_config = AdcConfig::new();
//! let mut pin = adc1_config.enable_pin(
//! analog_pin,
//! Attenuation::Attenuation11dB,
//! Attenuation::_11dB,
//! );
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//!
Expand Down Expand Up @@ -75,15 +75,15 @@ mod implementation;
#[allow(clippy::enum_variant_names, reason = "peripheral is unstable")]
pub enum Attenuation {
/// 0dB attenuation
Attenuation0dB = 0b00,
_0dB = 0b00,
/// 2.5dB attenuation
#[cfg(not(esp32c2))]
Attenuation2p5dB = 0b01,
_2p5dB = 0b01,
/// 6dB attenuation
#[cfg(not(esp32c2))]
Attenuation6dB = 0b10,
_6dB = 0b10,
/// 11dB attenuation
Attenuation11dB = 0b11,
_11dB = 0b11,
}

/// Calibration source of the ADC.
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ pub enum Pull {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DriveStrength {
/// Drive strength of approximately 5mA.
I5mA = 0,
_5mA = 0,
/// Drive strength of approximately 10mA.
I10mA = 1,
_10mA = 1,
/// Drive strength of approximately 20mA.
I20mA = 2,
_20mA = 2,
/// Drive strength of approximately 40mA.
I40mA = 3,
_40mA = 3,
}

/// Alternate functions
Expand Down Expand Up @@ -493,7 +493,7 @@ pub trait OutputPin: Pin + Into<AnyPin> + 'static {
if let Some(input_enable) = input_enable {
w.fun_ie().bit(input_enable);
}
w.fun_drv().bits(DriveStrength::I20mA as u8);
w.fun_drv().bits(DriveStrength::_20mA as u8);
w.slp_sel().clear_bit()
});
}
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
/// let mut adc1_config = AdcConfig::new();
/// let mut adc1_pin = adc1_config.enable_pin(
/// analog_pin,
/// Attenuation::Attenuation11dB
/// Attenuation::_11dB
/// );
/// let mut adc1 = Adc::<ADC1>::new(peripherals.ADC1, adc1_config);
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/soc/esp32c2/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Efuse {
2160 + diff_code0
};

if matches!(atten, Attenuation::Attenuation0dB) {
if matches!(atten, Attenuation::_0dB) {
return Some(code0);
}

Expand All @@ -121,8 +121,8 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c2/esp_efuse_rtc_calib.c#L65>
pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten {
Attenuation::Attenuation0dB => 400,
Attenuation::Attenuation11dB => 1370,
Attenuation::_0dB => 400,
Attenuation::_11dB => 1370,
}
}

Expand All @@ -144,7 +144,7 @@ impl Efuse {
1540 + diff_code0
};

if matches!(atten, Attenuation::Attenuation0dB) {
if matches!(atten, Attenuation::_0dB) {
return Some(code0);
}

Expand Down
24 changes: 12 additions & 12 deletions esp-hal/src/soc/esp32c3/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ impl Efuse {

// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_table.csv#L176-L179>
let init_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::Attenuation6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::Attenuation11dB => ADC1_INIT_CODE_ATTEN3,
Attenuation::_0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::_2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::_6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::_11dB => ADC1_INIT_CODE_ATTEN3,
});

Some(init_code + 1000) // version 1 logic
Expand All @@ -115,10 +115,10 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_rtc_calib.c#L49>
pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten {
Attenuation::Attenuation0dB => 400,
Attenuation::Attenuation2p5dB => 550,
Attenuation::Attenuation6dB => 750,
Attenuation::Attenuation11dB => 1370,
Attenuation::_0dB => 400,
Attenuation::_2p5dB => 550,
Attenuation::_6dB => 750,
Attenuation::_11dB => 1370,
}
}

Expand All @@ -134,10 +134,10 @@ impl Efuse {

// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_table.csv#L180-L183>
let cal_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::Attenuation6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::Attenuation11dB => ADC1_CAL_VOL_ATTEN3,
Attenuation::_0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::_2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::_6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::_11dB => ADC1_CAL_VOL_ATTEN3,
});

let cal_code = if cal_code & (1 << 9) != 0 {
Expand Down
24 changes: 12 additions & 12 deletions esp-hal/src/soc/esp32c6/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ impl Efuse {

// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_table.csv#L147-L152>
let init_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::Attenuation6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::Attenuation11dB => ADC1_INIT_CODE_ATTEN3,
Attenuation::_0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::_2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::_6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::_11dB => ADC1_INIT_CODE_ATTEN3,
});

Some(init_code + 1600) // version 1 logic
Expand All @@ -114,10 +114,10 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_rtc_calib.c#L42>
pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten {
Attenuation::Attenuation0dB => 400,
Attenuation::Attenuation2p5dB => 550,
Attenuation::Attenuation6dB => 750,
Attenuation::Attenuation11dB => 1370,
Attenuation::_0dB => 400,
Attenuation::_2p5dB => 550,
Attenuation::_6dB => 750,
Attenuation::_11dB => 1370,
}
}

Expand All @@ -133,10 +133,10 @@ impl Efuse {

// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_table.csv#L153-L156>
let cal_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::Attenuation6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::Attenuation11dB => ADC1_CAL_VOL_ATTEN3,
Attenuation::_0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::_2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::_6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::_11dB => ADC1_CAL_VOL_ATTEN3,
});

let cal_code = if cal_code & (1 << 9) != 0 {
Expand Down
16 changes: 8 additions & 8 deletions esp-hal/src/soc/esp32s3/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ impl Efuse {

Some(
adc_icode[match atten {
Attenuation::Attenuation0dB => 0,
Attenuation::Attenuation2p5dB => 1,
Attenuation::Attenuation6dB => 2,
Attenuation::Attenuation11dB => 3,
Attenuation::_0dB => 0,
Attenuation::_2p5dB => 1,
Attenuation::_6dB => 2,
Attenuation::_11dB => 3,
}],
)
}
Expand Down Expand Up @@ -180,10 +180,10 @@ impl Efuse {
adc2_vol[0] = adc1_vol[0] - adc_vol_diff[4] + 40;

let atten = match atten {
Attenuation::Attenuation0dB => 0,
Attenuation::Attenuation2p5dB => 1,
Attenuation::Attenuation6dB => 2,
Attenuation::Attenuation11dB => 3,
Attenuation::_0dB => 0,
Attenuation::_2p5dB => 1,
Attenuation::_6dB => 2,
Attenuation::_11dB => 3,
};

Some(if unit == 0 {
Expand Down

0 comments on commit 021676e

Please sign in to comment.