Skip to content

Zephyr: Add ADC support. #17616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bikeNomad
Copy link
Contributor

Summary

This PR adds support for ADC peripherals in the Zephyr port.

As is typical for Zephyr, the ADC channel setup is done in the devicetree (typically using an overlay).

This code requires ADC channels to be listed in the io-channels property of the zephyr,user root node like this:

/ {
	zephyr,user {
		io-channels = <&adc 0>, <&adc 1>, <&adc 4>, <&adc 5>, <&adc 7>;
	};
};

&adc {
	#address-cells = <1>;
	#size-cells = <0>;

	channel@0 {
		reg = <0>;
		zephyr,gain = "ADC_GAIN_1_6";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
		zephyr,input-positive = <NRF_SAADC_AIN0>; /* P0.02 */
		zephyr,resolution = <12>;
	};
       // other channels defined here (1, 4, 5, 7)
};

Testing

I have tested this on the Seeed Studio XIAO BLE NRF52840 SENSE board.

Trade-offs and Alternatives

This code may be enabled and disabled by the usual means in mpconfigport.h:

#define MICROPY_HW_ENABLE_ADC (1)
#define MICROPY_PY_MACHINE_ADC (1)
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/zephyr/machine_adc.c"
#define MICROPY_PY_MACHINE_ADC_READ (1)
#define MICROPY_PY_MACHINE_ADC_READ_UV (1)

Copy link

codecov bot commented Jul 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.56%. Comparing base (1b0cdc0) to head (b293326).
Report is 16 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17616   +/-   ##
=======================================
  Coverage   98.56%   98.56%           
=======================================
  Files         169      169           
  Lines       21946    21948    +2     
=======================================
+ Hits        21632    21634    +2     
  Misses        314      314           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bikeNomad bikeNomad marked this pull request as draft July 5, 2025 00:21
@bikeNomad
Copy link
Contributor Author

bikeNomad commented Jul 5, 2025

This PR includes @dpgeorge 's PRs #17610, #17599, and #17552. I don't think it'll work as well without those.

Copy link

github-actions bot commented Jul 5, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@jonnor
Copy link
Contributor

jonnor commented Jul 7, 2025

Hi @bikeNomad and thank you for this merge request. There seems to be a number of other commits included. Would it be possible to have just the commits related to the ADC here?

@dpgeorge
Copy link
Member

dpgeorge commented Jul 8, 2025

I've now merged those other PRs, so please can you rebase this PR on latest master?

bikeNomad added 2 commits July 8, 2025 15:40
This provides ADC functionality for Zephyr ports.
It requires a particular devicetree structure to be able to find
the ADC channels.

Signed-off-by: Ned Konz <ned@metamagix.tech>
@bikeNomad bikeNomad force-pushed the ned/zephyr-add-adc branch from b293326 to 2d35d46 Compare July 8, 2025 22:41
@bikeNomad
Copy link
Contributor Author

I've now merged those other PRs, so please can you rebase this PR on latest master?

Done.

@bikeNomad bikeNomad marked this pull request as ready for review July 8, 2025 22:44
@dpgeorge dpgeorge added this to the release-1.26.0 milestone Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy