HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmTemperature.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "BaseTemperature.h"
14#include "StmTypes.h"
15
16struct ADC_HandleTypeDef; // Forward declaration
17
28using hf_stm32_temp_convert_fn = float(*)(hf_u32_t raw_adc_count, hf_u8_t resolution_bits);
29
51
64public:
65
69 explicit StmTemperature(const hf_stm32_temp_sensor_config_t& config) noexcept;
70
74 explicit StmTemperature(ADC_HandleTypeDef* hadc = nullptr,
75 hf_u8_t resolution_bits = 12,
76 float vref_mv = 3300.0f) noexcept;
77
78 ~StmTemperature() noexcept override;
79
80 // ── Pure virtuals from BaseTemperature ──────────────────────────────────
81 hf_temp_err_t GetSensorInfo(hf_temp_sensor_info_t* info) const noexcept override;
82 hf_u32_t GetCapabilities() const noexcept override;
83
84 // ── Optional overrides ──────────────────────────────────────────────────
85 hf_temp_err_t SetRange(float min_celsius, float max_celsius) noexcept override;
86 hf_temp_err_t GetRange(float* min_celsius, float* max_celsius) const noexcept override;
87 hf_temp_err_t SetCalibrationOffset(float offset_celsius) noexcept override;
88 hf_temp_err_t GetCalibrationOffset(float* offset_celsius) const noexcept override;
89
90protected:
91 bool Initialize() noexcept override;
92 bool Deinitialize() noexcept override;
93 hf_temp_err_t ReadTemperatureCelsiusImpl(float* temperature_celsius) noexcept override;
94
95private:
98
100 static float DefaultInternalConvert(hf_u32_t raw, hf_u8_t resolution_bits);
101};
Abstract base class for temperature sensor implementations in the HardFOC system.
hf_temp_sensor_type_t
Temperature sensor types.
Definition BaseTemperature.h:147
@ HF_TEMP_SENSOR_TYPE_INTERNAL
Internal chip temperature sensor.
Definition BaseTemperature.h:149
hf_temp_err_t
Temperature sensor error codes enumeration.
Definition BaseTemperature.h:113
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
float(*)(hf_u32_t raw_adc_count, hf_u8_t resolution_bits) hf_stm32_temp_convert_fn
User-supplied function to convert a raw ADC count to Celsius.
Definition StmTemperature.h:28
STM32 platform-specific type definitions for hardware abstraction.
Abstract base class for all temperature sensor implementations.
Definition BaseTemperature.h:407
STM32 Temperature sensor implementation.
Definition StmTemperature.h:63
hf_u32_t GetCapabilities() const noexcept override
Get sensor capabilities.
Definition StmTemperature.cpp:143
StmTemperature(const hf_stm32_temp_sensor_config_t &config) noexcept
Construct from config.
Definition StmTemperature.cpp:29
hf_temp_err_t SetCalibrationOffset(float offset_celsius) noexcept override
Set calibration offset (advanced feature)
Definition StmTemperature.cpp:165
hf_temp_err_t GetRange(float *min_celsius, float *max_celsius) const noexcept override
Get temperature measurement range (advanced feature)
Definition StmTemperature.cpp:158
float calibration_offset_
User calibration offset (°C)
Definition StmTemperature.h:97
hf_temp_err_t SetRange(float min_celsius, float max_celsius) noexcept override
Set temperature measurement range (advanced feature)
Definition StmTemperature.cpp:151
hf_temp_err_t GetSensorInfo(hf_temp_sensor_info_t *info) const noexcept override
Get sensor information.
Definition StmTemperature.cpp:121
~StmTemperature() noexcept override
Definition StmTemperature.cpp:48
static float DefaultInternalConvert(hf_u32_t raw, hf_u8_t resolution_bits)
Default internal-sensor conversion (generic RM formula).
Definition StmTemperature.cpp:180
bool Deinitialize() noexcept override
Platform-specific implementation for deinitialization.
Definition StmTemperature.cpp:63
bool Initialize() noexcept override
Platform-specific implementation for initialization.
Definition StmTemperature.cpp:56
hf_temp_err_t ReadTemperatureCelsiusImpl(float *temperature_celsius) noexcept override
Platform-specific implementation for reading temperature in Celsius.
Definition StmTemperature.cpp:71
hf_temp_err_t GetCalibrationOffset(float *offset_celsius) const noexcept override
Get calibration offset (advanced feature)
Definition StmTemperature.cpp:170
hf_stm32_temp_sensor_config_t config_
Definition StmTemperature.h:96
STM32 Temperature sensor configuration.
Definition StmTemperature.h:33
hf_u32_t sample_count
Oversampling count (1 = no avg)
Definition StmTemperature.h:42
ADC_HandleTypeDef * hadc
ADC handle (CubeMX)
Definition StmTemperature.h:34
hf_stm32_temp_convert_fn convert_fn
Optional custom conversion.
Definition StmTemperature.h:38
hf_stm32_temp_sensor_config_t() noexcept
Definition StmTemperature.h:45
hf_u32_t timeout_ms
ADC poll timeout.
Definition StmTemperature.h:43
hf_u32_t channel
ADC channel number.
Definition StmTemperature.h:35
hf_u8_t resolution_bits
ADC resolution (8/10/12/16)
Definition StmTemperature.h:36
float range_max_celsius
Max measurable temp.
Definition StmTemperature.h:41
float vref_mv
ADC reference voltage in mV.
Definition StmTemperature.h:37
float range_min_celsius
Min measurable temp.
Definition StmTemperature.h:40
hf_temp_sensor_type_t sensor_type
Sensor type hint.
Definition StmTemperature.h:39
Temperature sensor information structure.
Definition BaseTemperature.h:237