Remove more enum prefixes (#2922)

This commit is contained in:
Dániel Buga 2025-01-09 16:33:58 +01:00 committed by GitHub
parent 848029b152
commit 021676e871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 84 additions and 63 deletions

View File

@ -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) - `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 ### Fixed
- Xtensa devices now correctly enable the `esp-hal-procmacros/rtc-slow` feature (#2594) - Xtensa devices now correctly enable the `esp-hal-procmacros/rtc-slow` feature (#2594)

View File

@ -458,3 +458,21 @@ The Address and Command enums have similarly had their variants changed from e.g
- Command::Command1 - Command::Command1
+ Command::_1Bit + 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
```

View File

@ -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> /// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32c3/curve_fitting_coefficients.c>
#[cfg(esp32c3)] #[cfg(esp32c3)]
CURVES_COEFFS1 [ CURVES_COEFFS1 [
Attenuation0dB => [ _0dB => [
-0.225966470500043, -0.225966470500043,
-0.0007265418501948, -0.0007265418501948,
0.0000109410402681, 0.0000109410402681,
], ],
Attenuation2p5dB => [ _2p5dB => [
0.4229623392600516, 0.4229623392600516,
-0.0000731527490903, -0.0000731527490903,
0.0000088166562521, 0.0000088166562521,
], ],
Attenuation6dB => [ _6dB => [
-1.017859239236435, -1.017859239236435,
-0.0097159265299153, -0.0097159265299153,
0.0000149794028038, 0.0000149794028038,
], ],
Attenuation11dB => [ _11dB => [
-1.4912262772850453, -1.4912262772850453,
-0.0228549975564099, -0.0228549975564099,
0.0000356391935717, 0.0000356391935717,
@ -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> /// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32c6/curve_fitting_coefficients.c>
#[cfg(esp32c6)] #[cfg(esp32c6)]
CURVES_COEFFS1 [ CURVES_COEFFS1 [
Attenuation0dB => [ _0dB => [
-0.0487166399931449, -0.0487166399931449,
0.0006436483033201, 0.0006436483033201,
0.0000030410131806, 0.0000030410131806,
], ],
Attenuation2p5dB => [ _2p5dB => [
-0.8665498165817785, -0.8665498165817785,
0.0015239070452946, 0.0015239070452946,
0.0000013818878844, 0.0000013818878844,
], ],
Attenuation6dB => [ _6dB => [
-1.2277821756674387, -1.2277821756674387,
0.0022275554717885, 0.0022275554717885,
0.0000005924302667, 0.0000005924302667,
], ],
Attenuation11dB => [ _11dB => [
-0.3801417550380255, -0.3801417550380255,
-0.0006020352420772, -0.0006020352420772,
0.0000012442478488, 0.0000012442478488,
@ -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> /// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32s3/curve_fitting_coefficients.c>
#[cfg(esp32s3)] #[cfg(esp32s3)]
CURVES_COEFFS1 [ CURVES_COEFFS1 [
Attenuation0dB => [ _0dB => [
-2.7856531419538344, -2.7856531419538344,
-0.0050871540569528, -0.0050871540569528,
0.0000097982495890, 0.0000097982495890,
], ],
Attenuation2p5dB => [ _2p5dB => [
-2.9831022915028695, -2.9831022915028695,
-0.0049393185868806, -0.0049393185868806,
0.0000101379430548, 0.0000101379430548,
], ],
Attenuation6dB => [ _6dB => [
-2.3285545746296417, -2.3285545746296417,
-0.0147640181047414, -0.0147640181047414,
0.0000208385525314, 0.0000208385525314,
], ],
Attenuation11dB => [ _11dB => [
-0.644403418269478, -0.644403418269478,
-0.0644334888647536, -0.0644334888647536,
0.0001297891447611, 0.0001297891447611,
@ -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> /// Error curve coefficients derived from <https://github.com/espressif/esp-idf/blob/903af13e8/components/esp_adc/esp32s3/curve_fitting_coefficients.c>
#[cfg(esp32s3)] #[cfg(esp32s3)]
CURVES_COEFFS2 [ CURVES_COEFFS2 [
Attenuation0dB => [ _0dB => [
-2.5668651654328927, -2.5668651654328927,
0.0001353548869615, 0.0001353548869615,
0.0000036615265189, 0.0000036615265189,
], ],
Attenuation2p5dB => [ _2p5dB => [
-2.3690184690298404, -2.3690184690298404,
-0.0066319894226185, -0.0066319894226185,
0.0000118964995959, 0.0000118964995959,
], ],
Attenuation6dB => [ _6dB => [
-0.9452499397020617, -0.9452499397020617,
-0.0200996773954387, -0.0200996773954387,
0.00000259011467956, 0.00000259011467956,
], ],
Attenuation11dB => [ _11dB => [
1.2247719764336924, 1.2247719764336924,
-0.0755717904943462, -0.0755717904943462,
0.0001478791187119, 0.0001478791187119,

View File

@ -36,7 +36,7 @@
//! let mut adc1_config = AdcConfig::new(); //! let mut adc1_config = AdcConfig::new();
//! let mut pin = adc1_config.enable_pin( //! let mut pin = adc1_config.enable_pin(
//! analog_pin, //! analog_pin,
//! Attenuation::Attenuation11dB, //! Attenuation::_11dB,
//! ); //! );
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); //! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//! //!
@ -75,15 +75,15 @@ mod implementation;
#[allow(clippy::enum_variant_names, reason = "peripheral is unstable")] #[allow(clippy::enum_variant_names, reason = "peripheral is unstable")]
pub enum Attenuation { pub enum Attenuation {
/// 0dB attenuation /// 0dB attenuation
Attenuation0dB = 0b00, _0dB = 0b00,
/// 2.5dB attenuation /// 2.5dB attenuation
#[cfg(not(esp32c2))] #[cfg(not(esp32c2))]
Attenuation2p5dB = 0b01, _2p5dB = 0b01,
/// 6dB attenuation /// 6dB attenuation
#[cfg(not(esp32c2))] #[cfg(not(esp32c2))]
Attenuation6dB = 0b10, _6dB = 0b10,
/// 11dB attenuation /// 11dB attenuation
Attenuation11dB = 0b11, _11dB = 0b11,
} }
/// Calibration source of the ADC. /// Calibration source of the ADC.

View File

@ -243,13 +243,13 @@ pub enum Pull {
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DriveStrength { pub enum DriveStrength {
/// Drive strength of approximately 5mA. /// Drive strength of approximately 5mA.
I5mA = 0, _5mA = 0,
/// Drive strength of approximately 10mA. /// Drive strength of approximately 10mA.
I10mA = 1, _10mA = 1,
/// Drive strength of approximately 20mA. /// Drive strength of approximately 20mA.
I20mA = 2, _20mA = 2,
/// Drive strength of approximately 40mA. /// Drive strength of approximately 40mA.
I40mA = 3, _40mA = 3,
} }
/// Alternate functions /// Alternate functions
@ -493,7 +493,7 @@ pub trait OutputPin: Pin + Into<AnyPin> + 'static {
if let Some(input_enable) = input_enable { if let Some(input_enable) = input_enable {
w.fun_ie().bit(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() w.slp_sel().clear_bit()
}); });
} }

View File

@ -78,7 +78,7 @@
/// let mut adc1_config = AdcConfig::new(); /// let mut adc1_config = AdcConfig::new();
/// let mut adc1_pin = adc1_config.enable_pin( /// let mut adc1_pin = adc1_config.enable_pin(
/// analog_pin, /// analog_pin,
/// Attenuation::Attenuation11dB /// Attenuation::_11dB
/// ); /// );
/// let mut adc1 = Adc::<ADC1>::new(peripherals.ADC1, adc1_config); /// let mut adc1 = Adc::<ADC1>::new(peripherals.ADC1, adc1_config);
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); /// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();

View File

@ -105,7 +105,7 @@ impl Efuse {
2160 + diff_code0 2160 + diff_code0
}; };
if matches!(atten, Attenuation::Attenuation0dB) { if matches!(atten, Attenuation::_0dB) {
return Some(code0); return Some(code0);
} }
@ -121,8 +121,8 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c2/esp_efuse_rtc_calib.c#L65> /// 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 { pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten { match atten {
Attenuation::Attenuation0dB => 400, Attenuation::_0dB => 400,
Attenuation::Attenuation11dB => 1370, Attenuation::_11dB => 1370,
} }
} }
@ -144,7 +144,7 @@ impl Efuse {
1540 + diff_code0 1540 + diff_code0
}; };
if matches!(atten, Attenuation::Attenuation0dB) { if matches!(atten, Attenuation::_0dB) {
return Some(code0); return Some(code0);
} }

View File

@ -101,10 +101,10 @@ impl Efuse {
// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_table.csv#L176-L179> // 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 { let init_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_INIT_CODE_ATTEN0, Attenuation::_0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_INIT_CODE_ATTEN1, Attenuation::_2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::Attenuation6dB => ADC1_INIT_CODE_ATTEN2, Attenuation::_6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::Attenuation11dB => ADC1_INIT_CODE_ATTEN3, Attenuation::_11dB => ADC1_INIT_CODE_ATTEN3,
}); });
Some(init_code + 1000) // version 1 logic Some(init_code + 1000) // version 1 logic
@ -115,10 +115,10 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_rtc_calib.c#L49> /// 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 { pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten { match atten {
Attenuation::Attenuation0dB => 400, Attenuation::_0dB => 400,
Attenuation::Attenuation2p5dB => 550, Attenuation::_2p5dB => 550,
Attenuation::Attenuation6dB => 750, Attenuation::_6dB => 750,
Attenuation::Attenuation11dB => 1370, Attenuation::_11dB => 1370,
} }
} }
@ -134,10 +134,10 @@ impl Efuse {
// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c3/esp_efuse_table.csv#L180-L183> // 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 { let cal_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_CAL_VOL_ATTEN0, Attenuation::_0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_CAL_VOL_ATTEN1, Attenuation::_2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::Attenuation6dB => ADC1_CAL_VOL_ATTEN2, Attenuation::_6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::Attenuation11dB => ADC1_CAL_VOL_ATTEN3, Attenuation::_11dB => ADC1_CAL_VOL_ATTEN3,
}); });
let cal_code = if cal_code & (1 << 9) != 0 { let cal_code = if cal_code & (1 << 9) != 0 {

View File

@ -100,10 +100,10 @@ impl Efuse {
// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_table.csv#L147-L152> // 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 { let init_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_INIT_CODE_ATTEN0, Attenuation::_0dB => ADC1_INIT_CODE_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_INIT_CODE_ATTEN1, Attenuation::_2p5dB => ADC1_INIT_CODE_ATTEN1,
Attenuation::Attenuation6dB => ADC1_INIT_CODE_ATTEN2, Attenuation::_6dB => ADC1_INIT_CODE_ATTEN2,
Attenuation::Attenuation11dB => ADC1_INIT_CODE_ATTEN3, Attenuation::_11dB => ADC1_INIT_CODE_ATTEN3,
}); });
Some(init_code + 1600) // version 1 logic Some(init_code + 1600) // version 1 logic
@ -114,10 +114,10 @@ impl Efuse {
/// see <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_rtc_calib.c#L42> /// 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 { pub fn rtc_calib_cal_mv(_unit: u8, atten: Attenuation) -> u16 {
match atten { match atten {
Attenuation::Attenuation0dB => 400, Attenuation::_0dB => 400,
Attenuation::Attenuation2p5dB => 550, Attenuation::_2p5dB => 550,
Attenuation::Attenuation6dB => 750, Attenuation::_6dB => 750,
Attenuation::Attenuation11dB => 1370, Attenuation::_11dB => 1370,
} }
} }
@ -133,10 +133,10 @@ impl Efuse {
// See <https://github.com/espressif/esp-idf/blob/903af13e8/components/efuse/esp32c6/esp_efuse_table.csv#L153-L156> // 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 { let cal_code: u16 = Self::read_field_le(match atten {
Attenuation::Attenuation0dB => ADC1_CAL_VOL_ATTEN0, Attenuation::_0dB => ADC1_CAL_VOL_ATTEN0,
Attenuation::Attenuation2p5dB => ADC1_CAL_VOL_ATTEN1, Attenuation::_2p5dB => ADC1_CAL_VOL_ATTEN1,
Attenuation::Attenuation6dB => ADC1_CAL_VOL_ATTEN2, Attenuation::_6dB => ADC1_CAL_VOL_ATTEN2,
Attenuation::Attenuation11dB => ADC1_CAL_VOL_ATTEN3, Attenuation::_11dB => ADC1_CAL_VOL_ATTEN3,
}); });
let cal_code = if cal_code & (1 << 9) != 0 { let cal_code = if cal_code & (1 << 9) != 0 {

View File

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