MAX22200 Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
max22200::MAX22200< SpiType > Class Template Reference

Main driver class for MAX22200 IC. More...

#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
 
MAX22200 & operator= (const MAX22200 &)=delete
 
 MAX22200 (MAX22200 &&)=default
 
MAX22200 & operator= (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 completed Initialize() successfully.
 
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 eight channels (CFG_CH0 through CFG_CH7)
 
DriverStatus GetAllChannelConfigs (ChannelConfigArray &configs) const
 Read configuration for all eight channels.
 
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)
 Set which channels are on (fast multi-channel update)
 
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 (byte 0, bits 7:1)
 
DriverStatus ClearFaultFlags ()
 Clear STATUS fault flags by reading the STATUS register.
 
DriverStatus ConfigureDpm (float start_current_ma, float dip_threshold_ma, float debounce_ms)
 Configure DPM in real units (easy API)
 
DriverStatus ConfigureDpm (float start_current_ma, float dip_threshold_ma, float debounce_ms, ChopFreq chop_freq)
 Configure DPM in real units for a given chopping frequency.
 
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)
 Enable or disable DPM (plunger movement detection) on selected channels.
 
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 (debug/advanced)
 
DriverStatus WriteRegister32 (uint8_t bank, uint32_t value)
 Write a 32-bit register by bank address (debug/advanced)
 
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
 Get last fault flags byte received from Command Register write.
 
DriverStatistics GetStatistics () const
 Get accumulated driver transfer statistics.
 
void ResetStatistics ()
 Reset all statistics counters to zero.
 
void SetFaultCallback (FaultCallback callback, void *user_data)
 Register a fault event callback.
 
void SetStateChangeCallback (StateChangeCallback callback, void *user_data)
 Register a channel state-change callback (stored for application use)
 
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)
 Check whether channel is a valid MAX22200 channel index.
 
static constexpr const char * GetDriverVersion () 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.
 

Detailed Description

template<typename SpiType>
class max22200::MAX22200< SpiType >

Main driver class for MAX22200 IC.

This class provides a high-level API for controlling the MAX22200 octal solenoid and motor driver. It handles the two-phase SPI protocol internally and provides convenient methods for channel configuration, control, and fault monitoring.

Template Parameters
SpiTypeThe SPI interface implementation type that inherits from max22200::SpiInterface<SpiType>. Must implement:
  • Transfer() for SPI data transfer
  • GpioSet() for CMD/ENABLE/FAULT pin control
  • GpioGet() for FAULT pin reading
Basic usage (CDR mode):
MySPI spi;
MAX22200<MySPI> driver(spi);
driver.SetBoardConfig(BoardConfig(30.0f, false)); // IFS from RREF
if (driver.Initialize() == DriverStatus::OK) {
ChannelConfig config;
config.hit_setpoint = 400.0f; // desired current, mA (IFS from SetBoardConfig above)
config.hold_setpoint = 200.0f; // mA
config.hit_time_ms = 10.0f;
driver.ConfigureChannel(0, config);
driver.EnableChannel(0);
}
Main driver class for MAX22200 IC.
Definition max22200.hpp:133
@ CDR
Current Drive Regulation (VDRnCDR = 0) — low-side only.
@ LOW_SIDE
Low-side driver (HSnLS = 0) — supports CDR and VDR.
@ OK
Operation completed successfully.
@ FMAIN_DIV2
FreqMain / 2 (fCHOP = 50kHz if FREQM=0, 40kHz if FREQM=1). With SRC=1 use only if FREQM=1 (40kHz).
Board/scale configuration for unit-based APIs.
Definition max22200_types.hpp:1089
Channel configuration structure.
Definition max22200_types.hpp:402
float hold_setpoint
HOLD setpoint: CDR = mA, VDR = duty % (0–100)
Definition max22200_types.hpp:407
bool hit_current_check_enabled
HIT current check enable (HHF fault if IHIT not reached)
Definition max22200_types.hpp:423
float hit_time_ms
Definition max22200_types.hpp:408
SideMode side_mode
Side mode: LOW_SIDE (CDR/VDR) or HIGH_SIDE (VDR only)
Definition max22200_types.hpp:418
DriveMode drive_mode
Drive mode: CDR (current) or VDR (voltage)
Definition max22200_types.hpp:417
float hit_setpoint
HIT setpoint: CDR = mA, VDR = duty % (0–100)
Definition max22200_types.hpp:406
ChopFreq chop_freq
Chopping frequency divider (FREQ_CFG[1:0])
Definition max22200_types.hpp:419
Fast HOLD current update (8-bit mode):
// Update HOLD on-the-fly: CFG_CH[31:24] = HFS (bit 7) | HOLD[6:0] (bits 6:0)
driver.GetChannelConfig(0, config);
uint8_t hold_raw = 60; // 7-bit raw (0-127); or derive from config.hold_setpoint
driver.WriteRegister8(RegBank::CFG_CH0, (config.half_full_scale ? 0x80u : 0u) | (hold_raw & 0x7Fu));
constexpr uint8_t CFG_CH0
Channel 0 configuration register (32-bit)
Definition max22200_registers.hpp:111
bool half_full_scale
Definition max22200_types.hpp:413
Channel-pair configuration (parallel mode):
StatusConfig status;
driver.ReadStatus(status);
status.channel_pair_mode_10 = ChannelMode::PARALLEL; // Channels 0-1 in parallel
status.channels_on_mask = 0; // Both channels must be OFF
driver.WriteStatus(status);
// Now configure channel 0 (channel 1 config is ignored)
@ PARALLEL
Channels in parallel mode (CMxy = 01) — double current.
STATUS register structure.
Definition max22200_types.hpp:683
ChannelMode channel_pair_mode_10
CH0/CH1 pair mode.
Definition max22200_types.hpp:703
uint8_t channels_on_mask
Definition max22200_types.hpp:685

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()

template<typename SpiType >
max22200::MAX22200< SpiType >::~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 STATUS fault flags by reading the STATUS register.

Performs ReadStatus() and discards the result. Clears UVM per datasheet; per-channel faults require ReadFaultRegister() or ClearAllFaults().

Returns
DriverStatus::OK on success

◆ ConfigureAllChannels()

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

Configure all eight channels (CFG_CH0 through CFG_CH7)

Calls ConfigureChannel() for each index. Stops and returns the first non-OK status if any channel fails.

Parameters
configsArray of eight ChannelConfig values (index N = channel N)
Returns
DriverStatus::OK if all channels configured successfully

◆ 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() [1/2]

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. The debounce is a count of chopping periods (TDEB = DPM_TDEB / fCHOP, datasheet CFG_DPM), and fCHOP is per channel, so this overload reads CFG_CH0..7 and uses the FREQ_CFG of the channels that have DPM_EN set (with FREQM from the cached STATUS). With no DPM channel yet it uses FREQ_CFG = 00 (FMAIN_DIV4, the reset value); enable DPM first, or use the overload that takes the frequency.

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, clamped to 15
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if IFS not set, a value is negative or NaN, or DPM channels use different FREQ_CFG (nothing is written)

◆ ConfigureDpm() [2/2]

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

Configure DPM in real units for a given chopping frequency.

As ConfigureDpm(float, float, float), but converts the debounce with chop_freq (and FREQM from the cached STATUS) instead of reading the channels.

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, clamped to 15
chop_freqFREQ_CFG of the channels DPM will monitor
Returns
DriverStatus::OK on success
DriverStatus::INVALID_PARAMETER if IFS not set or a value is negative or NaN

◆ 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

Read configuration for all eight channels.

Parameters
configsOutput array; index N receives channel N configuration
Returns
DriverStatus::OK on success

◆ 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[6:0] (datasheet Table 3; 100 and above read as 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

Get last fault flags byte received from Command Register write.

Every time the Command Register is written (Phase 1 of SPI protocol), the device responds with STATUS[7:0] (Fault Flag Byte) on SDO. This method returns the most recent value received.

Returns
STATUS[7:0] byte from last Command Register write
Note
Check for communication error: return value = 0x04 (COMER flag)
This byte contains: OVT, OCP, OLF, HHF, DPM, COMER, UVM, ACTIVE bits
Check for communication error:
uint8_t fault_byte = driver.GetLastFaultByte();
if (fault_byte == 0x04) {
// Communication error detected
}

◆ GetStatistics()

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

Get accumulated driver transfer statistics.

Returns
Copy of DriverStatistics. Currently total_transfers and failed_transfers are updated by SPI operations; fault_events, state_changes, and uptime_ms remain zero unless future driver revisions populate them.

◆ 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. Wake-up: wait tWU (2.5 ms) after ACTIVE = 1, then read STATUS again
  6. 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 2.5 ms (tWU) after ACTIVE=1. Initialize() waits tWU through the port's DelayUs() before it returns, so channels can be enabled as soon as it returns OK. Initialize() therefore takes at least 3 ms (tEN + tWU).
See also
MAX22200 datasheet Figure 6: Programming Flow Chart

◆ IsInitialized()

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

Check if driver completed Initialize() successfully.

Returns
true after a successful Initialize(); false after construction or Deinitialize()

◆ IsValidChannel()

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

Check whether channel is a valid MAX22200 channel index.

Parameters
channelChannel number to test
Returns
true if channel is 0–7

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ 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 (byte 0, bits 7:1)

Convenience wrapper around ReadStatus() when only global fault flags (OVT, OCP, OLF, HHF, DPM, COMER, UVM) are needed.

Parameters
statusPopulated with STATUS fields; inspect hasFault() or individual flags
Returns
DriverStatus::OK on success

◆ 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 (debug/advanced)

Two-phase SPI: Command Register (CMD HIGH, 8-bit) then 32-bit data (CMD LOW). Does not update cached_status_ when reading STATUS; prefer ReadStatus().

Parameters
bankRegBank address (0x00–0x0A)
valueReceived 32-bit register value
Returns
DriverStatus::OK on success

◆ 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)

Two-phase SPI with Command Register bit 0 set (8bit/n32 = 1). Reads only the most significant byte (e.g. STATUS[31:24] ONCH, FAULT[31:24] OCP).

Parameters
bankRegBank address (0x00–0x0A)
valueReceived MSB byte
Returns
DriverStatus::OK on success

◆ ReadStatus()

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

Read the full 32-bit STATUS register.

Performs a two-phase SPI read (Command Register with CMD HIGH, then 32-bit data with CMD LOW). Updates cached_status_ on success.

Parameters
statusPopulated with parsed STATUS fields (ONCH, masks, CMxy, fault flags)
Returns
DriverStatus::OK on success
Note
Reading STATUS clears the UVM flag and may deassert nFAULT.

◆ ResetStatistics()

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

Reset all statistics counters to zero.

◆ 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<MySpi> 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)

Set which channels are on (fast multi-channel update)

Updates all eight ONCH bits in one 8-bit write. Bit N = 1 means channel N is on; 0 means off. Use this instead of multiple EnableChannel() calls when updating several channels at once.

Parameters
channel_maskBitmask: bit 0 = channel 0, bit 1 = channel 1, ... bit 7 = channel 7
Returns
DriverStatus::OK on success
Turn on channels 0, 2, and 5:
driver.SetChannelsOn((1u << 0) | (1u << 2) | (1u << 5));

◆ 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)

Enable or disable DPM (plunger movement detection) on selected channels.

Reads each channel's config, sets or clears the DPM_EN bit according to channel_mask, and writes the config back. All other channel settings are unchanged. DPM algorithm parameters (start current, debounce, threshold) are global and set via ConfigureDpm() or WriteDpmConfig().

Parameters
channel_maskBit N = 1 to enable DPM on channel N, 0 to disable (channels 0–7).
Returns
DriverStatus::OK if all selected channels updated successfully.
Enable DPM on channels 0, 2, and 5:
driver.SetDpmEnabledChannels((1u << 0) | (1u << 2) | (1u << 5));

◆ SetFaultCallback()

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

Register a fault event callback.

The driver calls callback from the calling thread whenever it reads a fault:

The driver does not poll: read FAULT or STATUS (for example when the FAULT pin goes low) to get callbacks. Pass nullptr to stop them.

Parameters
callbackFunction to call for each fault read, or nullptr
user_dataOpaque pointer passed to callback

◆ 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::channel_pair_mode_10, 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, IFS not configured, or the channel is not in CDR (nothing is written)
Note
The current and duty setters never change VDRnCDR: the chip accepts a drive-mode change only while every channel is off and TRIGA/TRIGB are low. Select the mode with ConfigureChannel(), ConfigureChannelCdr() or ConfigureChannelVdr() first. The same applies to SetHoldCurrentMa(), the ...A() and ...CurrentPercent() variants.

◆ 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)

Writes the duty cycle as percent: raw = round(pct) (datasheet Table 3). 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
DriverStatus::INVALID_PARAMETER if channel >= 8 or the channel is not in VDR (nothing is written; the setter does not change VDRnCDR, see SetHitCurrentMa())

◆ 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)

Returns
DriverStatus::INVALID_PARAMETER if the channel is not in CDR (see SetHitCurrentMa())

◆ 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)

Returns
DriverStatus::INVALID_PARAMETER if the channel is not in VDR

◆ SetStateChangeCallback()

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

Register a channel state-change callback (stored for application use)

Parameters
callbackFunction invoked when a channel state transition occurs
user_dataOpaque pointer passed to callback
Note
The driver stores the callback but does not invoke it automatically; the driver does not track HIT/HOLD phase at runtime.

◆ 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 (debug/advanced)

Two-phase SPI write. Writing STATUS does not update cached_status_; prefer WriteStatus() for ONCH and ACTIVE updates.

Parameters
bankRegBank address (0x00–0x0A)
value32-bit value to write (LSB-first on SDI per datasheet)
Returns
DriverStatus::OK on success

◆ 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)

Two-phase SPI with 8-bit mode. Writes only the MSB (e.g. ONCH byte or HOLD[6:0]|HFS for on-the-fly current updates).

Parameters
bankRegBank address (0x00–0x0A)
valueMSB byte to write
Returns
DriverStatus::OK on success

◆ WriteStatus()

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

Write the STATUS register (writable bits only)

Performs a two-phase SPI write. Writable fields include ONCH, fault masks, CMxy, FREQM, and ACTIVE; fault flag bits are read-only and ignored on write. Updates cached_status_ on success.

Parameters
statusSTATUS configuration to encode and write
Returns
DriverStatus::OK on success

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