Conversation
…dt() Agent-Logs-Url: https://github.com/mlp6/Embedded-Medical-Devices/sessions/2f360183-6aae-4584-81b0-e572640881b7 Co-authored-by: mlp6 <3239175+mlp6@users.noreply.github.com>
There was a problem hiding this comment.
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.
|
|
||
| int ret; | ||
| ret = adc_read(adc_vadc.dev, &sequence); | ||
| // adc_read_dt() takes the adc_dt_spec struct directly (no .dev member needed) |
There was a problem hiding this comment.
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).
| // 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. |
| int ret = adc_read_async_dt(&adc_vadc, &sequence, &adc_signal); | ||
| if (ret < 0) { | ||
| LOG_ERR("Could not start async ADC read (%d)", ret); | ||
| } |
There was a problem hiding this comment.
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.
The ADC slides were using the legacy
adc_read(dev, &seq)/adc_read_async(dev, &seq, &sig)APIs that require manually dereferencing.devfrom the DT spec struct. The current recommended pattern passes theadc_dt_specdirectly.Changes in
slides/zephyr-adc.qmdSync read — replace
adc_read(adc_vadc.dev, &sequence)withadc_read_dt(&adc_vadc, &sequence); add inline return-value documentation:Async read — replace
adc_read_async(adc_dev, &sequence, &adc_signal)withadc_read_async_dt(&adc_vadc, &sequence, &adc_signal); add error-checking on the return valueReturn 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 completedProse — update all remaining
adc_read()/adc_read_async()references (including the callout-tip) to use the_dtvariants