|
HardFOC Flux V1 HAL
Unified HAL API for the HardFOC Flux valve-control platform (ESP32-S3)
|
Unified singleton for controlling all valve channels on the Flux board. More...
#include <ValveManager.h>
Public Member Functions | |
| ValveManager (const ValveManager &)=delete | |
| ValveManager & | operator= (const ValveManager &)=delete |
| ValveManager (ValveManager &&)=delete | |
| ValveManager & | operator= (ValveManager &&)=delete |
| bool | EnsureInitialized () noexcept |
| Ensure the valve manager system is initialized. | |
| bool | IsInitialized () const noexcept |
| Check whether the valve subsystem has been initialised. | |
| bool | IsBankReady (ValveDriverType bank) const noexcept |
| Whether one driver IC came up during the last bring-up attempt. | |
| flux::hal::ManagerError | GetManagerError () const noexcept |
Lifecycle / bind error of the last EnsureInitialized() (shared catalog). | |
| bool | Deinitialize () noexcept |
| Turn every channel off, release both driver handlers and reset to uninitialised. | |
| bool | DropEnablePins () noexcept |
| Drive MAX22200 ENABLE and TLE92466ED EN low: both banks de-energised in hardware. | |
| bool | RearmEnablePins () noexcept |
| Leave SafeHold: full re-bring-up of both banks, which raises the enable pins again. | |
| bool | IsOutputInhibited () const noexcept |
| The enable pins were dropped and not re-armed since. | |
| void | GetEnablePinStates (bool &max_enable, bool &tle_enable) const noexcept |
| Read back the two enable outputs. | |
| hf_valve_err_t | EnableChannel (ValveChannel channel) noexcept |
| Enable a valve channel output. | |
| hf_valve_err_t | DisableChannel (ValveChannel channel) noexcept |
| Disable a valve channel output. | |
| hf_valve_err_t | EnableChannelsMask (uint16_t mask) noexcept |
| Enable multiple channels by bitmask. | |
| hf_valve_err_t | DisableAllChannels () noexcept |
| Disable all channels on both drivers. | |
| bool | IsChannelEnabled (ValveChannel channel) const noexcept |
| Check if a channel is currently enabled. | |
| hf_valve_err_t | ConfigureSolenoidCdr (ValveChannel channel, uint16_t hit_ma, uint16_t hold_ma, float hit_time_ms) noexcept |
| Configure a solenoid channel with CDR (current drive regulation). | |
| hf_valve_err_t | ConfigureSolenoidVdr (ValveChannel channel, float hit_duty_pct, float hold_duty_pct, float hit_time_ms) noexcept |
| Configure a solenoid channel with VDR (voltage drive regulation). | |
| hf_valve_err_t | SetProportionalCurrent (ValveChannel channel, uint16_t current_ma) noexcept |
| Set current setpoint for a proportional valve channel. | |
| hf_valve_err_t | ConfigureProportionalPwm (ValveChannel channel, float frequency_hz) noexcept |
| Configure PWM frequency for a proportional channel. | |
| hf_valve_err_t | ConfigureProportionalDither (ValveChannel channel, float amplitude_ma, float frequency_hz) noexcept |
| Configure dither for a proportional channel. | |
| bool | HasFault () noexcept |
| Check if any driver reports a fault. | |
| hf_valve_err_t | ClearAllFaults () noexcept |
| Clear faults on both drivers. | |
| bool | HasSolenoidFault () noexcept |
| Check for MAX22200-specific faults. | |
| bool | HasProportionalFault () noexcept |
| Check for TLE92466ED-specific faults. | |
| hf_valve_err_t | GetSolenoidFaults (max22200::FaultStatus &faults) noexcept |
| Retrieve the MAX22200 fault status. | |
| hf_valve_err_t | GetProportionalFaults (tle92466ed::FaultReport &report) noexcept |
| Retrieve the TLE92466ED fault report. | |
| const ValveChannelState * | GetChannelState (ValveChannel channel) const noexcept |
| Get channel runtime state by enum. | |
| const ValveChannelInfo * | GetChannelInfo (std::string_view name) const noexcept |
| Get channel info (driver type, hw channel, name) by string name. | |
| ValveChannel | FindChannel (std::string_view name) const noexcept |
| Find a channel enum by name. | |
| Max22200Handler * | GetMax22200Handler () noexcept |
| Get the MAX22200 handler for advanced solenoid operations. | |
| Tle92466edHandler * | GetTle92466Handler () noexcept |
| Get the TLE92466ED handler for advanced proportional operations. | |
| hf_valve_err_t | GetLastError () const noexcept |
| Get the most recent failed valve operation's error code. | |
| hf_valve_err_t | GetSystemDiagnostics (ValveSystemDiagnostics &diag) const noexcept |
| Populate a ValveSystemDiagnostics snapshot. | |
| void | DumpStatistics () const noexcept |
| Log valve channel statistics and driver health to the console. | |
Static Public Member Functions | |
| static ValveManager & | GetInstance () noexcept |
| Return the singleton ValveManager instance. | |
Private Member Functions | |
| ValveManager () noexcept | |
| ~ValveManager ()=default | |
| hf_valve_err_t | Initialize () noexcept |
| flux::hal::ManagerError | InitializeMax22200 () noexcept |
| flux::hal::ManagerError | InitializeTle92466 () noexcept |
| hf_valve_err_t | DisableAllLocked () noexcept |
| Disable every channel on every bank that is up (mutex held by the caller). | |
| void | ReleaseDriversLocked () noexcept |
| Destroy both handlers and clear the bank flags (mutex held by the caller). | |
| hf_valve_err_t | Record (hf_valve_err_t result) const noexcept |
| Remember a failed operation result for GetLastError(); pass the result through. | |
Static Private Member Functions | |
| static bool | ResolveChannel (ValveChannel channel, ValveDriverType &driver_type, uint8_t &hw_channel) noexcept |
| Resolve channel enum to hw channel index and driver type. | |
Private Attributes | |
| std::optional< Max22200Handler > | max22200_ |
| bool | max22200_valid_ {false} |
| std::optional< Tle92466edHandler > | tle92466_ |
| bool | tle92466_valid_ {false} |
| std::array< ValveChannelState, static_cast< size_t >(ValveChannel::CHANNEL_COUNT)> | channel_states_ {} |
| std::atomic< bool > | initialized_ {false} |
| std::atomic< bool > | outputs_inhibited_ {false} |
| DropEnablePins() latched, until re-armed. | |
| std::atomic< flux::hal::ManagerError > | manager_error_ {flux::hal::ManagerError::NotInitialized} |
| std::atomic< hf_valve_err_t > | last_error_ {hf_valve_err_t::VALVE_SUCCESS} |
| RtosMutex | mutex_ |
Unified singleton for controlling all valve channels on the Flux board.
Provides a single API surface for both solenoid (MAX22200) and proportional (TLE92466ED) valve channels. The manager owns both handler instances and resolves channel requests to the correct backend automatically.
|
delete |
|
delete |
|
privatenoexcept |
|
privatedefault |
|
noexcept |
Clear faults on both drivers.
|
noexcept |
Configure dither for a proportional channel.
Dither superimposes a small oscillation on the current setpoint to reduce valve stiction and improve proportional control linearity.
| channel | Must be PROP_CH0..PROP_CH5 |
| amplitude_ma | Peak-to-peak dither amplitude in milliamps |
| frequency_hz | Dither oscillation frequency in Hz |
|
noexcept |
Configure PWM frequency for a proportional channel.
Accepts a frequency in Hz and internally converts to the TLE92466ED register encoding (mantissa, exponent, low-freq-range bit).
Valid range: ~30 Hz to 8 MHz.
| channel | Must be PROP_CH0..PROP_CH5 |
| frequency_hz | Desired PWM frequency in Hz |
|
noexcept |
Configure a solenoid channel with CDR (current drive regulation).
| channel | Must be SOL_CH0..SOL_CH7 |
| hit_ma | HIT (inrush) current in milliamps |
| hold_ma | HOLD (sustain) current in milliamps |
| hit_time_ms | Duration of HIT phase in milliseconds |
|
noexcept |
Configure a solenoid channel with VDR (voltage drive regulation).
| channel | Must be SOL_CH0..SOL_CH7 |
| hit_duty_pct | HIT duty cycle percentage (0-100) |
| hold_duty_pct | HOLD duty cycle percentage (0-100) |
| hit_time_ms | Duration of HIT phase in milliseconds |
|
noexcept |
Turn every channel off, release both driver handlers and reset to uninitialised.
Safe to call when not initialised. Channels are disabled before the handlers are destroyed, so a shutdown never leaves an output energised by a stale command.
|
noexcept |
Disable all channels on both drivers.
|
privatenoexcept |
Disable every channel on every bank that is up (mutex held by the caller).
|
noexcept |
Disable a valve channel output.
| channel | Valve channel to disable. |
|
noexcept |
Drive MAX22200 ENABLE and TLE92466ED EN low: both banks de-energised in hardware.
The hardware half of SafeHold (architecture-port design §3.4, §3.8). Writes the two enable GPIOs directly: no SPI transfer, no mutex, no allocation, no logging, so it is safe from the safety thread at any priority while another thread is mid-transfer on the valve bus. It works whether or not the manager is initialised (the pins exist as soon as GpioManager is up).
After a drop the manager refuses every channel-energising call (EnableChannel, EnableChannelsMask) with VALVE_ERR_WRONG_MODE, so software never believes a valve is on while its bank is gated off. De-energising calls still work. The drop holds until RearmEnablePins.
This does not decide when to drop the pins or whether to vent first: that is the caller's policy (the product's safety arbiter; vent-then-hold is owner question Q2).
gpio_set_level is not in IRAM).
|
noexcept |
Log valve channel statistics and driver health to the console.
|
noexcept |
Enable a valve channel output.
| channel | Valve channel to enable. |
|
noexcept |
Enable multiple channels by bitmask.
| mask | Lower 8 bits → MAX22200 channels, upper 6 bits → TLE92466ED. |
|
noexcept |
Ensure the valve manager system is initialized.
|
noexcept |
Find a channel enum by name.
| name | Channel name to look up. |
|
noexcept |
Get channel info (driver type, hw channel, name) by string name.
| name | Human-readable channel name (e.g. "SOL_CH0"). |
|
noexcept |
Get channel runtime state by enum.
| channel | Valve channel to query. |
|
noexcept |
Read back the two enable outputs.
| [out] | max_enable | MAX22200 ENABLE is driven high (false if the pin does not exist). |
| [out] | tle_enable | TLE92466ED EN is driven high (false if the pin does not exist). |
|
staticnoexcept |
|
inlinenoexcept |
Get the most recent failed valve operation's error code.
Operation lane (per call). Set by every channel, configuration and fault call that fails, and by a failed bring-up; never cleared by a later success. The lifecycle lane is GetManagerError().
|
inlinenoexcept |
Lifecycle / bind error of the last EnsureInitialized() (shared catalog).
ManagerError::None when initialised; otherwise why bring-up failed.
|
noexcept |
Get the MAX22200 handler for advanced solenoid operations.
|
noexcept |
Retrieve the TLE92466ED fault report.
| [out] | report | Fault report structure to fill. |
|
noexcept |
Retrieve the MAX22200 fault status.
| [out] | faults | Fault status structure to fill. |
|
noexcept |
Populate a ValveSystemDiagnostics snapshot.
| [out] | diag | Diagnostics structure to fill. |
|
noexcept |
Get the TLE92466ED handler for advanced proportional operations.
|
noexcept |
Check if any driver reports a fault.
|
noexcept |
Check for TLE92466ED-specific faults.
|
noexcept |
Check for MAX22200-specific faults.
|
privatenoexcept |
|
privatenoexcept |
|
privatenoexcept |
< UV trip: 24 V − 21 % (flag true supply loss)
< OV trip: 24 V + 21 % (flag regulator runaway)
|
noexcept |
Whether one driver IC came up during the last bring-up attempt.
True for a bank even when the manager as a whole failed (fail-closed) because the other bank did not come up; used for diagnosis (which part is missing).
| bank | ValveDriverType::MAX22200 or ValveDriverType::TLE92466. |
|
noexcept |
Check if a channel is currently enabled.
| channel | Valve channel to query. |
|
inlinenoexcept |
Check whether the valve subsystem has been initialised.
|
inlinenoexcept |
The enable pins were dropped and not re-armed since.
|
delete |
|
delete |
|
noexcept |
Leave SafeHold: full re-bring-up of both banks, which raises the enable pins again.
The MAX22200 is not guaranteed to keep its configuration across an ENABLE low period, so re-arming is Deinitialize() followed by EnsureInitialized(): every channel off, handlers rebuilt, chips re-initialised, pins raised by their drivers. Takes the manager mutex and uses SPI; never call it from the safety path.
|
inlineprivatenoexcept |
Remember a failed operation result for GetLastError(); pass the result through.
|
privatenoexcept |
Destroy both handlers and clear the bank flags (mutex held by the caller).
|
staticprivatenoexcept |
Resolve channel enum to hw channel index and driver type.
|
noexcept |
Set current setpoint for a proportional valve channel.
| channel | Must be PROP_CH0..PROP_CH5 |
| current_ma | Target current in milliamps (0–2000 single, 0–4000 parallel) |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
DropEnablePins() latched, until re-armed.
|
private |
|
private |