Skip to content

ADC slides: migrate to adc_read_dt() / adc_read_async_dt() with return value coverage#13

Merged
mlp6 merged 2 commits intomainfrom
copilot/update-adc-read-functions
Apr 5, 2026
Merged

ADC slides: migrate to adc_read_dt() / adc_read_async_dt() with return value coverage#13
mlp6 merged 2 commits intomainfrom
copilot/update-adc-read-functions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 5, 2026

The ADC slides were using the legacy adc_read(dev, &seq) / adc_read_async(dev, &seq, &sig) APIs that require manually dereferencing .dev from the DT spec struct. The current recommended pattern passes the adc_dt_spec directly.

Changes in slides/zephyr-adc.qmd

  • Sync read — replace adc_read(adc_vadc.dev, &sequence) with adc_read_dt(&adc_vadc, &sequence); add inline return-value documentation:

    // Return values: 0 on success, -EINVAL (bad param), -ENOMEM (buffer too small),
    //                -ENOTSUP (mode not supported), -EBUSY (previous sampling still in progress)
    ret = adc_read_dt(&adc_vadc, &sequence);
  • Async read — replace adc_read_async(adc_dev, &sequence, &adc_signal) with adc_read_async_dt(&adc_vadc, &sequence, &adc_signal); add error-checking on the return value

  • Return value coverage — add a bullet list in the "Asynchronous ADC" section explicitly documenting all return codes (0, -EINVAL, -ENOMEM, -ENOTSUP, -EBUSY) and clarifying that the return is immediate — it signals whether the sequence was started, not completed

  • Prose — update all remaining adc_read()/adc_read_async() references (including the callout-tip) to use the _dt variants

Copilot AI assigned Copilot and mlp6 Apr 5, 2026
Copilot AI linked an issue Apr 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Update ADC functions to use adc_read_dt and adc_read_async_dt ADC slides: migrate to adc_read_dt() / adc_read_async_dt() with return value coverage Apr 5, 2026
Copilot AI requested a review from mlp6 April 5, 2026 18:13
Copilot finished work on behalf of mlp6 April 5, 2026 18:13
@mlp6 mlp6 marked this pull request as ready for review April 5, 2026 18:34
Copilot AI review requested due to automatic review settings April 5, 2026 18:34
@mlp6 mlp6 merged commit 516f0fa into main Apr 5, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Zephyr ADC slide deck to use the recommended adc_*_dt() APIs that accept struct adc_dt_spec * directly, and expands the documentation around asynchronous return values to reduce confusion about “started vs completed”.

Changes:

  • Migrate synchronous reads to adc_read_dt(&adc_vadc, &sequence) and document expected return codes inline.
  • Migrate asynchronous reads to adc_read_async_dt(&adc_vadc, &sequence, &adc_signal) and add basic return-value checking.
  • Expand “Asynchronous ADC” section to explicitly document immediate return semantics and error codes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread slides/zephyr-adc.qmd

int ret;
ret = adc_read(adc_vadc.dev, &sequence);
// adc_read_dt() takes the adc_dt_spec struct directly (no .dev member needed)
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

The note "no .dev member needed" is a bit ambiguous in this snippet because .dev is still used for logging just above; consider rephrasing to clarify that .dev is not needed for the adc_read_dt() call, but the dt spec still contains .dev for other uses (e.g., name/ready checks).

Suggested change
// adc_read_dt() takes the adc_dt_spec struct directly (no .dev member needed)
// adc_read_dt() takes the adc_dt_spec struct directly; for this call, do not pass `.dev`.
// The dt spec still contains `.dev` for other uses, such as logging the device name above.

Copilot uses AI. Check for mistakes.
Comment thread slides/zephyr-adc.qmd
Comment on lines +266 to +269
int ret = adc_read_async_dt(&adc_vadc, &sequence, &adc_signal);
if (ret < 0) {
LOG_ERR("Could not start async ADC read (%d)", ret);
}
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

If adc_read_async_dt() fails (ret < 0), the slide's flow still proceeds to a k_poll(..., K_FOREVER) wait below, which would block forever because no signal will be raised. Consider returning/branching on error (or using a finite timeout) so the example can't deadlock when startup fails.

Copilot uses AI. Check for mistakes.
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.

ADC: use adc_read_dt()

3 participants