mirror of
https://github.com/esp-rs/esp-idf-hal.git
synced 2025-09-29 21:31:17 +00:00
ESP IDF 5 compat
This commit is contained in:
parent
dcc2b813e1
commit
dfba3a6a52
@ -28,13 +28,13 @@ nb = "0.1.2"
|
|||||||
mutex-trait = { version = "0.2", optional = true, default-features = false }
|
mutex-trait = { version = "0.2", optional = true, default-features = false }
|
||||||
embedded-hal = "=1.0.0-alpha.8"
|
embedded-hal = "=1.0.0-alpha.8"
|
||||||
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
|
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
|
||||||
embedded-svc = { version = "0.22.0", optional = true, default-features = false }
|
embedded-svc = { version = "0.22", optional = true, default-features = false }
|
||||||
esp-idf-sys = { version = "0.31.4", optional = true, default-features = false, features = ["native"] }
|
esp-idf-sys = { version = "0.31.9", optional = true, default-features = false, features = ["native"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
embuild = "0.29"
|
embuild = "0.30.3"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
esp-idf-sys = { version = "0.31.4", features = ["native", "binstart"] }
|
esp-idf-sys = { version = "0.31.9", features = ["native", "binstart"] }
|
||||||
|
31
src/adc.rs
31
src/adc.rs
@ -106,7 +106,7 @@ pub mod config {
|
|||||||
#[derive(Debug, Copy, Clone, Default)]
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub resolution: Resolution,
|
pub resolution: Resolution,
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
pub calibration: bool,
|
pub calibration: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ pub mod config {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn calibration(mut self, calibration: bool) -> Self {
|
pub fn calibration(mut self, calibration: bool) -> Self {
|
||||||
self.calibration = calibration;
|
self.calibration = calibration;
|
||||||
@ -134,7 +134,7 @@ pub mod config {
|
|||||||
pub struct PoweredAdc<ADC: Adc> {
|
pub struct PoweredAdc<ADC: Adc> {
|
||||||
adc: ADC,
|
adc: ADC,
|
||||||
resolution: config::Resolution,
|
resolution: config::Resolution,
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
cal_characteristics:
|
cal_characteristics:
|
||||||
Option<[Option<esp_adc_cal_characteristics_t>; adc_atten_t_ADC_ATTEN_DB_11 as usize + 1]>,
|
Option<[Option<esp_adc_cal_characteristics_t>; adc_atten_t_ADC_ATTEN_DB_11 as usize + 1]>,
|
||||||
}
|
}
|
||||||
@ -144,13 +144,22 @@ unsafe impl<ADC: Adc> Send for PoweredAdc<ADC> {}
|
|||||||
|
|
||||||
#[cfg(not(feature = "riscv-ulp-hal"))]
|
#[cfg(not(feature = "riscv-ulp-hal"))]
|
||||||
impl<ADC: Adc> PoweredAdc<ADC> {
|
impl<ADC: Adc> PoweredAdc<ADC> {
|
||||||
#[cfg(all(esp32, esp_idf_comp_esp_adc_cal_enabled))]
|
#[cfg(all(
|
||||||
|
esp32,
|
||||||
|
any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled)
|
||||||
|
))]
|
||||||
const CALIBRATION_SCHEME: esp_adc_cal_value_t = esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_VREF;
|
const CALIBRATION_SCHEME: esp_adc_cal_value_t = esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_VREF;
|
||||||
|
|
||||||
#[cfg(all(any(esp32c3, esp32s2), esp_idf_comp_esp_adc_cal_enabled))]
|
#[cfg(all(
|
||||||
|
any(esp32c3, esp32s2),
|
||||||
|
any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled)
|
||||||
|
))]
|
||||||
const CALIBRATION_SCHEME: esp_adc_cal_value_t = esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_TP;
|
const CALIBRATION_SCHEME: esp_adc_cal_value_t = esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_TP;
|
||||||
|
|
||||||
#[cfg(all(esp32s3, esp_idf_comp_esp_adc_cal_enabled))]
|
#[cfg(all(
|
||||||
|
esp32s3,
|
||||||
|
any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled)
|
||||||
|
))]
|
||||||
const CALIBRATION_SCHEME: esp_adc_cal_value_t =
|
const CALIBRATION_SCHEME: esp_adc_cal_value_t =
|
||||||
esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_TP_FIT;
|
esp_adc_cal_value_t_ESP_ADC_CAL_VAL_EFUSE_TP_FIT;
|
||||||
|
|
||||||
@ -161,7 +170,7 @@ impl<ADC: Adc> PoweredAdc<ADC> {
|
|||||||
const MAX_READING: u32 = 8191;
|
const MAX_READING: u32 = 8191;
|
||||||
|
|
||||||
pub fn new(adc: ADC, config: config::Config) -> Result<Self, EspError> {
|
pub fn new(adc: ADC, config: config::Config) -> Result<Self, EspError> {
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
if config.calibration {
|
if config.calibration {
|
||||||
esp!(unsafe { esp_adc_cal_check_efuse(Self::CALIBRATION_SCHEME) })?;
|
esp!(unsafe { esp_adc_cal_check_efuse(Self::CALIBRATION_SCHEME) })?;
|
||||||
}
|
}
|
||||||
@ -173,7 +182,7 @@ impl<ADC: Adc> PoweredAdc<ADC> {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
adc,
|
adc,
|
||||||
resolution: config.resolution,
|
resolution: config.resolution,
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
cal_characteristics: if config.calibration {
|
cal_characteristics: if config.calibration {
|
||||||
Some(Default::default())
|
Some(Default::default())
|
||||||
} else {
|
} else {
|
||||||
@ -191,14 +200,14 @@ impl<ADC: Adc> PoweredAdc<ADC> {
|
|||||||
measurement: c_types::c_int,
|
measurement: c_types::c_int,
|
||||||
attenuation: adc_atten_t,
|
attenuation: adc_atten_t,
|
||||||
) -> Result<u16, EspError> {
|
) -> Result<u16, EspError> {
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
let mv = if let Some(cal) = self.get_cal_characteristics(attenuation)? {
|
let mv = if let Some(cal) = self.get_cal_characteristics(attenuation)? {
|
||||||
unsafe { esp_adc_cal_raw_to_voltage(measurement as u32, &cal as *const _) as u16 }
|
unsafe { esp_adc_cal_raw_to_voltage(measurement as u32, &cal as *const _) as u16 }
|
||||||
} else {
|
} else {
|
||||||
(measurement as u32 * Self::get_max_mv(attenuation) / Self::MAX_READING) as u16
|
(measurement as u32 * Self::get_max_mv(attenuation) / Self::MAX_READING) as u16
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(esp_idf_comp_esp_adc_cal_enabled))]
|
#[cfg(not(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled)))]
|
||||||
let mv = (measurement as u32 * Self::get_max_mv(attenuation) / Self::MAX_READING) as u16;
|
let mv = (measurement as u32 * Self::get_max_mv(attenuation) / Self::MAX_READING) as u16;
|
||||||
|
|
||||||
Ok(mv)
|
Ok(mv)
|
||||||
@ -236,7 +245,7 @@ impl<ADC: Adc> PoweredAdc<ADC> {
|
|||||||
mv
|
mv
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(esp_idf_comp_esp_adc_cal_enabled)]
|
#[cfg(any(esp_idf_comp_esp_adc_cal_enabled, esp_idf_comp_esp_adc_enabled))]
|
||||||
fn get_cal_characteristics(
|
fn get_cal_characteristics(
|
||||||
&mut self,
|
&mut self,
|
||||||
attenuation: adc_atten_t,
|
attenuation: adc_atten_t,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user