Skip to content

arch/arm/ameba: add shared ADC driver for RTL8721Dx / RTL8720F / RTL8721F - #19899

Open
dcgong2917 wants to merge 3 commits into
apache:masterfrom
dcgong2917:ameba-adc
Open

arch/arm/ameba: add shared ADC driver for RTL8721Dx / RTL8720F / RTL8721F#19899
dcgong2917 wants to merge 3 commits into
apache:masterfrom
dcgong2917:ameba-adc

Conversation

@dcgong2917

Copy link
Copy Markdown
Contributor

Summary

Adds a shared Ameba SAR-ADC driver plus per-chip integration for three
Realtek parts. Structured as three self-contained commits (each builds and
can be reviewed independently):

  • arch/arm/rtl8721dx: the shared driver (arch/arm/src/common/ameba/ ameba_adc.{c,h}) + pke8721daf integration and board table
  • arch/arm/rtl8720f: RTL8720F chip header + board table
  • arch/arm/rtl8721f: RTL8721F chip header + board table

The converter is exposed as a NuttX ADC character device at /dev/adc0.
It has a single channel-switch list; the board bring-up selects which
channels are sampled and which analog pad each external channel maps to.
Every listed channel is sampled, in order, on each ANIOC_TRIGGER.

The driver sits on the SDK fwlib register layer and reads the auto
channel-switch FIFO by polling in task context (the hardware does not
enable a software-trigger path, so this is the supported on-demand read).
It reports the raw right-aligned conversion code, matching the NuttX
convention used by other in-tree ADC drivers.

Per-chip differences (pinmux code, aux clock gate, the real fwlib
ADC_InitTypeDef size) live in each ameba_adc_chip.h; the shared driver
mirrors only the leading opmode/cvlistlen/cvlist prefix it actually writes
and sizes a reserved[] tail from AMEBA_ADC_INIT_SIZE with a
static_assert so a new port cannot under-size the stack object. The
per-chip ClkDiv write is guarded by AMEBA_ADC_HAS_CLKDIV (only amebadplus
has that field at that offset).

Impact

New opt-in feature (CONFIG_AMEBA_ADC, default n). No change to existing
configurations. Documentation updated for each board's index.rst.

Testing

Built and hardware-tested on all three targets (<board>:adc config,
adc NSH example):

  • pke8721daf (RTL8721Dx): PB19 grounded -> 132, PB19 @3.3V -> 3886,
    other channel steady (channel isolation OK)
  • rtl8720f_evb (RTL8720F): grounded -> 5, @3.3V -> 3863, isolation OK
  • rtl8721f_evb (RTL8721F): grounded -> 123, @3.3V -> 3918, isolation OK

nxstyle clean (only the standing vendor-symbol Mixed-case exemptions).
CMake and make builds both verified for each board.

Add a NuttX ADC lower-half for the Ameba SoC family, wired for the
amebadplus/pke8721daf as /dev/adc0.  The driver uses the fwlib ROM
API and drives on-demand polled conversions via ADC_ReceiveBuf with
the hardware auto channel-switch FIFO, because amebadplus disables the
ADC software-trigger path.  Per-chip wiring (channel count, pinmux
function id, APB clock bits, optional aux clock) lives in a chip
header so a new IC only supplies its own values without touching the
shared driver.

Reports raw conversion codes per the NuttX convention (12-bit
effective, 0..~3876 for 0..3.3V), consistent with the STM32/i.MXRT/
Tiva ADC drivers.

Verified on hardware: 0V->121, 3.3V->3876 on CH0(PB19) while
CH1(PB18) held steady, confirming sampling, full-scale and
multi-channel switch-list isolation.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
Wire the shared Ameba ADC driver into the RTL8720F build: add the
per-chip ameba_adc_chip.h (9 channels, CH0..CH5 external on
PA13..PA18, PINMUX function 5, APB clock on bit24), the board ADC
table and registration, the adc board config, and build glue for
both cmake and make (including the fwlib RAM-layer ameba_adc.c in
ameba_board.mk). Document the ADC on the board index.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
Wire the shared Ameba ADC driver into the RTL8721F build: add the
per-chip ameba_adc_chip.h (12 channels, CH0..CH7 external on
PA20,PA19,PA18,PA17,PA15,PA14,PA13,PA12, PINMUX function 5), the
board ADC table and registration, the adc board config, and build
glue for both cmake and make (including the fwlib RAM-layer
ameba_adc.c in ameba_board.mk). Document the ADC on the board index.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm Issues related to ARM (32-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm labels Aug 19, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

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

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Documentation Improvements or additions to documentation Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants