Skip to content

feat: add adc frontend interface - #206

Draft
IM-TechieScientist wants to merge 1 commit into
fossasia:dev26from
IM-TechieScientist:adc-frontend-interface
Draft

feat: add adc frontend interface#206
IM-TechieScientist wants to merge 1 commit into
fossasia:dev26from
IM-TechieScientist:adc-frontend-interface

Conversation

@IM-TechieScientist

@IM-TechieScientist IM-TechieScientist commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Working on #201.
This PR adds a hardware agnostic ADC frontend interface for the DSO/MSO capture paths.

  • Adds a generic ADC frontend registry and driver interface in system/instrument.
  • Adds the current RP2350 internal ADC as the first registered backend.
  • Refactors DSO and mixed signal capture to use the frontend interface instead of directly depending on platform/adc_capture.
  • Keeps the existing internal ADC behavior working while creating a clean path for the future external parallel ADC backend.
  • Adds frontend capabilities for channel/rate/sample count limits and sample width.

Summary by Sourcery

Introduce a hardware-agnostic ADC frontend layer and migrate existing capture paths to use it.

New Features:

  • Add a generic ADC frontend abstraction with backend selection, capability querying, and capture control APIs.
  • Register the RP2350 internal ADC as an ADC frontend backend with defined capabilities and capture metadata reporting.
  • Add an optional capture-complete callback mechanism for ADC frontend users.

Enhancements:

  • Refactor DSO and mixed-signal instruments to use the ADC frontend interface instead of the platform-specific ADC capture API while preserving behavior.
  • Expose ADC capabilities such as channel limits, sample rate bounds, maximum sample count, and sample width to instrument code for validation.
  • Integrate ADC frontend and internal ADC backend initialization into the platform startup sequence.

Build:

  • Include the new ADC frontend core and internal ADC backend source files in the build configuration.

@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a hardware-agnostic ADC frontend layer and registry, wires the existing RP2350 internal ADC through this abstraction, and refactors DSO and mixed-signal capture paths to use the new interface and capability reporting instead of depending directly on platform/adc_capture.

Sequence diagram for DSO capture via ADC frontend

sequenceDiagram
    participant Dso as DsoInstrument
    participant Frontend as AdcFrontend
    participant Driver as AdcFrontendDriver_internal
    participant Capture as AdcCapture

    Dso->>Frontend: adc_frontend_init(config{backend=INTERNAL})
    Frontend->>Frontend: adc_frontend_select_backend(INTERNAL)
    Frontend->>Driver: init(config)
    Driver-->>Frontend: bool
    Frontend-->>Dso: bool

    Dso->>Frontend: adc_frontend_run(buffer, sample_count, info)
    Frontend->>Driver: run(buffer, sample_count, info)
    Driver->>Capture: adc_capture_run(buffer, sample_count, capture_info)
    Capture-->>Driver: bool
    Driver-->>Frontend: bool
    Frontend-->>Dso: bool
Loading

File-Level Changes

Change Details Files
Add a generic ADC frontend abstraction and driver registry for multiple ADC backends.
  • Introduce adc_frontend.h defining backend enums, capability/config/capture metadata structs, driver vtable, and public API for registering/selecting backends and performing captures.
  • Implement adc_frontend.c with a small fixed registry of drivers, active-backend tracking, init/configure/deinit logic, validation of sample counts, conversion of driver results into last_info, and an optional completion callback.
  • Expose helpers to query backend capabilities, map channels to GPIOs, and query busy state, ensuring the active backend is deinitialized when switching.
src/system/instrument/adc_frontend.h
src/system/instrument/adc_frontend.c
Wrap the existing platform adc_capture implementation as the first ADC frontend backend for the RP2350 internal ADC.
  • Add an internal ADC frontend driver that adapts AdcFrontendConfig and AdcFrontendCaptureInfo to and from the existing AdcCaptureConfig/AdcCaptureInfo structures and API.
  • Define driver capabilities using ADC_CAPTURE_* constants and a fixed INTERNAL_ADC_MAX_SAMPLE_COUNT and sample_width_bits=12.
  • Provide an internal_adc_frontend_register() function and call it from PLATFORM_init() so the driver is registered at startup, and wire the new source file into the build.
src/platform/internal_adc_frontend.h
src/platform/internal_adc_frontend.c
src/platform/platform.c
CMakeLists.txt
Refactor DSO capture path to use the ADC frontend interface and capabilities instead of platform adc_capture directly.
  • Replace adc_capture.h usage with adc_frontend.h, selecting ADC_FRONTEND_BACKEND_INTERNAL in configuration and capture calls.
  • Use adc_frontend_get_capabilities() to validate requested channel and sample rate against backend limits instead of ADC_CAPTURE_* macros.
  • Update capture initiation, streaming, trigger sampling, status, and GPIO mapping paths to call adc_frontend_init/configure/run/read_once/is_busy/channel_to_gpio and to use AdcFrontendCaptureInfo.
src/system/instrument/dso.c
Refactor mixed-signal capture to use the ADC frontend abstraction for analog captures while preserving logic analyser handling.
  • Replace adc_capture integration with adc_frontend calls, configuring ADC_FRONTEND_BACKEND_INTERNAL for the analog channel while leaving logic_analyser usage unchanged.
  • Use adc_frontend_get_capabilities() to validate analog channel and sample rate and to determine max channel and rate limits.
  • Update initiation flow to arm/start/wait/abort analog captures through adc_frontend_* functions and to consume AdcFrontendCaptureInfo instead of AdcCaptureInfo.
src/system/instrument/mixed_signal.c

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

1 participant