HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmAdc.h
Go to the documentation of this file.
1
25#pragma once
26
27#include "BaseAdc.h"
28#include "StmTypes.h"
29
40class StmAdc : public BaseAdc {
41public:
46 explicit StmAdc(const hf_stm32_adc_config_t& config) noexcept;
47
49 explicit StmAdc(ADC_HandleTypeDef* hal_handle, hf_u8_t num_channels = 1) noexcept;
50
51 ~StmAdc() noexcept override;
52
53 // ── BaseAdc overrides ────────────────────────────────────────────────
54
55 bool Initialize() noexcept override;
56 bool Deinitialize() noexcept override;
57 hf_u8_t GetMaxChannels() const noexcept override;
58 bool IsChannelAvailable(hf_channel_id_t channel_id) const noexcept override;
59
60 hf_adc_err_t ReadChannelV(hf_channel_id_t channel_id, float& channel_reading_v,
61 hf_u8_t numOfSamplesToAvg = 1,
62 hf_time_t timeBetweenSamples = 0) noexcept override;
63
64 hf_adc_err_t ReadChannelCount(hf_channel_id_t channel_id, hf_u32_t& channel_reading_count,
65 hf_u8_t numOfSamplesToAvg = 1,
66 hf_time_t timeBetweenSamples = 0) noexcept override;
67
68 hf_adc_err_t ReadChannel(hf_channel_id_t channel_id, hf_u32_t& channel_reading_count,
69 float& channel_reading_v, hf_u8_t numOfSamplesToAvg = 1,
70 hf_time_t timeBetweenSamples = 0) noexcept override;
71
72 // ── STM32-specific ───────────────────────────────────────────────────
73
75 ADC_HandleTypeDef* GetHalHandle() const noexcept { return config_.hal_handle; }
76
78 float GetVref() const noexcept { return config_.vref_v; }
79
81 hf_u8_t GetResolutionBits() const noexcept;
82
84 hf_u32_t GetMaxCount() const noexcept;
85
87 float CountToVoltage(hf_u32_t count) const noexcept;
88
89private:
91 hf_adc_err_t ReadRawCount(hf_u32_t& count) noexcept;
92
94 static hf_adc_err_t ConvertHalStatus(hf_u32_t hal_status) noexcept;
95
97};
Abstract base class for ADC implementations in the HardFOC system.
hf_adc_err_t
Definition BaseAdc.h:115
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
hf_u32_t hf_time_t
Platform-agnostic time type in milliseconds.
Definition HardwareTypes.h:173
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_u32_t hf_channel_id_t
Platform-agnostic channel identifier type.
Definition HardwareTypes.h:163
STM32 platform-specific type definitions for hardware abstraction.
Base class for ADCs.
Definition BaseAdc.h:196
STM32 ADC wrapper — wraps STM32 HAL ADC with full channel management.
Definition StmAdc.h:40
hf_u8_t GetMaxChannels() const noexcept override
Get the maximum number of channels supported by this ADC.
Definition StmAdc.cpp:71
bool Initialize() noexcept override
Initializes the ADC peripheral (must be implemented by derived classes).
Definition StmAdc.cpp:50
bool Deinitialize() noexcept override
Deinitializes the ADC peripheral (must be implemented by derived classes)..
Definition StmAdc.cpp:60
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.
Definition StmAdc.cpp:83
~StmAdc() noexcept override
Definition StmAdc.cpp:40
ADC_HandleTypeDef * GetHalHandle() const noexcept
Get the underlying HAL ADC handle.
Definition StmAdc.h:75
StmAdc(const hf_stm32_adc_config_t &config) noexcept
Construct with full configuration.
Definition StmAdc.cpp:34
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).
Definition StmAdc.cpp:111
bool IsChannelAvailable(hf_channel_id_t channel_id) const noexcept override
Check if a specific channel is available.
Definition StmAdc.cpp:75
float GetVref() const noexcept
Get the configured reference voltage.
Definition StmAdc.h:78
float CountToVoltage(hf_u32_t count) const noexcept
Convert raw ADC count to voltage.
Definition StmAdc.cpp:163
hf_u32_t GetMaxCount() const noexcept
Get the maximum ADC count for current resolution.
Definition StmAdc.cpp:159
static hf_adc_err_t ConvertHalStatus(hf_u32_t hal_status) noexcept
Convert HAL status to ADC error code.
Definition StmAdc.cpp:196
hf_adc_err_t ReadRawCount(hf_u32_t &count) noexcept
Perform a single ADC conversion and return the raw count.
Definition StmAdc.cpp:173
hf_u8_t GetResolutionBits() const noexcept
Get the current ADC resolution in bits.
Definition StmAdc.cpp:155
hf_stm32_adc_config_t config_
ADC configuration.
Definition StmAdc.h:96
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.
Definition StmAdc.cpp:138
ADC configuration for STM32.
Definition StmTypes.h:431
ADC_HandleTypeDef * hal_handle
Pointer to CubeMX-generated ADC handle.
Definition StmTypes.h:432
float vref_v
Reference voltage (V)
Definition StmTypes.h:434