Skip to content

Commit

Permalink
Workaround for ESP32-C6 one-shot ADC (#876)
Browse files Browse the repository at this point in the history
* Workaround for ESP32-C6 one-shot ADC

* CHANGELOG.md entry
  • Loading branch information
bjoernQ authored Oct 26, 2023
1 parent 6b04092 commit 663cbd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed a race condition causing SpiDma to stop working unexpectedly (#869)
- Fixed async uart serial, and updated the embassy_serial examples (#871).
- Fix ESP32-S3 direct-boot (#873)
- Fix ESP32-C6 ADC (#876)

### Removed

Expand Down
13 changes: 13 additions & 0 deletions esp-hal-common/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,19 @@ where
let attenuation = self.attenuations[channel as usize].unwrap() as u8;
ADCI::config_onetime_sample(channel, attenuation);
ADCI::start_onetime_sample();

// see https://github.com/espressif/esp-idf/blob/b4268c874a4cf8fcf7c0c4153cffb76ad2ddda4e/components/hal/adc_oneshot_hal.c#L105-L107
// the delay might be a bit generous but longer delay seem to not cause problems
#[cfg(esp32c6)]
{
extern "C" {
fn ets_delay_us(us: u32);
}
unsafe {
ets_delay_us(40);
}
ADCI::start_onetime_sample();
}
}

// Wait for ADC to finish conversion
Expand Down

0 comments on commit 663cbd9

Please sign in to comment.