HF-MAX22200 Driver 0.1.0-dev
HF-MAX22200 C++ Driver
Loading...
Searching...
No Matches
max22200 Namespace Reference

Namespaces

namespace  CfgChReg
 Channel configuration register bit field definitions.
 
namespace  CfgDpmReg
 CFG_DPM register bit field definitions.
 
namespace  CommandReg
 Command Register bit field definitions and helper functions.
 
namespace  FaultReg
 FAULT register bit field definitions.
 
namespace  RegBank
 Register bank addresses for MAX22200.
 
namespace  StatusReg
 STATUS register bit field definitions.
 

Classes

struct  BoardConfig
 Board/scale configuration for unit-based APIs. More...
 
struct  ChannelConfig
 Channel configuration structure. More...
 
struct  DpmConfig
 DPM (Detection of Plunger Movement) algorithm configuration. More...
 
struct  DriverStatistics
 Driver statistics structure. More...
 
struct  DutyLimits
 Duty cycle limits (δMIN, δMAX) for a given configuration. More...
 
struct  FaultStatus
 Per-channel fault information from FAULT register (0x09) More...
 
class  MAX22200
 
class  SpiInterface
 CRTP-based template interface for SPI communication. More...
 
struct  StatusConfig
 STATUS register structure. More...
 

Typedefs

using ChannelConfigArray = std::array<ChannelConfig, NUM_CHANNELS_>
 Array type for channel configurations.
 
using FaultCallback
 Callback function type for fault events.
 
using StateChangeCallback
 Callback function type for channel state changes.
 

Enumerations

enum class  CtrlPin : uint8_t { ENABLE = 0 , FAULT , CMD }
 Identifies the hardware control pins of the MAX22200. More...
 
enum class  GpioSignal : uint8_t { INACTIVE = 0 , ACTIVE = 1 }
 Abstract signal level for control pins. More...
 
enum class  DriveMode : uint8_t { CDR = 0 , VDR = 1 }
 Drive mode enumeration (VDRnCDR bit in CFG_CHx[7]) More...
 
enum class  SideMode : uint8_t { LOW_SIDE = 0 , HIGH_SIDE = 1 }
 High-side / Low-side selection (HSnLS bit in CFG_CHx[6]) More...
 
enum class  ChannelMode : uint8_t { INDEPENDENT = 0 , PARALLEL = 1 , HBRIDGE = 2 }
 Channel-pair mode (CMxy bits in STATUS[15:8]) More...
 
enum class  ChopFreq : uint8_t { FMAIN_DIV4 = 0 , FMAIN_DIV3 = 1 , FMAIN_DIV2 = 2 , FMAIN = 3 }
 Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4]) More...
 
enum class  FaultType : uint8_t {
  OCP = 0 , HHF = 1 , OLF = 2 , DPM = 3 ,
  OVT = 4 , UVM = 5 , COMER = 6
}
 Fault type enumeration. More...
 
enum class  FullBridgeState : uint8_t { HiZ = 0 , Forward = 1 , Reverse = 2 , Brake = 3 }
 Full-bridge state for a channel pair (datasheet Table 7) More...
 
enum class  DriverStatus : uint8_t {
  OK = 0 , INITIALIZATION_ERROR , COMMUNICATION_ERROR , INVALID_PARAMETER ,
  HARDWARE_FAULT , TIMEOUT
}
 Driver status enumeration. More...
 
enum class  ChannelState : uint8_t {
  DISABLED = 0 , ENABLED , HIT_PHASE , HOLD_PHASE ,
  FAULT
}
 Channel state enumeration. More...
 

Functions

const charGetDriverVersion () noexcept
 
constexpr uint8_t getChannelCfgBank (uint8_t channel)
 
uint32_t getChopFreqKhz (bool master_clock_80khz, ChopFreq cf)
 Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)
 
uint8_t currentMaToRaw (uint32_t full_scale_current_ma, uint32_t ma)
 Convert current in mA to 7-bit raw value (0–127) for CDR.
 
uint8_t hitTimeMsToRaw (float ms, bool master_clock_80khz, ChopFreq cf)
 Convert HIT time in ms to 8-bit raw value (0–255)
 
float getMaxHitTimeMs (bool master_clock_80khz, ChopFreq cf)
 Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).
 
const charFaultTypeToStr (FaultType ft)
 Human-readable fault type name (for logging and tests)
 
const charDriverStatusToStr (DriverStatus s)
 Return a human-readable string for DriverStatus (for logging and tests)
 

Variables

constexpr uint8_t NUM_CHANNELS_ = 8
 Number of channels on the MAX22200.
 
constexpr uint32_t MAX_SPI_FREQ_STANDALONE_ = 10000000
 Maximum SPI clock frequency without daisy chaining (Hz)
 
constexpr uint32_t MAX_SPI_FREQ_DAISY_CHAIN_ = 5000000
 Maximum SPI clock frequency with daisy chaining (Hz)
 

Typedef Documentation

◆ ChannelConfigArray

◆ FaultCallback

Initial value:
void (*)(uint8_t channel, FaultType fault_type,
void *user_data)
FaultType
Fault type enumeration.
Definition max22200_types.hpp:280

Callback function type for fault events.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ StateChangeCallback

Initial value:
void (*)(uint8_t channel, ChannelState old_state,
ChannelState new_state, void *user_data)
ChannelState
Channel state enumeration.
Definition max22200_types.hpp:959

Callback function type for channel state changes.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

Enumeration Type Documentation

◆ ChannelMode

Channel-pair mode (CMxy bits in STATUS[15:8])

Configures pairs of contiguous channels (0-1, 2-3, 4-5, 6-7) for different operating modes. These bits can only be written when both channels in the pair are OFF (ONCHx = 0, ONCHy = 0).

INDEPENDENT (CMxy = 00)

  • Each channel operates independently
  • Standard half-bridge operation
  • Each channel uses its own configuration register (CFG_CHx)

PARALLEL (CMxy = 01)

  • Two channels connected in parallel to double current capability
  • Output pins must be connected together externally
  • Configuration taken from lower channel number (e.g., CFG_CH0 for pair 0-1)
  • Higher channel's configuration register is ignored
  • Activation remains independent (ONCHx and ONCHy control individually)
  • TRGnSPI bits determine trigger source (see datasheet Table 6)

HBRIDGE (CMxy = 10)

  • Two channels form a full-bridge (H-bridge) for bidirectional drive
  • Used for latched (bi-stable) solenoid valves or brushed DC motors
  • Four states: Hi-Z, Forward, Reverse, Brake (see datasheet Table 7)
  • Forward mode uses CFG_CHy settings, Reverse mode uses CFG_CHx settings
  • HSnLS bit is ignored in full-bridge mode
  • TRGnSPI bits determine trigger source (see datasheet Table 8)
Note
Channel pairs: CM10 (ch0-1), CM32 (ch2-3), CM54 (ch4-5), CM76 (ch6-7)
CMxy = 11 is reserved — do not use
Enumerator
INDEPENDENT 

Channels independently controlled (CMxy = 00)

PARALLEL 

Channels in parallel mode (CMxy = 01) — double current.

HBRIDGE 

Channels in H-bridge mode (CMxy = 10) — bidirectional drive.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_registers.hpp, and /home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ ChannelState

Channel state enumeration.

Enumerator
DISABLED 
ENABLED 
HIT_PHASE 
HOLD_PHASE 
FAULT 
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ ChopFreq

Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4])

Selects the chopping frequency divider relative to the master frequency (FREQM). The actual chopping frequency fCHOP depends on both FREQM (STATUS[16]) and FREQ_CFG:

FREQM FREQ_CFG fCHOP (kHz) Period (μs)
0 00 25 40
0 01 33.33 30
0 10 50 20
0 11 100 10
1 00 20 50
1 01 26.66 37.5
1 10 40 25
1 11 80 12.5

Effects of Chopping Frequency

  • Higher frequency: Lower current ripple, better average current control, but higher switching losses and EMI
  • Lower frequency: Higher current ripple, but lower switching losses

Duty Cycle Limits

Minimum and maximum duty cycles (δMIN, δMAX) depend on FREQM, FREQ_CFG, and SRC:

  • SRC = 0 (Fast Mode):
    • FREQ_CFG = 11: δMIN = 8%, δMAX = 92%
    • Other FREQ_CFG: δMIN = 4%, δMAX = 96%
  • SRC = 1 (Slew-Rate Controlled):
    • FREQ_CFG = 01 or 00: δMIN = 7%, δMAX = 93%
    • FREQ_CFG = 10 (FREQM=1 only): δMIN = 7%, δMAX = 93%

SRC + fCHOP restriction (datasheet)

SRC mode is only available for switching frequencies less than 50 kHz. When SRC = 1, use only FREQ_CFG that yields fCHOP < 50 kHz:

  • FREQM = 0: use FMAIN_DIV4 (25 kHz) or FMAIN_DIV3 (33.33 kHz); do not use FMAIN_DIV2 (50 kHz) or FMAIN (100 kHz).
  • FREQM = 1: use FMAIN_DIV4 (20 kHz), FMAIN_DIV3 (26.66 kHz), or FMAIN_DIV2 (40 kHz); do not use FMAIN (80 kHz).
Note
FREQ_CFG can be changed "on-the-fly" while channel is operating.
FREQM is a global setting in STATUS register (affects all channels).
Enumerator
FMAIN_DIV4 

FreqMain / 4 (fCHOP = 25kHz if FREQM=0, 20kHz if FREQM=1). Valid with SRC=1.

FMAIN_DIV3 

FreqMain / 3 (fCHOP = 33.33kHz if FREQM=0, 26.66kHz if FREQM=1). Valid with SRC=1.

FMAIN_DIV2 

FreqMain / 2 (fCHOP = 50kHz if FREQM=0, 40kHz if FREQM=1). With SRC=1 use only if FREQM=1 (40kHz).

FMAIN 

FreqMain (fCHOP = 100kHz if FREQM=0, 80kHz if FREQM=1). Not valid with SRC=1.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ CtrlPin

Identifies the hardware control pins of the MAX22200.

Used with GpioSet() / GpioRead() / GpioSetActive() / GpioSetInactive() to control the IC's dedicated GPIO pins through the SpiInterface.

The mapping from GpioSignal::ACTIVE / INACTIVE to physical HIGH / LOW is determined by the platform bus implementation, based on the board's active-level design:

  • ENABLE: Active-high (ACTIVE → physical HIGH, enables driver outputs)
  • FAULT: Active-low (ACTIVE → physical LOW, fault condition present)
  • CMD: Active-high (ACTIVE → physical HIGH, SPI register mode)
Enumerator
ENABLE 

Output enable (active-high on the physical pin)

FAULT 

Fault status output (active-low, open-drain)

CMD 

Command mode select (HIGH = SPI register, LOW = direct drive)

◆ DriveMode

Drive mode enumeration (VDRnCDR bit in CFG_CHx[7])

Determines how the channel regulates output current/voltage.

CDR (Current Drive Regulation)

  • Uses integrated lossless current sensing (ICS)
  • Regulates peak current cycle-by-cycle
  • More efficient than VDR (no design margin needed)
  • Only supported in low-side mode (HSnLS = 0)
  • Current accuracy: ±6% for 71-100% of IFS, ±10% for 20-70%, ±15% for 10-20%, ±25% for 5-10%

VDR (Voltage Drive Regulation)

  • Outputs PWM voltage with programmable duty cycle
  • Duty cycle resolution: 1% steps
  • Supported in both low-side and high-side modes
  • Output current proportional to duty cycle for given supply voltage and load resistance
Note
VDRnCDR bit can only be changed when all channels are OFF and both TRIGA and TRIGB inputs are logic-low.
Enumerator
CDR 

Current Drive Regulation (VDRnCDR = 0) — low-side only.

VDR 

Voltage Drive Regulation (VDRnCDR = 1) — low-side or high-side.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_registers.hpp, and /home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ DriverStatus

Driver status enumeration.

Enumerator
OK 

Operation successful.

INITIALIZATION_ERROR 

Initialization failed.

COMMUNICATION_ERROR 

SPI communication error.

INVALID_PARAMETER 

Invalid parameter provided.

HARDWARE_FAULT 

Hardware fault detected.

TIMEOUT 

Operation timeout.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ FaultType

Fault type enumeration.

Enumerator
OCP 

Overcurrent protection (OCP)

HHF 

HIT current not reached (HHF)

OLF 

Open-load detection (OLF)

DPM 

Detection of plunger movement (DPM)

OVT 

Overtemperature (OVT, from STATUS)

UVM 

Undervoltage lockout (UVM, from STATUS)

COMER 

Communication error (COMER, from STATUS)

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ FullBridgeState

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

For a pair (x, y) = (0,1), (2,3), (4,5), or (6,7): ONCHy and ONCHx determine the bridge state. Forward uses CFG_CHy; Reverse uses CFG_CHx.

Enumerator
HiZ 

ONCHx=0, ONCHy=0 — high impedance.

Forward 

ONCHx=1, ONCHy=0 — forward (control from CFG_CHy)

Reverse 

ONCHx=0, ONCHy=1 — reverse (control from CFG_CHx)

Brake 

ONCHx=1, ONCHy=1 — brake (both outputs to GND)

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ GpioSignal

Abstract signal level for control pins.

Decouples the driver's intent from the physical pin polarity. The platform bus implementation translates ACTIVE / INACTIVE to the correct electrical level for each pin.

Enumerator
INACTIVE 

Pin function is deasserted.

ACTIVE 

Pin function is asserted.

◆ SideMode

High-side / Low-side selection (HSnLS bit in CFG_CHx[6])

Determines whether the channel drives the load connected to the positive rail (low-side) or to ground (high-side).

Low-Side Mode (HSnLS = 0)

  • Load connected between OUTx and VM (positive rail)
  • Supports both CDR and VDR modes
  • Supports HFS (half full-scale) bit for improved accuracy at low currents
  • Supports SRC (slew rate control) and DPM (plunger movement detection)

High-Side Mode (HSnLS = 1)

  • Load connected between OUTx and GND
  • Only supports VDR mode (CDR not available)
  • HFS, SRC, and DPM functions are not supported in high-side mode
Note
HSnLS bit can only be changed when all channels are OFF and both TRIGA and TRIGB inputs are logic-low.
Enumerator
LOW_SIDE 

Low-side driver (HSnLS = 0) — supports CDR and VDR.

HIGH_SIDE 

High-side driver (HSnLS = 1) — VDR only, no CDR/HFS/SRC/DPM.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

Function Documentation

◆ currentMaToRaw()

uint8_t max22200::currentMaToRaw ( uint32_t full_scale_current_ma,
uint32_t ma )
inline

Convert current in mA to 7-bit raw value (0–127) for CDR.

Parameters
full_scale_current_maFull-scale current in mA (must be > 0)
maDesired current in mA
Returns
Raw 7-bit value; clamped to 127 if ma >= full_scale_current_ma
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ DriverStatusToStr()

const char * max22200::DriverStatusToStr ( DriverStatus s)
inline

Return a human-readable string for DriverStatus (for logging and tests)

Parameters
sStatus value
Returns
Non-null C string
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ FaultTypeToStr()

const char * max22200::FaultTypeToStr ( FaultType ft)
inline

Human-readable fault type name (for logging and tests)

Parameters
ftFaultType value
Returns
Non-null C string (e.g. "Overcurrent", "HIT not reached")
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ getChannelCfgBank()

◆ getChopFreqKhz()

uint32_t max22200::getChopFreqKhz ( bool master_clock_80khz,
ChopFreq cf )
inline

Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)

Parameters
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChannel ChopFreq (FREQ_CFG)
Returns
fCHOP in kHz (e.g. 25, 33, 50, 100 for 100 kHz base)
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ GetDriverVersion()

const char * max22200::GetDriverVersion ( )
inlinenoexcept

◆ getMaxHitTimeMs()

float max22200::getMaxHitTimeMs ( bool master_clock_80khz,
ChopFreq cf )
inline

Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).

Parameters
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChopping frequency (FREQ_CFG)
Returns
Max finite hit time in ms; values above this map to raw 255 (continuous)
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

◆ hitTimeMsToRaw()

uint8_t max22200::hitTimeMsToRaw ( float ms,
bool master_clock_80khz,
ChopFreq cf )
inline

Convert HIT time in ms to 8-bit raw value (0–255)

Parameters
msHIT time in ms (0 = no HIT; < 0 or very large = continuous, 255)
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChopping frequency (FREQ_CFG)
Returns
Raw 8-bit HIT_T; 255 = continuous
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_types.hpp.

Variable Documentation

◆ MAX_SPI_FREQ_DAISY_CHAIN_

constexpr uint32_t max22200::MAX_SPI_FREQ_DAISY_CHAIN_ = 5000000
constexpr

Maximum SPI clock frequency with daisy chaining (Hz)

When multiple MAX22200 devices are connected in a daisy chain, the maximum SPI clock frequency is reduced to 5 MHz.

Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_registers.hpp.

◆ MAX_SPI_FREQ_STANDALONE_

constexpr uint32_t max22200::MAX_SPI_FREQ_STANDALONE_ = 10000000
constexpr

Maximum SPI clock frequency without daisy chaining (Hz)

Per datasheet: "The SPI supports daisy-chain configurations and can operate up to 5MHz" (with daisy chain), and "10MHz without Daisy Chain" (standalone).

Note
Use MAX_SPI_FREQ_DAISY_CHAIN_ when multiple devices are daisy-chained.
Examples
/home/runner/work/hf-max22200-driver/hf-max22200-driver/inc/max22200_registers.hpp.

◆ NUM_CHANNELS_