feat(adc): Update to support newer chips; improve API consistency; improve continuous adc performance; remove warnings#668
Merged
Conversation
|
✅Static analysis result - no issues found! ✅ |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR updates the ADC component to support newer ESP chips (notably ESP32-P4), align Oneshot/Continuous APIs, improve continuous-mode performance, and replace abort-style failures with clearer validation/logging.
Changes:
- OneshotAdc: add
get_raw()/get_mv()wrappers, fix per-attenuation calibration handling, and tighten channel validation. - ContinuousAdc: derive/validate conversion mode and aggregate sampling rate per chip, remove per-sample hashing/allocations, and add rate-limited logging for invalid/unexpected samples.
- Example/CI: add Kconfig-driven board presets, reorder example sections for ESP32-P4, and build the example for esp32/esp32s3/esp32p4 in CI.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| components/adc/include/oneshot_adc.hpp | Per-attenuation calibration, new API wrappers, improved validation/logging. |
| components/adc/include/continuous_adc.hpp | Chip-aware validation/format selection, dense indexing for hot loop performance, safer shutdown behavior. |
| components/adc/include/adc_types.hpp | Mark comparison operators as optionally unused to reduce warnings. |
| components/adc/example/main/adc_example.cpp | Kconfig-driven unit/channel selection and ESP32-P4 ordering workaround. |
| components/adc/example/main/Kconfig.projbuild | Add board presets + custom configuration menu for unit/channels. |
| components/adc/example/README.md | Document new configuration workflow and board presets. |
| .github/workflows/build.yml | Add ADC example builds for esp32s3 and esp32p4 targets. |
…prove continuous adc performance; remove warnings
…d so the defaults for tab5 work
b71bd4f to
dfca031
Compare
- OneshotAdc / ContinuousAdc destructors are now safe when init() fails or returns early: the driver handles are null-initialized and guarded, and ContinuousAdc no longer creates/starts its reader task (start() errors cleanly) when construction failed - ContinuousAdc::init() now fails fast: validation errors (invalid unit / channel, non-DMA-capable unit, aggregate sample frequency out of range) accumulate and abort initialization before any driver call, so the first reported error is the root cause instead of a later opaque ESP_ERROR_CHECK abort - Encode the 0-based adc_unit_t assumption (ADC_UNIT_1 == 0, matching the SOC_ADC_* capability macros and the DMA output unit field) with a static_assert, and size the id lookup table from SOC_ADC_PERIPH_NUM instead of a hardcoded unit count - Fix compilation on single-ADC chips (C2/C6/H2/...), whose type2 DMA output data has no unit field (pre-existing break, surfaced by the new SOC-based sizing work); add esp32c6 to the example CI matrix to keep it covered Verified: example clean-builds for esp32, esp32p4, and esp32c6. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…of both classes Thread-safety review of both classes. OneshotAdc was already thread-safe (all reads serialize on its recursive mutex; remaining state is immutable after construction) - documented as such. ContinuousAdc had three gaps, now fixed: - start()/stop() had a check-then-act race: concurrent callers could both pass the running_ check and double-start (or double-stop) the driver, turning a driver error into an ESP_ERROR_CHECK abort. Both methods now serialize on a control mutex. - The reader task could wake and read from a driver that another task had just stopped, producing the (benign but noisy) "driver is already stopped" error seen at every stop/destruction; the task now skips the read when not running. - task_handle_ is written by the reader task and read by the conversion-done ISR and the destructor; it is now std::atomic (the ISR does a lock-free load). Verified: example clean-builds for esp32, esp32p4, and esp32c6. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…not BOTH Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Document the two multi-unit continuous conversion modes in both the ContinuousAdc class docs and the continuous_adc rst page: ALTER (the derived default) performs one conversion per trigger alternating between units, keeping every channel at ~sample_rate_hz for any channel mix - right for general multi-channel monitoring; BOTH converts on both units simultaneously in lockstep - right when relative timing matters (e.g. simultaneous voltage + current for instantaneous power), with a note that the effective per-channel rate is then higher than sample_rate_hz. Includes example configurations for each. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
and the aggregate sample frequency against the chip's SOC capabilities with
clear errors instead of an opaque abort
get_mv()andget_raw()to match ContinuousAdcMotivation and Context
How has this been tested?
adc/exampleon ESP32, ESP32-S3, and ESP32-P4 (M5Stack Tab5) with the example preset for each board; verify that the continuous ADC section produces plausible readings and that the oneshot section produces correct calibrated voltagesScreenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.