Skip to content

ADC Improvements - #6360

Open
bjoernQ wants to merge 2 commits into
esp-rs:mainfrom
bjoernQ:try-fix-adc
Open

bjoernQ wants to merge 2 commits into
esp-rs:mainfrom
bjoernQ:try-fix-adc

Conversation

@bjoernQ

@bjoernQ bjoernQ commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Tester: https://github.com/bjoernQ/adc-foo

This aligns the ADC implementation with what is found in ESP-IDF (6.1)

The tester now shows numbers very close between ESP-IDF and this branch. (i.e. deviations in the same range as multiple runs of the IDF tester, with the exception of S31: Rust reads about 0.35% higher than IDF
, lets dig into that in a follow up given the current support status of S31). The same raw values result in the same calibrated reads.


Changelog

esp-hal

  • Changed: ADC one-shot calibration now follows ESP-IDF 6.1.
  • Changed: Reading an unconfigured ADC channel now panics on ESP32, ESP32-S2/S3 and ESP32-P4, as it already did on the other chips.
  • Removed: adc::AdcCalSource and AdcCalScheme::adc_cal.
  • Removed: ADC2 is no longer supported on ESP32-C3

Comment thread esp-hal/src/efuse/esp32c2/mod.rs Outdated
Comment on lines 118 to 124
// The diff is signed and subtracted from the attenuation-0 reference point, so a negative
// diff raises the code.
let code11 = if diff_code11 & (1 << 5) != 0 {
code0 + (diff_code11 & 0x1f)
} else {
code0 + diff_code11
code0 - diff_code11
} - 123;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be extracted into an n-bit signed subtraction, I think this isn't the only place we use something similar?

// This chip does not follow the ESP32-C6 layout: there are no reference-connect
// bits, and the ground-connect bits live in register 8.
//
// See <https://github.com/espressif/esp-idf/blob/v6.1/components/soc/esp32c5/include/soc/regi2c_saradc.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep the link, drop the comment. The chip also doesn't follow a bunch of other things, calling out C6 is a sort of "why I'm changing this" comment, not something that needs to be kept. LLMs do this way too much.

@bjoernQ bjoernQ linked an issue Sep 22, 2026 that may be closed by this pull request
@bjoernQ bjoernQ changed the title WIP Fix ADC ADC Improvements Sep 22, 2026
@bjoernQ
bjoernQ marked this pull request as ready for review September 22, 2026 15:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect results from calibrated ADC readings

2 participants