1. ADC v2
1.1. Overview
The ADC v2 component provides a unified HAL over HPMicro ADC12 and ADC16 peripherals.
It replaces per-IP adc12_* / adc16_* branching in application code. IP type is
detected at runtime from the handle base address via hpm_adc_v2_get_ip_type.
Enable the component in a sample or application CMakeLists.txt:
set(CONFIG_HPM_ADC_V2 1)
Typical use cases include motor FOC preemption sampling, sequence DMA capture, and
period/oneshot conversion. See samples/motor_ctrl/bldc_foc for a full preempt-DMA
example.
1.2. Features
Unified instance handle
HPM_ADC_V2_HANDLE(base)creates a statelessadc_v2_handle_thpm_adc_v2_get_ip_typematchesbaseagainst SoCHPM_ADCx_BASEmacros; invalid addresses returnadc_v2_ip_unknownOn dual-IP SoCs (
HPM_ADC_V2_HAS_DUAL_IP),HPM_ADC3_BASEmaps to ADC16; other valid ADC bases map to ADC12
Conversion modes (
adc_v2_conv_mode_t)Oneshot:
hpm_adc_v2_get_oneshot_resultPeriod:
hpm_adc_v2_set_period_configandhpm_adc_v2_get_prd_resultSequence:
hpm_adc_v2_set_sequence_config, sequence DMA, SW/HW triggerPreemption:
hpm_adc_v2_set_preempt_config, preempt DMA, motor FOC path
Compile-time capability macros
Gate optional features in application code:
HPM_ADC_V2_HAS_ADC12/HPM_ADC_V2_HAS_ADC16: SoC IP presenceHPM_ADC_V2_HAS_DUAL_IP: both ADC12 and ADC16 on the same SoCHPM_ADC_V2_HAS_SIGNAL_MODE: ADC12 single-ended / differential viasignal_modeHPM_ADC_V2_HAS_DIFF_MODE: ADC16 differential mode (configure viahpm_adc16_drv.h)HPM_ADC_V2_HAS_ADC_LOOP: ADC16 channel oversampling loopHPM_ADC_V2_HAS_DMA_SEQ16BIT: ADC16 sequence DMA 16-bit-only outputHPM_ADC_V2_HAS_SEQ_STOP_POS_INT: ADC16 STOP_POS interrupt bitHPM_ADC_V2_HAS_MOTOR_MODE: ADC16 motor-control data path
Interrupt and DMA helpers
Unified
adc_v2_event_tflags for status, enable, and clear APIshpm_adc_v2_parse_pmt_dma_word/hpm_adc_v2_parse_seq_dma_worddecode packed DMA words (do not use fixed bit masks on ADC16; layout depends on SoC IP version)
1.3. Data Structures
Main structures (defined in hpm_adc_v2.h):
adc_v2_handle_tbase: peripheral base address
adc_v2_config_tInstance configuration: resolution, conversion mode, clock divider, and IP-specific fields (
signal_modefor ADC12,port3_realtime/dma_seq16bitfor ADC16).adc_v2_channel_config_tPer-channel sample time, watchdog thresholds, and optional oversampling (ADC16).
adc_v2_pmt_config_t(aliasadc_v2_preempt_config_t)Preemption trigger slots, channels, and interrupt enables.
adc_v2_seq_config_t/adc_v2_dma_config_tSequence queue and DMA buffer layout (including
stop_pos/stop_en).adc_v2_dma_sample_tParsed DMA sample fields returned by the parse APIs.
1.4. API Description
1.4.1. Initialization
hpm_adc_v2_get_ip_type: detect ADC12 vs ADC16 from handle basehpm_adc_v2_get_default_config/hpm_adc_v2_get_channel_default_config: fill defaultshpm_adc_v2_init/hpm_adc_v2_deinit: apply or tear down instance confighpm_adc_v2_init_channel: configure one channel
1.4.2. Mode configuration
hpm_adc_v2_set_period_config: period-mode timinghpm_adc_v2_set_sequence_config: sequence queue and triggershpm_adc_v2_set_preempt_config: preemption (motor) trigger mappinghpm_adc_v2_set_seq_stop_pos: sequence DMA stop index
1.4.3. DMA and triggers
hpm_adc_v2_init_pmt_dma/hpm_adc_v2_init_seq_dma: start preempt or sequence DMAhpm_adc_v2_is_seq_dma_16bit_enabled: query ADC16 16-bit sequence DMA modehpm_adc_v2_trigger_seq_by_sw/hpm_adc_v2_trigger_pmt_by_sw: software triggershpm_adc_v2_enable_pmt_queue/hpm_adc_v2_disable_pmt_queue: ADC16 queue control
1.4.4. Results and status
hpm_adc_v2_get_oneshot_result/hpm_adc_v2_get_prd_result: read conversion datahpm_adc_v2_get_conv_valid_status: channel valid flaghpm_adc_v2_get_status_flags/hpm_adc_v2_clear_status_flagshpm_adc_v2_enable_interrupts/hpm_adc_v2_disable_interruptshpm_adc_v2_set_nonblocking_read/hpm_adc_v2_set_blocking_read
1.4.5. Motor control (optional)
When HPM_ADC_V2_HAS_MOTOR_MODE is 1, call hpm_adc_v2_enable_motor_mode after
preempt DMA setup in motor FOC samples.
1.5. Usage Example
Preemption (motor FOC) flow:
adc_v2_handle_t adc = HPM_ADC_V2_HANDLE(BOARD_BLDC_ADC_U_BASE);
adc_v2_config_t cfg;
adc_v2_channel_config_t ch_cfg;
adc_v2_pmt_config_t pmt_cfg;
hpm_adc_v2_get_default_config(adc, &cfg);
cfg.conv_mode = adc_v2_conv_mode_preemption;
hpm_adc_v2_init(adc, &cfg);
hpm_adc_v2_get_channel_default_config(adc, &ch_cfg);
ch_cfg.ch = BOARD_BLDC_ADC_CH_U;
ch_cfg.signal_mode = adc_v2_signal_mode_single_ended;
hpm_adc_v2_init_channel(adc, &ch_cfg);
hpm_adc_v2_set_preempt_config(adc, &pmt_cfg);
hpm_adc_v2_enable_pmt_queue(adc, BOARD_BLDC_ADC_TRG);
hpm_adc_v2_init_pmt_dma(adc, dma_buffer_sys_addr);
#if HPM_ADC_V2_HAS_MOTOR_MODE
hpm_adc_v2_enable_motor_mode(adc);
#endif
hpm_adc_v2_enable_interrupts(adc, HPM_ADC_V2_EVENT_TRIG_COMPLETE);
1.7. Notes
Prefer
hpm_adc_v2.hover the deprecatedhpm_adc_interfacecomponent.ADC12 differential input uses
signal_modeinadc_v2_config_toradc_v2_channel_config_t.When
HPM_ADC_V2_HAS_DIFF_MODEis 1, use ADC16 differential APIs inhpm_adc16_drv.h(seesamples/drivers/adc/adc16_differential).