HF-MAX22200 Driver 0.1.0-dev
HF-MAX22200 C++ Driver
Loading...
Searching...
No Matches
max22200::MAX22200< SpiType > Class Template Reference

#include <max22200.hpp>

Public Member Functions

 MAX22200 (SpiType &spi_interface)
 Constructor (SPI only; set board config later with SetBoardConfig())
 
 MAX22200 (SpiType &spi_interface, const BoardConfig &board_config)
 Constructor with board config (SPI + IFS/limits)
 
 ~MAX22200 ()
 Destructor — calls Deinitialize() if initialized.
 
 MAX22200 (const MAX22200 &)=delete
 
MAX22200operator= (const MAX22200 &)=delete
 
 MAX22200 (MAX22200 &&)=default
 
MAX22200operator= (MAX22200 &&)=delete
 
DriverStatus Initialize ()
 Initialize the driver per datasheet flowchart (Figure 6)
 
DriverStatus Deinitialize ()
 Deinitialize — disable channels, ACTIVE=0, ENABLE low.
 
bool IsInitialized () const
 Check if driver is initialized.
 
DriverStatus ReadStatus (StatusConfig &status) const
 Read the full 32-bit STATUS register.
 
DriverStatus WriteStatus (const StatusConfig &status)
 Write the STATUS register (writable bits only)
 
DriverStatus ConfigureChannel (uint8_t channel, const ChannelConfig &config)
 Configure a channel (write full 32-bit CFG_CHx register)
 
DriverStatus GetChannelConfig (uint8_t channel, ChannelConfig &config) const
 Read a channel's configuration.
 
DriverStatus ConfigureAllChannels (const ChannelConfigArray &configs)
 Configure all channels.
 
DriverStatus GetAllChannelConfigs (ChannelConfigArray &configs) const
 Get all channel configurations.
 
DriverStatus EnableChannel (uint8_t channel)
 Turn on a channel (set ONCHx = 1)
 
DriverStatus DisableChannel (uint8_t channel)
 Turn off a channel (set ONCHx = 0)
 
DriverStatus SetChannelEnabled (uint8_t channel, bool enable)
 Set a channel on or off (convenience when toggling from a variable)
 
DriverStatus EnableAllChannels ()
 Turn on all channels.
 
DriverStatus DisableAllChannels ()
 Turn off all channels.
 
DriverStatus SetAllChannelsEnabled (bool enable)
 Set all channels on or off at once (convenience when toggling from a variable)
 
DriverStatus SetChannelsOn (uint8_t channel_mask)
 
DriverStatus SetFullBridgeState (uint8_t pair_index, FullBridgeState state)
 Set full-bridge state for a channel pair (datasheet Table 7)
 
DriverStatus ReadFaultRegister (FaultStatus &faults) const
 Read per-channel fault register (FAULT)
 
DriverStatus ClearAllFaults ()
 Clear all fault flags (read FAULT register and discard)
 
DriverStatus ClearChannelFaults (uint8_t channel_mask, FaultStatus *out_faults=nullptr) const
 Clear fault flags for selected channels only (MAX22200A)
 
DriverStatus ReadFaultRegisterSelectiveClear (uint8_t ocp_mask, uint8_t hhf_mask, uint8_t olf_mask, uint8_t dpm_mask, FaultStatus &faults) const
 [Advanced] Read FAULT register with per-type selective clear (MAX22200A)
 
DriverStatus ReadFaultFlags (StatusConfig &status) const
 Read fault flags from STATUS register.
 
DriverStatus ClearFaultFlags ()
 Clear fault flags by reading STATUS register.
 
DriverStatus ConfigureDpm (float start_current_ma, float dip_threshold_ma, float debounce_ms)
 Configure DPM in real units (easy API)
 
DriverStatus ReadDpmConfig (DpmConfig &config) const
 Read DPM algorithm configuration (CFG_DPM register)
 
DriverStatus WriteDpmConfig (const DpmConfig &config)
 Write DPM algorithm configuration (CFG_DPM register)
 
DriverStatus SetDpmEnabledChannels (uint8_t channel_mask)
 
DriverStatus EnableDevice ()
 Enable device (ENABLE pin high); SPI and channels can be used.
 
DriverStatus DisableDevice ()
 Disable device (ENABLE pin low); low-power state.
 
DriverStatus SetDeviceEnable (bool enable)
 Set ENABLE pin state (true = on, false = off)
 
DriverStatus GetFaultPinState (bool &fault_active) const
 Read nFAULT pin state (true = fault active, false = no fault)
 
DriverStatus ReadRegister32 (uint8_t bank, uint32_t &value) const
 Read a 32-bit register by bank address.
 
DriverStatus WriteRegister32 (uint8_t bank, uint32_t value)
 Write a 32-bit register by bank address.
 
DriverStatus ReadRegister8 (uint8_t bank, uint8_t &value) const
 Read 8-bit MSB of a register (fast 8-bit mode)
 
DriverStatus WriteRegister8 (uint8_t bank, uint8_t value)
 Write 8-bit MSB of a register (fast 8-bit mode)
 
uint8_t GetLastFaultByte () const
 
DriverStatistics GetStatistics () const
 
void ResetStatistics ()
 
void SetFaultCallback (FaultCallback callback, void *user_data)
 
void SetStateChangeCallback (StateChangeCallback callback, void *user_data)
 
void SetBoardConfig (const BoardConfig &config)
 Set board configuration (IFS, max current, max duty)
 
BoardConfig GetBoardConfig () const
 Get current board configuration.
 
DriverStatus SetHitCurrentMa (uint8_t channel, uint32_t ma)
 Set HIT current in milliamps (CDR mode)
 
DriverStatus SetHoldCurrentMa (uint8_t channel, uint32_t ma)
 Set HOLD current in milliamps (CDR mode)
 
DriverStatus SetHitCurrentA (uint8_t channel, float amps)
 Set HIT current in Amps (CDR mode)
 
DriverStatus SetHoldCurrentA (uint8_t channel, float amps)
 Set HOLD current in Amps (CDR mode)
 
DriverStatus SetHitCurrentPercent (uint8_t channel, float percent)
 Set HIT current as percentage of IFS (CDR mode)
 
DriverStatus SetHoldCurrentPercent (uint8_t channel, float percent)
 Set HOLD current as percentage of IFS (CDR mode)
 
DriverStatus GetHitCurrentMa (uint8_t channel, uint32_t &ma) const
 Get HIT current in milliamps (CDR mode)
 
DriverStatus GetHoldCurrentMa (uint8_t channel, uint32_t &ma) const
 Get HOLD current in milliamps (CDR mode)
 
DriverStatus GetHitCurrentPercent (uint8_t channel, float &percent) const
 Get HIT current as percentage of IFS (CDR mode)
 
DriverStatus GetHoldCurrentPercent (uint8_t channel, float &percent) const
 Get HOLD current as percentage of IFS (CDR mode)
 
DriverStatus SetHitDutyPercent (uint8_t channel, float percent)
 Set HIT duty cycle in percent (VDR mode)
 
DriverStatus SetHoldDutyPercent (uint8_t channel, float percent)
 Set HOLD duty cycle in percent (VDR mode)
 
DriverStatus GetHitDutyPercent (uint8_t channel, float &percent) const
 Get HIT duty cycle in percent (VDR mode)
 
DriverStatus GetHoldDutyPercent (uint8_t channel, float &percent) const
 Get HOLD duty cycle in percent (VDR mode)
 
DriverStatus GetDutyLimits (uint8_t channel, DutyLimits &limits) const
 Get duty cycle limits for a channel (uses channel's chop_freq and SRC)
 
DriverStatus SetHitTimeMs (uint8_t channel, float ms)
 Set HIT time in milliseconds.
 
DriverStatus GetHitTimeMs (uint8_t channel, float &ms) const
 Get HIT time in milliseconds.
 
DriverStatus ConfigureChannelCdr (uint8_t channel, uint32_t hit_ma, uint32_t hold_ma, float hit_time_ms, SideMode side_mode=SideMode::LOW_SIDE, ChopFreq chop_freq=ChopFreq::FMAIN_DIV4, bool slew_rate_control_enabled=false, bool open_load_detection_enabled=false, bool plunger_movement_detection_enabled=false, bool hit_current_check_enabled=false)
 Configure channel in real units (CDR mode)
 
DriverStatus ConfigureChannelVdr (uint8_t channel, float hit_duty_percent, float hold_duty_percent, float hit_time_ms, SideMode side_mode=SideMode::LOW_SIDE, ChopFreq chop_freq=ChopFreq::FMAIN_DIV4, bool slew_rate_control_enabled=false, bool open_load_detection_enabled=false, bool plunger_movement_detection_enabled=false, bool hit_current_check_enabled=false)
 Configure channel in real units (VDR mode)
 

Static Public Member Functions

static DriverStatus GetDutyLimits (bool master_clock_80khz, ChopFreq chop_freq, bool slew_rate_control_enabled, DutyLimits &limits)
 Get duty cycle limits (δMIN, δMAX) for a configuration.
 
static bool IsValidChannel (uint8_t channel)
 
static constexpr const charGetDriverVersion () noexcept
 Get the compiled driver version string.
 
static constexpr uint8_t GetDriverVersionMajor () noexcept
 Get the compiled driver major version number.
 
static constexpr uint8_t GetDriverVersionMinor () noexcept
 Get the compiled driver minor version number.
 
static constexpr uint8_t GetDriverVersionPatch () noexcept
 Get the compiled driver patch version number.
 

Constructor & Destructor Documentation

◆ MAX22200() [1/4]

template<typename SpiType >
max22200::MAX22200< SpiType >::MAX22200 ( SpiType & spi_interface)
explicit

Constructor (SPI only; set board config later with SetBoardConfig())

Use when board config is unknown at construction (e.g. loaded from NVS or another source after the driver is created). Unit APIs (SetHitCurrentMa, ConfigureChannel with CDR, etc.) require IFS to be set (SetBoardConfig with RREF) and will return INVALID_PARAMETER if board IFS is 0.

Parameters
spi_interfaceReference to SPI interface implementation

◆ MAX22200() [2/4]

template<typename SpiType >
max22200::MAX22200< SpiType >::MAX22200 ( SpiType & spi_interface,
const BoardConfig & board_config )

Constructor with board config (SPI + IFS/limits)

Use when the board is known at construction (e.g. fixed RREF). The driver is immediately valid for unit-based APIs without calling SetBoardConfig().

Parameters
spi_interfaceReference to SPI interface implementation
board_configBoard configuration (IFS from RREF, optional limits)

◆ ~MAX22200()

Destructor — calls Deinitialize() if initialized.

◆ MAX22200() [3/4]

template<typename SpiType >
max22200::MAX22200< SpiType >::MAX22200 ( const MAX22200< SpiType > & )
delete

◆ MAX22200() [4/4]

template<typename SpiType >
max22200::MAX22200< SpiType >::MAX22200 ( MAX22200< SpiType > && )
default

Member Function Documentation

◆ ClearAllFaults()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ClearAllFaults ( )

Clear all fault flags (read FAULT register and discard)

Clears OCP, HHF, OLF, and DPM for all channels and deasserts nFAULT. Use when you only need to clear and do not need the fault snapshot.

Returns
DriverStatus::OK on success

◆ ClearChannelFaults()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ClearChannelFaults ( uint8_t channel_mask,
FaultStatus * out_faults = nullptr ) const

Clear fault flags for selected channels only (MAX22200A)

On MAX22200A, clears OCP/HHF/OLF/DPM only for channels whose bit is set in channel_mask. On MAX22200, the device clears all flags on any read (same as ClearAllFaults).

Parameters
channel_maskBit N = 1 to clear faults for channel N (0–7)
out_faultsOptional: if non-null, filled with FAULT state after clear
Returns
DriverStatus::OK on success

◆ ClearFaultFlags()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ClearFaultFlags ( )

Clear fault flags by reading STATUS register.

◆ ConfigureAllChannels()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ConfigureAllChannels ( const ChannelConfigArray & configs)

Configure all channels.

◆ ConfigureChannel()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ConfigureChannel ( uint8_t channel,
const ChannelConfig & config )

Configure a channel (write full 32-bit CFG_CHx register)

Writes the complete 32-bit configuration register for the specified channel. This includes all drive parameters: HIT/HOLD currents, timing, drive mode, etc.

Parameters
channelChannel number (0-7)
configChannel configuration structure
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if channel >= 8
Note
For channels in PARALLEL mode, only the lower channel number's configuration is used (e.g., configure channel 0 for pair 0-1).
For channels in HBRIDGE mode, both channels' configurations are used (CFG_CHy for forward, CFG_CHx for reverse).
VDRnCDR and HSnLS bits can only be changed when all channels are OFF and both TRIGA and TRIGB are logic-low.
FREQ_CFG and SRC can be changed "on-the-fly" while channel is operating.
See also
ChannelConfig for detailed field descriptions

◆ ConfigureChannelCdr()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ConfigureChannelCdr ( uint8_t channel,
uint32_t hit_ma,
uint32_t hold_ma,
float hit_time_ms,
SideMode side_mode = SideMode::LOW_SIDE,
ChopFreq chop_freq = ChopFreq::FMAIN_DIV4,
bool slew_rate_control_enabled = false,
bool open_load_detection_enabled = false,
bool plunger_movement_detection_enabled = false,
bool hit_current_check_enabled = false )

Configure channel in real units (CDR mode)

Convenience method that sets all channel parameters using real units (mA, ms) instead of raw register values. Units: hit_ma (mA), hold_ma (mA), hit_time_ms (ms).

Parameters
channelChannel number (0-7)
hit_maHIT current in milliamps
hold_maHOLD current in milliamps
hit_time_msHIT time in milliseconds (-1 = continuous)
side_modeLow-side or high-side (default: LOW_SIDE)
chop_freqChopping frequency (default: FMAIN_DIV4)
slew_rate_control_enabledSlew rate control (default: false)
open_load_detection_enabledOpen load detection (default: false)
plunger_movement_detection_enabledDPM detection (default: false)
hit_current_check_enabledHIT current check (default: false)
Returns
DriverStatus::OK on success

◆ ConfigureChannelVdr()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ConfigureChannelVdr ( uint8_t channel,
float hit_duty_percent,
float hold_duty_percent,
float hit_time_ms,
SideMode side_mode = SideMode::LOW_SIDE,
ChopFreq chop_freq = ChopFreq::FMAIN_DIV4,
bool slew_rate_control_enabled = false,
bool open_load_detection_enabled = false,
bool plunger_movement_detection_enabled = false,
bool hit_current_check_enabled = false )

Configure channel in real units (VDR mode)

Convenience method for VDR mode using duty cycle percentages. Units: hit_duty_percent (%), hold_duty_percent (%), hit_time_ms (ms).

Parameters
channelChannel number (0-7)
hit_duty_percentHIT duty cycle in percent (0-100)
hold_duty_percentHOLD duty cycle in percent (0-100)
hit_time_msHIT time in milliseconds (-1 = continuous)
side_modeLow-side or high-side
chop_freqChopping frequency
slew_rate_control_enabledSlew rate control
open_load_detection_enabledOpen load detection
plunger_movement_detection_enabledDPM detection (low-side only)
hit_current_check_enabledHIT current check
Returns
DriverStatus::OK on success

◆ ConfigureDpm()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ConfigureDpm ( float start_current_ma,
float dip_threshold_ma,
float debounce_ms )

Configure DPM in real units (easy API)

Sets start current, dip threshold, and debounce time. Uses board IFS for current conversion and cached STATUS (FREQM) + FMAIN_DIV4 for debounce fCHOP. Call SetBoardConfig() first so IFS is set; call ReadStatus or Initialize so cache is valid.

Parameters
start_current_maCurrent (mA) above which DPM monitors for dip
dip_threshold_maMinimum dip amplitude (mA) to count as valid
debounce_msMin dip duration (ms); converted to chopping periods using actual fCHOP
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if IFS not set or values out of range
Note
For custom fCHOP or raw register control use ReadDpmConfig/WriteDpmConfig.

◆ Deinitialize()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::Deinitialize ( )

Deinitialize — disable channels, ACTIVE=0, ENABLE low.

Performs a clean shutdown sequence:

  1. Disable all channels (ONCH = 0)
  2. Set ACTIVE=0 (device enters low-power mode)
  3. Set ENABLE pin LOW (device enters sleep mode)

After Deinitialize(), the device consumes < 11μA from VM.

Returns
DriverStatus::OK on success
Note
All channels are three-stated when ACTIVE=0.
It takes 2.5ms (tDIS) from ENABLE falling edge to OUT_ tristate.

◆ DisableAllChannels()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::DisableAllChannels ( )

Turn off all channels.

Returns
DriverStatus::OK on success

◆ DisableChannel()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::DisableChannel ( uint8_t channel)

Turn off a channel (set ONCHx = 0)

Parameters
channelChannel number (0-7)
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if channel >= 8

◆ DisableDevice()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::DisableDevice ( )

Disable device (ENABLE pin low); low-power state.

◆ EnableAllChannels()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::EnableAllChannels ( )

Turn on all channels.

Returns
DriverStatus::OK on success

◆ EnableChannel()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::EnableChannel ( uint8_t channel)

Turn on a channel (set ONCHx = 1)

Sets the ONCHx bit so the channel is active (delivering current).

Parameters
channelChannel number (0-7)
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if channel >= 8
Note
Use DisableChannel() to turn off. For multiple channels use SetChannelsOn().
Channel must be configured with ConfigureChannel() before enabling.

◆ EnableDevice()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::EnableDevice ( )

Enable device (ENABLE pin high); SPI and channels can be used.

◆ GetAllChannelConfigs()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetAllChannelConfigs ( ChannelConfigArray & configs) const

Get all channel configurations.

◆ GetBoardConfig()

template<typename SpiType >
BoardConfig max22200::MAX22200< SpiType >::GetBoardConfig ( ) const

Get current board configuration.

◆ GetChannelConfig()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetChannelConfig ( uint8_t channel,
ChannelConfig & config ) const

Read a channel's configuration.

Parameters
channelChannel number (0-7)
configReference to store configuration

◆ GetDriverVersion()

template<typename SpiType >
static constexpr const char * max22200::MAX22200< SpiType >::GetDriverVersion ( )
inlinestaticconstexprnoexcept

Get the compiled driver version string.

◆ GetDriverVersionMajor()

template<typename SpiType >
static constexpr uint8_t max22200::MAX22200< SpiType >::GetDriverVersionMajor ( )
inlinestaticconstexprnoexcept

Get the compiled driver major version number.

◆ GetDriverVersionMinor()

template<typename SpiType >
static constexpr uint8_t max22200::MAX22200< SpiType >::GetDriverVersionMinor ( )
inlinestaticconstexprnoexcept

Get the compiled driver minor version number.

◆ GetDriverVersionPatch()

template<typename SpiType >
static constexpr uint8_t max22200::MAX22200< SpiType >::GetDriverVersionPatch ( )
inlinestaticconstexprnoexcept

Get the compiled driver patch version number.

◆ GetDutyLimits() [1/2]

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetDutyLimits ( bool master_clock_80khz,
ChopFreq chop_freq,
bool slew_rate_control_enabled,
DutyLimits & limits )
static

Get duty cycle limits (δMIN, δMAX) for a configuration.

Returns the minimum and maximum duty cycle percentages based on FREQM, FREQ_CFG, and SRC settings (datasheet Table 2).

Parameters
master_clock_80khzMaster clock 80 kHz base (from STATUS register)
chop_freqChopping frequency divider
slew_rate_control_enabledSlew rate control enabled
limitsOutput: min_percent and max_percent
Returns
DriverStatus::OK on success

◆ GetDutyLimits() [2/2]

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetDutyLimits ( uint8_t channel,
DutyLimits & limits ) const

Get duty cycle limits for a channel (uses channel's chop_freq and SRC)

Reads the channel config and uses cached STATUS (FREQM) to return δMIN/δMAX. Convenience wrapper when configuring VDR on a specific channel.

Parameters
channelChannel number (0-7)
limitsOutput: min_percent and max_percent
Returns
DriverStatus::OK on success

◆ GetFaultPinState()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetFaultPinState ( bool & fault_active) const

Read nFAULT pin state (true = fault active, false = no fault)

◆ GetHitCurrentMa()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHitCurrentMa ( uint8_t channel,
uint32_t & ma ) const

Get HIT current in milliamps (CDR mode)

Reads channel config and converts: ma = (hit_current / 127.0) × IFS_ma

◆ GetHitCurrentPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHitCurrentPercent ( uint8_t channel,
float & percent ) const

Get HIT current as percentage of IFS (CDR mode)

◆ GetHitDutyPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHitDutyPercent ( uint8_t channel,
float & percent ) const

Get HIT duty cycle in percent (VDR mode)

Reads channel config: percent = (hit_current / 127.0) × 100

◆ GetHitTimeMs()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHitTimeMs ( uint8_t channel,
float & ms ) const

Get HIT time in milliseconds.

Reads channel config and STATUS (FREQM): ms = (HIT_T × 40 / fCHOP) × 1000

◆ GetHoldCurrentMa()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHoldCurrentMa ( uint8_t channel,
uint32_t & ma ) const

Get HOLD current in milliamps (CDR mode)

◆ GetHoldCurrentPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHoldCurrentPercent ( uint8_t channel,
float & percent ) const

Get HOLD current as percentage of IFS (CDR mode)

◆ GetHoldDutyPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::GetHoldDutyPercent ( uint8_t channel,
float & percent ) const

Get HOLD duty cycle in percent (VDR mode)

◆ GetLastFaultByte()

template<typename SpiType >
uint8_t max22200::MAX22200< SpiType >::GetLastFaultByte ( ) const

◆ GetStatistics()

template<typename SpiType >
DriverStatistics max22200::MAX22200< SpiType >::GetStatistics ( ) const

◆ Initialize()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::Initialize ( )

Initialize the driver per datasheet flowchart (Figure 6)

Performs the complete initialization sequence as specified in the MAX22200 datasheet Programming Flow Chart:

  1. Initialize SPI: Configure SPI interface to Mode 0 (CPOL=0, CPHA=0)
  2. Power-up: Set ENABLE pin HIGH, wait 0.5ms (tEN) for SPI ready
  3. Read STATUS: Clear UVM flag and deassert nFAULT pin
    • Checks for communication error (STATUS[7:0] = 0x04)
    • If COMER detected, initialization fails
  4. Write STATUS: Set ACTIVE=1, configure default HW settings
    • All channels OFF (ONCH = 0)
    • All channel pairs in INDEPENDENT mode
    • Fault masks set to defaults (M_COMF = 1, others = 0)
  5. Cache STATUS: Store STATUS for fast ONCH updates
Returns
DriverStatus::OK on success
DriverStatus::COMMUNICATION_ERROR if COMER flag detected
DriverStatus::INITIALIZATION_ERROR if SPI or GPIO operations fail
Note
After Initialize(), channels must be configured with ConfigureChannel() before they can be enabled.
The device enters normal operation after ACTIVE=1 with a wake-up time of 2.5ms (tWU). Channels can be enabled immediately after Initialize().
See also
MAX22200 datasheet Figure 6: Programming Flow Chart

◆ IsInitialized()

template<typename SpiType >
bool max22200::MAX22200< SpiType >::IsInitialized ( ) const

Check if driver is initialized.

◆ IsValidChannel()

template<typename SpiType >
static bool max22200::MAX22200< SpiType >::IsValidChannel ( uint8_t channel)
inlinestatic

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ ReadDpmConfig()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadDpmConfig ( DpmConfig & config) const

Read DPM algorithm configuration (CFG_DPM register)

DPM settings are global and apply to all channels that have DPM_EN set.

Parameters
configReference to DpmConfig to populate
Returns
DriverStatus::OK on success
See also
DpmConfig, WriteDpmConfig, ConfigureDpm

◆ ReadFaultFlags()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadFaultFlags ( StatusConfig & status) const

Read fault flags from STATUS register.

◆ ReadFaultRegister()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadFaultRegister ( FaultStatus & faults) const

Read per-channel fault register (FAULT)

Reads the FAULT register (OCP, HHF, OLF, DPM per channel). Reading also clears the flags and deasserts nFAULT when no other faults remain.

Parameters
faultsReference to FaultStatus to populate
Returns
DriverStatus::OK on success
See also
ClearAllFaults() to clear without keeping the result
ClearChannelFaults() to clear only specific channels (MAX22200A)

◆ ReadFaultRegisterSelectiveClear()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadFaultRegisterSelectiveClear ( uint8_t ocp_mask,
uint8_t hhf_mask,
uint8_t olf_mask,
uint8_t dpm_mask,
FaultStatus & faults ) const

[Advanced] Read FAULT register with per-type selective clear (MAX22200A)

For MAX22200A only: separate masks for OCP, HHF, OLF, DPM let you clear only certain fault types per channel. On MAX22200, SDI is ignored and all flags are cleared. Prefer ClearAllFaults() or ClearChannelFaults() for normal use.

Parameters
ocp_maskChannel mask for OCP bits to clear (bit N = channel N)
hhf_maskChannel mask for HHF bits to clear
olf_maskChannel mask for OLF bits to clear
dpm_maskChannel mask for DPM bits to clear
faultsPopulated with FAULT register value after the read
Returns
DriverStatus::OK on success

◆ ReadRegister32()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadRegister32 ( uint8_t bank,
uint32_t & value ) const

Read a 32-bit register by bank address.

◆ ReadRegister8()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadRegister8 ( uint8_t bank,
uint8_t & value ) const

Read 8-bit MSB of a register (fast 8-bit mode)

◆ ReadStatus()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::ReadStatus ( StatusConfig & status) const

Read the full 32-bit STATUS register.

◆ ResetStatistics()

template<typename SpiType >
void max22200::MAX22200< SpiType >::ResetStatistics ( )

◆ SetAllChannelsEnabled()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetAllChannelsEnabled ( bool enable)

Set all channels on or off at once (convenience when toggling from a variable)

Parameters
enabletrue = all on, false = all off
Returns
DriverStatus::OK on success

◆ SetBoardConfig()

template<typename SpiType >
void max22200::MAX22200< SpiType >::SetBoardConfig ( const BoardConfig & config)

Set board configuration (IFS, max current, max duty)

Configures the full-scale current and optional safety limits used by convenience APIs (SetHitCurrentMa, SetHitDutyPercent, etc.). Can be called at any time to change limits; IFS is required for unit-based APIs.

Parameters
configBoard configuration (IFS in mA, optional max limits)
Note
Alternatively pass BoardConfig at construction: MAX22200 driver(spi, BoardConfig(30.0f, false));

◆ SetChannelEnabled()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetChannelEnabled ( uint8_t channel,
bool enable )

Set a channel on or off (convenience when toggling from a variable)

Parameters
channelChannel number (0-7)
enabletrue = on, false = off
Returns
DriverStatus::OK on success

◆ SetChannelsOn()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetChannelsOn ( uint8_t channel_mask)

◆ SetDeviceEnable()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetDeviceEnable ( bool enable)

Set ENABLE pin state (true = on, false = off)

Prefer EnableDevice() / DisableDevice() for clarity.

◆ SetDpmEnabledChannels()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetDpmEnabledChannels ( uint8_t channel_mask)

◆ SetFaultCallback()

template<typename SpiType >
void max22200::MAX22200< SpiType >::SetFaultCallback ( FaultCallback callback,
void * user_data )

◆ SetFullBridgeState()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetFullBridgeState ( uint8_t pair_index,
FullBridgeState state )

Set full-bridge state for a channel pair (datasheet Table 7)

Updates ONCHx and ONCHy for the given pair to achieve HiZ, Forward, Reverse, or Brake. Other channels' ONCH bits are preserved.

Parameters
pair_indexPair index 0–3 (0 = ch0–ch1, 1 = ch2–ch3, 2 = ch4–ch5, 3 = ch6–ch7)
stateFullBridgeState::HiZ, Forward, Reverse, or Brake
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if pair_index > 3
Note
The pair must be configured as HBRIDGE in STATUS (CMxy = 10).
See also
FullBridgeState, StatusConfig::cm10, ChannelMode::HBRIDGE

◆ SetHitCurrentA()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHitCurrentA ( uint8_t channel,
float amps )

Set HIT current in Amps (CDR mode)

Convenience wrapper: converts A to mA and calls SetHitCurrentMa.

◆ SetHitCurrentMa()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHitCurrentMa ( uint8_t channel,
uint32_t ma )

Set HIT current in milliamps (CDR mode)

Converts mA to 7-bit register value: raw = round((ma / IFS_ma) × 127). Clamps to max_current_ma if set, then to 0-127.

Parameters
channelChannel number (0-7)
maCurrent in milliamps
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if channel >= 8 or IFS not configured

◆ SetHitCurrentPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHitCurrentPercent ( uint8_t channel,
float percent )

Set HIT current as percentage of IFS (CDR mode)

Parameters
channelChannel number (0-7)
percentPercentage (0-100)
Returns
DriverStatus::OK on success

◆ SetHitDutyPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHitDutyPercent ( uint8_t channel,
float percent )

Set HIT duty cycle in percent (VDR mode)

Converts percent to 7-bit: raw = round((pct / 100) × 127). Clamps to max_duty_percent if set, then to [δMIN, δMAX] based on FREQM, FREQ_CFG, and SRC settings.

Parameters
channelChannel number (0-7)
percentDuty cycle in percent (0-100)
Returns
DriverStatus::OK on success

◆ SetHitTimeMs()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHitTimeMs ( uint8_t channel,
float ms )

Set HIT time in milliseconds.

Converts ms to 8-bit register value: HIT_T = round((ms / 1000) × fCHOP / 40). Needs FREQM (from STATUS) and channel's chop_freq to compute fCHOP.

Parameters
channelChannel number (0-7)
msHIT time in milliseconds (0 = no HIT, -1 or 0xFFFF = continuous)
Returns
DriverStatus::OK on success

◆ SetHoldCurrentA()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHoldCurrentA ( uint8_t channel,
float amps )

Set HOLD current in Amps (CDR mode)

◆ SetHoldCurrentMa()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHoldCurrentMa ( uint8_t channel,
uint32_t ma )

Set HOLD current in milliamps (CDR mode)

◆ SetHoldCurrentPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHoldCurrentPercent ( uint8_t channel,
float percent )

Set HOLD current as percentage of IFS (CDR mode)

◆ SetHoldDutyPercent()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::SetHoldDutyPercent ( uint8_t channel,
float percent )

Set HOLD duty cycle in percent (VDR mode)

◆ SetStateChangeCallback()

template<typename SpiType >
void max22200::MAX22200< SpiType >::SetStateChangeCallback ( StateChangeCallback callback,
void * user_data )

◆ WriteDpmConfig()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::WriteDpmConfig ( const DpmConfig & config)

Write DPM algorithm configuration (CFG_DPM register)

Parameters
configDPM configuration (plunger_movement_start_current, plunger_movement_debounce_time, plunger_movement_current_threshold)
Returns
DriverStatus::OK on success
See also
DpmConfig, ReadDpmConfig, ConfigureDpm

◆ WriteRegister32()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::WriteRegister32 ( uint8_t bank,
uint32_t value )

Write a 32-bit register by bank address.

◆ WriteRegister8()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::WriteRegister8 ( uint8_t bank,
uint8_t value )

Write 8-bit MSB of a register (fast 8-bit mode)

◆ WriteStatus()

template<typename SpiType >
DriverStatus max22200::MAX22200< SpiType >::WriteStatus ( const StatusConfig & status)

Write the STATUS register (writable bits only)


The documentation for this class was generated from the following files: