From 60018dd8419d27893e183a0733f826d4158cccbb Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 12 Jun 2023 14:43:10 -0400 Subject: [PATCH] extracting method --- pt2001/include/rusefi/pt2001.h | 1 + pt2001/src/pt2001.cpp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pt2001/include/rusefi/pt2001.h b/pt2001/include/rusefi/pt2001.h index 644af5b..eb758d0 100644 --- a/pt2001/include/rusefi/pt2001.h +++ b/pt2001/include/rusefi/pt2001.h @@ -71,6 +71,7 @@ private: // Chip IO helpers uint16_t readDram(MC33816Mem addr); void writeDram(MC33816Mem addr, uint16_t data); + uint16_t readStatus(int reg); uint16_t readDriverStatus(); uint16_t readDriverStatus2(); void clearDriverStatus(); diff --git a/pt2001/src/pt2001.cpp b/pt2001/src/pt2001.cpp index b69cb9c..d859fc6 100644 --- a/pt2001/src/pt2001.cpp +++ b/pt2001/src/pt2001.cpp @@ -185,23 +185,21 @@ void Pt2001Base::clearDriverStatus(){ deselect(); } -uint16_t Pt2001Base::readDriverStatus() { +uint16_t Pt2001Base::readStatus(int reg) { setupSpi(); // ensure on common page? select(); - send((0x8000 | 0x1D2 << 5) + 1); + send((0x8000 | reg << 5) + 1); uint16_t driverStatus = recv(); deselect(); return driverStatus; } +uint16_t Pt2001Base::readDriverStatus() { + return readStatus(0x1D2); +} + uint16_t Pt2001Base::readDriverStatus2() { - // todo: shame on me extract method! - setupSpi(); // ensure on common page? - select(); - send((0x8000 | 0x1A5 << 5) + 1); - uint16_t driverStatus = recv(); - deselect(); - return driverStatus; + return readStatus(0x1A5); } static bool checkUndervoltVccP(uint16_t driverStatus){ @@ -490,6 +488,7 @@ bool Pt2001Base::restart() { } status = readDriverStatus(); + status2 = readDriverStatus2(); if (checkUndervoltVccP(status)) { onError(McFault::UnderVoltage7); shutdown();