-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
fix: USB C vbus Kconfig #62740
Closed
Closed
fix: USB C vbus Kconfig #62740
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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(vbatt) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains 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,50 @@ | ||||||
.. _vbatt_sample: | ||||||
|
||||||
Battery Voltage Measurement Sample | ||||||
################################## | ||||||
|
||||||
Overview | ||||||
******** | ||||||
|
||||||
This sample demonstrates how one can use the configuration of the Zephyr ADC infrastructure to | ||||||
measure the voltage of the device power supply using a voltage-divider. The sample assumes a | ||||||
regulator that provides a fixed voltage to IO38 of the esp32 behind a voltage divider. In this | ||||||
sample the voltage divider consists of 300k and 100k Ohms resistors. It will then print the measured | ||||||
battery voltage to the console. If you take care to not power the device thru the usb port, you can | ||||||
see how the battery voltage decreases over time, Thus indicating the current charging level. | ||||||
|
||||||
Application Details | ||||||
=================== | ||||||
|
||||||
The application initializes battery measurement on startup, then loops | ||||||
displaying the battery status every five seconds. | ||||||
|
||||||
Requirements | ||||||
************ | ||||||
|
||||||
A charging regulator (e.g. MAX777) connected to a voltage divider to the | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence is incomplete. |
||||||
|
||||||
|
||||||
Building and Running | ||||||
******************** | ||||||
|
||||||
This application can be built and executed on QEMU as follows: | ||||||
|
||||||
.. zephyr-app-commands:: | ||||||
:zephyr-app: samples/drivers/vbatt | ||||||
:host-os: unix | ||||||
:board: esp32_devkitc_wrover | ||||||
:goals: build flash | ||||||
:compact: | ||||||
|
||||||
To build for another board, change "qemu_x86" above to that board's name. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Sample Output | ||||||
============= | ||||||
|
||||||
.. code-block:: console | ||||||
|
||||||
bat=1.85V | ||||||
bat=1.80V | ||||||
bat=1.85V | ||||||
bat=1.80V |
This file contains 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,34 @@ | ||
/* | ||
* Copyright (c) 2023 Mark Kettner <mark@kettner.io> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
aliases { | ||
battery = &vbatt; | ||
}; | ||
|
||
vbatt: vbatt { | ||
compatible = "zephyr,usb-c-vbus-adc"; | ||
status = "okay"; | ||
io-channels = <&adc0 3>; | ||
output-ohms = <300000>; | ||
full-ohms = <(300000 + 100000)>; | ||
}; | ||
|
||
}; | ||
|
||
&adc0 { | ||
status = "okay"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
channel@3 { | ||
reg = <3>; | ||
zephyr,gain = "ADC_GAIN_1_4"; | ||
zephyr,reference = "ADC_REF_INTERNAL"; | ||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; | ||
zephyr,resolution = <12>; | ||
}; | ||
}; |
This file contains 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,5 @@ | ||
CONFIG_USBC_VBUS_ADC=y | ||
CONFIG_USBC_VBUS_DRIVER=y | ||
|
||
CONFIG_GPIO=y | ||
CONFIG_ADC=y |
This file contains 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,24 @@ | ||
/* | ||
* Copyright (c) 2023 Mark Kettner <mark@kettner.io> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/usb_c/usbc_vbus.h> | ||
#include <zephyr/kernel.h> | ||
|
||
#define BAT_NODE DT_ALIAS(battery) | ||
static const struct device *bat_dev = DEVICE_DT_GET(BAT_NODE); | ||
|
||
int main(void) | ||
{ | ||
int rc = 0; | ||
int mea; | ||
|
||
for (;;) { | ||
usbc_vbus_measure(bat_dev, &mea); | ||
printf("bat=%i.%iV", mea / 100, mea % 100); | ||
k_sleep(K_SECONDS(5)); | ||
} | ||
} |
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.
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'm not sure what you mean by "indicates the current charging level". Your sample only prints the battery voltage. Without knowing the battery capacity and/or empty voltage, I'm not sure how one infers the charge level.