From 021676e8714e83d0498eea4fe058909c5b44a7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 9 Jan 2025 16:33:58 +0100 Subject: [PATCH] Remove more enum prefixes (#2922) --- esp-hal/CHANGELOG.md | 3 ++ esp-hal/MIGRATING-0.22.md | 18 ++++++++++++ esp-hal/src/analog/adc/calibration/curve.rs | 32 ++++++++++----------- esp-hal/src/analog/adc/mod.rs | 10 +++---- esp-hal/src/gpio/mod.rs | 10 +++---- esp-hal/src/rng.rs | 2 +- esp-hal/src/soc/esp32c2/efuse/mod.rs | 8 +++--- esp-hal/src/soc/esp32c3/efuse/mod.rs | 24 ++++++++-------- esp-hal/src/soc/esp32c6/efuse/mod.rs | 24 ++++++++-------- esp-hal/src/soc/esp32s3/efuse/mod.rs | 16 +++++------ 10 files changed, 84 insertions(+), 63 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index a186ea25e..dcc4525d6 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -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) diff --git a/esp-hal/MIGRATING-0.22.md b/esp-hal/MIGRATING-0.22.md index 888366622..82f44edf6 100644 --- a/esp-hal/MIGRATING-0.22.md +++ b/esp-hal/MIGRATING-0.22.md @@ -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 +``` diff --git a/esp-hal/src/analog/adc/calibration/curve.rs b/esp-hal/src/analog/adc/calibration/curve.rs index b14766c4b..ce60626d6 100644 --- a/esp-hal/src/analog/adc/calibration/curve.rs +++ b/esp-hal/src/analog/adc/calibration/curve.rs @@ -146,22 +146,22 @@ mod impls { /// Error curve coefficients derived from #[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, @@ -173,22 +173,22 @@ mod impls { /// Error curve coefficients derived from #[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, @@ -198,22 +198,22 @@ mod impls { /// Error curve coefficients derived from #[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, @@ -225,22 +225,22 @@ mod impls { /// Error curve coefficients derived from #[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, diff --git a/esp-hal/src/analog/adc/mod.rs b/esp-hal/src/analog/adc/mod.rs index 2b899cfcb..df8f92308 100644 --- a/esp-hal/src/analog/adc/mod.rs +++ b/esp-hal/src/analog/adc/mod.rs @@ -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); //! @@ -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. diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 0cd1a26a9..9a32f316a 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -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 @@ -493,7 +493,7 @@ pub trait OutputPin: Pin + Into + '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() }); } diff --git a/esp-hal/src/rng.rs b/esp-hal/src/rng.rs index 2efa64fc1..ba918497b 100644 --- a/esp-hal/src/rng.rs +++ b/esp-hal/src/rng.rs @@ -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::::new(peripherals.ADC1, adc1_config); /// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); diff --git a/esp-hal/src/soc/esp32c2/efuse/mod.rs b/esp-hal/src/soc/esp32c2/efuse/mod.rs index e5609e85f..027599055 100644 --- a/esp-hal/src/soc/esp32c2/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c2/efuse/mod.rs @@ -105,7 +105,7 @@ impl Efuse { 2160 + diff_code0 }; - if matches!(atten, Attenuation::Attenuation0dB) { + if matches!(atten, Attenuation::_0dB) { return Some(code0); } @@ -121,8 +121,8 @@ impl Efuse { /// see 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, } } @@ -144,7 +144,7 @@ impl Efuse { 1540 + diff_code0 }; - if matches!(atten, Attenuation::Attenuation0dB) { + if matches!(atten, Attenuation::_0dB) { return Some(code0); } diff --git a/esp-hal/src/soc/esp32c3/efuse/mod.rs b/esp-hal/src/soc/esp32c3/efuse/mod.rs index 6189b2ab8..661576689 100644 --- a/esp-hal/src/soc/esp32c3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c3/efuse/mod.rs @@ -101,10 +101,10 @@ impl Efuse { // See 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 @@ -115,10 +115,10 @@ impl Efuse { /// see 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, } } @@ -134,10 +134,10 @@ impl Efuse { // See 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 { diff --git a/esp-hal/src/soc/esp32c6/efuse/mod.rs b/esp-hal/src/soc/esp32c6/efuse/mod.rs index 664e716cd..71d4d9c17 100644 --- a/esp-hal/src/soc/esp32c6/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c6/efuse/mod.rs @@ -100,10 +100,10 @@ impl Efuse { // See 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 @@ -114,10 +114,10 @@ impl Efuse { /// see 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, } } @@ -133,10 +133,10 @@ impl Efuse { // See 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 { diff --git a/esp-hal/src/soc/esp32s3/efuse/mod.rs b/esp-hal/src/soc/esp32s3/efuse/mod.rs index ca847eb55..878220bf9 100644 --- a/esp-hal/src/soc/esp32s3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32s3/efuse/mod.rs @@ -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, }], ) } @@ -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 {