Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix wrong `dram_seg` length in `esp32s2-hal` linker script (#732)
- Fix setting alarm when a timer group is used as the alarm source. (#730)
- Fix `Instant::now()` not counting in some cases when using TIMG0 as the timebase (#737)
- Fix number of ADC attenuations for ESP32-C6 (#771)

### Removed

Expand Down
16 changes: 13 additions & 3 deletions esp-hal-common/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ cfg_if::cfg_if! {
}
}

// The number of analog IO pins, and in turn the number of attentuations,
// depends on which chip is being used
cfg_if::cfg_if! {
if #[cfg(esp32c6)] {
const NUM_ATTENS: usize = 7;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea, what do you think about using constant in 'esp-hal-common/src/soc/esp32XX/mod.rs' instead of this config block?

} else {
const NUM_ATTENS: usize = 5;
}
}

/// The sampling/readout resolution of the ADC
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Resolution {
Expand Down Expand Up @@ -179,7 +189,7 @@ where

pub struct AdcConfig<ADCI> {
pub resolution: Resolution,
pub attenuations: [Option<Attenuation>; 5],
pub attenuations: [Option<Attenuation>; NUM_ATTENS],
_phantom: PhantomData<ADCI>,
}

Expand Down Expand Up @@ -271,7 +281,7 @@ impl<ADCI> Default for AdcConfig<ADCI> {
fn default() -> Self {
AdcConfig {
resolution: Resolution::Resolution12Bit,
attenuations: [None; 5],
attenuations: [None; NUM_ATTENS],
_phantom: PhantomData::default(),
}
}
Expand Down Expand Up @@ -537,7 +547,7 @@ impl CalibrationAccess for ADC2 {

pub struct ADC<'d, ADCI> {
_adc: PeripheralRef<'d, ADCI>,
attenuations: [Option<Attenuation>; 5],
attenuations: [Option<Attenuation>; NUM_ATTENS],
active_channel: Option<u8>,
}

Expand Down