-
Notifications
You must be signed in to change notification settings - Fork 8k
low cost power shield solution #95056
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
Draft
hakehuang
wants to merge
4
commits into
zephyrproject-rtos:main
Choose a base branch
from
nxp-upstream:lc_power_shield
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,973
−22
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f2526d
samples: boards: nxp: enable power shield on mimxrt595_evk
hakehuang ecc136b
samples: adc: add power shield application
hakehuang 3b1bf2e
tests: scripts: add general power shield support
hakehuang 815f2b6
tests: pm: power_mgmt_soc: enable measurement on rt1060
hakehuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(ADC) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) 2024 Centro de Inovacao EDGE. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config SEQUENCE_SAMPLES | ||
int "Number of samples to be made on the sequence for each channel." | ||
default 5 | ||
|
||
config SEQUENCE_RESOLUTION | ||
int "Set the resolution of the sequence readings." | ||
default 12 | ||
|
||
config SEQUENCE_32BITS_REGISTERS | ||
bool "ADC data sequences are on 32bits" | ||
|
||
source "Kconfig.zephyr" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
.. zephyr:code-sample:: adc_power_shield | ||
:name: Analog-to-Digital Converter (ADC) power shield sample | ||
:relevant-api: adc_interface | ||
|
||
Read analog inputs from ADC channels, using a sequence. | ||
|
||
Overview | ||
******** | ||
|
||
This sample is to enable general power shield for platfroms that have ADC support. | ||
|
||
|
||
Building and Running | ||
******************** | ||
|
||
Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a | ||
child node, with your desired settings like gain, reference, or acquisition time and | ||
oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the | ||
desired adc. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay | ||
<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of | ||
such setup. | ||
|
||
Building and Running for Nordic nRF52840 | ||
======================================== | ||
|
||
The sample can be built and executed for the | ||
:zephyr:board:`nrf52840dk` as follows: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/drivers/adc/adc_sequence | ||
:board: nrf52840dk/nrf52840 | ||
:goals: build flash | ||
:compact: | ||
|
||
To build for another board, change "nrf52840dk/nrf52840" above to that board's name | ||
and provide a corresponding devicetree overlay. | ||
|
||
Sample output | ||
============= | ||
|
||
the output as below, repeated every time you input any char in the console: | ||
|
||
.. code-block:: console | ||
|
||
ADC sequence reading [1]: | ||
- ADC_0, channel 0, 5 sequence samples: | ||
- - 36 = 65mV | ||
- - 35 = 63mV | ||
- - 36 = 65mV | ||
- - 35 = 63mV | ||
- - 36 = 65mV | ||
- ADC_0, channel 1, 5 sequence samples: | ||
- - 0 = 0mV | ||
- - 0 = 0mV | ||
- - 1 = 1mV | ||
- - 0 = 0mV | ||
- - 1 = 1mV | ||
|
||
.. note:: If the ADC is not supported, the output will be an error message. | ||
|
||
You should get similar output as below, if you input a return: | ||
|
||
.. code-block:: console | ||
|
||
==== start of adc features === | ||
CHANNEL_COUNT: 4 | ||
Resolution: 12 | ||
channel_id 0 features: | ||
- is single mode | ||
- verf is 3300 mv | ||
channel_id 3 features: | ||
- is single mode | ||
- verf is 3300 mv | ||
channel_id 4 features: | ||
- is single mode | ||
- verf is 3300 mv | ||
channel_id 7 features: | ||
- is single mode | ||
- verf is 3300 mv | ||
==== end of adc features === |
44 changes: 44 additions & 0 deletions
44
samples/drivers/adc/adc_power_shield/boards/arduino_due.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2024 Centro de Inovacao EDGE | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
aliases { | ||
adc0 = &adc0; | ||
}; | ||
}; | ||
|
||
&adc0 { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
status = "okay"; | ||
|
||
pinctrl-0 = <&adc0_default>; | ||
pinctrl-names = "default"; | ||
|
||
prescaler = <9>; | ||
startup-time = <64>; | ||
settling-time = <3>; | ||
tracking-time = <2>; | ||
|
||
/* External ADC(+) */ | ||
channel@6 { // Connector A1 | ||
reg = <6>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_EXTERNAL0"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <6>; | ||
zephyr,vref-mv = <3300>; | ||
}; | ||
|
||
channel@7 { // Connector A0 | ||
nordicjm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reg = <7>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_EXTERNAL0"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <7>; | ||
zephyr,vref-mv = <3300>; | ||
}; | ||
}; |
62 changes: 62 additions & 0 deletions
62
samples/drivers/adc/adc_power_shield/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* Copyright (c) 2025 Ezurio LLC | ||
*/ | ||
|
||
/ { | ||
zephyr,user { | ||
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>; | ||
}; | ||
}; | ||
|
||
/ { | ||
aliases { | ||
adc0 = &adc; | ||
}; | ||
}; | ||
|
||
&adc { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
channel@0 { | ||
reg = <0>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */ | ||
zephyr,resolution = <10>; | ||
}; | ||
|
||
channel@1 { | ||
reg = <1>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */ | ||
zephyr,resolution = <12>; | ||
zephyr,oversampling = <8>; | ||
}; | ||
|
||
channel@2 { | ||
reg = <2>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */ | ||
zephyr,resolution = <12>; | ||
zephyr,oversampling = <8>; | ||
}; | ||
|
||
channel@7 { | ||
reg = <7>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */ | ||
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */ | ||
zephyr,resolution = <12>; | ||
}; | ||
}; |
62 changes: 62 additions & 0 deletions
62
samples/drivers/adc/adc_power_shield/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* Copyright (c) 2025 Ezurio LLC | ||
*/ | ||
|
||
/ { | ||
zephyr,user { | ||
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>; | ||
}; | ||
}; | ||
|
||
/ { | ||
aliases { | ||
adc0 = &adc; | ||
}; | ||
}; | ||
|
||
&adc { | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
channel@0 { | ||
reg = <0>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */ | ||
zephyr,resolution = <10>; | ||
}; | ||
|
||
channel@1 { | ||
reg = <1>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */ | ||
zephyr,resolution = <12>; | ||
zephyr,oversampling = <8>; | ||
}; | ||
|
||
channel@2 { | ||
reg = <2>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */ | ||
zephyr,resolution = <12>; | ||
zephyr,oversampling = <8>; | ||
}; | ||
|
||
channel@7 { | ||
reg = <7>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */ | ||
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */ | ||
zephyr,resolution = <12>; | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
samples/drivers/adc/adc_power_shield/boards/cy8cproto_062_4343w.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SEQUENCE_RESOLUTION=12 |
35 changes: 35 additions & 0 deletions
35
samples/drivers/adc/adc_power_shield/boards/cy8cproto_062_4343w.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024 Centro de Inovacao EDGE | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/dt-bindings/adc/adc.h> | ||
|
||
/ { | ||
aliases { | ||
adc0 = &adc0; | ||
}; | ||
}; | ||
|
||
&adc0 { | ||
status = "okay"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
channel@0 { | ||
reg = <0>; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,input-positive = <0>; /* P10.0 */ | ||
}; | ||
|
||
channel@1 { | ||
reg = <1>; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,input-positive = <1>; /* P10.1 */ | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
samples/drivers/adc/adc_power_shield/boards/cy8cproto_063_ble.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SEQUENCE_RESOLUTION=12 |
35 changes: 35 additions & 0 deletions
35
samples/drivers/adc/adc_power_shield/boards/cy8cproto_063_ble.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024 Centro de Inovacao EDGE | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/dt-bindings/adc/adc.h> | ||
|
||
/ { | ||
aliases { | ||
adc0 = &adc0; | ||
}; | ||
}; | ||
|
||
&adc0 { | ||
status = "okay"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
channel@0 { | ||
reg = <0>; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,input-positive = <2>; /* P10.2 */ | ||
}; | ||
|
||
channel@1 { | ||
reg = <1>; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>; | ||
zephyr,gain = "ADC_GAIN_1"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,input-positive = <3>; /* P10.3 */ | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE=y |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this is very stale and copied from the original sample (related: do you really need to duplicate the 100s of overlays too??). I have to admit I don't really understand what this is trying to accomplish and the fact that the README hasn't been updated is not really helping.
Just a thought but, if you are calling this a "shield" then maybe you want to create an actual shield (or snippet?), and not a sample?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kartben, the sample application is modified from adc_sequence sample. The idea here is to create a general power shield, which means any adc featured zephyr platform can be used as a power shield. so we can take any of those 100s boards and flashed with this sample, you can use them as general_power_shield fixture for measuring power, see the https://github.com/zephyrproject-rtos/zephyr/blob/af6248f8b7509f505982b8fe5d6e9a6efd8bc0f5/scripts/pylib/power-twister-harness/README.rst this is a full picture for the usage.
the sample readme is just describe how the sample runs.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to provide a platform agonic solution, such as any same feature Zephyr platform can function as the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment thread still applies IMO. I am sorry if I am missing something but simply copying an existing code sample (and its dozens of overlays!) and then calling this a "shield" while shields are something completely different in Zephyr is really incredibly confusing.
Please don't ask for re-review when comments havne't been addressed - the README being an exact copy-paste of the original sample is also pretty problematic. Thanks!