HF-MAX22200 Driver 0.1.0-dev
HF-MAX22200 C++ Driver
Loading...
Searching...
No Matches
max22200_types.hpp
Go to the documentation of this file.
1
66#pragma once
68#include <array>
69#include <cstdint>
70
71namespace max22200 {
72
73// ============================================================================
74// Enumerations
75// ============================================================================
76
98enum class DriveMode : uint8_t {
99 CDR = 0,
100 VDR = 1
101};
102
123enum class SideMode : uint8_t {
124 LOW_SIDE = 0,
125 HIGH_SIDE = 1
126};
127
159enum class ChannelMode : uint8_t {
160 INDEPENDENT = 0,
161 PARALLEL = 1,
162 HBRIDGE = 2
163};
164
211enum class ChopFreq : uint8_t {
212 FMAIN_DIV4 = 0,
213 FMAIN_DIV3 = 1,
214 FMAIN_DIV2 = 2,
215 FMAIN = 3
216};
217
224inline uint32_t getChopFreqKhz(bool master_clock_80khz, ChopFreq cf) {
225 switch (cf) {
226 case ChopFreq::FMAIN_DIV4: return master_clock_80khz ? 20u : 25u;
227 case ChopFreq::FMAIN_DIV3: return master_clock_80khz ? 26u : 33u;
228 case ChopFreq::FMAIN_DIV2: return master_clock_80khz ? 40u : 50u;
229 case ChopFreq::FMAIN: return master_clock_80khz ? 80u : 100u;
230 default: return 25u;
231 }
232}
233
240inline uint8_t currentMaToRaw(uint32_t full_scale_current_ma, uint32_t ma) {
241 if (full_scale_current_ma == 0) return 0;
242 if (ma >= full_scale_current_ma) return 127;
243 uint32_t raw = (ma * 127u + full_scale_current_ma / 2u) / full_scale_current_ma;
244 return raw > 127u ? 127u : static_cast<uint8_t>(raw);
245}
246
254inline uint8_t hitTimeMsToRaw(float ms, bool master_clock_80khz, ChopFreq cf) {
255 uint32_t fchop_khz = getChopFreqKhz(master_clock_80khz, cf);
256 if (ms < 0.0f || ms >= 1000000.0f) return 255;
257 if (ms == 0.0f) return 0;
258 float fchop_hz = static_cast<float>(fchop_khz) * 1000.0f;
259 uint32_t raw = static_cast<uint32_t>((ms / 1000.0f) * fchop_hz / 40.0f + 0.5f);
260 if (raw > 254u) return 255;
261 if (raw == 0u) return 1;
262 return static_cast<uint8_t>(raw);
263}
264
271inline float getMaxHitTimeMs(bool master_clock_80khz, ChopFreq cf) {
272 const uint32_t fchop_khz = getChopFreqKhz(master_clock_80khz, cf);
273 const float fchop_hz = static_cast<float>(fchop_khz) * 1000.0f;
274 return (254.0f * 40.0f / fchop_hz) * 1000.0f;
275}
276
280enum class FaultType : uint8_t {
281 OCP = 0,
282 HHF = 1,
283 OLF = 2,
284 DPM = 3,
285 OVT = 4,
286 UVM = 5,
287 COMER = 6
288};
289
295inline const char *FaultTypeToStr(FaultType ft) {
296 switch (ft) {
297 case FaultType::OCP: return "Overcurrent";
298 case FaultType::HHF: return "HIT not reached";
299 case FaultType::OLF: return "Open-load";
300 case FaultType::DPM: return "Plunger movement";
301 case FaultType::OVT: return "Overtemperature";
302 case FaultType::UVM: return "Undervoltage";
303 case FaultType::COMER: return "Communication error";
304 default: return "Unknown fault";
305 }
306}
307
308// ============================================================================
309// Structures
310// ============================================================================
311
361 // ── User Units (Primary Storage) ──────────────────────────────────────────
362 // CDR: setpoint in mA. VDR: setpoint in duty % (0–100). Use accessors for intent-revealing names.
363
369
370 // ── Register Fields (Direct Mapping) ─────────────────────────────────────
382
393
402 c.drive_mode = DriveMode::CDR;
403 c.side_mode = SideMode::LOW_SIDE;
404 c.hit_setpoint = hit_ma;
405 c.hold_setpoint = hold_ma;
406 c.hit_time_ms = hit_time_ms;
407 c.chop_freq = ChopFreq::FMAIN_DIV4;
408 return c;
409 }
410
419 c.drive_mode = DriveMode::VDR;
420 c.side_mode = SideMode::LOW_SIDE;
421 c.hit_setpoint = hit_pct;
422 c.hold_setpoint = hold_pct;
423 c.hit_time_ms = hit_time_ms;
424 c.chop_freq = ChopFreq::FMAIN_DIV4;
425 return c;
426 }
427
428 // ── Mode-aware accessors (same storage; use for clear intent at call site) ─
429 void set_hit_ma(float ma) { hit_setpoint = ma; }
430 void set_hold_ma(float ma) { hold_setpoint = ma; }
433 float hit_ma() const { return hit_setpoint; }
434 float hold_ma() const { return hold_setpoint; }
435 float hit_duty_percent() const { return hit_setpoint; }
436 float hold_duty_percent() const { return hold_setpoint; }
437
447 uint32_t toRegister(uint32_t board_ifs_ma = 0, bool master_clock_80khz = false) const {
448 // Effective IFS for CDR: HFS=1 halves the scale (datasheet KFS 7.5k vs 15k)
450 ? (board_ifs_ma / 2u)
451 : board_ifs_ma;
452
453 // Convert hit_setpoint to raw 7-bit
455 if (drive_mode == DriveMode::CDR) {
456 // CDR: hit_setpoint is in mA (relative to effective IFS for this channel)
457 if (ifs_ma == 0) {
458 hit_raw = 0; // Invalid IFS
459 } else if (hit_setpoint >= static_cast<float>(ifs_ma)) {
460 hit_raw = 127;
461 } else {
462 uint32_t ma = static_cast<uint32_t>(hit_setpoint + 0.5f);
464 }
465 } else {
466 // VDR: hit_setpoint is duty percent (0-100)
467 if (hit_setpoint <= 0.0f) {
468 hit_raw = 0;
469 } else if (hit_setpoint >= 100.0f) {
470 hit_raw = 127;
471 } else {
472 uint32_t r = static_cast<uint32_t>((hit_setpoint / 100.0f) * 127.0f + 0.5f);
473 hit_raw = (r > 127u) ? 127u : static_cast<uint8_t>(r);
474 }
475 }
476
477 // Convert hold_setpoint to raw 7-bit
479 if (drive_mode == DriveMode::CDR) {
480 // CDR: hold_setpoint is in mA
481 if (ifs_ma == 0) {
482 hold_raw = 0;
483 } else if (hold_setpoint >= static_cast<float>(ifs_ma)) {
484 hold_raw = 127;
485 } else {
486 uint32_t ma = static_cast<uint32_t>(hold_setpoint + 0.5f);
488 }
489 } else {
490 // VDR: hold_setpoint is duty percent (0-100)
491 if (hold_setpoint <= 0.0f) {
492 hold_raw = 0;
493 } else if (hold_setpoint >= 100.0f) {
494 hold_raw = 127;
495 } else {
496 uint32_t r = static_cast<uint32_t>((hold_setpoint / 100.0f) * 127.0f + 0.5f);
497 hold_raw = (r > 127u) ? 127u : static_cast<uint8_t>(r);
498 }
499 }
500
501 // Convert hit_time_ms to raw 8-bit (master_clock_80khz from parameter, not stored on config)
503
504 // Build register value
505 uint32_t val = 0;
507 val |= (static_cast<uint32_t>(hold_raw & 0x7F) << CfgChReg::HOLD_SHIFT);
509 val |= (static_cast<uint32_t>(hit_raw & 0x7F) << CfgChReg::HIT_SHIFT);
510 val |= (static_cast<uint32_t>(hit_time_raw) << CfgChReg::HITT_SHIFT);
513 val |= (static_cast<uint32_t>(chop_freq) << CfgChReg::FREQ_CFG_SHIFT);
518 return val;
519 }
520
531 // Parse register fields
533 uint8_t hold_raw = static_cast<uint8_t>((val >> CfgChReg::HOLD_SHIFT) & 0x7F);
535 uint8_t hit_raw = static_cast<uint8_t>((val >> CfgChReg::HIT_SHIFT) & 0x7F);
536 uint8_t hit_time_raw = static_cast<uint8_t>((val >> CfgChReg::HITT_SHIFT) & 0xFF);
539 chop_freq = static_cast<ChopFreq>((val >> CfgChReg::FREQ_CFG_SHIFT) & 0x03);
544
545 // Convert raw → user units (master_clock_80khz_param used for hit_time only; not stored on config)
546 if (drive_mode == DriveMode::CDR) {
547 // CDR: raw → mA (use effective IFS when HFS=1)
549 ? (board_ifs_ma / 2u)
550 : board_ifs_ma;
551 if (effective_ifs > 0) {
552 hit_setpoint = (static_cast<float>(hit_raw) / 127.0f) * static_cast<float>(effective_ifs);
553 hold_setpoint = (static_cast<float>(hold_raw) / 127.0f) * static_cast<float>(effective_ifs);
554 } else {
555 hit_setpoint = 0.0f;
556 hold_setpoint = 0.0f;
557 }
558 } else {
559 // VDR: raw → duty percent
560 hit_setpoint = (static_cast<float>(hit_raw) / 127.0f) * 100.0f;
561 hold_setpoint = (static_cast<float>(hold_raw) / 127.0f) * 100.0f;
562 }
563
564 // Convert hit_time raw → ms
565 if (hit_time_raw == 0) {
566 hit_time_ms = 0.0f;
567 } else if (hit_time_raw == 255) {
568 hit_time_ms = -1.0f; // Continuous (infinite)
569 } else {
571 float fchop_hz = static_cast<float>(fchop_khz) * 1000.0f;
572 hit_time_ms = (static_cast<float>(hit_time_raw) * 40.0f / fchop_hz) * 1000.0f;
573 }
574 }
575
576 // ── Inline probe helpers (human-readable, compiler can optimize away) ─────
577
578 bool isCdr() const { return drive_mode == DriveMode::CDR; }
579 bool isVdr() const { return drive_mode == DriveMode::VDR; }
580 bool isLowSide() const { return side_mode == SideMode::LOW_SIDE; }
581 bool isHighSide() const { return side_mode == SideMode::HIGH_SIDE; }
582 bool hasHitTime() const { return hit_time_ms > 0.0f; }
583 bool isContinuousHit() const { return hit_time_ms < 0.0f || hit_time_ms >= 1000000.0f; }
584 bool isTriggeredBySpi() const { return !trigger_from_pin; }
585 bool isTriggeredByPin() const { return trigger_from_pin; }
586 bool isHalfFullScale() const { return half_full_scale; }
592 ChopFreq getChopFreq() const { return chop_freq; }
593};
594
635 // Byte 3 (bits 31:24)
639
640 // Byte 2 (bits 23:16) — fault masks (1=masked, 0=signaled on FAULT pin)
649
650 // Byte 1 (bits 15:8) — channel-pair mode
655
656 // Byte 0 (bits 7:0) — fault flags (read-only) + ACTIVE
657 bool active;
658
659 // Read-only fault flags (populated on read, cleared by reading STATUS or FAULT register)
667
681
703
730
738
739 // ── Inline probe helpers ─────────────────────────────────────────────────
740
741 bool hasOvertemperature() const { return overtemperature; }
742 bool hasOvercurrent() const { return overcurrent; }
743 bool hasOpenLoadFault() const { return open_load_fault; }
744 bool hasHitNotReached() const { return hit_not_reached; }
747 bool hasUndervoltage() const { return undervoltage; }
748 bool isActive() const { return active; }
749 bool isChannelOn(uint8_t ch) const {
750 return ch < 8u && (channels_on_mask & (1u << ch)) != 0u;
751 }
753 uint8_t n = 0;
754 for (uint8_t i = 0; i < 8; i++) {
755 if (channels_on_mask & (1u << i)) n++;
756 }
757 return n;
758 }
759
767
768 bool is80KHzBase() const { return master_clock_80khz; }
769 bool is100KHzBase() const { return !master_clock_80khz; }
770
776};
777
810
813
820
828
833 uint8_t count = 0;
834 for (uint8_t i = 0; i < 8; i++) {
835 if (overcurrent_channel_mask & (1u << i)) count++;
836 if (hit_not_reached_channel_mask & (1u << i)) count++;
837 if (open_load_fault_channel_mask & (1u << i)) count++;
839 }
840 return count;
841 }
842
843 // ── Inline probe helpers (human-readable, compiler can optimize away) ─────
844
845 bool hasOvercurrent() const { return overcurrent_channel_mask != 0; }
846 bool hasHitNotReached() const { return hit_not_reached_channel_mask != 0; }
847 bool hasOpenLoadFault() const { return open_load_fault_channel_mask != 0; }
854 return ch < NUM_CHANNELS_ && (overcurrent_channel_mask & (1u << ch)) != 0u;
855 }
857 return ch < NUM_CHANNELS_ && (hit_not_reached_channel_mask & (1u << ch)) != 0u;
858 }
860 return ch < NUM_CHANNELS_ && (open_load_fault_channel_mask & (1u << ch)) != 0u;
861 }
869};
870
906
914 HiZ = 0,
915 Forward = 1,
916 Reverse = 2,
917 Brake = 3
918};
919
931
937inline const char *DriverStatusToStr(DriverStatus s) {
938 switch (s) {
939 case DriverStatus::OK:
940 return "OK";
942 return "INITIALIZATION_ERROR";
944 return "COMMUNICATION_ERROR";
946 return "INVALID_PARAMETER";
948 return "HARDWARE_FAULT";
950 return "TIMEOUT";
951 default:
952 return "UNKNOWN";
953 }
954}
955
959enum class ChannelState : uint8_t {
960 DISABLED = 0,
961 ENABLED,
962 HIT_PHASE,
964 FAULT
965};
966
970using ChannelConfigArray = std::array<ChannelConfig, NUM_CHANNELS_>;
971
976 void *user_data);
977
983
1050
1060
1062
1068 bool inRange(float percent) const {
1069 return percent >= static_cast<float>(min_percent) && percent <= static_cast<float>(max_percent);
1070 }
1072 float clamp(float percent) const {
1073 if (percent <= static_cast<float>(min_percent)) return static_cast<float>(min_percent);
1074 if (percent >= static_cast<float>(max_percent)) return static_cast<float>(max_percent);
1075 return percent;
1076 }
1077};
1078
1106
1107} // namespace max22200
Definition max22200.hpp:133
Register definitions and constants for MAX22200 IC.
constexpr uint32_t DPM_EN_BIT
DPM_EN bit (0=disabled, 1=enabled)
Definition max22200_registers.hpp:393
constexpr uint32_t HITT_SHIFT
HIT time bit shift.
Definition max22200_registers.hpp:373
constexpr uint32_t HOLD_SHIFT
HOLD current bit shift.
Definition max22200_registers.hpp:362
constexpr uint32_t OL_EN_BIT
OL_EN bit (0=disabled, 1=enabled)
Definition max22200_registers.hpp:390
constexpr uint32_t SRC_BIT
SRC bit (0=fast, 1=slew-rate controlled)
Definition max22200_registers.hpp:387
constexpr uint32_t FREQ_CFG_SHIFT
FREQ_CFG bit shift.
Definition max22200_registers.hpp:383
constexpr uint32_t HIT_SHIFT
HIT current bit shift.
Definition max22200_registers.hpp:369
constexpr uint32_t VDRNCDR_BIT
VDRnCDR bit (0=CDR, 1=VDR)
Definition max22200_registers.hpp:377
constexpr uint32_t TRGNSPI_BIT
TRGnSPI bit (0=SPI ONCH, 1=TRIG pin)
Definition max22200_registers.hpp:366
constexpr uint32_t HHF_EN_BIT
HHF_EN bit (0=disabled, 1=enabled)
Definition max22200_registers.hpp:396
constexpr uint32_t HFS_BIT
HFS bit (0=1x full-scale, 1=0.5x half-scale)
Definition max22200_registers.hpp:359
constexpr uint32_t HSNLS_BIT
HSnLS bit (0=low-side, 1=high-side)
Definition max22200_registers.hpp:380
constexpr uint32_t DPM_TDEB_SHIFT
DPM_TDEB bit shift (bits 7:4)
Definition max22200_registers.hpp:511
constexpr uint32_t DPM_ISTART_SHIFT
DPM_ISTART bit shift (bits 14:8)
Definition max22200_registers.hpp:509
constexpr uint32_t DPM_IPTH_SHIFT
DPM_IPTH bit shift (bits 3:0)
Definition max22200_registers.hpp:513
constexpr uint32_t OCP_SHIFT
OCP bit shift (bits 31:24)
Definition max22200_registers.hpp:440
constexpr uint32_t DPM_SHIFT
DPM bit shift (bits 7:0)
Definition max22200_registers.hpp:446
constexpr uint32_t OLF_SHIFT
OLF bit shift (bits 15:8)
Definition max22200_registers.hpp:444
constexpr uint32_t HHF_SHIFT
HHF bit shift (bits 23:16)
Definition max22200_registers.hpp:442
constexpr uint32_t M_UVM_BIT
UVM fault mask.
Definition max22200_registers.hpp:230
constexpr uint32_t OVT_BIT
Overtemperature fault flag (read-only)
Definition max22200_registers.hpp:244
constexpr uint32_t M_OVT_BIT
OVT fault mask (1=masked, 0=signaled)
Definition max22200_registers.hpp:224
constexpr uint32_t CM32_SHIFT
CM32 bit shift (bits 11:10)
Definition max22200_registers.hpp:238
constexpr uint32_t M_DPM_BIT
DPM fault mask.
Definition max22200_registers.hpp:228
constexpr uint32_t CM54_SHIFT
CM54 bit shift (bits 13:12)
Definition max22200_registers.hpp:236
constexpr uint32_t HHF_BIT
HIT current not reached flag (read-only)
Definition max22200_registers.hpp:247
constexpr uint32_t M_HHF_BIT
HHF fault mask.
Definition max22200_registers.hpp:227
constexpr uint32_t OCP_BIT
Overcurrent fault flag (read-only)
Definition max22200_registers.hpp:245
constexpr uint32_t M_COMF_BIT
Communication fault mask (reset value = 1, masked by default)
Definition max22200_registers.hpp:229
constexpr uint32_t OLF_BIT
Open-load fault flag (read-only)
Definition max22200_registers.hpp:246
constexpr uint32_t CM76_SHIFT
CM76 bit shift (bits 15:14)
Definition max22200_registers.hpp:234
constexpr uint32_t M_OCP_BIT
OCP fault mask.
Definition max22200_registers.hpp:225
constexpr uint32_t ACTIVE_BIT
Global enable bit (write: 0=low-power, 1=normal operation)
Definition max22200_registers.hpp:253
constexpr uint32_t FREQM_BIT
Master frequency (0=100kHz, 1=80kHz)
Definition max22200_registers.hpp:231
constexpr uint32_t CM10_SHIFT
CM10 bit shift (bits 9:8)
Definition max22200_registers.hpp:240
constexpr uint32_t DPM_BIT
Plunger movement detection flag (read-only)
Definition max22200_registers.hpp:248
constexpr uint32_t UVM_BIT
Undervoltage flag (read-only, set at POR, cleared by read)
Definition max22200_registers.hpp:252
constexpr uint32_t COMER_BIT
Definition max22200_registers.hpp:249
constexpr uint32_t ONCH_SHIFT
ONCH bit shift (bits 31:24)
Definition max22200_registers.hpp:220
constexpr uint32_t M_OLF_BIT
OLF fault mask.
Definition max22200_registers.hpp:226
Definition max22200.ipp:15
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.
Definition max22200_types.hpp:240
const char * DriverStatusToStr(DriverStatus s)
Return a human-readable string for DriverStatus (for logging and tests)
Definition max22200_types.hpp:937
DriveMode
Drive mode enumeration (VDRnCDR bit in CFG_CHx[7])
Definition max22200_types.hpp:98
@ VDR
Voltage Drive Regulation (VDRnCDR = 1) — low-side or high-side.
@ CDR
Current Drive Regulation (VDRnCDR = 0) — low-side only.
ChannelMode
Channel-pair mode (CMxy bits in STATUS[15:8])
Definition max22200_types.hpp:159
@ HBRIDGE
Channels in H-bridge mode (CMxy = 10) — bidirectional drive.
@ INDEPENDENT
Channels independently controlled (CMxy = 00)
@ PARALLEL
Channels in parallel mode (CMxy = 01) — double current.
ChannelState
Channel state enumeration.
Definition max22200_types.hpp:959
std::array< ChannelConfig, NUM_CHANNELS_ > ChannelConfigArray
Array type for channel configurations.
Definition max22200_types.hpp:970
const char * FaultTypeToStr(FaultType ft)
Human-readable fault type name (for logging and tests)
Definition max22200_types.hpp:295
SideMode
High-side / Low-side selection (HSnLS bit in CFG_CHx[6])
Definition max22200_types.hpp:123
@ HIGH_SIDE
High-side driver (HSnLS = 1) — VDR only, no CDR/HFS/SRC/DPM.
@ LOW_SIDE
Low-side driver (HSnLS = 0) — supports CDR and VDR.
uint8_t hitTimeMsToRaw(float ms, bool master_clock_80khz, ChopFreq cf)
Convert HIT time in ms to 8-bit raw value (0–255)
Definition max22200_types.hpp:254
DriverStatus
Driver status enumeration.
Definition max22200_types.hpp:923
@ TIMEOUT
Operation timeout.
@ HARDWARE_FAULT
Hardware fault detected.
@ INITIALIZATION_ERROR
Initialization failed.
@ COMMUNICATION_ERROR
SPI communication error.
@ OK
Operation successful.
@ INVALID_PARAMETER
Invalid parameter provided.
FullBridgeState
Full-bridge state for a channel pair (datasheet Table 7)
Definition max22200_types.hpp:913
@ 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)
@ HiZ
ONCHx=0, ONCHy=0 — high impedance.
uint32_t getChopFreqKhz(bool master_clock_80khz, ChopFreq cf)
Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)
Definition max22200_types.hpp:224
FaultType
Fault type enumeration.
Definition max22200_types.hpp:280
@ HHF
HIT current not reached (HHF)
@ OCP
Overcurrent protection (OCP)
@ UVM
Undervoltage lockout (UVM, from STATUS)
@ OVT
Overtemperature (OVT, from STATUS)
@ OLF
Open-load detection (OLF)
@ DPM
Detection of plunger movement (DPM)
@ COMER
Communication error (COMER, from STATUS)
ChopFreq
Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4])
Definition max22200_types.hpp:211
@ 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.
@ 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.
constexpr uint8_t NUM_CHANNELS_
Number of channels on the MAX22200.
Definition max22200_registers.hpp:60
float getMaxHitTimeMs(bool master_clock_80khz, ChopFreq cf)
Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).
Definition max22200_types.hpp:271
@ FAULT
Fault status output (active-low, open-drain)
Board/scale configuration for unit-based APIs.
Definition max22200_types.hpp:1010
uint32_t full_scale_current_ma
Full-scale current in mA (from RREF: IFS = KFS×1000/RREF)
Definition max22200_types.hpp:1011
BoardConfig()
Definition max22200_types.hpp:1015
BoardConfig(float rref_kohm, bool hfs)
Definition max22200_types.hpp:1031
uint32_t max_current_ma
Max current limit in mA (0 = no limit, applies to all channels)
Definition max22200_types.hpp:1012
bool hasMaxCurrentLimit() const
True if a max current limit is configured (0 = no limit)
Definition max22200_types.hpp:1038
bool hasIfsConfigured() const
True if IFS is configured (non-zero)
Definition max22200_types.hpp:1042
uint8_t max_duty_percent
Max duty limit in percent (0 = no limit, applies to VDR mode)
Definition max22200_types.hpp:1013
bool hasMaxDutyLimit() const
True if a max duty limit is configured (0 = no limit)
Definition max22200_types.hpp:1040
uint32_t getMaxCurrentLimitMa() const
Max current limit in mA (0 = no limit)
Definition max22200_types.hpp:1046
uint32_t getFullScaleCurrentMa() const
Full-scale current in mA (IFS from RREF)
Definition max22200_types.hpp:1044
uint8_t getMaxDutyLimitPercent() const
Max duty limit in percent (0 = no limit)
Definition max22200_types.hpp:1048
Channel configuration structure.
Definition max22200_types.hpp:360
float hold_setpoint
HOLD setpoint: CDR = mA, VDR = duty % (0–100)
Definition max22200_types.hpp:365
bool isPlungerMovementDetectionEnabled() const
Definition max22200_types.hpp:589
void set_hold_ma(float ma)
Definition max22200_types.hpp:430
bool isTriggeredByPin() const
Definition max22200_types.hpp:585
float hold_duty_percent() const
Definition max22200_types.hpp:436
bool open_load_detection_enabled
Open-load detection enable.
Definition max22200_types.hpp:379
bool isCdr() const
Definition max22200_types.hpp:578
void fromRegister(uint32_t val, uint32_t board_ifs_ma, bool master_clock_80khz_param)
Parse a 32-bit register value into user units.
Definition max22200_types.hpp:530
float hold_ma() const
Definition max22200_types.hpp:434
bool half_full_scale
Definition max22200_types.hpp:371
uint32_t toRegister(uint32_t board_ifs_ma=0, bool master_clock_80khz=false) const
Build 32-bit register value from user units.
Definition max22200_types.hpp:447
bool isSlewRateControlEnabled() const
Definition max22200_types.hpp:587
static ChannelConfig makeSolenoidCdr(float hit_ma, float hold_ma, float hit_time_ms)
Preset: solenoid in CDR mode (low-side, currents in mA)
Definition max22200_types.hpp:400
bool trigger_from_pin
Definition max22200_types.hpp:373
float hit_ma() const
Definition max22200_types.hpp:433
void set_hit_duty_percent(float pct)
Definition max22200_types.hpp:431
bool hit_current_check_enabled
HIT current check enable (HHF fault if IHIT not reached)
Definition max22200_types.hpp:381
bool isHitCurrentCheckEnabled() const
Definition max22200_types.hpp:590
float hit_duty_percent() const
Definition max22200_types.hpp:435
void set_hit_ma(float ma)
Definition max22200_types.hpp:429
float hit_time_ms
Definition max22200_types.hpp:366
bool hasHitTime() const
Definition max22200_types.hpp:582
SideMode side_mode
Side mode: LOW_SIDE (CDR/VDR) or HIGH_SIDE (VDR only)
Definition max22200_types.hpp:376
bool plunger_movement_detection_enabled
Plunger movement detection enable (low-side only)
Definition max22200_types.hpp:380
bool slew_rate_control_enabled
Slew rate control enable; reduces EMI; fCHOP < 50 kHz.
Definition max22200_types.hpp:378
bool isTriggeredBySpi() const
Definition max22200_types.hpp:584
bool isVdr() const
Definition max22200_types.hpp:579
bool isHalfFullScale() const
Definition max22200_types.hpp:586
bool isHighSide() const
Definition max22200_types.hpp:581
bool isLowSide() const
Definition max22200_types.hpp:580
ChopFreq getChopFreq() const
Chopping frequency config (FREQ_CFG); see ChopFreq enum.
Definition max22200_types.hpp:592
DriveMode drive_mode
Drive mode: CDR (current) or VDR (voltage)
Definition max22200_types.hpp:375
ChannelConfig()
Default constructor — safe defaults.
Definition max22200_types.hpp:386
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
bool isOpenLoadDetectionEnabled() const
Definition max22200_types.hpp:588
bool isContinuousHit() const
Definition max22200_types.hpp:583
void set_hold_duty_percent(float pct)
Definition max22200_types.hpp:432
static ChannelConfig makeSolenoidVdr(float hit_pct, float hold_pct, float hit_time_ms)
Preset: solenoid in VDR mode (low-side, duty percent)
Definition max22200_types.hpp:417
DPM (Detection of Plunger Movement) algorithm configuration.
Definition max22200_types.hpp:882
uint8_t getPlungerMovementCurrentThreshold() const
Definition max22200_types.hpp:904
uint8_t getPlungerMovementStartCurrent() const
Definition max22200_types.hpp:902
uint8_t plunger_movement_start_current
DPM_ISTART (0-127) — starting current for dip search.
Definition max22200_types.hpp:883
uint32_t toRegister() const
Definition max22200_types.hpp:890
uint8_t plunger_movement_debounce_time
DPM_TDEB (0-15) — min dip duration in chopping periods.
Definition max22200_types.hpp:884
uint8_t plunger_movement_current_threshold
DPM_IPTH (0-15) — min dip amplitude threshold.
Definition max22200_types.hpp:885
uint8_t getPlungerMovementDebounceTime() const
Definition max22200_types.hpp:903
void fromRegister(uint32_t val)
Definition max22200_types.hpp:896
DpmConfig()
Definition max22200_types.hpp:887
Driver statistics structure.
Definition max22200_types.hpp:1082
DriverStatistics()
Definition max22200_types.hpp:1089
float getSuccessRate() const
Definition max22200_types.hpp:1093
uint32_t fault_events
Definition max22200_types.hpp:1085
uint32_t total_transfers
Definition max22200_types.hpp:1083
uint32_t getFailedTransfers() const
Definition max22200_types.hpp:1101
bool hasFailures() const
Definition max22200_types.hpp:1098
uint32_t state_changes
Definition max22200_types.hpp:1086
uint32_t uptime_ms
Definition max22200_types.hpp:1087
uint32_t getUptimeMs() const
Definition max22200_types.hpp:1104
uint32_t failed_transfers
Definition max22200_types.hpp:1084
uint32_t getFaultEvents() const
Definition max22200_types.hpp:1102
bool isHealthy() const
Definition max22200_types.hpp:1099
uint32_t getTotalTransfers() const
Definition max22200_types.hpp:1100
uint32_t getStateChanges() const
Definition max22200_types.hpp:1103
Duty cycle limits (δMIN, δMAX) for a given configuration.
Definition max22200_types.hpp:1057
uint8_t max_percent
Maximum duty cycle in percent (δMAX)
Definition max22200_types.hpp:1059
uint8_t getMaxPercent() const
Maximum duty cycle in percent (δMAX)
Definition max22200_types.hpp:1066
uint8_t getMinPercent() const
Minimum duty cycle in percent (δMIN)
Definition max22200_types.hpp:1064
DutyLimits()
Definition max22200_types.hpp:1061
bool inRange(float percent) const
True if percent is within [min_percent, max_percent].
Definition max22200_types.hpp:1068
uint8_t min_percent
Minimum duty cycle in percent (δMIN)
Definition max22200_types.hpp:1058
float clamp(float percent) const
Clamp percent to [min_percent, max_percent].
Definition max22200_types.hpp:1072
Per-channel fault information from FAULT register (0x09)
Definition max22200_types.hpp:805
bool hasOpenLoadFaultOnChannel(uint8_t ch) const
Definition max22200_types.hpp:859
uint8_t overcurrent_channel_mask
OCP per-channel bitmask (bit N = channel N)
Definition max22200_types.hpp:806
bool hasOvercurrent() const
Definition max22200_types.hpp:845
bool hasPlungerMovementFaultOnChannel(uint8_t ch) const
Definition max22200_types.hpp:862
bool hasPlungerMovementFault() const
Definition max22200_types.hpp:848
FaultStatus()
Definition max22200_types.hpp:811
bool hasOpenLoadFault() const
Definition max22200_types.hpp:847
bool hasOvercurrentOnChannel(uint8_t ch) const
Definition max22200_types.hpp:853
bool hasHitNotReached() const
Definition max22200_types.hpp:846
bool hasFault() const
Check if any per-channel fault is active.
Definition max22200_types.hpp:824
uint8_t plunger_movement_fault_channel_mask
DPM per-channel bitmask (bit N = channel N)
Definition max22200_types.hpp:809
void fromRegister(uint32_t val)
Definition max22200_types.hpp:814
uint8_t channelsWithAnyFault() const
Definition max22200_types.hpp:865
uint8_t getFaultCount() const
Count total per-channel faults.
Definition max22200_types.hpp:832
uint8_t open_load_fault_channel_mask
OLF per-channel bitmask (bit N = channel N)
Definition max22200_types.hpp:808
bool hasHitNotReachedOnChannel(uint8_t ch) const
Definition max22200_types.hpp:856
bool hasFaultOnChannel(uint8_t ch) const
Definition max22200_types.hpp:849
uint8_t hit_not_reached_channel_mask
HHF per-channel bitmask (bit N = channel N)
Definition max22200_types.hpp:807
STATUS register structure.
Definition max22200_types.hpp:634
ChannelMode getChannelPairMode54() const
Definition max22200_types.hpp:772
bool hasPlungerMovementFault() const
Definition max22200_types.hpp:745
ChannelMode getChannelPairMode76() const
Definition max22200_types.hpp:771
bool hit_not_reached_masked
HHF fault mask; when true HHF does not assert FAULT pin.
Definition max22200_types.hpp:644
ChannelMode channel_pair_mode_10
CH0/CH1 pair mode.
Definition max22200_types.hpp:654
bool open_load_fault
OLF fault flag (read-only); load disconnected if OL enabled.
Definition max22200_types.hpp:662
bool hasUndervoltage() const
Definition max22200_types.hpp:747
bool hit_not_reached
HHF fault flag (read-only); IHIT not reached by end of tHIT.
Definition max22200_types.hpp:663
void fromRegister(uint32_t val)
Parse a 32-bit register value.
Definition max22200_types.hpp:707
bool hasOvercurrent() const
Definition max22200_types.hpp:742
bool overcurrent
OCP fault flag (read-only); output exceeded OCP level.
Definition max22200_types.hpp:661
bool is80KHzBase() const
Definition max22200_types.hpp:768
bool isOvertemperatureMasked() const
Definition max22200_types.hpp:760
bool isChannelOn(uint8_t ch) const
Definition max22200_types.hpp:749
ChannelMode channel_pair_mode_76
CH6/CH7 pair mode; change only when both CH6 and CH7 are OFF.
Definition max22200_types.hpp:651
bool isOvercurrentMasked() const
Definition max22200_types.hpp:761
bool is100KHzBase() const
Definition max22200_types.hpp:769
bool isHitNotReachedMasked() const
Definition max22200_types.hpp:763
uint8_t getChannelsOnMask() const
Definition max22200_types.hpp:775
ChannelMode getChannelPairMode32() const
Definition max22200_types.hpp:773
bool hasHitNotReached() const
Definition max22200_types.hpp:744
uint8_t channelCountOn() const
Definition max22200_types.hpp:752
bool master_clock_80khz
Master clock base (false=100kHz, true=80kHz); affects fCHOP.
Definition max22200_types.hpp:648
bool hasOvertemperature() const
Definition max22200_types.hpp:741
bool open_load_fault_masked
OLF fault mask; when true OLF does not assert FAULT pin.
Definition max22200_types.hpp:643
bool undervoltage_masked
UVM fault mask; when true UVM does not assert FAULT pin.
Definition max22200_types.hpp:647
bool communication_error
COMER flag (read-only); SPI error detected.
Definition max22200_types.hpp:665
bool communication_error_masked
COMER mask (default=true); when true COMER does not assert FAULT pin.
Definition max22200_types.hpp:646
bool isUndervoltageMasked() const
Definition max22200_types.hpp:766
bool hasOpenLoadFault() const
Definition max22200_types.hpp:743
bool overcurrent_masked
OCP fault mask; when true OCP does not assert FAULT pin.
Definition max22200_types.hpp:642
bool undervoltage
UVM fault flag (read-only); clear by reading STATUS at init.
Definition max22200_types.hpp:666
bool isActive() const
Definition max22200_types.hpp:748
bool hasCommunicationError() const
Definition max22200_types.hpp:746
bool overtemperature
OVT fault flag (read-only); die over temp.
Definition max22200_types.hpp:660
ChannelMode channel_pair_mode_54
CH4/CH5 pair mode.
Definition max22200_types.hpp:652
ChannelMode channel_pair_mode_32
CH2/CH3 pair mode.
Definition max22200_types.hpp:653
bool overtemperature_masked
OVT fault mask; when true OVT does not assert FAULT pin.
Definition max22200_types.hpp:641
bool isCommunicationErrorMasked() const
Definition max22200_types.hpp:765
uint8_t channels_on_mask
Definition max22200_types.hpp:636
bool plunger_movement_fault
DPM fault flag (read-only); no valid plunger movement.
Definition max22200_types.hpp:664
bool isOpenLoadFaultMasked() const
Definition max22200_types.hpp:762
uint32_t toRegister() const
Build 32-bit register value from writable fields.
Definition max22200_types.hpp:685
bool isPlungerMovementFaultMasked() const
Definition max22200_types.hpp:764
ChannelMode getChannelPairMode10() const
Definition max22200_types.hpp:774
bool active
Global enable (0=low-power, 1=normal); set to 1 during init.
Definition max22200_types.hpp:657
bool plunger_movement_fault_masked
DPM fault mask; when true DPM does not assert FAULT pin.
Definition max22200_types.hpp:645
StatusConfig()
Default constructor.
Definition max22200_types.hpp:671
bool hasFault() const
Check if any fault flag is active.
Definition max22200_types.hpp:734