Skip to content

Conversation

AdrianSoundy
Copy link
Member

@AdrianSoundy AdrianSoundy commented Oct 2, 2025

Description

This updates the IDF api for ADC from legacy to latest API before it gets removed from IDF.

Because there is a dependency between the legacy ADC and the legacy I2S was not able to upgrade the ESP32 target until the I2S driver has been updated. The reason for this is the ESP32 has an internal DAC & ADC which can be used with I2S. The other ESP32 series don't have these. It also looks like the latest API for I2S doesn't support the internal DAC and once upgraded ww will have to remove that support from managed I2S driver.

The ADC driver is now re-enabled for Esp32_C6 and ESP32_H2 as it no longer hangs on start with new API.

Motivation and Context

Start of change to update all legacy IDF api drivers and fix missing ADC from C6 & H2 targets

Part of change for nanoframework/Home#1580

How Has This Been Tested?

Tested with ESP32_S3 and ESP32_C6 targets

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features

    • Enabled analog input (System.Device.Adc) on ESP32-C6 and ESP32-H2 targets.
    • Added ADC support and GPIO channel mappings for ESP32-P4.
  • Refactor

    • Improved ADC initialization and per-unit management for more reliable readings across ESP32 variants.
    • Target-aware header selection for better compatibility with ESP-IDF targets.
  • Chores

    • Integrated ESP-IDF ADC component into the ESP32 build and updated presets.
  • Style

    • Minor formatting and comment cleanups in device mappings.

Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Enables and wires ESP32 ADC support: adds esp_adc to build, toggles ADC feature flags for C6/H2, updates ESP32 device pin mappings, conditions ADC header inclusion per target, and refactors native ADC controller/channel code to a per-unit adc_oneshot flow with per-unit handles and new lifecycle/channel APIs.

Changes

Cohort / File(s) Summary
Build system: enable ADC on ESP32
CMake/binutils.ESP32.cmake
Adds esp_adc to IDF_COMPONENTS_TO_ADD and idf::esp_adc to IDF_LIBRARIES_TO_ADD inside nf_add_idf_as_library.
Feature presets: ADC ON for C6/H2
CMake/riscv-esp32c6.json, CMake/riscv-esp32h2.json
Sets API_System.Device.Adc from OFF to ON in both RISCV ESP32 preset configs.
CMake module formatting
CMake/Modules/FindSystem.Device.Adc.cmake
Removed an extraneous blank line; no semantic change.
ESP32 ADC headers selection
targets/ESP32/_include/esp32_idf.h
Conditionally includes driver/adc.h for CONFIG_IDF_TARGET_ESP32 and esp_adc/adc_oneshot.h for other targets.
Device mappings updates
targets/ESP32/_common/ESP32_H2_DeviceMapping.cpp, targets/ESP32/_common/ESP32_P4_DeviceMapping.cpp, targets/ESP32/_common/ESP32_C6_DeviceMapping.cpp
H2: ADC1 mapping changed to explicit 5-channel list {1,2,3,4,5}; P4: ADC1 mapped to GPIO16–23 and ADC2 to GPIO49–54; C6: formatting/comment updates and minor UART formatting tweaks.
ADC native channel read split
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp
Splits read flow by target: legacy CONFIG_IDF_TARGET_ESP32 path uses driver APIs (including temperature sensor handling), other targets use adc_oneshot_read via per-unit handles; updates channel handling and error mapping.
ADC native controller refactor
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp
Introduces per-unit adc_oneshot handle management and lifecycle APIs (GetAdcHandle, AdcController_Initialize, AdcController_delete), per-unit lazy init, updated NativeOpenChannel and added getters: NativeGetChannelCount, NativeGetMaxValue, NativeGetMinValue, NativeIsChannelModeSupported, NativeGetResolutionInBits, NativeInit; separates flows with #if defined(CONFIG_IDF_TARGET_ESP32).
Public-like declaration added
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp
Adds adc_oneshot_unit_handle_t GetAdcHandle(adc_unit_t unit); declaration in target-conditional branch.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App as Managed App
  participant Ctl as AdcController (native)
  participant Map as DeviceMapping
  participant IDF as ESP-IDF (adc_oneshot)
  rect rgb(238,247,255)
  note right of Ctl: New per-unit adc_oneshot flow (non-classic ESP32)
  end

  App->>Ctl: NativeInit / NativeOpenChannel(channel)
  Ctl->>Map: Resolve unit, gpio, channel
  Ctl->>Ctl: AdcController_Initialize(unit) [lazy init]
  Ctl->>IDF: adc_oneshot_new_unit(unit)
  Ctl->>IDF: adc_oneshot_config_channel(unit, channel, cfg)
  App->>Ctl: NativeReadValue
  Ctl->>IDF: adc_oneshot_read(unit, channel)
  IDF-->>Ctl: value or error
  Ctl-->>App: value or mapped error
Loading
sequenceDiagram
  autonumber
  actor App as Managed App
  participant Ctl as AdcChannel (classic ESP32)
  participant IDF as ESP-IDF legacy ADC
  rect rgb(255,249,240)
  note right of Ctl: Classic ESP32 path (driver/adc.h)
  end

  App->>Ctl: Read channel N
  alt ADC1
    Ctl->>IDF: adc1_get_raw(N)
  else ADC2
    Ctl->>IDF: adc2_get_raw(N, &value)
  else Internal Temp (channel 8)
    Ctl->>IDF: temprature_sens_read()
  else Removed Hall (channel 9)
    Ctl-->>App: CLR_E_INVALID_PARAMETER
  end
  IDF-->>Ctl: value or status
  Ctl-->>App: value or mapped error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately captures the core update of migrating the ADC integration to the latest ESP32 API and explicitly mentions enabling ADC support for the esp32_H2 and esp32_C6 targets in a concise, single sentence.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9f6e5d and f242cea.

📒 Files selected for processing (1)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (2)
src/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController_stubs.cpp (14)
  • NativeOpenChannel___VOID__I4 (9-17)
  • NativeOpenChannel___VOID__I4 (9-10)
  • NativeGetChannelCount___I4 (19-26)
  • NativeGetChannelCount___I4 (19-19)
  • NativeGetMaxValue___I4 (28-35)
  • NativeGetMaxValue___I4 (28-28)
  • NativeGetMinValue___I4 (37-44)
  • NativeGetMinValue___I4 (37-37)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (46-54)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (46-47)
  • NativeGetResolutionInBits___I4 (56-64)
  • NativeGetResolutionInBits___I4 (56-57)
  • NativeInit___VOID (66-73)
  • NativeInit___VOID (66-66)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (1)
  • GetAdcHandle (91-91)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: nf-interpreter (Build_WIN32_nanoCLR)
  • GitHub Check: nf-interpreter (Build_Azure_RTOS_targets SL_STK3701A)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_P4_UART)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_ETHERNET_KIT_1.2)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_S3_ALL)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_H2_THREAD)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C6_THREAD)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C3)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_BLE_REV0)
  • GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F769I_DISCOVERY)
  • GitHub Check: nf-interpreter (Build_NXP_targets NXP_MIMXRT1060_EVK)
  • GitHub Check: nf-interpreter (Build_TI_SimpleLink_targets TI_CC1352R1_LAUNCHXL_915)
  • GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_PSRAM_REV0)
  • GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F429I_DISCOVERY)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ST_NUCLEO64_F091RC)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (8)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (8)

28-46: LGTM!

The documentation clearly describes the ADC channel mappings across ESP32 variants and explains the rationale for maintaining the legacy driver path for ESP32 (I2S dependency).


50-112: LGTM!

The legacy ESP32 ADC initialization correctly validates channel bounds, determines the ADC unit, and configures channels using the legacy ESP-IDF API with appropriate error handling.


114-179: LGTM!

The legacy query methods return appropriate values for ESP32's ADC configuration (20 channels, 12-bit resolution, single-ended mode only).


183-217: LGTM!

The per-unit handle management correctly implements lazy initialization with proper bounds checking, initialization guards, and cleanup. The use of ESP_ERROR_CHECK is appropriate for initialization failures.


219-265: LGTM!

The new per-unit NativeOpenChannel correctly validates channel bounds, determines the ADC unit, performs lazy initialization, adjusts channel numbers for ADC_UNIT_2, and configures channels using the new ESP-IDF oneshot API with proper error handling.

Also applies to: 273-281


283-293: LGTM!

The new implementation correctly calculates the channel count dynamically from CONFIG_SOC_ADC_MAX_CHANNEL_NUM and CONFIG_SOC_ADC_PERIPH_NUM, making it adaptable across ESP32 variants rather than using a hardcoded value.


295-337: LGTM!

The query method implementations correctly return values consistent with 12-bit ADC resolution (max=4095, min=0, resolution=12) and single-ended channel mode support, matching the legacy implementation.


339-348: LGTM!

The no-op implementation is appropriate since ADC initialization is handled lazily in NativeOpenChannel via AdcController_Initialize.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ddddae and f7cf1ea.

📒 Files selected for processing (12)
  • CMake/Modules/FindSystem.Device.Adc.cmake (1 hunks)
  • CMake/binutils.ESP32.cmake (2 hunks)
  • CMake/riscv-esp32c6.json (1 hunks)
  • CMake/riscv-esp32h2.json (1 hunks)
  • targets/ESP32/_common/ESP32_C6_DeviceMapping.cpp (1 hunks)
  • targets/ESP32/_common/ESP32_H2_DeviceMapping.cpp (1 hunks)
  • targets/ESP32/_common/ESP32_P4_DeviceMapping.cpp (1 hunks)
  • targets/ESP32/_include/esp32_idf.h (1 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (2 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (1 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (3 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController_legacy.cpp (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController_legacy.cpp (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (4)
  • NativeOpenChannel___VOID__I4 (83-145)
  • NativeOpenChannel___VOID__I4 (83-84)
  • NativeGetChannelCount___I4 (147-157)
  • NativeGetChannelCount___I4 (147-147)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (2)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (2)
  • NativeReadValue___I4 (13-67)
  • NativeReadValue___I4 (13-13)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (2)
  • GetAdcHandle (49-57)
  • GetAdcHandle (49-49)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController_legacy.cpp (2)
  • NativeOpenChannel___VOID__I4 (35-97)
  • NativeOpenChannel___VOID__I4 (35-36)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (5)
  • NativeReadValue___I4 (16-73)
  • NativeReadValue___I4 (16-16)
  • temperature_sens_read (11-11)
  • NativeDisposeChannel___VOID (75-84)
  • NativeDisposeChannel___VOID (75-75)
🔇 Additional comments (8)
targets/ESP32/_common/ESP32_P4_DeviceMapping.cpp (1)

62-72: LGTM: ADC pin mappings updated for ESP32_P4.

The explicit GPIO mappings for ADC1 (8 channels) and ADC2 (6 channels) are correctly specified and align with the PR objectives to update ESP32 ADC integration.

Note: The comment on lines 65-66 ("ESP32P4 ADC1 channels 0 - 9, ADC2 channels 10 - 19") is inconsistent with the actual mapping (8 + 6 = 14 channels). Consider removing or updating this comment to match the new description on lines 62-64.

CMake/riscv-esp32h2.json (1)

28-28: LGTM: ADC API enabled for ESP32-H2.

The change enables API_System.Device.Adc for the RISCV ESP32-H2 preset, aligning with the PR objectives to enable ADC support for ESP32_H2 targets.

targets/ESP32/_common/ESP32_H2_DeviceMapping.cpp (1)

61-66: LGTM: ADC mapping updated for ESP32_H2.

The explicit channel mapping (1-5) for ESP32_H2 ADC1 is correctly specified and aligns with the PR objectives to enable ADC support for ESP32_H2 targets using the oneshot API.

targets/ESP32/_common/ESP32_C6_DeviceMapping.cpp (1)

59-65: LGTM: ADC mapping updated for ESP32_C6.

The explicit channel mapping (0-6) for ESP32_C6 ADC1 is correctly specified and aligns with the PR objectives to enable ADC support for ESP32_C6 targets using the oneshot API.

CMake/riscv-esp32c6.json (1)

28-28: LGTM: ADC API enabled for ESP32-C6.

The change enables API_System.Device.Adc for the RISCV ESP32-C6 preset, aligning with the PR objectives to enable ADC support for ESP32_C6 targets.

targets/ESP32/_include/esp32_idf.h (1)

66-72: LGTM: Conditional ADC header inclusion for ESP32 targets.

The conditional inclusion routes ESP32 through the legacy ADC driver (driver/adc.h) due to the dependency with the legacy I2S driver and internal DAC, while other ESP32 variants use the oneshot ADC driver (esp_adc/adc_oneshot.h). This aligns with the PR objectives to update ADC to the latest ESP32 API while preserving legacy support for ESP32.

The comment clearly explains the rationale for the conditional inclusion.

CMake/binutils.ESP32.cmake (1)

690-690: LGTM: esp_adc component integrated into ESP32 IDF build.

The additions of esp_adc to IDF_COMPONENTS_TO_ADD (line 690) and idf::esp_adc to IDF_LIBRARIES_TO_ADD (line 706) correctly integrate the ESP32 ADC component into the IDF build and link stages, aligning with the PR objectives to update ADC to the latest ESP32 API.

Also applies to: 706-706

CMake/Modules/FindSystem.Device.Adc.cmake (1)

19-39: LGTM: Conditional ADC source selection for ESP32 targets.

The conditional logic correctly routes ESP32 targets to legacy ADC source files (sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp, sys_dev_adc_native_System_Device_Adc_AdcController_legacy.cpp) due to the dependency with the legacy I2S driver and internal DAC, while preserving the standard non-legacy sources for other targets. This aligns with the PR objectives to update ADC to the latest ESP32 API while maintaining backward compatibility for ESP32.

The comment on line 19 clearly explains the rationale for the conditional logic.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7cf1ea and 21b4b00.

📒 Files selected for processing (1)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (1)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (4)
  • NativeReadValue___I4 (16-73)
  • NativeReadValue___I4 (16-16)
  • NativeDisposeChannel___VOID (75-84)
  • NativeDisposeChannel___VOID (75-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ST_NUCLEO64_F091RC)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (5)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_legacy.cpp (5)

9-11: Legacy SDK symbol correctly declared.

The misspelled temprature_sens_read() matches the legacy ESP32 SDK's actual symbol name. The call site at line 38 correctly uses this name.


36-45: ESP32 internal sensor handling is correct.

The temperature sensor correctly calls the legacy SDK's temprature_sens_read(), and the Hall sensor appropriately returns an error since it's no longer available in IDF 5.x.


52-68: ADC2 handling is correct.

The ADC2 channel adjustment, legacy API call with proper bitwidth, error checking, and invalid ADC number handling are all implemented correctly.


70-72: Result handling is correct.

The reading value is properly returned to managed code using the standard stack result mechanism.


75-84: Dispose implementation is appropriate.

The no-op implementation matches the non-legacy version and is correct for the legacy ADC API, which doesn't require explicit channel cleanup.

…be14-d2c2-4941-ac40-0d7cd5432a77

Code style fixes for nanoframework/nf-interpreter PR#3216
@nanoframework nanoframework deleted a comment from coderabbitai bot Oct 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad2c3c and a9f6e5d.

📒 Files selected for processing (3)
  • CMake/Modules/FindSystem.Device.Adc.cmake (0 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (4 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (2 hunks)
💤 Files with no reviewable changes (1)
  • CMake/Modules/FindSystem.Device.Adc.cmake
🧰 Additional context used
🧬 Code graph analysis (2)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (2)
src/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel_stubs.cpp (2)
  • NativeReadValue___I4 (9-16)
  • NativeReadValue___I4 (9-9)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (2)
  • GetAdcHandle (185-193)
  • GetAdcHandle (185-185)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (3)
src/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController_stubs.cpp (14)
  • NativeOpenChannel___VOID__I4 (9-17)
  • NativeOpenChannel___VOID__I4 (9-10)
  • NativeGetChannelCount___I4 (19-26)
  • NativeGetChannelCount___I4 (19-19)
  • NativeGetMaxValue___I4 (28-35)
  • NativeGetMaxValue___I4 (28-28)
  • NativeGetMinValue___I4 (37-44)
  • NativeGetMinValue___I4 (37-37)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (46-54)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (46-47)
  • NativeGetResolutionInBits___I4 (56-64)
  • NativeGetResolutionInBits___I4 (56-57)
  • NativeInit___VOID (66-73)
  • NativeInit___VOID (66-66)
targets/ChibiOS/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (14)
  • NativeOpenChannel___VOID__I4 (9-74)
  • NativeOpenChannel___VOID__I4 (9-10)
  • NativeGetChannelCount___I4 (76-84)
  • NativeGetChannelCount___I4 (76-76)
  • NativeGetMaxValue___I4 (86-94)
  • NativeGetMaxValue___I4 (86-86)
  • NativeGetMinValue___I4 (96-103)
  • NativeGetMinValue___I4 (96-96)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (105-116)
  • NativeIsChannelModeSupported___BOOLEAN__I4 (105-106)
  • NativeGetResolutionInBits___I4 (118-127)
  • NativeGetResolutionInBits___I4 (118-119)
  • NativeInit___VOID (129-138)
  • NativeInit___VOID (129-129)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (1)
  • GetAdcHandle (91-91)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ST_NUCLEO64_F091RC)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (8)
targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcChannel.cpp (4)

8-11: LGTM! Good addition of device mapping and target-specific guard.

The inclusion of Esp32_DeviceMapping.h and the CONFIG_IDF_TARGET_ESP32 guard properly separate legacy from new ADC API paths.


38-46: LGTM! Correct handling of deprecated internal channels.

The temperature sensor read and the hall sensor deprecation (IDF 5.x removal) are properly handled for the ESP32 legacy path.


59-60: LGTM! Improved readability.

The multi-line formatting of the adc2_get_raw call improves readability without changing functionality.


107-110: TARGET_ADC_NUM_PINS defined in all ESP32 device mappings Verified the macro is present in every mapping file under targets/ESP32/_common.

targets/ESP32/_nanoCLR/System.Device.Adc/sys_dev_adc_native_System_Device_Adc_AdcController.cpp (4)

28-46: LGTM! Comprehensive documentation of ADC channel layouts.

The updated comments clearly document the ADC channel configurations for all ESP32 variants (ESP32, S2, S3, P4, C3, C6, H2), including the note about IDF 5.x deprecating internal sensors.


283-293: LGTM! Dynamic channel count calculation improves maintainability.

The dynamic calculation using CONFIG_SOC_ADC_MAX_CHANNEL_NUM * CONFIG_SOC_ADC_PERIPH_NUM correctly determines the total channel count for each target without hardcoding, making it more maintainable than the legacy path's hardcoded value of 20.


295-348: LGTM! Native methods correctly implement ADC properties.

All native methods (GetMaxValue, GetMinValue, IsChannelModeSupported, GetResolutionInBits, Init) are correctly implemented and consistent with the 12-bit ADC configuration and legacy behavior.


185-193: Verify adc_unit_t signedness: confirm in the ESP-IDF headers whether adc_unit_t is signed; if it’s unsigned, the unit < 0 check is always false and can be removed.

…a5ff-9201-440e-ba6c-cd7e890bfd23

Code style fixes for nanoframework/nf-interpreter PR#3216
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.

2 participants