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

Portable C++20 driver for the MAX22200 octal solenoid and motor driver with SPI interface

C++ License CI Docs

📚 Table of Contents

  1. Overview
  2. Features
  3. Quick Start
  4. Installation
  5. API Reference
  6. Examples
  7. Documentation
  8. References
  9. Contributing
  10. License

📦 Overview

📖 📚🌐 Live Complete Documentation - Interactive guides, examples, and step-by-step tutorials

HF-MAX22200 is a portable C++20 driver for the MAX22200 octal (eight-channel) solenoid and motor driver IC. The MAX22200 features eight half-bridges, each capable of handling up to 36V and 1A RMS, with integrated current sensing, current/voltage regulation, and comprehensive protection features.

The driver uses a CRTP-based SpiInterface for hardware abstraction, allowing it to run on any platform (ESP32, STM32, Arduino, etc.) with zero runtime overhead. It implements all major features from the MAX22200 datasheet including channel configuration, current/voltage regulation modes, integrated current sensing (ICS), fault detection, and callback support for event-driven programming.

MAX22200 octal half-bridge topology with HIT/HOLD current profile

✨ Features

  • Eight Half-Bridges: Each channel handles up to 36V and 1A RMS
  • Current and Voltage Regulation: Supports both CDR (Current Drive Regulation) and VDR (Voltage Drive Regulation) modes
  • Integrated Current Sensing (ICS): Real-time current monitoring without external sense resistors
  • Half-Bridge and Full-Bridge Modes: Flexible bridge configurations
  • HIT/HOLD Current Control: Programmable hit current, hold current, and hit time
  • Comprehensive Protection: OCP, OL, DPM, UVLO, TSD, and fault registers
  • Hardware Agnostic: SPI interface for platform independence
  • Modern C++: C++20 with CRTP-based design
  • Zero Overhead: CRTP-based design for compile-time polymorphism
  • Callback Support: Event-driven programming with fault and state callbacks
  • Statistics Tracking: Runtime performance and error monitoring

🚀 Quick Start

#include "max22200.hpp"
// 1. Implement the SPI interface (see platform_integration.md)
class MySpi : public max22200::SpiInterface<MySpi> {
public:
void transfer(const uint8_t* tx, uint8_t* rx, size_t len) {
// Your SPI transfer implementation
}
};
// 2. Create driver instance
MySpi spi;
max22200::MAX22200 driver(spi);
// 3. Set board config (IFS from RREF; required for CDR)
driver.SetBoardConfig(max22200::BoardConfig(30.0f, false));
// 4. Initialize
if (driver.Initialize() == max22200::DriverStatus::OK) {
// 5. Configure channel 0 (CDR, low-side)
config.hit_setpoint = 500.0f; // desired current, mA
config.hold_setpoint = 200.0f;
config.hit_time_ms = 10.0f;
driver.ConfigureChannel(0, config);
driver.EnableChannel(0);
}
Definition max22200.hpp:133
CRTP-based template interface for SPI communication.
Definition max22200_spi_interface.hpp:114
Main driver class for MAX22200 octal solenoid and motor driver.
@ CDR
Current Drive Regulation (VDRnCDR = 0) — low-side only.
@ LOW_SIDE
Low-side driver (HSnLS = 0) — supports CDR and VDR.
@ OK
Operation successful.
@ 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:1010
Channel configuration structure.
Definition max22200_types.hpp:360
float hold_setpoint
HOLD setpoint: CDR = mA, VDR = duty % (0–100)
Definition max22200_types.hpp:365
float hit_time_ms
Definition max22200_types.hpp:366
SideMode side_mode
Side mode: LOW_SIDE (CDR/VDR) or HIGH_SIDE (VDR only)
Definition max22200_types.hpp:376
DriveMode drive_mode
Drive mode: CDR (current) or VDR (voltage)
Definition max22200_types.hpp:375
float hit_setpoint
HIT setpoint: CDR = mA, VDR = duty % (0–100)
Definition max22200_types.hpp:364
ChopFreq chop_freq
Chopping frequency divider (FREQ_CFG[1:0])
Definition max22200_types.hpp:377

For detailed setup, see Installation and Quick Start Guide.

🔧 Installation

  1. Clone or copy the driver files into your project
  2. Implement the SPI interface for your platform (see Platform Integration)
  3. Include the header in your code:
    #include "max22200.hpp"
  4. Compile with a C++20 or newer compiler

For detailed installation instructions, see docs/installation.md.

📖 API Reference

Method Description
Initialize() / Deinitialize() Initialize or shut down (ENABLE, STATUS ACTIVE)
ConfigureChannel() Configure a channel (CFG_CHx)
EnableChannel() / DisableChannel() Turn a channel on or off
EnableAllChannels() / DisableAllChannels() Turn all channels on or off
SetChannelsOn(mask) Set which channels are on (bitmask)
ReadStatus() / WriteStatus() Read/write STATUS (ONCH, fault masks, ACTIVE)
ReadFaultRegister() / ClearAllFaults() Read or clear per-channel faults (OCP, HHF, OLF, DPM)
SetBoardConfig() Set IFS and limits for mA/% APIs
SetHitCurrentMa() / GetHitCurrentMa() Set/get current in mA (CDR)
ConfigureDpm() Configure plunger movement detection in mA/ms
EnableDevice() / DisableDevice() ENABLE pin on/off
SetFaultCallback() Fault event callback; use FaultTypeToStr() for names
GetStatistics() Driver statistics

For complete API documentation, see docs/api_reference.md.

📊 Examples

For ESP32 examples, see the examples/esp32 directory. Additional examples for other platforms are available in the examples directory.

Detailed example walkthroughs are available in docs/examples.md.

📚 Documentation

For complete documentation, see the docs directory.

🔗 References

Resource Link
ADI/Maxim MAX22200 product page https://www.analog.com/en/products/max22200.html
MAX22200 datasheet (ADI) https://www.analog.com/media/en/technical-documentation/data-sheets/max22200.pdf
ESP-IDF SPI master https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/spi_master.html
C++20 language reference https://en.cppreference.com/w/cpp/20

🤝 Contributing

Pull requests and suggestions are welcome! Please follow the existing code style and include tests for new features.

📄 License

This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details.