HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
AdcComprehensiveTest.cpp File Reference

Comprehensive ADC testing suite for ESP32-C6 DevKit-M-1 (noexcept) More...

#include "base/BaseAdc.h"
#include "mcu/esp32/EspAdc.h"
#include "mcu/esp32/utils/EspTypes_ADC.h"
#include "TestFramework.h"
#include "hal/adc_types.h"
Include dependency graph for AdcComprehensiveTest.cpp:

Classes

struct  adc_queue_message_t
 

Functions

bool test_hardware_validation () noexcept
 Test hardware setup validation.
 
bool test_adc_initialization () noexcept
 Test ADC initialization and basic setup.
 
bool test_adc_channel_configuration () noexcept
 Test ADC channel configuration.
 
bool test_adc_basic_conversion () noexcept
 Test basic ADC conversion functionality.
 
bool test_adc_calibration () noexcept
 Test ADC calibration functionality.
 
bool test_adc_multiple_channels () noexcept
 Test reading from multiple ADC channels.
 
bool test_adc_averaging () noexcept
 Test ADC averaging functionality.
 
bool test_adc_continuous_mode () noexcept
 Test ADC continuous mode functionality.
 
bool test_adc_monitor_thresholds () noexcept
 Test ADC monitor threshold functionality with proper ESP-IDF sequence.
 
bool test_adc_error_handling () noexcept
 Test ADC error handling.
 
bool test_adc_statistics () noexcept
 Test ADC statistics and diagnostics.
 
bool test_adc_performance () noexcept
 Test ADC performance characteristics.
 
bool initialize_test_adc (EspAdc &adc) noexcept
 Initialize ADC for testing with proper configuration.
 
bool configure_test_channels (EspAdc &adc) noexcept
 Configure test channels with appropriate settings.
 
bool validate_voltage_reading (uint32_t voltage_mv, const char *channel_name) noexcept
 Validate if voltage reading is within reasonable range.
 
bool continuous_callback (const hf_adc_continuous_data_t *data, void *user_data) noexcept
 Continuous mode callback function (ISR-safe) - extracts latest voltage in real-time.
 
void setup_adc_config (hf_adc_unit_config_t &config, hf_adc_mode_t mode) noexcept
 Setup ADC configuration with test channels pre-configured.
 
void monitor_callback (const hf_adc_monitor_event_t *event, void *user_data) noexcept
 Monitor callback function for threshold testing (ISR-safe)
 
void app_main (void)
 

Variables

static const char * TAG = "ADC_Test"
 
static TestResults g_test_results
 
static constexpr hf_channel_id_t TEST_CHANNEL_1 = 3
 
static constexpr hf_channel_id_t TEST_CHANNEL_2 = 0
 
static constexpr hf_channel_id_t TEST_CHANNEL_3 = 1
 
static constexpr uint32_t MIN_VALID_VOLTAGE_MV = 100
 
static constexpr uint32_t MAX_VALID_VOLTAGE_MV = 3200
 
static constexpr uint32_t VOLTAGE_DIVIDER_EXPECTED_MV = 1650
 
static constexpr uint32_t VOLTAGE_DIVIDER_TOLERANCE_MV = 150
 
static constexpr uint32_t GROUND_TOLERANCE_MV = 300
 
static constexpr uint32_t POTENTIOMETER_MAX_MV = 3300
 
static constexpr uint32_t ADC_12BIT_MAX_VALUE = 4095
 
static constexpr uint32_t ADC_12BIT_MID_VALUE = 2048
 
static constexpr uint32_t ADC_VOLTAGE_SCALE_FACTOR = 1000
 
static constexpr uint32_t MONITOR_TEST_DURATION_MS = 15000
 
static constexpr uint32_t MONITOR_UPDATE_INTERVAL_MS = 2000
 
static constexpr uint32_t MONITOR_THRESHOLD_SEPARATION_MV = 800
 
static constexpr uint32_t MONITOR_THRESHOLD_OFFSET_MV = 400
 
static constexpr uint32_t PERFORMANCE_NUM_CONVERSIONS = 1000
 
static constexpr uint32_t PERFORMANCE_MAX_TIME_US = 1000
 
static constexpr uint32_t CONTINUOUS_TEST_DURATION_MS = 2000
 
static constexpr uint32_t CONTINUOUS_SAMPLES_PER_FRAME = 64
 
static constexpr uint32_t CONTINUOUS_MAX_STORE_FRAMES = 4
 
static QueueHandle_t adc_data_queue = nullptr
 
static volatile bool continuous_test_active = false
 
static volatile uint32_t continuous_samples_received = 0
 
static volatile bool monitor_test_active = false
 
static volatile uint32_t high_threshold_count = 0
 
static volatile uint32_t low_threshold_count = 0
 
static volatile uint64_t last_monitor_event_time = 0
 
static constexpr bool ENABLE_CORE_TESTS
 
static constexpr bool ENABLE_CONVERSION_TESTS
 
static constexpr bool ENABLE_ADVANCED_TESTS
 
static constexpr bool ENABLE_PERFORMANCE_TESTS = true
 

Detailed Description

Comprehensive ADC testing suite for ESP32-C6 DevKit-M-1 (noexcept)

This file contains a dedicated, comprehensive test suite for the EspAdc class targeting ESP32-C6 with ESP-IDF v5.5+. It provides thorough testing of all ADC functionalities including basic operations, calibration, continuous conversion, and hardware-specific capabilities.

Hardware Configuration (ESP32-C6 DevKit-M-1):

  • GPIO3 (ADC1_CH3) - Connect to 3.3V via voltage divider (should read ~1.65V)
  • GPIO0 (ADC1_CH0) - Connect to potentiometer center tap (0-3.3V variable for monitor testing)
  • GPIO1 (ADC1_CH1) - Connect to ground via 10k resistor (should read ~0V)

Monitor Test Requirements:

  • Adjust potentiometer on GPIO0 during monitor test to trigger thresholds
  • Test will set thresholds automatically based on initial reading
Author
Nebiyu Tadesse
Date
2025

Function Documentation

◆ app_main()

void app_main ( void )

◆ configure_test_channels()

bool configure_test_channels ( EspAdc & adc)
noexcept

Configure test channels with appropriate settings.

◆ continuous_callback()

bool continuous_callback ( const hf_adc_continuous_data_t * data,
void * user_data )
noexcept

Continuous mode callback function (ISR-safe) - extracts latest voltage in real-time.

◆ initialize_test_adc()

bool initialize_test_adc ( EspAdc & adc)
noexcept

Initialize ADC for testing with proper configuration.

◆ monitor_callback()

void monitor_callback ( const hf_adc_monitor_event_t * event,
void * user_data )
noexcept

Monitor callback function for threshold testing (ISR-safe)

◆ setup_adc_config()

void setup_adc_config ( hf_adc_unit_config_t & config,
hf_adc_mode_t mode = hf_adc_mode_t::ONESHOT )
noexcept

Setup ADC configuration with test channels pre-configured.

◆ test_adc_averaging()

bool test_adc_averaging ( )
noexcept

Test ADC averaging functionality.

◆ test_adc_basic_conversion()

bool test_adc_basic_conversion ( )
noexcept

Test basic ADC conversion functionality.

◆ test_adc_calibration()

bool test_adc_calibration ( )
noexcept

Test ADC calibration functionality.

◆ test_adc_channel_configuration()

bool test_adc_channel_configuration ( )
noexcept

Test ADC channel configuration.

◆ test_adc_continuous_mode()

bool test_adc_continuous_mode ( )
noexcept

Test ADC continuous mode functionality.

◆ test_adc_error_handling()

bool test_adc_error_handling ( )
noexcept

Test ADC error handling.

◆ test_adc_initialization()

bool test_adc_initialization ( )
noexcept

Test ADC initialization and basic setup.

◆ test_adc_monitor_thresholds()

bool test_adc_monitor_thresholds ( )
noexcept

Test ADC monitor threshold functionality with proper ESP-IDF sequence.

Tests threshold monitoring on the potentiometer channel (GPIO0)

Proper ESP-IDF v5.5 sequence:

  1. Use oneshot mode to read baseline voltage from potentiometer
  2. Stop oneshot mode and setup continuous mode with monitor
  3. Configure monitor -> Register callbacks -> Enable monitor -> Start continuous

Expected hardware setup:

  • GPIO0: Connected to potentiometer (0-3.3V variable)

◆ test_adc_multiple_channels()

bool test_adc_multiple_channels ( )
noexcept

Test reading from multiple ADC channels.

◆ test_adc_performance()

bool test_adc_performance ( )
noexcept

Test ADC performance characteristics.

◆ test_adc_statistics()

bool test_adc_statistics ( )
noexcept

Test ADC statistics and diagnostics.

◆ test_hardware_validation()

bool test_hardware_validation ( )
noexcept

Test hardware setup validation.

Validates the expected hardware connections before running other tests

◆ validate_voltage_reading()

bool validate_voltage_reading ( uint32_t voltage_mv,
const char * channel_name )
noexcept

Validate if voltage reading is within reasonable range.

Variable Documentation

◆ ADC_12BIT_MAX_VALUE

constexpr uint32_t ADC_12BIT_MAX_VALUE = 4095
staticconstexpr

◆ ADC_12BIT_MID_VALUE

constexpr uint32_t ADC_12BIT_MID_VALUE = 2048
staticconstexpr

◆ adc_data_queue

QueueHandle_t adc_data_queue = nullptr
static

◆ ADC_VOLTAGE_SCALE_FACTOR

constexpr uint32_t ADC_VOLTAGE_SCALE_FACTOR = 1000
staticconstexpr

◆ CONTINUOUS_MAX_STORE_FRAMES

constexpr uint32_t CONTINUOUS_MAX_STORE_FRAMES = 4
staticconstexpr

◆ CONTINUOUS_SAMPLES_PER_FRAME

constexpr uint32_t CONTINUOUS_SAMPLES_PER_FRAME = 64
staticconstexpr

◆ continuous_samples_received

volatile uint32_t continuous_samples_received = 0
static

◆ continuous_test_active

volatile bool continuous_test_active = false
static

◆ CONTINUOUS_TEST_DURATION_MS

constexpr uint32_t CONTINUOUS_TEST_DURATION_MS = 2000
staticconstexpr

◆ ENABLE_ADVANCED_TESTS

constexpr bool ENABLE_ADVANCED_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_CONVERSION_TESTS

constexpr bool ENABLE_CONVERSION_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_CORE_TESTS

constexpr bool ENABLE_CORE_TESTS
staticconstexpr
Initial value:
=
true

◆ ENABLE_PERFORMANCE_TESTS

constexpr bool ENABLE_PERFORMANCE_TESTS = true
staticconstexpr

◆ g_test_results

TestResults g_test_results
static

◆ GROUND_TOLERANCE_MV

constexpr uint32_t GROUND_TOLERANCE_MV = 300
staticconstexpr

◆ high_threshold_count

volatile uint32_t high_threshold_count = 0
static

◆ last_monitor_event_time

volatile uint64_t last_monitor_event_time = 0
static

◆ low_threshold_count

volatile uint32_t low_threshold_count = 0
static

◆ MAX_VALID_VOLTAGE_MV

constexpr uint32_t MAX_VALID_VOLTAGE_MV = 3200
staticconstexpr

◆ MIN_VALID_VOLTAGE_MV

constexpr uint32_t MIN_VALID_VOLTAGE_MV = 100
staticconstexpr

◆ monitor_test_active

volatile bool monitor_test_active = false
static

◆ MONITOR_TEST_DURATION_MS

constexpr uint32_t MONITOR_TEST_DURATION_MS = 15000
staticconstexpr

◆ MONITOR_THRESHOLD_OFFSET_MV

constexpr uint32_t MONITOR_THRESHOLD_OFFSET_MV = 400
staticconstexpr

◆ MONITOR_THRESHOLD_SEPARATION_MV

constexpr uint32_t MONITOR_THRESHOLD_SEPARATION_MV = 800
staticconstexpr

◆ MONITOR_UPDATE_INTERVAL_MS

constexpr uint32_t MONITOR_UPDATE_INTERVAL_MS = 2000
staticconstexpr

◆ PERFORMANCE_MAX_TIME_US

constexpr uint32_t PERFORMANCE_MAX_TIME_US = 1000
staticconstexpr

◆ PERFORMANCE_NUM_CONVERSIONS

constexpr uint32_t PERFORMANCE_NUM_CONVERSIONS = 1000
staticconstexpr

◆ POTENTIOMETER_MAX_MV

constexpr uint32_t POTENTIOMETER_MAX_MV = 3300
staticconstexpr

◆ TAG

const char* TAG = "ADC_Test"
static

◆ TEST_CHANNEL_1

constexpr hf_channel_id_t TEST_CHANNEL_1 = 3
staticconstexpr

◆ TEST_CHANNEL_2

constexpr hf_channel_id_t TEST_CHANNEL_2 = 0
staticconstexpr

◆ TEST_CHANNEL_3

constexpr hf_channel_id_t TEST_CHANNEL_3 = 1
staticconstexpr

◆ VOLTAGE_DIVIDER_EXPECTED_MV

constexpr uint32_t VOLTAGE_DIVIDER_EXPECTED_MV = 1650
staticconstexpr

◆ VOLTAGE_DIVIDER_TOLERANCE_MV

constexpr uint32_t VOLTAGE_DIVIDER_TOLERANCE_MV = 150
staticconstexpr