|
HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
|
Singleton manager for all analogue-to-digital channels on Flux V1. More...
#include <AdcManager.h>
Public Member Functions | |
| AdcManager (const AdcManager &)=delete | |
| AdcManager & | operator= (const AdcManager &)=delete |
| AdcManager (AdcManager &&)=delete | |
| AdcManager & | operator= (AdcManager &&)=delete |
| bool | EnsureInitialized () noexcept |
| Initialise the ADC subsystem if not already initialised. | |
| bool | IsInitialized () const noexcept |
| Check whether the ADC subsystem has been initialised. | |
| flux::hal::ManagerError | GetManagerError () const noexcept |
Lifecycle / bind error of the last EnsureInitialized() (shared catalog). | |
| bool | IsInternalAdcReady () const noexcept |
| The MCU ADC unit came up during the last bring-up attempt. | |
| bool | IsAds7952Ready (uint8_t device_index) const noexcept |
ADS7952 device device_index came up during the last bring-up attempt. | |
| bool | Deinitialize () noexcept |
| Release all ADC resources and reset to uninitialized state. | |
| BaseAdc * | Get (std::string_view name) noexcept |
| Get the BaseAdc driver for a named channel. | |
| BaseAdc * | Get (HfFunctionalAdcChannel channel) noexcept |
| Get the BaseAdc driver by functional enum — O(1) lookup. | |
| bool | Contains (std::string_view name) const noexcept |
| Check whether a named ADC channel is registered. | |
| size_t | Size () const noexcept |
| Get the number of registered ADC channels. | |
| hf_adc_err_t | ReadVoltage (std::string_view name, float &voltage, uint8_t samples=1, uint16_t timeBetweenSamples=0) noexcept |
| Read voltage from a channel by name (already divided if divider > 1). | |
| hf_adc_err_t | ReadVoltage (HfFunctionalAdcChannel channel, float &voltage, uint8_t samples=1, uint16_t timeBetweenSamples=0) noexcept |
| Read voltage from a channel by enum — O(1) lookup, preferred for real-time paths. | |
| hf_adc_err_t | ReadRaw (std::string_view name, uint32_t &raw_count, uint8_t samples=1, uint16_t timeBetweenSamples=0) noexcept |
| Read raw ADC count from a channel by name. | |
| hf_adc_err_t | ReadRaw (HfFunctionalAdcChannel channel, uint32_t &raw_count, uint8_t samples=1, uint16_t timeBetweenSamples=0) noexcept |
| Read raw ADC count from a channel by enum — O(1) lookup, preferred for real-time paths. | |
| hf_adc_err_t | GetLastError () const noexcept |
| Get the most recent error code. | |
| hf_adc_err_t | GetSystemDiagnostics (AdcSystemDiagnostics &diag) const noexcept |
| Populate an AdcSystemDiagnostics snapshot. | |
| void | DumpStatistics () const noexcept |
| Log ADC channel statistics and health info to the console. | |
Static Public Member Functions | |
| static AdcManager & | GetInstance () noexcept |
| Return the singleton AdcManager instance. | |
Private Member Functions | |
| AdcManager () noexcept=default | |
| ~AdcManager ()=default | |
| bool | Initialize () noexcept |
| void | ReleaseLocked () noexcept |
| Release the MCU ADC, every ADS7952 handler and the registry (mutex held). | |
| size_t | FindByName (std::string_view name) const noexcept |
| Find entry index by string name. Returns kInvalidIndex if not found. O(N) linear scan. | |
| size_t | FindByEnum (HfFunctionalAdcChannel channel) const noexcept |
| Find entry index by functional enum. Returns kInvalidIndex if not found. O(1) direct index. | |
| hf_adc_err_t | ReadVoltageByIndex (size_t idx, float &voltage, uint8_t samples, uint16_t timeBetweenSamples) noexcept |
| Read from an entry by index — shared implementation for both name and enum overloads. | |
| hf_adc_err_t | ReadRawByIndex (size_t idx, uint32_t &raw_count, uint8_t samples, uint16_t timeBetweenSamples) noexcept |
Private Attributes | |
| std::array< AdcEntry, kMaxChannels > | entries_ {} |
| std::array< size_t, kMaxChannels > | enum_to_index_ {} |
| O(1) enum → entries index lookup. | |
| size_t | registered_count_ {0} |
| uint64_t | init_time_ms_ {0} |
| Timestamp (ms) when Initialize() completed. | |
| BaseAdc * | internal_adc_ {nullptr} |
| std::array< std::optional< Ads7952Handler >, kMaxAds7952Devices > | ads7952_handlers_ {} |
| size_t | ads7952_device_count_ {0} |
| std::atomic< bool > | initialized_ {false} |
| std::atomic< flux::hal::ManagerError > | manager_error_ {flux::hal::ManagerError::NotInitialized} |
| std::atomic< hf_adc_err_t > | last_error_ {hf_adc_err_t::ADC_SUCCESS} |
| RtosMutex | mutex_ |
Static Private Attributes | |
| static constexpr size_t | kMaxChannels |
| static constexpr size_t | kInvalidIndex = SIZE_MAX |
| static constexpr size_t | kMaxAds7952Devices = 4 |
Singleton manager for all analogue-to-digital channels on Flux V1.
Provides a uniform API over the internal ESP32 ADC and optional external ADS7952 ADC(s). Channels are registered from the pincfg X-MACRO table at initialisation and can be looked up by name (linear scan) or by functional enum (O(1) index).
|
delete |
|
delete |
|
privatedefaultnoexcept |
|
privatedefault |
|
noexcept |
Check whether a named ADC channel is registered.
| name | Channel name to look up. |
|
noexcept |
Release all ADC resources and reset to uninitialized state.
|
noexcept |
Log ADC channel statistics and health info to the console.
|
noexcept |
Initialise the ADC subsystem if not already initialised.
|
privatenoexcept |
Find entry index by functional enum. Returns kInvalidIndex if not found. O(1) direct index.
|
privatenoexcept |
Find entry index by string name. Returns kInvalidIndex if not found. O(N) linear scan.
|
noexcept |
Get the BaseAdc driver by functional enum — O(1) lookup.
| channel | Functional ADC channel enum. |
|
noexcept |
Get the BaseAdc driver for a named channel.
| name | Channel name from the pincfg table (linear scan). |
|
staticnoexcept |
|
inlinenoexcept |
Get the most recent error code.
|
inlinenoexcept |
Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
ManagerError::None when initialised; otherwise why bring-up failed.
|
noexcept |
Populate an AdcSystemDiagnostics snapshot.
| [out] | diag | Diagnostics structure to fill. |
|
privatenoexcept |
|
noexcept |
ADS7952 device device_index came up during the last bring-up attempt.
Valid for diagnosis even when the manager failed closed.
|
inlinenoexcept |
Check whether the ADC subsystem has been initialised.
|
inlinenoexcept |
The MCU ADC unit came up during the last bring-up attempt.
|
delete |
|
delete |
|
noexcept |
Read raw ADC count from a channel by enum — O(1) lookup, preferred for real-time paths.
| channel | Functional ADC channel enum |
| raw_count | Output: raw ADC count |
| samples | Number of samples to average (default 1) |
| timeBetweenSamples | Delay in ms between consecutive samples (default 0) |
|
noexcept |
Read raw ADC count from a channel by name.
| name | Channel name (linear string search — use enum overload in tight loops) |
| raw_count | Output: raw ADC count |
| samples | Number of samples to average (default 1) |
| timeBetweenSamples | Delay in ms between consecutive samples (default 0) |
|
privatenoexcept |
|
noexcept |
Read voltage from a channel by enum — O(1) lookup, preferred for real-time paths.
| channel | Functional ADC channel enum |
| voltage | Output: voltage at the input, if divider == 1, or bus voltage |
| samples | Number of samples to average (default 1) |
| timeBetweenSamples | Delay in ms between consecutive samples (default 0) |
|
noexcept |
Read voltage from a channel by name (already divided if divider > 1).
| name | Channel name (linear string search — use enum overload in tight loops) |
| voltage | Output: voltage at the input, if divider == 1, or bus voltage |
| samples | Number of samples to average (default 1) |
| timeBetweenSamples | Delay in ms between consecutive samples (default 0) |
|
privatenoexcept |
Read from an entry by index — shared implementation for both name and enum overloads.
|
privatenoexcept |
Release the MCU ADC, every ADS7952 handler and the registry (mutex held).
|
noexcept |
Get the number of registered ADC channels.
|
private |
|
private |
|
private |
|
private |
O(1) enum → entries index lookup.
|
private |
Timestamp (ms) when Initialize() completed.
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |
|
private |
|
mutableprivate |
|
private |