|
HardFOC Core
API reference
|
Unified handler for MAX22200 octal solenoid/motor driver. More...
#include <Max22200Handler.h>
Public Types | |
| using | DriverType = max22200::MAX22200< HalSpiMax22200Comm > |
| Underlying max22200::MAX22200 driver type. | |
Public Member Functions | |
| Max22200Handler (BaseSpi &spi, BaseGpio &enable, BaseGpio &cmd, BaseGpio *fault=nullptr) noexcept | |
| Construct MAX22200 handler. | |
| ~Max22200Handler () noexcept | |
| Max22200Handler (const Max22200Handler &)=delete | |
| Max22200Handler & | operator= (const Max22200Handler &)=delete |
| Max22200Handler (Max22200Handler &&)=delete | |
| Max22200Handler & | operator= (Max22200Handler &&)=delete |
| max22200::DriverStatus | Initialize () noexcept |
| Initialize driver (ENABLE HIGH, read/clear STATUS, set ACTIVE). | |
| bool | EnsureInitialized () noexcept |
| Ensure driver is initialized (lazy init entrypoint). | |
| max22200::DriverStatus | Initialize (const max22200::BoardConfig &board_config) noexcept |
| Initialize with board configuration. | |
| max22200::DriverStatus | Deinitialize () noexcept |
| Deinitialize — disable all channels, ACTIVE=0, ENABLE LOW. | |
| bool | IsInitialized () const noexcept |
| Check if Initialize completed successfully. | |
| uint8_t | GetLastFaultByte () const noexcept |
| STATUS[7:0] captured on the last command-phase SPI byte. | |
| max22200::DriverStatus | ConfigureChannel (uint8_t channel, const max22200::ChannelConfig &config) noexcept |
| Configure a channel completely. | |
| max22200::DriverStatus | SetupCdrChannel (uint8_t channel, uint16_t hit_ma, uint16_t hold_ma, float hit_time_ms) noexcept |
| Quick CDR setup with milliamp values. | |
| max22200::DriverStatus | SetupVdrChannel (uint8_t channel, float hit_duty_pct, float hold_duty_pct, float hit_time_ms) noexcept |
| Quick VDR setup with duty cycle percentages. | |
| max22200::DriverStatus | EnableChannel (uint8_t channel) noexcept |
| Enable a channel (sets bit in STATUS channels_on_mask). | |
| max22200::DriverStatus | DisableChannel (uint8_t channel) noexcept |
| Disable a channel. | |
| max22200::DriverStatus | EnableAllChannels () noexcept |
| Enable all eight channels (writes full channels_on_mask). | |
| max22200::DriverStatus | DisableAllChannels () noexcept |
| Disable all channels. | |
| bool | IsChannelEnabled (uint8_t channel) noexcept |
| Check if a channel is enabled (reads STATUS channels_on_mask). | |
| max22200::DriverStatus | SetChannelsMask (uint8_t mask) noexcept |
| Set channels enabled by bitmask. | |
| max22200::DriverStatus | GetStatus (max22200::StatusConfig &status) noexcept |
| Read the STATUS register. | |
| max22200::DriverStatus | GetChannelFaults (uint8_t channel, max22200::FaultStatus &faults) noexcept |
| Read the device-wide FAULT register (channel param is range-checked only). | |
| bool | HasFault () noexcept |
| Check if any fault flag is set (reads STATUS fault summary). | |
| max22200::DriverStatus | ClearFaults () noexcept |
| Clear all latched fault flags (read-clear FAULT register). | |
| max22200::DriverStatus | ReadFaultRegister (max22200::FaultStatus &faults) noexcept |
| Read the FAULT register (OCP/OLF/HHF/DPM channel bitmasks). | |
| template<typename Fn > | |
| auto | WithDriver (Fn &&fn) noexcept |
Run fn against the raw driver with mutex_ held. | |
| DriverType * | GetDriver () noexcept |
| Get the underlying driver for advanced operations. | |
| const DriverType * | GetDriver () const noexcept |
| Const view of GetDriver (delegates via const_cast). | |
| void | DumpDiagnostics () noexcept |
| Log STATUS, FAULT register, and SPI transfer statistics. | |
Static Public Attributes | |
| static constexpr uint8_t | kNumChannels = 8 |
| Number of MAX22200 output channels (0..7). | |
Private Member Functions | |
| max22200::DriverStatus | InitializeLocked () noexcept |
| Initialize while mutex_ is held (no board IFS). | |
| bool | EnsureInitializedLocked () noexcept |
| bool | WaitForActiveAndDrainFaults () noexcept |
| Post-init wake poll: poke ACTIVE=1, wait for latch or SPI-live fallback. | |
| template<typename Fn > | |
| auto | withDriver (Fn &&fn) noexcept |
| Execute a lambda with a locked, initialized driver. | |
Private Attributes | |
| bool | initialized_ {false} |
| RtosMutex | mutex_ |
| std::unique_ptr< HalSpiMax22200Comm > | comm_ |
| std::unique_ptr< DriverType > | driver_ |
| uint8_t | last_fault_byte_ {0xFF} |
Unified handler for MAX22200 octal solenoid/motor driver.
Serialises all driver access behind an internal mutex. Production callers should use WithDriver for multi-register sequences; GetDriver does not protect subsequent use of the returned pointer.
Provides thread-safe access to all MAX22200 driver features:
| using Max22200Handler::DriverType = max22200::MAX22200<HalSpiMax22200Comm> |
Underlying max22200::MAX22200 driver type.
|
noexcept |
Construct MAX22200 handler.
| spi | Reference to pre-configured BaseSpi (Mode 0). |
| enable | BaseGpio for ENABLE pin (active HIGH). |
| cmd | BaseGpio for CMD pin. |
| fault | Optional BaseGpio for nFAULT (active LOW). |
|
noexcept |
|
delete |
|
delete |
|
noexcept |
Clear all latched fault flags (read-clear FAULT register).
|
noexcept |
Configure a channel completely.
| channel | Channel number (0-7). |
| config | Full channel configuration. |
|
noexcept |
Deinitialize — disable all channels, ACTIVE=0, ENABLE LOW.
|
noexcept |
Disable all channels.
|
noexcept |
Disable a channel.
| channel | Channel number (0-7). |
|
noexcept |
Log STATUS, FAULT register, and SPI transfer statistics.
|
noexcept |
Enable all eight channels (writes full channels_on_mask).
|
noexcept |
Enable a channel (sets bit in STATUS channels_on_mask).
| channel | Channel number (0-7). |
|
noexcept |
Ensure driver is initialized (lazy init entrypoint).
|
privatenoexcept |
|
noexcept |
Read the device-wide FAULT register (channel param is range-checked only).
| channel | Channel number (0-7); validated but not used — FaultStatus carries per-channel bitmasks for all eight outputs. | |
| [out] | faults | Populated fault register snapshot. |
|
noexcept |
|
noexcept |
Get the underlying driver for advanced operations.
|
noexcept |
STATUS[7:0] captured on the last command-phase SPI byte.
|
noexcept |
Read the STATUS register.
| [out] | status | Status structure to fill. |
|
noexcept |
Check if any fault flag is set (reads STATUS fault summary).
|
noexcept |
Initialize driver (ENABLE HIGH, read/clear STATUS, set ACTIVE).
|
noexcept |
Initialize with board configuration.
| board_config | Board-specific IFS (from RREF) and max-current limits. |
|
privatenoexcept |
Initialize while mutex_ is held (no board IFS).
|
noexcept |
Check if a channel is enabled (reads STATUS channels_on_mask).
| channel | Channel number (0-7). |
|
inlinenoexcept |
Check if Initialize completed successfully.
|
delete |
|
delete |
|
noexcept |
Read the FAULT register (OCP/OLF/HHF/DPM channel bitmasks).
| [out] | faults | Device-wide fault snapshot. |
|
noexcept |
Set channels enabled by bitmask.
| mask | Bitmask of channels to enable (bit 0 = CH0, bit 7 = CH7). |
|
noexcept |
Quick CDR setup with milliamp values.
| channel | Channel number (0-7). |
| hit_ma | HIT current in milliamps (bench CH0: 500 mA). |
| hold_ma | HOLD current in milliamps (bench CH0: 250 mA). |
| hit_time_ms | HIT phase duration in milliseconds. |
Switches the channel to CDR first if it is in VDR (the driver's current setters no longer do), keeping its other CFG_CHx fields. The chip ignores that switch while any channel is on or a TRIG pin is high.
|
noexcept |
Quick VDR setup with duty cycle percentages.
| channel | Channel number (0-7). |
| hit_duty_pct | HIT duty cycle (0..100 %). |
| hold_duty_pct | HOLD duty cycle (0..100 %). |
| hit_time_ms | HIT phase duration in milliseconds. |
Switches the channel to VDR first if it is in CDR, keeping its other CFG_CHx fields. The duty is written as percent (HIT[6:0] = 40 for 40 %).
|
privatenoexcept |
Post-init wake poll: poke ACTIVE=1, wait for latch or SPI-live fallback.
Must be called with mutex_ held and driver_ constructed.
The driver's Initialize() returns OK as soon as its STATUS write transaction completes, but the chip's t_WU = 2.5 ms (per datasheet) and the V18 LDO can take dozens of ms to settle on real boards. Polls STATUS while re-issuing a bare ACTIVE=1 write each iteration. UVM may remain set on soft-rail setups — logged but not fatal. If ACTIVE never latches, accepts SPI-live after >=3 OK STATUS polls, then read-clears FAULT so nFAULT releases.
|
inlinenoexcept |
Run fn against the raw driver with mutex_ held.
Preferred over GetDriver for any multi-register sequence: the MAX22200 uses a two-phase CMD-pin protocol (command byte, then data), so a peer transaction landing between the phases desynchronizes the device. Holding the handler mutex across the whole callback keeps the sequence coherent.
| Fn | Callable taking DriverType&. |
fn's result, or INITIALIZATION_ERROR / a value-initialized result when the driver is unavailable. When fn returns void, this returns bool (true when fn actually ran).
|
inlineprivatenoexcept |
Execute a lambda with a locked, initialized driver.
Acquires the mutex, ensures initialization, and invokes fn(*driver_). Returns a default-constructed R on failure.
|
private |
|
private |
|
private |
|
staticconstexpr |
Number of MAX22200 output channels (0..7).
|
private |
Retained after failed init when driver_ is reset (CDC max_fault).
|
mutableprivate |