MAX22200 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
max22200_types.hpp
Go to the documentation of this file.
1
12#ifndef MAX22200_TYPES_HPP
13#define MAX22200_TYPES_HPP
14
15#include <array>
16#include <cstddef>
17#include <cstdint>
18
19#include "max22200_detail.hpp"
21#include "max22200_version.h"
22
24namespace max22200 {
25
39enum class [[nodiscard]] Error : uint8_t {
40 // Base set: the same names and values in every driver of the org (standards/driver.md).
41 Ok = 0,
42 NotInitialized = 1,
44 InvalidArgument = 2,
45 Bus = 3,
46 Timeout = 4,
52 Crc = 6,
53 Busy = 7,
54 DeviceFault = 8,
56 Unsupported = 9,
58 // Chip-specific values start at 16; each one is returned by some call (tests/test_errors.cpp).
59 NoDevice = 16,
61 Pin = 17,
69 WriteMismatch = 19,
72 Undervoltage = 20,
76 ChannelsActive = 21,
79 DeviceReset = 22,
83 Uncertain = 23,
89};
90
96constexpr const char* ToString(Error error) noexcept {
97 // A switch over every enumerator, so -Wswitch-enum names a new one that has no string
98 // (KB-CPP-053); `default` takes a value that is not an enumerator (MISRA C++:2023 Rule 9.4.2).
99 switch (error) {
100 case Error::Ok:
101 return "Ok";
103 return "NotInitialized";
105 return "InvalidArgument";
106 case Error::Bus:
107 return "Bus";
108 case Error::Timeout:
109 return "Timeout";
111 return "DeviceIdMismatch";
112 case Error::Crc:
113 return "Crc";
114 case Error::Busy:
115 return "Busy";
117 return "DeviceFault";
119 return "Unsupported";
120 case Error::NoDevice:
121 return "NoDevice";
122 case Error::Pin:
123 return "Pin";
125 return "CommunicationError";
127 return "WriteMismatch";
129 return "Undervoltage";
131 return "ChannelsActive";
133 return "DeviceReset";
134 case Error::Uncertain:
135 return "Uncertain";
136 default:
137 break;
138 }
139 return "Unknown";
140}
141
149template <typename T>
150struct [[nodiscard]] Result {
151 T value{};
152 Error error{Error::Ok};
153
155 [[nodiscard]] constexpr bool ok() const noexcept {
156 return error == Error::Ok;
157 }
159 constexpr explicit operator bool() const noexcept {
160 return ok();
161 }
162
168 static constexpr Result Success(T v) noexcept {
169 return {v, Error::Ok};
170 }
176 static constexpr Result Failure(Error e) noexcept {
177 return {T{}, e};
178 }
179};
180
182template <>
183struct [[nodiscard]] Result<void> {
184 Error error{Error::Ok};
185
187 [[nodiscard]] constexpr bool ok() const noexcept {
188 return error == Error::Ok;
189 }
191 constexpr explicit operator bool() const noexcept {
192 return ok();
193 }
194
196 static constexpr Result Success() noexcept {
197 return {Error::Ok};
198 }
204 static constexpr Result Failure(Error e) noexcept {
205 return {e};
206 }
207};
208
210enum class LogLevel : uint8_t {
211 Error = 0,
212 Warning,
213 Info,
214 Debug,
215};
216
224enum class Verify : uint8_t {
225 None = 0,
226 ReadBack = 1,
227};
228
239enum class Variant : uint8_t {
240 Max22200A = 0,
241 Max22200 = 1,
242};
243
245enum class MasterClock : uint8_t {
246 Khz100 = 0,
247 Khz80 = 1,
248};
249
251enum class ChopDivider : uint8_t {
252 Div4 = 0,
253 Div3 = 1,
254 Div2 = 2,
255 Div1 = 3,
256};
257
259enum class DriveMode : uint8_t {
260 Cdr = 0,
262 Vdr = 1,
263};
264
266enum class Side : uint8_t {
267 Low = 0,
268 High = 1,
269};
270
272enum class PairMode : uint8_t {
273 Independent = 0,
274 Parallel = 1,
275 FullBridge = 2,
276};
277
279enum class BridgeState : uint8_t {
280 HiZ = 0,
281 Forward = 1,
282 Reverse = 2,
283 Brake = 3,
284};
285
286namespace detail {
288// The last enumerator of each contiguous enumeration, for `IsEnumerator()` (KB-CPP20-025, -026).
289template <>
290struct EnumLast<LogLevel> {
291 static constexpr LogLevel kValue = LogLevel::Debug;
292};
293template <>
294struct EnumLast<Verify> {
295 static constexpr Verify kValue = Verify::ReadBack;
296};
297template <>
298struct EnumLast<Variant> {
299 static constexpr Variant kValue = Variant::Max22200;
300};
301template <>
302struct EnumLast<MasterClock> {
303 static constexpr MasterClock kValue = MasterClock::Khz80;
304};
305template <>
306struct EnumLast<ChopDivider> {
307 static constexpr ChopDivider kValue = ChopDivider::Div1;
308};
309template <>
310struct EnumLast<DriveMode> {
311 static constexpr DriveMode kValue = DriveMode::Vdr;
312};
313template <>
314struct EnumLast<Side> {
315 static constexpr Side kValue = Side::High;
316};
317template <>
318struct EnumLast<PairMode> {
319 static constexpr PairMode kValue = PairMode::FullBridge;
320};
321template <>
322struct EnumLast<BridgeState> {
323 static constexpr BridgeState kValue = BridgeState::Brake;
324};
326} // namespace detail
327
328// FREQ_CFG is two bits and every value is an enumerator, so decoding it needs no check; CMxy is two
329// bits with only three enumerators, so its decode does (`DecodePairMode()`).
330static_assert(detail::ToUnderlying(ChopDivider::Div1) == 3U, "Table 1: FREQ_CFG 0 to 3");
331static_assert(detail::ToUnderlying(PairMode::FullBridge) == 2U, "Register Details: CMxy 0 to 2");
332
334inline constexpr uint8_t kChannels = 8;
336inline constexpr uint8_t kPairs = 4;
339inline constexpr uint8_t kMaxCdrCode = 126;
341inline constexpr uint8_t kMaxVdrCode = 100;
343inline constexpr uint8_t kHitTimeNone = 0;
345inline constexpr uint8_t kMaxHitTimeCode = 254;
348inline constexpr uint8_t kHitTimeContinuous = 255;
350inline constexpr uint32_t kMinRrefOhm = 15000;
352inline constexpr uint32_t kMaxRrefOhm = 100000;
356inline constexpr uint32_t kNoRref = 0;
358inline constexpr uint32_t kKfs = 15000;
360inline constexpr uint8_t kStartAttempts = 3;
364inline constexpr uint32_t kDefaultWakeTimeoutUs = 100000;
366inline constexpr uint32_t kMinWakeTimeoutUs = reg::kWakeUpUs;
368inline constexpr uint32_t kMaxWakeTimeoutUs = 10000000;
371inline constexpr uint32_t kWakePollUs = 10000;
372
387 uint8_t hit{0};
388 uint8_t hold{0};
389 uint8_t hit_time{0};
391 bool half_scale{false};
392 bool trigger_pin{false};
393 bool slew_rate_control{false};
394 bool open_load_detect{false};
395 bool plunger_detect{false};
396 bool hit_current_check{false};
397
403 [[nodiscard]] friend constexpr bool operator==(const ChannelConfig& lhs,
404 const ChannelConfig& rhs) noexcept = default;
405};
406
411struct FaultMask {
412 bool overtemperature{false};
413 bool overcurrent{false};
414 bool open_load{false};
415 bool hit_not_reached{false};
416 bool plunger{false};
417 bool communication{true};
418 bool undervoltage{false};
419
425 [[nodiscard]] friend constexpr bool operator==(const FaultMask& lhs,
426 const FaultMask& rhs) noexcept = default;
427};
428
433struct DpmConfig {
434 uint8_t start{0};
435 uint8_t debounce{0};
436 uint8_t threshold{0};
437
443 [[nodiscard]] friend constexpr bool operator==(const DpmConfig& lhs,
444 const DpmConfig& rhs) noexcept = default;
445};
446
456struct Config {
461 uint32_t rref_ohm{kNoRref};
469 uint8_t loaded_channels{0};
472 std::array<PairMode, kPairs> pairs{};
473 std::array<ChannelConfig, kChannels> channels{};
475};
476
478struct Status {
479 uint8_t on_mask{0};
480 bool overtemperature{false};
481 bool overcurrent{false};
482 bool open_load{false};
483 bool hit_not_reached{false};
484 bool plunger{false};
485 bool communication{false};
486 bool undervoltage{false};
487 bool active{false};
488 uint32_t raw{0};
489
491 [[nodiscard]] constexpr bool AnyFlag() const noexcept {
492 return (raw & reg::kFlagsMask) != 0U;
493 }
494};
495
500struct Faults {
501 uint8_t overcurrent{0};
502 uint8_t hit_not_reached{0};
503 uint8_t open_load{0};
504 uint8_t plunger{0};
505
507 static constexpr Faults All() noexcept {
508 return {.overcurrent = 0xFF, .hit_not_reached = 0xFF, .open_load = 0xFF, .plunger = 0xFF};
509 }
511 [[nodiscard]] constexpr bool Any() const noexcept {
512 return Channels() != 0U;
513 }
515 [[nodiscard]] constexpr uint8_t Channels() const noexcept {
516 return static_cast<uint8_t>(static_cast<uint32_t>(overcurrent) |
517 static_cast<uint32_t>(hit_not_reached) |
518 static_cast<uint32_t>(open_load) | static_cast<uint32_t>(plunger));
519 }
524 [[nodiscard]] constexpr Faults Or(const Faults& other) const noexcept {
525 return {.overcurrent = static_cast<uint8_t>(static_cast<uint32_t>(overcurrent) |
526 static_cast<uint32_t>(other.overcurrent)),
527 .hit_not_reached = static_cast<uint8_t>(static_cast<uint32_t>(hit_not_reached) |
528 static_cast<uint32_t>(other.hit_not_reached)),
529 .open_load = static_cast<uint8_t>(static_cast<uint32_t>(open_load) |
530 static_cast<uint32_t>(other.open_load)),
531 .plunger = static_cast<uint8_t>(static_cast<uint32_t>(plunger) |
532 static_cast<uint32_t>(other.plunger))};
533 }
538 [[nodiscard]] constexpr Faults And(const Faults& mask) const noexcept {
539 return {.overcurrent = static_cast<uint8_t>(static_cast<uint32_t>(overcurrent) &
540 static_cast<uint32_t>(mask.overcurrent)),
541 .hit_not_reached = static_cast<uint8_t>(static_cast<uint32_t>(hit_not_reached) &
542 static_cast<uint32_t>(mask.hit_not_reached)),
543 .open_load = static_cast<uint8_t>(static_cast<uint32_t>(open_load) &
544 static_cast<uint32_t>(mask.open_load)),
545 .plunger = static_cast<uint8_t>(static_cast<uint32_t>(plunger) &
546 static_cast<uint32_t>(mask.plunger))};
547 }
553 [[nodiscard]] friend constexpr bool operator==(const Faults& lhs,
554 const Faults& rhs) noexcept = default;
555};
556
566 bool overtemperature{false};
567 bool undervoltage{false};
569 bool overcurrent{false};
570 bool open_load{false};
571 bool hit_not_reached{false};
572 bool plunger{false};
573 bool lost{false};
578
580 [[nodiscard]] constexpr bool Any() const noexcept {
582 plunger || lost || faults.Any();
583 }
589 [[nodiscard]] friend constexpr bool operator==(const LatchedFaults& lhs,
590 const LatchedFaults& rhs) noexcept = default;
591};
592
595 uint8_t min_percent;
596 uint8_t max_percent;
597};
598
599// -------------------------------------------------------------------------------------------------
600// Register encoding
601// -------------------------------------------------------------------------------------------------
602
608constexpr uint32_t EncodeChannel(const ChannelConfig& c) noexcept {
609 uint32_t v = 0;
610 v |= c.half_scale ? reg::kHfs : 0U;
611 v |= (static_cast<uint32_t>(c.hold) & reg::kCodeMask) << reg::kHoldShift;
612 v |= c.trigger_pin ? reg::kTrgnspi : 0U;
613 v |= (static_cast<uint32_t>(c.hit) & reg::kCodeMask) << reg::kHitShift;
614 v |= static_cast<uint32_t>(c.hit_time) << reg::kHitTimeShift;
615 v |= (c.drive == DriveMode::Vdr) ? reg::kVdrncdr : 0U;
616 v |= (c.side == Side::High) ? reg::kHsnls : 0U;
617 v |= (static_cast<uint32_t>(detail::ToUnderlying(c.chop)) & 0x03U) << reg::kFreqCfgShift;
618 v |= c.slew_rate_control ? reg::kSrc : 0U;
619 v |= c.open_load_detect ? reg::kOlEn : 0U;
620 v |= c.plunger_detect ? reg::kDpmEn : 0U;
621 v |= c.hit_current_check ? reg::kHhfEn : 0U;
622 return v;
623}
624
630constexpr ChannelConfig DecodeChannel(uint32_t v) noexcept {
631 ChannelConfig c{};
632 c.half_scale = (v & reg::kHfs) != 0U;
633 c.hold = static_cast<uint8_t>((v >> reg::kHoldShift) & reg::kCodeMask);
634 c.trigger_pin = (v & reg::kTrgnspi) != 0U;
635 c.hit = static_cast<uint8_t>((v >> reg::kHitShift) & reg::kCodeMask);
636 c.hit_time = static_cast<uint8_t>((v >> reg::kHitTimeShift) & 0xFFU);
637 c.drive = ((v & reg::kVdrncdr) != 0U) ? DriveMode::Vdr : DriveMode::Cdr;
638 c.side = ((v & reg::kHsnls) != 0U) ? Side::High : Side::Low;
639 c.chop = static_cast<ChopDivider>((v >> reg::kFreqCfgShift) & 0x03U); // 0 to 3: all enumerators
640 c.slew_rate_control = (v & reg::kSrc) != 0U;
641 c.open_load_detect = (v & reg::kOlEn) != 0U;
642 c.plunger_detect = (v & reg::kDpmEn) != 0U;
643 c.hit_current_check = (v & reg::kHhfEn) != 0U;
644 return c;
645}
646
654constexpr uint32_t EncodeStatus(const Config& config, uint8_t on_mask, bool active) noexcept {
655 const FaultMask& m = config.fault_mask;
656 uint32_t v = static_cast<uint32_t>(on_mask) << reg::kOnchShift;
657 v |= m.overtemperature ? reg::kMaskOvt : 0U;
658 v |= m.overcurrent ? reg::kMaskOcp : 0U;
659 v |= m.open_load ? reg::kMaskOlf : 0U;
660 v |= m.hit_not_reached ? reg::kMaskHhf : 0U;
661 v |= m.plunger ? reg::kMaskDpm : 0U;
662 v |= m.communication ? reg::kMaskComf : 0U;
663 v |= m.undervoltage ? reg::kMaskUvm : 0U;
664 v |= (config.clock == MasterClock::Khz80) ? reg::kFreqm : 0U;
665 for (uint8_t p = 0; p < kPairs; ++p) {
666 v |= (static_cast<uint32_t>(detail::ToUnderlying(config.pairs[p])) & 0x03U)
667 << reg::PairModeShift(p);
668 }
669 v |= active ? reg::kActive : 0U;
670 return v;
671}
672
678constexpr Status DecodeStatus(uint32_t v) noexcept {
679 Status s{};
680 s.on_mask = static_cast<uint8_t>(v >> reg::kOnchShift);
681 s.overtemperature = (v & reg::kOvt) != 0U;
682 s.overcurrent = (v & reg::kOcp) != 0U;
683 s.open_load = (v & reg::kOlf) != 0U;
684 s.hit_not_reached = (v & reg::kHhf) != 0U;
685 s.plunger = (v & reg::kDpm) != 0U;
686 s.communication = (v & reg::kComer) != 0U;
687 s.undervoltage = (v & reg::kUvm) != 0U;
688 s.active = (v & reg::kActive) != 0U;
689 s.raw = v;
690 return s;
691}
692
701constexpr Result<PairMode> DecodePairMode(uint32_t status, uint8_t pair) noexcept {
702 const uint32_t field = (status >> reg::PairModeShift(pair)) & 0x03U;
703 if (field > static_cast<uint32_t>(detail::ToUnderlying(PairMode::FullBridge))) {
705 }
706 return Result<PairMode>::Success(static_cast<PairMode>(field));
707}
708
714constexpr Faults DecodeFaults(uint32_t v) noexcept {
715 return {.overcurrent = static_cast<uint8_t>(v >> reg::kFaultOcpShift),
716 .hit_not_reached = static_cast<uint8_t>(v >> reg::kFaultHhfShift),
717 .open_load = static_cast<uint8_t>(v >> reg::kFaultOlfShift),
718 .plunger = static_cast<uint8_t>(v >> reg::kFaultDpmShift)};
719}
720
726constexpr uint32_t EncodeDpm(const DpmConfig& d) noexcept {
727 return ((static_cast<uint32_t>(d.start) & reg::kDpmIstartMask) << reg::kDpmIstartShift) |
728 ((static_cast<uint32_t>(d.debounce) & reg::kDpmTdebMask) << reg::kDpmTdebShift) |
729 ((static_cast<uint32_t>(d.threshold) & reg::kDpmIpthMask) << reg::kDpmIpthShift);
730}
731
737constexpr DpmConfig DecodeDpm(uint32_t v) noexcept {
738 return {.start = static_cast<uint8_t>((v >> reg::kDpmIstartShift) & reg::kDpmIstartMask),
739 .debounce = static_cast<uint8_t>((v >> reg::kDpmTdebShift) & reg::kDpmTdebMask),
740 .threshold = static_cast<uint8_t>((v >> reg::kDpmIpthShift) & reg::kDpmIpthMask)};
741}
742
743// -------------------------------------------------------------------------------------------------
744// Units
745// -------------------------------------------------------------------------------------------------
746
753constexpr uint32_t ChopPeriodNs(MasterClock clock, ChopDivider chop) noexcept {
754 const uint32_t main_period_ns = (clock == MasterClock::Khz80) ? 12500U : 10000U;
755 return main_period_ns * (4U - (static_cast<uint32_t>(detail::ToUnderlying(chop)) & 0x03U));
756}
757
765constexpr DutyLimits DutyLimitsOf(ChopDivider chop, bool slew_rate_control) noexcept {
766 if (slew_rate_control) {
767 return {.min_percent = 7, .max_percent = 93};
768 }
769 return (chop == ChopDivider::Div1) ? DutyLimits{.min_percent = 8, .max_percent = 92}
770 : DutyLimits{.min_percent = 4, .max_percent = 96};
771}
772
781constexpr Result<uint32_t> HitTimeUs(uint8_t code, MasterClock clock, ChopDivider chop) noexcept {
782 if (code == kHitTimeContinuous) {
784 }
785 return Result<uint32_t>::Success((static_cast<uint32_t>(code) * 40U * ChopPeriodNs(clock, chop)) /
786 1000U);
787}
788
801constexpr Result<uint8_t> HitTimeCode(uint32_t us, MasterClock clock, ChopDivider chop) noexcept {
802 if (us == 0U) {
804 }
805 const uint64_t step_ns = 40ULL * ChopPeriodNs(clock, chop);
806 const uint64_t code = ((static_cast<uint64_t>(us) * 1000U) + (step_ns / 2U)) / step_ns;
807 if (code > kMaxHitTimeCode) {
809 }
810 return Result<uint8_t>::Success((code == 0U) ? uint8_t{1} : static_cast<uint8_t>(code));
811}
812
820constexpr uint32_t DebounceUs(uint8_t code, MasterClock clock, ChopDivider chop) noexcept {
821 return ((static_cast<uint32_t>(code) & reg::kDpmTdebMask) * ChopPeriodNs(clock, chop)) / 1000U;
822}
823
832constexpr Result<uint32_t> FullScaleUa(uint32_t rref_ohm, bool half_scale) noexcept {
833 if ((rref_ohm < kMinRrefOhm) || (rref_ohm > kMaxRrefOhm)) {
835 }
836 const uint64_t ua = (static_cast<uint64_t>(kKfs) * 1000000ULL) / rref_ohm;
837 return Result<uint32_t>::Success(static_cast<uint32_t>(half_scale ? (ua / 2U) : ua));
838}
839
848constexpr Result<uint32_t> CurrentUa(uint8_t code, uint32_t rref_ohm, bool half_scale) noexcept {
849 const auto ifs = FullScaleUa(rref_ohm, half_scale);
850 if ((code > kMaxCdrCode) || !ifs) {
852 }
854 static_cast<uint32_t>((static_cast<uint64_t>(code) * ifs.value) / 128U));
855}
856
866constexpr Result<uint8_t> CurrentCode(uint32_t ma, uint32_t rref_ohm, bool half_scale) noexcept {
867 const auto ifs = FullScaleUa(rref_ohm, half_scale);
868 if (!ifs) {
870 }
871 const uint32_t ifs_ua = ifs.value;
872 if (ma == 0U) {
873 return Result<uint8_t>::Success(0);
874 }
875 const uint64_t code = ((static_cast<uint64_t>(ma) * 128000U) + (ifs_ua / 2U)) / ifs_ua;
876 if ((code == 0U) || (code > kMaxCdrCode)) {
878 }
879 return Result<uint8_t>::Success(static_cast<uint8_t>(code));
880}
881
890constexpr Result<uint8_t> DpmCurrentCode(uint32_t ma, uint32_t rref_ohm,
891 uint8_t max_code) noexcept {
892 const auto ifs = FullScaleUa(rref_ohm, false);
893 if (!ifs) {
895 }
896 const uint32_t ifs_ua = ifs.value;
897 const uint64_t code = ((static_cast<uint64_t>(ma) * 127000U) + (ifs_ua / 2U)) / ifs_ua;
898 if (code > max_code) {
900 }
901 return Result<uint8_t>::Success(static_cast<uint8_t>(code));
902}
903
904// -------------------------------------------------------------------------------------------------
905// Validation
906// -------------------------------------------------------------------------------------------------
907
914constexpr bool ValidCode(uint8_t code, DriveMode drive) noexcept {
915 return code <= ((drive == DriveMode::Cdr) ? kMaxCdrCode : kMaxVdrCode);
916}
917
923constexpr bool ValidHighSide(const ChannelConfig& c) noexcept {
924 return (c.side == Side::Low) || ((c.drive == DriveMode::Vdr) && !c.slew_rate_control &&
925 !c.half_scale && !c.plunger_detect);
926}
927
937constexpr Error ValidateChannel(const ChannelConfig& c, MasterClock clock) noexcept {
938 if (!detail::IsEnumerator(c.drive) || !detail::IsEnumerator(c.side) ||
939 !detail::IsEnumerator(c.chop) || !detail::IsEnumerator(clock)) {
941 }
942 if (!ValidCode(c.hit, c.drive) || !ValidCode(c.hold, c.drive)) {
944 }
945 if (!ValidHighSide(c)) {
947 }
948 if (c.slew_rate_control && (ChopPeriodNs(clock, c.chop) <= 20000U)) {
949 return Error::InvalidArgument; // fCHOP >= 50 kHz
950 }
951 if (c.hit_current_check && (c.drive == DriveMode::Vdr)) {
953 }
954 return Error::Ok;
955}
956
966constexpr bool ValidLoadDiagnostics(const ChannelConfig& c, uint8_t loaded_channels,
967 uint8_t channel) noexcept {
968 const bool diagnostics = c.open_load_detect || c.plunger_detect || c.hit_current_check;
969 const bool loaded =
970 ((static_cast<uint32_t>(loaded_channels) >> (static_cast<uint32_t>(channel) & 0x07U)) & 1U) !=
971 0U;
972 return !diagnostics || loaded;
973}
974
975namespace detail {
981constexpr bool ValidTimings(const Config& config) noexcept {
982 const bool rref_ok = (config.rref_ohm == kNoRref) ||
983 ((config.rref_ohm >= kMinRrefOhm) && (config.rref_ohm <= kMaxRrefOhm));
984 return rref_ok && (config.wake_timeout_us >= kMinWakeTimeoutUs) &&
985 (config.wake_timeout_us <= kMaxWakeTimeoutUs);
986}
987} // namespace detail
988
1000constexpr Error Validate(const Config& config) noexcept {
1001 if (!detail::IsEnumerator(config.variant) || !detail::IsEnumerator(config.clock)) {
1003 }
1004 if (!detail::ValidTimings(config)) {
1006 }
1007 for (const PairMode p : config.pairs) {
1008 if (!detail::IsEnumerator(p)) {
1010 }
1011 }
1012 for (uint8_t ch = 0; ch < kChannels; ++ch) {
1013 const ChannelConfig& c = config.channels[ch];
1014 if ((ValidateChannel(c, config.clock) != Error::Ok) ||
1015 !ValidLoadDiagnostics(c, config.loaded_channels, ch)) {
1017 }
1018 }
1019 const DpmConfig& d = config.dpm;
1023 }
1024 return Error::Ok;
1025}
1026
1027// --- Compile-time proofs (KB-CPP20-012) ---------------------------------------------------------
1028// Inside detail, where the typed literals (_u8, _u32) are declared.
1029namespace detail {
1030// The reset configuration encodes to the reset values (Register Details) and is valid.
1031static_assert(EncodeChannel(ChannelConfig{}) == 0U, "Register Details: CFG_CHn resets to 0");
1032static_assert(EncodeStatus(Config{}, 0_u8, false) == (reg::kStatusReset & reg::kWritableMask),
1033 "Register Details: STATUS resets with only M_COMF set among the writable bits");
1034static_assert(Validate(Config{}) == Error::Ok, "Config{} is a valid configuration");
1035// Every field lands where Table 11 puts it and decodes back.
1036static_assert(DecodeChannel(EncodeChannel({.drive = DriveMode::Vdr,
1037 .side = Side::High,
1038 .hit = 100,
1039 .hold = 30,
1040 .hit_time = 254,
1041 .chop = ChopDivider::Div1,
1042 .trigger_pin = true,
1043 .open_load_detect = true})) ==
1044 ChannelConfig{.drive = DriveMode::Vdr,
1045 .side = Side::High,
1046 .hit = 100,
1047 .hold = 30,
1048 .hit_time = 254,
1049 .chop = ChopDivider::Div1,
1050 .trigger_pin = true,
1051 .open_load_detect = true});
1052static_assert(DecodeChannel(EncodeChannel({.hit = 126,
1053 .hold = 1,
1054 .hit_time = 1,
1055 .chop = ChopDivider::Div3,
1056 .half_scale = true,
1057 .slew_rate_control = true,
1058 .plunger_detect = true,
1059 .hit_current_check = true})) ==
1060 ChannelConfig{.hit = 126,
1061 .hold = 1,
1062 .hit_time = 1,
1063 .chop = ChopDivider::Div3,
1064 .half_scale = true,
1065 .slew_rate_control = true,
1066 .plunger_detect = true,
1067 .hit_current_check = true});
1068static_assert(DecodeDpm(EncodeDpm({.start = 127, .debounce = 15, .threshold = 15})) ==
1069 DpmConfig{.start = 127, .debounce = 15, .threshold = 15});
1070static_assert(EncodeDpm({.start = 127, .debounce = 15, .threshold = 15}) == reg::kDpmUsedMask);
1071// CMxy: every mode round-trips, the reserved value 3 is refused.
1074 0_u8, true),
1075 2_u8)
1076 .value == PairMode::FullBridge);
1077static_assert(!DecodePairMode(0x0000'C000_u32, 3_u8).ok(), "CMxy = 3 is not a mode");
1078static_assert(DecodeFaults(0x0102'0408_u32) == Faults{.overcurrent = 0x01,
1079 .hit_not_reached = 0x02,
1080 .open_load = 0x04,
1081 .plunger = 0x08});
1082// RREF and the current are both uint32_t: a call with the two swapped is always refused, because no
1083// current the chip can regulate is a valid RREF and no valid RREF is a current it can regulate.
1084static_assert(CurrentCode(250_u32, 30000_u32, false).ok() &&
1085 !CurrentCode(30000_u32, 250_u32, false).ok());
1086static_assert(!CurrentCode(kMinRrefOhm, kMaxRrefOhm, false).ok());
1087static_assert(!FullScaleUa(kNoRref, false).ok() &&
1088 (FullScaleUa(15000_u32, false).value == 1000000U));
1090} // namespace detail
1091
1093constexpr const char* GetDriverVersion() noexcept {
1094 return MAX22200_VERSION_STRING;
1095}
1097constexpr uint32_t GetDriverVersionMajor() noexcept {
1098 return MAX22200_VERSION_MAJOR;
1099}
1101constexpr uint32_t GetDriverVersionMinor() noexcept {
1102 return MAX22200_VERSION_MINOR;
1103}
1105constexpr uint32_t GetDriverVersionPatch() noexcept {
1106 return MAX22200_VERSION_PATCH;
1107}
1108
1111} // namespace max22200
1112
1113#endif // MAX22200_TYPES_HPP
constexpr uint32_t kFaultOcpShift
OCP[7:0]; channel 0 is the LSB of each byte.
Definition max22200_registers.hpp:132
constexpr uint32_t kOlEn
OL_EN: open-load detection.
Definition max22200_registers.hpp:125
constexpr uint32_t kMaskOlf
M_OLF.
Definition max22200_registers.hpp:75
constexpr uint32_t kHoldShift
HOLD[6:0] at bits 30:24.
Definition max22200_registers.hpp:115
constexpr uint32_t kDpmEn
DPM_EN: plunger-movement detection.
Definition max22200_registers.hpp:126
constexpr uint32_t kHhf
HHF flag: some channel has an HHF bit in FAULT.
Definition max22200_registers.hpp:89
constexpr uint32_t kHfs
HFS: half full-scale (KFS 7.5k instead of 15k).
Definition max22200_registers.hpp:113
constexpr uint32_t kTrgnspi
TRGnSPI: the TRIGA/TRIGB pin switches it.
Definition max22200_registers.hpp:116
constexpr uint32_t kMaskOvt
M_OVT: OVT does not assert FAULT.
Definition max22200_registers.hpp:73
constexpr uint32_t kStatusReset
0x00040002 after power-up.
Definition max22200_registers.hpp:101
constexpr uint32_t kFlagsMask
The seven read-only flags, bits 7:1.
Definition max22200_registers.hpp:99
constexpr uint32_t kDpm
DPM flag: some channel has a DPM bit in FAULT.
Definition max22200_registers.hpp:91
constexpr uint32_t kFaultDpmShift
DPM[7:0].
Definition max22200_registers.hpp:135
constexpr uint32_t kOnchShift
ONCH[7:0]: bit 24 + n switches channel n on.
Definition max22200_registers.hpp:72
constexpr uint32_t kHitTimeShift
HIT_T[7:0] at bits 15:8.
Definition max22200_registers.hpp:119
constexpr uint32_t kDpmIpthMask
DPM_IPTH width.
Definition max22200_registers.hpp:163
constexpr uint32_t kOvt
OVT flag; a STATUS read clears it.
Definition max22200_registers.hpp:84
constexpr uint32_t PairModeShift(uint8_t pair) noexcept
Shift of a channel pair's CMxy field in STATUS.
Definition max22200_registers.hpp:108
constexpr uint32_t kVdrncdr
VDRnCDR: 1 = voltage drive, 0 = current drive.
Definition max22200_registers.hpp:120
constexpr uint32_t kWritableMask
Every bit a write sets.
Definition max22200_registers.hpp:100
constexpr uint32_t kDpmIstartMask
DPM_ISTART width.
Definition max22200_registers.hpp:159
constexpr uint32_t kHitShift
HIT[6:0] at bits 22:16.
Definition max22200_registers.hpp:118
constexpr uint32_t kSrc
SRC: slew-rate controlled edges.
Definition max22200_registers.hpp:124
constexpr uint32_t kDpmUsedMask
Bits 31:15 "must be set at zero".
Definition max22200_registers.hpp:164
constexpr uint32_t kComer
COMER: a write had the wrong number of clocks.
Definition max22200_registers.hpp:93
constexpr uint32_t kDpmIpthShift
DPM_IPTH[3:0] at bits 3:0.
Definition max22200_registers.hpp:162
constexpr uint32_t kActive
ACTIVE: 0 = low-power, channels Hi-Z (reset).
Definition max22200_registers.hpp:97
constexpr uint32_t kHhfEn
HHF_EN: HIT-current check.
Definition max22200_registers.hpp:127
constexpr uint32_t kDpmTdebShift
DPM_TDEB[3:0] at bits 7:4.
Definition max22200_registers.hpp:160
constexpr uint32_t kMaskUvm
M_UVM.
Definition max22200_registers.hpp:79
constexpr uint32_t kMaskOcp
M_OCP.
Definition max22200_registers.hpp:74
constexpr uint32_t kFreqm
FREQM: 0 = 100 kHz, 1 = 80 kHz oscillator.
Definition max22200_registers.hpp:80
constexpr uint32_t kDpmIstartShift
DPM_ISTART[6:0] at bits 14:8.
Definition max22200_registers.hpp:158
constexpr uint32_t kOlf
OLF flag: some channel has an OLF bit in FAULT.
Definition max22200_registers.hpp:87
constexpr uint32_t kFaultHhfShift
HHF[7:0].
Definition max22200_registers.hpp:133
constexpr uint32_t kMaskComf
M_COMF; 1 at reset (COMER masked).
Definition max22200_registers.hpp:78
constexpr uint32_t kDpmTdebMask
DPM_TDEB width.
Definition max22200_registers.hpp:161
constexpr uint32_t kFreqCfgShift
FREQ_CFG[1:0] at bits 5:4.
Definition max22200_registers.hpp:123
constexpr uint32_t kWakeUpUs
tWU max: ACTIVE = 1 to outputs active.
Definition max22200_registers.hpp:168
constexpr uint32_t kOcp
OCP flag: some channel has an OCP bit in FAULT.
Definition max22200_registers.hpp:85
constexpr uint32_t kMaskDpm
M_DPM.
Definition max22200_registers.hpp:77
constexpr uint32_t kUvm
Definition max22200_registers.hpp:95
constexpr uint32_t kFaultOlfShift
OLF[7:0].
Definition max22200_registers.hpp:134
constexpr uint32_t kCodeMask
Width of HIT and HOLD.
Definition max22200_registers.hpp:128
constexpr uint32_t kHsnls
HSnLS: 1 = high side (VDR only).
Definition max22200_registers.hpp:122
constexpr uint32_t kMaskHhf
M_HHF.
Definition max22200_registers.hpp:76
constexpr const char * GetDriverVersion() noexcept
Definition max22200_types.hpp:1093
constexpr bool ValidLoadDiagnostics(const ChannelConfig &c, uint8_t loaded_channels, uint8_t channel) noexcept
Check that a channel enables a load-dependent diagnostic only when a load is declared on it (handbook...
Definition max22200_types.hpp:966
constexpr uint8_t kChannels
Channels of the chip.
Definition max22200_types.hpp:334
constexpr uint32_t EncodeChannel(const ChannelConfig &c) noexcept
Encode a channel configuration as its CFG_CHn value (Table 11).
Definition max22200_types.hpp:608
constexpr bool ValidCode(uint8_t code, DriveMode drive) noexcept
Check a HIT or HOLD code against its channel's drive mode.
Definition max22200_types.hpp:914
constexpr uint8_t kPairs
Channel pairs (0-1, 2-3, 4-5, 6-7).
Definition max22200_types.hpp:336
constexpr Result< PairMode > DecodePairMode(uint32_t status, uint8_t pair) noexcept
Decode one pair's CMxy field of a STATUS value. The field is two bits wide but only 0 to 2 are modes ...
Definition max22200_types.hpp:701
constexpr uint32_t kDefaultWakeTimeoutUs
Definition max22200_types.hpp:364
BridgeState
The state of a pair in PairMode::FullBridge (Table 7).
Definition max22200_types.hpp:279
constexpr uint32_t EncodeStatus(const Config &config, uint8_t on_mask, bool active) noexcept
The STATUS value the driver writes (Table 10): ONCH, the masks, FREQM, CMxy and ACTIVE.
Definition max22200_types.hpp:654
constexpr uint8_t kHitTimeNone
HIT_T code for no HIT phase (Table 5).
Definition max22200_types.hpp:343
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition max22200_types.hpp:96
constexpr uint32_t kKfs
KFS with HFS = 0, in A/A (Electrical Characteristics, KFS0): IFS = KFS x 1 V / RREF.
Definition max22200_types.hpp:358
constexpr ChannelConfig DecodeChannel(uint32_t v) noexcept
Decode a CFG_CHn value (Table 11).
Definition max22200_types.hpp:630
constexpr Status DecodeStatus(uint32_t v) noexcept
Decode a STATUS value.
Definition max22200_types.hpp:678
constexpr uint8_t kHitTimeContinuous
Definition max22200_types.hpp:348
DriveMode
How a channel regulates, VDRnCDR.
Definition max22200_types.hpp:259
constexpr DpmConfig DecodeDpm(uint32_t v) noexcept
Decode a CFG_DPM value.
Definition max22200_types.hpp:737
constexpr Result< uint32_t > HitTimeUs(uint8_t code, MasterClock clock, ChopDivider chop) noexcept
The HIT time of a code: code x 40 / fCHOP (Table 5). Exact.
Definition max22200_types.hpp:781
constexpr uint32_t kNoRref
Definition max22200_types.hpp:356
constexpr Result< uint8_t > HitTimeCode(uint32_t us, MasterClock clock, ChopDivider chop) noexcept
The HIT_T code nearest to a HIT time (Table 5).
Definition max22200_types.hpp:801
constexpr Result< uint32_t > FullScaleUa(uint32_t rref_ohm, bool half_scale) noexcept
The full-scale current IFS = KFS x 1 V / RREF ("Full-Scale Current Setting"); HFS halves KFS.
Definition max22200_types.hpp:832
constexpr Error ValidateChannel(const ChannelConfig &c, MasterClock clock) noexcept
Check one channel's configuration without touching the chip.
Definition max22200_types.hpp:937
constexpr uint32_t DebounceUs(uint8_t code, MasterClock clock, ChopDivider chop) noexcept
The DPM debounce time of a code: code / fCHOP (CFG_DPM). Exact.
Definition max22200_types.hpp:820
MasterClock
The oscillator, STATUS.FREQM (global): the time base of every channel.
Definition max22200_types.hpp:245
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition max22200_types.hpp:1097
constexpr uint32_t kMaxRrefOhm
Largest RREF of the recommended range, in ohms.
Definition max22200_types.hpp:352
Verify
Extra verification for one call, chosen per call (handbook KB-ARCH-041).
Definition max22200_types.hpp:224
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition max22200_types.hpp:39
constexpr uint32_t kMaxWakeTimeoutUs
Longest Config::wake_timeout_us: 10 s.
Definition max22200_types.hpp:368
Variant
Which part is fitted. The chip cannot tell, so it is configured: the two differ only in how a FAULT r...
Definition max22200_types.hpp:239
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition max22200_types.hpp:1105
constexpr uint32_t kWakePollUs
Definition max22200_types.hpp:371
constexpr uint8_t kMaxVdrCode
Highest VDR duty code: 100 is 100 % (Table 3); 101 to 127 mean the same and are refused.
Definition max22200_types.hpp:341
PairMode
What a channel pair does, CMxy in STATUS ("Supported Driver Configurations").
Definition max22200_types.hpp:272
constexpr Result< uint8_t > DpmCurrentCode(uint32_t ma, uint32_t rref_ohm, uint8_t max_code) noexcept
The DPM_ISTART or DPM_IPTH code nearest to a current: current x 127 / IFS (CFG_DPM; note 127 here,...
Definition max22200_types.hpp:890
constexpr uint32_t EncodeDpm(const DpmConfig &d) noexcept
Encode the DPM settings as the CFG_DPM value; bits 31:15 stay 0.
Definition max22200_types.hpp:726
constexpr uint32_t ChopPeriodNs(MasterClock clock, ChopDivider chop) noexcept
One chopping period, in nanoseconds: divider / fMAIN (Table 1). Exact.
Definition max22200_types.hpp:753
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition max22200_types.hpp:1101
constexpr DutyLimits DutyLimitsOf(ChopDivider chop, bool slew_rate_control) noexcept
The duty-cycle limits the chip applies to a channel (Table 2). The chip clamps the codes by itself; t...
Definition max22200_types.hpp:765
constexpr bool ValidHighSide(const ChannelConfig &c) noexcept
Check what the high side lacks ("Low-Side/High-Side Operations (HSnLS)").
Definition max22200_types.hpp:923
constexpr Result< uint32_t > CurrentUa(uint8_t code, uint32_t rref_ohm, bool half_scale) noexcept
The CDR peak current of a code: code / 128 x IFS (Table 4, "/ 2^7").
Definition max22200_types.hpp:848
ChopDivider
A channel's chopping frequency as a division of the oscillator, FREQ_CFG (Table 1).
Definition max22200_types.hpp:251
Side
Where the load is tied, HSnLS.
Definition max22200_types.hpp:266
LogLevel
Severity passed to the optional Log() hook.
Definition max22200_types.hpp:210
constexpr uint32_t kMinRrefOhm
Smallest RREF of the recommended range, in ohms ("Full-Scale Current Setting").
Definition max22200_types.hpp:350
constexpr uint8_t kMaxCdrCode
Definition max22200_types.hpp:339
constexpr uint32_t kMinWakeTimeoutUs
Shortest Config::wake_timeout_us: one tWU.
Definition max22200_types.hpp:366
constexpr Result< uint8_t > CurrentCode(uint32_t ma, uint32_t rref_ohm, bool half_scale) noexcept
The CDR code nearest to a peak current: current x 128 / IFS (Table 4).
Definition max22200_types.hpp:866
constexpr uint8_t kMaxHitTimeCode
Highest finite HIT_T code (Table 5).
Definition max22200_types.hpp:345
constexpr Faults DecodeFaults(uint32_t v) noexcept
Decode a FAULT value (Table 12).
Definition max22200_types.hpp:714
constexpr uint8_t kStartAttempts
Start-up attempts when the chip reports COMER (Figure 6: "repeat the procedure").
Definition max22200_types.hpp:360
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the chip.
Definition max22200_types.hpp:1000
@ Forward
ONCHy = 0, ONCHx = 1: OUTx at VM, OUTy regulated with CFG_CHy.
@ Reverse
ONCHy = 1, ONCHx = 0: OUTy at VM, OUTx regulated with CFG_CHx.
@ Brake
ONCHy = 1, ONCHx = 1: both outputs at ground.
@ HiZ
ONCHy = 0, ONCHx = 0: both outputs Hi-Z.
@ Vdr
Voltage drive regulation: HIT and HOLD are PWM duty cycles in percent (Table 3).
@ Khz100
100 kHz. The reset value.
@ None
No extra transfer and no compare. The default.
@ ReadBack
Read the register back and compare it; check COMER.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ Crc
Not returned by this driver (the chip sends no CRC).
@ Bus
The port's Transfer() (or EnsureInitialized()) returned false.
@ Ok
The call succeeded.
@ Busy
Not returned by this driver (the chip is never busy to SPI).
@ Max22200A
Selective clear on read: only the flags whose SDI bit is high clear.
@ Max22200
Every FAULT read clears every flag, whatever SDI carries. The default.
@ Parallel
OUTx and OUTy tied together; the lower channel's CFG_CH drives both.
@ FullBridge
An H-bridge: ONCHy and ONCHx choose the state (Table 7).
@ Independent
Two half-bridges. The reset value.
@ Div1
fMAIN: 100 kHz (80 kHz).
@ Div3
fMAIN / 3: 33.3 kHz (26.7 kHz).
@ Div4
fMAIN / 4: 25 kHz (20 kHz at 80 kHz). The reset value.
@ Div2
fMAIN / 2: 50 kHz (40 kHz).
@ Low
Load from OUTn to VM. The reset value.
@ High
Load from OUTn to ground: VDR only, no SRC, HFS or DPM.
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised.
@ Debug
Detail for bring-up.
Compile-time helpers of the MAX22200 driver: exact hook matching, typed register fields and enumerati...
MAX22200 register map: the Command Register, the 32-bit register banks, their fields,...
The MAX22200 driver: everything it declares lives here; internals in detail.
Definition max22200.hpp:27
One channel's CFG_CHn register, as codes (Table 11). ChannelConfig{} is the reset value: CDR,...
Definition max22200_types.hpp:381
bool plunger_detect
DPM_EN: low side only; settings in DpmConfig.
Definition max22200_types.hpp:395
uint8_t hold
HOLD[6:0], as hit. Can change on the fly (SetHoldCode()).
Definition max22200_types.hpp:388
bool half_scale
HFS: IFS halved, RON doubled; low side only.
Definition max22200_types.hpp:391
uint8_t hit_time
HIT_T[7:0]: 0 none, 1 to 254 (HitTimeUs()), 255 continuous (Table 5).
Definition max22200_types.hpp:389
bool hit_current_check
HHF_EN: CDR only.
Definition max22200_types.hpp:396
uint8_t hit
Definition max22200_types.hpp:387
bool slew_rate_control
SRC: low side, fCHOP below 50 kHz only.
Definition max22200_types.hpp:393
friend constexpr bool operator==(const ChannelConfig &lhs, const ChannelConfig &rhs) noexcept=default
ChopDivider chop
FREQ_CFG.
Definition max22200_types.hpp:390
DriveMode drive
VDRnCDR. Changes only with every channel off.
Definition max22200_types.hpp:382
Side side
Definition max22200_types.hpp:383
bool trigger_pin
TRGnSPI: switched by TRIGA (even) or TRIGB (odd), not ONCH.
Definition max22200_types.hpp:392
bool open_load_detect
OL_EN.
Definition max22200_types.hpp:394
What the driver is told about the chip and the board. Config{} holds the reset values of STATUS and e...
Definition max22200_types.hpp:456
FaultMask fault_mask
M_OVT to M_UVM.
Definition max22200_types.hpp:471
MasterClock clock
FREQM.
Definition max22200_types.hpp:470
std::array< ChannelConfig, kChannels > channels
CFG_CH0 to CFG_CH7; index = channel.
Definition max22200_types.hpp:473
Variant variant
Definition max22200_types.hpp:457
DpmConfig dpm
CFG_DPM.
Definition max22200_types.hpp:474
uint8_t loaded_channels
Definition max22200_types.hpp:469
std::array< PairMode, kPairs > pairs
CM10, CM32, CM54, CM76; index = pair.
Definition max22200_types.hpp:472
uint32_t wake_timeout_us
Definition max22200_types.hpp:464
uint32_t rref_ohm
Definition max22200_types.hpp:461
The plunger-movement detection settings, CFG_DPM (global, for every channel with ChannelConfig::plung...
Definition max22200_types.hpp:433
uint8_t threshold
DPM_IPTH, 0 to 15: dip threshold = code x IFS / 127.
Definition max22200_types.hpp:436
friend constexpr bool operator==(const DpmConfig &lhs, const DpmConfig &rhs) noexcept=default
uint8_t debounce
DPM_TDEB, 0 to 15: chopping periods (DebounceUs()).
Definition max22200_types.hpp:435
uint8_t start
DPM_ISTART, 0 to 127: ISTART = code x IFS / 127 (DpmCurrentCode()).
Definition max22200_types.hpp:434
The duty-cycle limits the chip applies (Table 2), in percent.
Definition max22200_types.hpp:594
uint8_t max_percent
δMAX.
Definition max22200_types.hpp:596
uint8_t min_percent
δMIN.
Definition max22200_types.hpp:595
The fault masks, STATUS[23:17]: a masked fault does not pull FAULT low (its flag is still set)....
Definition max22200_types.hpp:411
bool hit_not_reached
M_HHF.
Definition max22200_types.hpp:415
bool overcurrent
M_OCP.
Definition max22200_types.hpp:413
bool open_load
M_OLF.
Definition max22200_types.hpp:414
bool overtemperature
M_OVT.
Definition max22200_types.hpp:412
bool undervoltage
M_UVM.
Definition max22200_types.hpp:418
friend constexpr bool operator==(const FaultMask &lhs, const FaultMask &rhs) noexcept=default
bool plunger
M_DPM.
Definition max22200_types.hpp:416
bool communication
M_COMF; masked at reset.
Definition max22200_types.hpp:417
The FAULT register: one byte per fault type, bit n for channel n (Table 12). Also used to say which f...
Definition max22200_types.hpp:500
static constexpr Faults All() noexcept
Definition max22200_types.hpp:507
uint8_t plunger
DPM[7:0]: no valid current dip during HIT.
Definition max22200_types.hpp:504
uint8_t hit_not_reached
HHF[7:0]: IHIT not reached by the end of tHIT.
Definition max22200_types.hpp:502
friend constexpr bool operator==(const Faults &lhs, const Faults &rhs) noexcept=default
constexpr Faults Or(const Faults &other) const noexcept
Definition max22200_types.hpp:524
uint8_t overcurrent
OCP[7:0]: the channel was switched off (turn it off, then on).
Definition max22200_types.hpp:501
constexpr bool Any() const noexcept
Definition max22200_types.hpp:511
uint8_t open_load
OLF[7:0].
Definition max22200_types.hpp:503
constexpr uint8_t Channels() const noexcept
Definition max22200_types.hpp:515
constexpr Faults And(const Faults &mask) const noexcept
Definition max22200_types.hpp:538
The flags the driver has seen since the last ClearLatchedFaults() (handbook KB-CPP-119): OVT and UVM ...
Definition max22200_types.hpp:565
bool open_load
OLF in a fault byte: some channel had an OLF flag.
Definition max22200_types.hpp:570
bool undervoltage
Definition max22200_types.hpp:567
Faults faults
Definition max22200_types.hpp:576
bool hit_not_reached
HHF in a fault byte: some channel had an HHF flag.
Definition max22200_types.hpp:571
bool plunger
DPM in a fault byte: some channel had a DPM flag.
Definition max22200_types.hpp:572
bool lost
Definition max22200_types.hpp:573
constexpr bool Any() const noexcept
Definition max22200_types.hpp:580
friend constexpr bool operator==(const LatchedFaults &lhs, const LatchedFaults &rhs) noexcept=default
bool overcurrent
OCP in a fault byte: some channel had an OCP flag.
Definition max22200_types.hpp:569
bool overtemperature
OVT seen by a STATUS read or in a fault byte.
Definition max22200_types.hpp:566
static constexpr Result Success() noexcept
Definition max22200_types.hpp:196
constexpr bool ok() const noexcept
Definition max22200_types.hpp:187
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition max22200_types.hpp:204
The value of a call, or why there is none.
Definition max22200_types.hpp:150
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition max22200_types.hpp:176
constexpr bool ok() const noexcept
Definition max22200_types.hpp:155
static constexpr Result Success(T v) noexcept
A successful result.
Definition max22200_types.hpp:168
STATUS as read (ReadStatus()): the channels that are on and the seven flags.
Definition max22200_types.hpp:478
bool overcurrent
OCP: some channel has an OCP flag in FAULT.
Definition max22200_types.hpp:481
uint8_t on_mask
ONCH[7:0]: bit n = channel n on.
Definition max22200_types.hpp:479
bool hit_not_reached
HHF: some channel has an HHF flag in FAULT.
Definition max22200_types.hpp:483
uint32_t raw
The whole register.
Definition max22200_types.hpp:488
bool active
ACTIVE.
Definition max22200_types.hpp:487
bool undervoltage
UVM: VM fell below UVLO (cleared by this read).
Definition max22200_types.hpp:486
bool plunger
DPM: some channel has a DPM flag in FAULT.
Definition max22200_types.hpp:484
bool communication
COMER: a write was ignored for its clock count.
Definition max22200_types.hpp:485
bool open_load
OLF: some channel has an OLF flag in FAULT.
Definition max22200_types.hpp:482
constexpr bool AnyFlag() const noexcept
Definition max22200_types.hpp:491
bool overtemperature
OVT (cleared by this read).
Definition max22200_types.hpp:480