HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmAdc Class Reference

STM32 ADC wrapper — wraps STM32 HAL ADC with full channel management. More...

#include <StmAdc.h>

Inheritance diagram for StmAdc:
[legend]
Collaboration diagram for StmAdc:
[legend]

Public Member Functions

 StmAdc (const hf_stm32_adc_config_t &config) noexcept
 Construct with full configuration.
 
 StmAdc (ADC_HandleTypeDef *hal_handle, hf_u8_t num_channels=1) noexcept
 Construct from raw HAL handle with defaults.
 
 ~StmAdc () noexcept override
 
bool Initialize () noexcept override
 Initializes the ADC peripheral (must be implemented by derived classes).
 
bool Deinitialize () noexcept override
 Deinitializes the ADC peripheral (must be implemented by derived classes)..
 
hf_u8_t GetMaxChannels () const noexcept override
 Get the maximum number of channels supported by this ADC.
 
bool IsChannelAvailable (hf_channel_id_t channel_id) const noexcept override
 Check if a specific channel is available.
 
hf_adc_err_t ReadChannelV (hf_channel_id_t channel_id, float &channel_reading_v, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override
 Read channel voltage.
 
hf_adc_err_t ReadChannelCount (hf_channel_id_t channel_id, hf_u32_t &channel_reading_count, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override
 Read channel count (raw ADC value).
 
hf_adc_err_t ReadChannel (hf_channel_id_t channel_id, hf_u32_t &channel_reading_count, float &channel_reading_v, hf_u8_t numOfSamplesToAvg=1, hf_time_t timeBetweenSamples=0) noexcept override
 Read both channel count and voltage.
 
ADC_HandleTypeDef * GetHalHandle () const noexcept
 Get the underlying HAL ADC handle.
 
float GetVref () const noexcept
 Get the configured reference voltage.
 
hf_u8_t GetResolutionBits () const noexcept
 Get the current ADC resolution in bits.
 
hf_u32_t GetMaxCount () const noexcept
 Get the maximum ADC count for current resolution.
 
float CountToVoltage (hf_u32_t count) const noexcept
 Convert raw ADC count to voltage.
 
- Public Member Functions inherited from BaseAdc
virtual ~BaseAdc () noexcept=default
 Virtual destructor.
 
 BaseAdc (const BaseAdc &)=delete
 
BaseAdcoperator= (const BaseAdc &)=delete
 
 BaseAdc (BaseAdc &&) noexcept=default
 
BaseAdcoperator= (BaseAdc &&) noexcept=default
 
bool EnsureInitialized () noexcept
 Ensures that the ADC is initialized (lazy initialization).
 
bool EnsureDeinitialized () noexcept
 Ensures that the ADC is initialized (lazy initialization).
 
bool IsInitialized () const noexcept
 Checks if the class is initialized.
 
virtual hf_adc_err_t ReadMultipleChannels (const hf_channel_id_t *channel_ids, hf_u8_t num_channels, hf_u32_t *readings, float *voltages) noexcept
 Read multiple channels simultaneously.
 
virtual hf_adc_err_t ResetStatistics () noexcept
 Reset ADC operation statistics.
 
virtual hf_adc_err_t ResetDiagnostics () noexcept
 Reset ADC diagnostic information.
 
virtual hf_adc_err_t GetStatistics (hf_adc_statistics_t &statistics) noexcept
 Get ADC operation statistics.
 
virtual hf_adc_err_t GetDiagnostics (hf_adc_diagnostics_t &diagnostics) noexcept
 Get ADC diagnostic information.
 

Private Member Functions

hf_adc_err_t ReadRawCount (hf_u32_t &count) noexcept
 Perform a single ADC conversion and return the raw count.
 

Static Private Member Functions

static hf_adc_err_t ConvertHalStatus (hf_u32_t hal_status) noexcept
 Convert HAL status to ADC error code.
 

Private Attributes

hf_stm32_adc_config_t config_
 ADC configuration.
 

Additional Inherited Members

- Protected Member Functions inherited from BaseAdc
 BaseAdc () noexcept
 Protected default constructor.
 
- Protected Attributes inherited from BaseAdc
bool initialized_
 Initialization status.
 
hf_adc_statistics_t statistics_
 ADC operation statistics.
 
hf_adc_diagnostics_t diagnostics_
 ADC diagnostic information.
 

Detailed Description

STM32 ADC wrapper — wraps STM32 HAL ADC with full channel management.

Features:

  • Single-conversion and multi-sample averaging via HAL_ADC_Start/PollForConversion
  • Voltage conversion using configurable Vref and resolution
  • Raw count reading for custom calibration workflows
  • Combined count + voltage reads in a single call
  • Statistics tracking (total reads, errors, timing)

Constructor & Destructor Documentation

◆ StmAdc() [1/2]

StmAdc::StmAdc ( const hf_stm32_adc_config_t & config)
explicitnoexcept

Construct with full configuration.

Parameters
configADC config including CubeMX HAL handle, resolution, Vref, channel count

◆ StmAdc() [2/2]

StmAdc::StmAdc ( ADC_HandleTypeDef * hal_handle,
hf_u8_t num_channels = 1 )
explicitnoexcept

Construct from raw HAL handle with defaults.

◆ ~StmAdc()

StmAdc::~StmAdc ( )
overridenoexcept

Member Function Documentation

◆ ConvertHalStatus()

hf_adc_err_t StmAdc::ConvertHalStatus ( hf_u32_t hal_status)
staticprivatenoexcept

Convert HAL status to ADC error code.

◆ CountToVoltage()

float StmAdc::CountToVoltage ( hf_u32_t count) const
noexcept

Convert raw ADC count to voltage.

◆ Deinitialize()

bool StmAdc::Deinitialize ( )
overridevirtualnoexcept

Deinitializes the ADC peripheral (must be implemented by derived classes)..

Returns
True if deinitialization is successful, false otherwise.

Implements BaseAdc.

◆ GetHalHandle()

ADC_HandleTypeDef * StmAdc::GetHalHandle ( ) const
inlinenoexcept

Get the underlying HAL ADC handle.

◆ GetMaxChannels()

hf_u8_t StmAdc::GetMaxChannels ( ) const
overridevirtualnoexcept

Get the maximum number of channels supported by this ADC.

Returns
Maximum channel count

Implements BaseAdc.

◆ GetMaxCount()

hf_u32_t StmAdc::GetMaxCount ( ) const
noexcept

Get the maximum ADC count for current resolution.

◆ GetResolutionBits()

hf_u8_t StmAdc::GetResolutionBits ( ) const
noexcept

Get the current ADC resolution in bits.

◆ GetVref()

float StmAdc::GetVref ( ) const
inlinenoexcept

Get the configured reference voltage.

◆ Initialize()

bool StmAdc::Initialize ( )
overridevirtualnoexcept

Initializes the ADC peripheral (must be implemented by derived classes).

Returns
True if the initialization is successful, false otherwise.

Implements BaseAdc.

◆ IsChannelAvailable()

bool StmAdc::IsChannelAvailable ( hf_channel_id_t channel_id) const
overridevirtualnoexcept

Check if a specific channel is available.

Parameters
channel_idChannel ID to check
Returns
true if channel is available, false otherwise

Implements BaseAdc.

◆ ReadChannel()

hf_adc_err_t StmAdc::ReadChannel ( hf_channel_id_t channel_id,
hf_u32_t & channel_reading_count,
float & channel_reading_v,
hf_u8_t numOfSamplesToAvg = 1,
hf_time_t timeBetweenSamples = 0 )
overridevirtualnoexcept

Read both channel count and voltage.

Parameters
channel_idChannel ID to read from
channel_reading_countReference to store count reading
channel_reading_vReference to store voltage reading
numOfSamplesToAvgNumber of samples to average (default 1)
timeBetweenSamplesTime between samples in milliseconds (default 0)
Returns
hf_adc_err_t error code

Implements BaseAdc.

◆ ReadChannelCount()

hf_adc_err_t StmAdc::ReadChannelCount ( hf_channel_id_t channel_id,
hf_u32_t & channel_reading_count,
hf_u8_t numOfSamplesToAvg = 1,
hf_time_t timeBetweenSamples = 0 )
overridevirtualnoexcept

Read channel count (raw ADC value).

Parameters
channel_idChannel ID to read from
channel_reading_countReference to store count reading
numOfSamplesToAvgNumber of samples to average (default 1)
timeBetweenSamplesTime between samples in milliseconds (default 0)
Returns
hf_adc_err_t error code

Implements BaseAdc.

◆ ReadChannelV()

hf_adc_err_t StmAdc::ReadChannelV ( hf_channel_id_t channel_id,
float & channel_reading_v,
hf_u8_t numOfSamplesToAvg = 1,
hf_time_t timeBetweenSamples = 0 )
overridevirtualnoexcept

Read channel voltage.

Parameters
channel_idChannel ID to read from
channel_reading_vReference to store voltage reading
numOfSamplesToAvgNumber of samples to average (default 1)
timeBetweenSamplesTime between samples in milliseconds (default 0)
Returns
hf_adc_err_t error code

Implements BaseAdc.

◆ ReadRawCount()

hf_adc_err_t StmAdc::ReadRawCount ( hf_u32_t & count)
privatenoexcept

Perform a single ADC conversion and return the raw count.

Member Data Documentation

◆ config_

hf_stm32_adc_config_t StmAdc::config_
private

ADC configuration.


The documentation for this class was generated from the following files: