-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add ADC support on ESP32|S2|S3|C3|C6|H2 #16228
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
Add ADC support on ESP32|S2|S3|C3|C6|H2 #16228
Conversation
[Experimental Bot, please feedback here] This PR appears to meet the NuttX requirements, although some minor improvements could be made. Strengths:
Areas for Improvement:
Verdict: Overall, the PR seems well-structured and provides enough information to understand the changes. Addressing the minor points above, particularly including "before change" logs, would further strengthen the PR. |
static void esp_adc_reset(struct adc_dev_s *dev) | ||
{ | ||
struct esp_adc_dev_s *priv = (struct esp_adc_dev_s *)dev->ad_priv; | ||
|
||
DEBUGASSERT(priv); | ||
} |
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.
Why? 🙃
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.
Why what? Nothing inside? Future use could benefit, right now I didn't see a clear use case.
What do you think?
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.
Ok, I suggest include some comments just to make it clean
Add common ADC source for ESP32|S2|S3. Remove legacy ADC from ESP32S3. Signed-off-by: Filipe Cavalcanti <[email protected]>
Add common source for ADC that supports ESP32-C3|C6|H2. Signed-off-by: Filipe Cavalcanti <[email protected]>
Adds adc defconfig and board support for: esp32-devkitc, esp32s2-saola-1 and esp32s3-devkit. Signed-off-by: Filipe Cavalcanti <[email protected]>
Adds adc defconfig and board support for: esp32c3-generic, esp32c6-devkitc and esp32h2-devkit. Signed-off-by: Filipe Cavalcanti <[email protected]>
Add documentation for ADC on RISC-V and Xtensa Espressif devices. Signed-off-by: Filipe Cavalcanti <[email protected]>
e0fd5b5
to
f0e2dbd
Compare
Summary
This PR adds support for ADC oneshot on Espressif devices.
It supports reading of all available ADC channels of the device. The user may use the adc defconfig which enables one ADC unit, usually with 3 or 4 channels by default.
The documentation has been updated for each SoC, describing the all GPIOs associated to a particular channel, some limitations and usage example.
On the usability side, all channels, ADC units and input voltage attenuation can be modified via menuconfig. Also, ADC calibration is enabled and applied by default (if the device supports it).
Special mention for ESP32S3: this device already had an ADC implementation. I have removed it but added some Kconfig entries to keep backwards compatibility, so the user should be able to compile but not use the same as before, since device registration has changed to keep up with ADC API.
Impact
Impact on user: Yes. Impacts users that use ADC on ESP32S3. Application should still compile, however the ADC character driver now represents an entire ADC unit instead of registering one character driver for each channel.
Impact on build: No.
Impact on hardware: Yes. This PR adds support for ADC on: ESP32|S2|S3|C3|C6|H2.
Impact on documentation: Yes. Updates documentation for ESP32|S2|S3|C3|C6|H2 regarding ADC peripheral support.
Impact on security: No.
Impact on compatibility: Only for ESP32S3. See "impact on user".
Testing
This procedure was done manually for all boards of this PR. All ADC channels were tested by setting 0 and 3.3 V and reading the ADC application output. A complementary test had a potentiometer to evaluate the voltage range.
A test application was developed to apply the internal pull-up and pull-down resistors of the GPIOs to automatically test the ADC (which will be running on Espressif's internal CI).
Building
The ADC defconfig enables the ADC unit 1 and 3 or 4 channels by default. For testing, we enable the ADC unit 2 and all possible channels.
./tools/configure.sh esp32-devkitc:adc
CONFIG_DEBUG_FEATURES
CONFIG_DEBUG_ASSERTIONS
CONFIG_DEBUG_ANALOG
CONFIG_ESPRESSIF_ADC_2
CONFIG_ESPRESSIF_ADC_1_CH0
throughCONFIG_ESPRESSIF_ADC_1_CH9
CONFIG_ESPRESSIF_ADC_2_CH0
throughCONFIG_ESPRESSIF_ADC_2_CH9
CONFIG_EXAMPLES_ADC_GROUPSIZE=10
CONFIG_ADC_FIFOSIZE=11
Running
Connect the GPIO pins to a test voltage and run the ADC example for each unit:
adc -n 1 -p /dev/adc0
adc -n 1 -p /dev/adc1
Results
I'll summarize the results. OK means the voltage reading was good even though it might be off by some mV, which is expected on some SoCs.
I have some tables with the test results (SOC, channel, voltage max, min, etc) but I won't put it here since it is too long. I can upload somewhere if necessary.
ESP32 (ESP32_DevKitc_V4)
ESP32S2 (ESP32-S2-Saola-1_V1.2)
ESP32S3 (ESP32-S3-DevKitC-1 v1.0)
ESP32C3 (ESP32-C3-DevKitC-02 V1.1)
ESP32C6 (ESP32-C6-DevKitC-1 V1.1)
ESP32H2 (ESP32-H2-DevKitM-1 V1.2)
Here's the log output for the ESP32S3, with verbosity high. All ADC channels are enabled on both ADC units (/dev/adc0 and /dev/adc1). We can see the ADC bringup, calibration and results. It is similar to all devices.
Now reading the ADC unit 1. We expect values to be floating since nothing is connected to the pins.
And finally ADC unit 2: