diff --git a/pt2001/include/rusefi/pt2001.h b/pt2001/include/rusefi/pt2001.h index c03d2fa..f313dbc 100644 --- a/pt2001/include/rusefi/pt2001.h +++ b/pt2001/include/rusefi/pt2001.h @@ -14,6 +14,18 @@ void initMc33816(); +enum class McFault : uint8_t +{ + None = 0, + NoFlash = 1, + UnderVoltageAfter = 2, + NoComm = 3, + flag0 = 4, + UnderVoltage5 = 5, + Driven = 6, + UnderVoltage7 = 7, +}; + class Pt2001Base { public: // Reinitialize the PT2001 chip, returns true if successful @@ -22,12 +34,18 @@ public: // Disable the PT2001 chip. void shutdown(); + void onError(McFault fault) { + this->fault = fault; + } + // Re-read timing configuration and reconfigure the chip. This is safe to call while operating. void setTimings(); // Set the boost voltage target. This is safe to call while operating. void setBoostVoltage(float volts); + McFault fault = McFault::None; + private: // SPI tx/rx helpers void send(uint16_t tx) { diff --git a/pt2001/src/pt2001.cpp b/pt2001/src/pt2001.cpp index 6ae9de0..292bdc1 100644 --- a/pt2001/src/pt2001.cpp +++ b/pt2001/src/pt2001.cpp @@ -436,14 +436,14 @@ bool Pt2001Base::restart() { clearDriverStatus(); // Initial clear necessary uint16_t status = readDriverStatus(); if (checkUndervoltV5(status)) { - onError("MC33 5V Under-Voltage!"); + onError(McFault::UnderVoltage5); shutdown(); return false; } uint16_t chipId = readId(); if (!validateChipId(chipId)) { - onError("No comm with MC33"); + onError(McFault::NoComm); shutdown(); return false; } @@ -456,7 +456,7 @@ bool Pt2001Base::restart() { // current configuration of REG_MAIN would toggle flag0 from LOW to HIGH flag0after = readFlag0(); if (flag0before || !flag0after) { - onError("MC33 flag0 transition no buena"); + onError(McFault::flag0); shutdown(); return false; } @@ -475,14 +475,14 @@ bool Pt2001Base::restart() { sleepMs(10); if (!checkFlash()) { - onError("MC33 no flash"); + onError(McFault::NoFlash); shutdown(); return false; } status = readDriverStatus(); if (checkUndervoltVccP(status)) { - onError("MC33 VccP (7V) Under-Voltage!"); + onError(McFault::UnderVoltage7); shutdown(); return false; } @@ -492,14 +492,14 @@ bool Pt2001Base::restart() { sleepMs(10); // Give it a moment status = readDriverStatus(); if (!checkDrivenEnabled(status)) { - onError("MC33 Driven did not stick!"); + onError(McFault::Driven); shutdown(); return false; } status = readDriverStatus(); if (checkUndervoltVccP(status)) { - onError("MC33 VccP Under-Voltage After Driven"); // Likely DC-DC LS7 is dead! + onError(McFault::UnderVoltageAfter); // Likely DC-DC LS7 is dead! shutdown(); return false; }