Skip to content

Commit

Permalink
GDI error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Jun 12, 2023
1 parent 1e60b23 commit 11612c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions pt2001/include/rusefi/pt2001.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,12 +34,18 @@ class Pt2001Base {
// 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) {
Expand Down
14 changes: 7 additions & 7 deletions pt2001/src/pt2001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 11612c6

Please sign in to comment.