43#define HF_ADC_ERR_LIST(X) \
45 X(ADC_SUCCESS, 0, "Success") \
47 X(ADC_ERR_FAILURE, 1, "General failure") \
48 X(ADC_ERR_NOT_INITIALIZED, 2, "Not initialized") \
49 X(ADC_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
50 X(ADC_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
51 X(ADC_ERR_NULL_POINTER, 5, "Null pointer") \
52 X(ADC_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
54 X(ADC_ERR_CHANNEL_NOT_FOUND, 7, "Channel not found") \
55 X(ADC_ERR_CHANNEL_NOT_ENABLED, 8, "Channel not enabled") \
56 X(ADC_ERR_CHANNEL_NOT_CONFIGURED, 9, "Channel not configured") \
57 X(ADC_ERR_CHANNEL_ALREADY_REGISTERED, 10, "Channel already registered") \
58 X(ADC_ERR_CHANNEL_READ_ERR, 11, "Channel read error") \
59 X(ADC_ERR_CHANNEL_WRITE_ERR, 12, "Channel write error") \
60 X(ADC_ERR_INVALID_CHANNEL, 13, "Invalid channel") \
61 X(ADC_ERR_CHANNEL_BUSY, 14, "Channel busy") \
63 X(ADC_ERR_INVALID_SAMPLE_COUNT, 15, "Invalid sample count") \
64 X(ADC_ERR_SAMPLE_TIMEOUT, 16, "Sample timeout") \
65 X(ADC_ERR_SAMPLE_OVERFLOW, 17, "Sample overflow") \
66 X(ADC_ERR_SAMPLE_UNDERFLOW, 18, "Sample underflow") \
68 X(ADC_ERR_HARDWARE_FAULT, 19, "Hardware fault") \
69 X(ADC_ERR_COMMUNICATION_FAILURE, 20, "Communication failure") \
70 X(ADC_ERR_DEVICE_NOT_RESPONDING, 21, "Device not responding") \
71 X(ADC_ERR_CALIBRATION_FAILURE, 22, "Calibration failure") \
72 X(ADC_ERR_VOLTAGE_OUT_OF_RANGE, 23, "Voltage out of range") \
74 X(ADC_ERR_INVALID_CONFIGURATION, 24, "Invalid configuration") \
75 X(ADC_ERR_UNSUPPORTED_OPERATION, 25, "Unsupported operation") \
76 X(ADC_ERR_RESOURCE_BUSY, 26, "Resource busy") \
77 X(ADC_ERR_RESOURCE_UNAVAILABLE, 27, "Resource unavailable") \
79 X(ADC_ERR_CALIBRATION_NOT_FOUND, 28, "Calibration data not found") \
80 X(ADC_ERR_CALIBRATION_INVALID, 29, "Invalid calibration data") \
81 X(ADC_ERR_CALIBRATION_EXPIRED, 30, "Calibration has expired") \
82 X(ADC_ERR_CALIBRATION_DRIFT, 31, "Calibration drift detected") \
83 X(ADC_ERR_CALIBRATION_POINTS_INSUFFICIENT, 32, "Insufficient calibration points") \
84 X(ADC_ERR_CALIBRATION_POINTS_INVALID, 33, "Invalid calibration points") \
85 X(ADC_ERR_CALIBRATION_LINEARITY_ERROR, 34, "Calibration linearity error") \
86 X(ADC_ERR_CALIBRATION_STORAGE_FAILURE, 35, "Calibration storage failure") \
87 X(ADC_ERR_CALIBRATION_LOAD_FAILURE, 36, "Calibration load failure") \
88 X(ADC_ERR_CALIBRATION_VERIFICATION_FAILED, 37, "Calibration verification failed") \
89 X(ADC_ERR_CALIBRATION_TEMPERATURE_ERROR, 38, "Temperature compensation error") \
90 X(ADC_ERR_CALIBRATION_POLYNOMIAL_ERROR, 39, "Polynomial calibration error") \
92 X(ADC_ERR_SYSTEM_ERROR, 40, "System error") \
93 X(ADC_ERR_PERMISSION_DENIED, 41, "Permission denied") \
94 X(ADC_ERR_OPERATION_ABORTED, 42, "Operation aborted") \
97 X(ADC_ERR_INITIALIZATION_FAILED, 43, "Initialization failed") \
98 X(ADC_ERR_INVALID_PARAM, 44, "Invalid parameter") \
99 X(ADC_ERR_TIMEOUT, 45, "Operation timeout") \
100 X(ADC_ERR_NOT_SUPPORTED, 46, "Not supported") \
103 X(ADC_ERR_INVALID_STATE, 47, "Invalid state") \
104 X(ADC_ERR_DRIVER_ERROR, 48, "Driver error") \
105 X(ADC_ERR_DMA_ERROR, 49, "DMA error") \
106 X(ADC_ERR_FILTER_ERROR, 50, "Filter configuration error") \
107 X(ADC_ERR_NO_CALLBACK, 51, "No callback provided") \
108 X(ADC_ERR_NOT_STARTED, 52, "Operation not started") \
109 X(ADC_ERR_CALIBRATION, 53, "Calibration error") \
110 X(ADC_ERR_BUSY, 54, "Resource busy") \
111 X(ADC_ERR_HARDWARE_FAILURE, 55, "Hardware failure") \
112 X(ADC_ERR_CHANNEL_DISABLED, 56, "Channel disabled") \
113 X(ADC_ERR_UNKNOWN, 57, "Unknown error")
116#define X(NAME, VALUE, DESC) NAME = VALUE,
128#define X(NAME, VALUE, DESC) \
129 case hf_adc_err_t::NAME: \
288 hf_time_t timeBetweenSamples = 0) noexcept = 0;
300 hf_time_t timeBetweenSamples = 0) noexcept = 0;
312 float& channel_reading_v,
hf_u8_t numOfSamplesToAvg = 1,
313 hf_time_t timeBetweenSamples = 0) noexcept = 0;
330 float* voltages) noexcept {
331 if (!channel_ids || !readings || !voltages) {
335 for (
hf_u8_t i = 0; i < num_channels; ++i) {
constexpr std::string_view HfAdcErrToString(hf_adc_err_t err) noexcept
Convert hf_adc_err_t to human-readable string.
Definition BaseAdc.h:126
#define X(NAME, VALUE, DESC)
Definition BaseAdc.h:116
hf_adc_err_t
Definition BaseAdc.h:115
@ ADC_ERR_UNSUPPORTED_OPERATION
Platform-agnostic hardware type definitions for the HardFOC system.
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
Base class for ADCs.
Definition BaseAdc.h:196
hf_adc_statistics_t statistics_
ADC operation statistics.
Definition BaseAdc.h:399
virtual hf_u8_t GetMaxChannels() const noexcept=0
Get the maximum number of channels supported by this ADC.
virtual hf_adc_err_t ResetStatistics() noexcept
Reset ADC operation statistics.
Definition BaseAdc.h:351
virtual bool Deinitialize() noexcept=0
Deinitializes the ADC peripheral (must be implemented by derived classes)..
virtual hf_adc_err_t GetDiagnostics(hf_adc_diagnostics_t &diagnostics) noexcept
Get ADC diagnostic information.
Definition BaseAdc.h:383
hf_adc_diagnostics_t diagnostics_
ADC diagnostic information.
Definition BaseAdc.h:400
virtual bool IsChannelAvailable(hf_channel_id_t channel_id) const noexcept=0
Check if a specific channel is available.
virtual ~BaseAdc() noexcept=default
Virtual destructor.
bool IsInitialized() const noexcept
Checks if the class is initialized.
Definition BaseAdc.h:245
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.
Definition BaseAdc.h:328
bool EnsureInitialized() noexcept
Ensures that the ADC is initialized (lazy initialization).
Definition BaseAdc.h:223
virtual 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=0
Read channel voltage.
virtual bool Initialize() noexcept=0
Initializes the ADC peripheral (must be implemented by derived classes).
virtual hf_adc_err_t ResetDiagnostics() noexcept
Reset ADC diagnostic information.
Definition BaseAdc.h:361
virtual 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=0
Read both channel count and voltage.
bool EnsureDeinitialized() noexcept
Ensures that the ADC is initialized (lazy initialization).
Definition BaseAdc.h:234
bool initialized_
Initialization status.
Definition BaseAdc.h:398
virtual hf_adc_err_t GetStatistics(hf_adc_statistics_t &statistics) noexcept
Get ADC operation statistics.
Definition BaseAdc.h:372
BaseAdc() noexcept
Protected default constructor.
Definition BaseAdc.h:392
virtual 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=0
Read channel count (raw ADC value).
#define HF_ADC_ERR_LIST(X)
ADC error codes.
Definition BaseAdc.h:43
ADC diagnostic information.
Definition BaseAdc.h:165
bool adcHealthy
Overall ADC health status.
Definition BaseAdc.h:166
hf_adc_diagnostics_t()
Definition BaseAdc.h:176
bool initialization_state
Initialization state.
Definition BaseAdc.h:174
bool calibrationValid
Calibration validity.
Definition BaseAdc.h:172
hf_u32_t consecutiveErrors
Consecutive error count.
Definition BaseAdc.h:169
float temperatureC
ADC temperature (if available)
Definition BaseAdc.h:170
hf_u32_t enabled_channels
Bit mask of enabled channels.
Definition BaseAdc.h:173
float referenceVoltage
Reference voltage.
Definition BaseAdc.h:171
hf_adc_err_t lastErrorCode
Last error code.
Definition BaseAdc.h:167
hf_u32_t lastErrorTimestamp
Last error timestamp.
Definition BaseAdc.h:168
ADC operation statistics.
Definition BaseAdc.h:145
hf_u32_t thresholdViolations
Threshold monitor violations.
Definition BaseAdc.h:153
hf_u32_t maxConversionTimeUs
Maximum conversion time.
Definition BaseAdc.h:150
hf_u32_t successfulConversions
Successful conversions.
Definition BaseAdc.h:147
hf_u32_t totalConversions
Total conversions performed.
Definition BaseAdc.h:146
hf_u32_t failedConversions
Failed conversions.
Definition BaseAdc.h:148
hf_u32_t calibrationCount
Number of calibrations performed.
Definition BaseAdc.h:152
hf_u32_t minConversionTimeUs
Minimum conversion time.
Definition BaseAdc.h:151
hf_u32_t averageConversionTimeUs
Average conversion time (microseconds)
Definition BaseAdc.h:149
hf_adc_statistics_t()
Definition BaseAdc.h:156
hf_u32_t calibration_errors
Calibration errors.
Definition BaseAdc.h:154