From a86e42c66e75631241f0e6b8262669abd6c6bcb6 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Sat, 16 Mar 2024 17:33:35 +0100 Subject: [PATCH] Add array for data pins --- cpp/buses/rpi_bus.cpp | 61 +++++++++++-------------------------------- cpp/buses/rpi_bus.h | 3 +++ 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/cpp/buses/rpi_bus.cpp b/cpp/buses/rpi_bus.cpp index 6de1e0d6..0e3a79c6 100644 --- a/cpp/buses/rpi_bus.cpp +++ b/cpp/buses/rpi_bus.cpp @@ -234,19 +234,10 @@ void RpiBus::Reset() SetControl(PIN_DTD, IsTarget() ? DTD_IN : DTD_OUT); const int dir = IsTarget() ? IN : OUT; - SetMode(PIN_SEL, dir); - SetMode(PIN_ATN, dir); - SetMode(PIN_ACK, dir); - SetMode(PIN_RST, dir); - SetMode(PIN_DT0, dir); - SetMode(PIN_DT1, dir); - SetMode(PIN_DT2, dir); - SetMode(PIN_DT3, dir); - SetMode(PIN_DT4, dir); - SetMode(PIN_DT5, dir); - SetMode(PIN_DT6, dir); - SetMode(PIN_DT7, dir); - SetMode(PIN_DP, dir); + for (int pin : { PIN_SEL, PIN_ATN, PIN_ACK, PIN_RST, PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, + PIN_DT7, PIN_DP }) { + SetMode(pin, dir); + } // Initialize all signals signals = 0; @@ -327,26 +318,11 @@ bool RpiBus::GetIO() if (!IsTarget()) { // Change the data input/output direction by IO signal - if (state) { - SetControl(PIN_DTD, DTD_IN); - SetMode(PIN_DT0, IN); - SetMode(PIN_DT1, IN); - SetMode(PIN_DT2, IN); - SetMode(PIN_DT3, IN); - SetMode(PIN_DT4, IN); - SetMode(PIN_DT5, IN); - SetMode(PIN_DT6, IN); - SetMode(PIN_DT7, IN); - } else { - SetControl(PIN_DTD, DTD_OUT); - SetMode(PIN_DT0, OUT); - SetMode(PIN_DT1, OUT); - SetMode(PIN_DT2, OUT); - SetMode(PIN_DT3, OUT); - SetMode(PIN_DT4, OUT); - SetMode(PIN_DT5, OUT); - SetMode(PIN_DT6, OUT); - SetMode(PIN_DT7, OUT); + SetControl(PIN_DTD, state ? DTD_IN : DTD_OUT); + + const int dir = state ? IN : OUT; + for (int pin : DATA_PINS) { + SetMode(pin, dir); } } @@ -361,16 +337,11 @@ void RpiBus::SetIO(bool state) // Change the data input/output direction by IO signal SetControl(PIN_DTD, state ? DTD_OUT : DTD_IN); + const int dir = state ? OUT : IN; - SetMode(PIN_DT0, dir); - SetMode(PIN_DT1, dir); - SetMode(PIN_DT2, dir); - SetMode(PIN_DT3, dir); - SetMode(PIN_DT4, dir); - SetMode(PIN_DT5, dir); - SetMode(PIN_DT6, dir); - SetMode(PIN_DT7, dir); - SetMode(PIN_DP, dir); + for (int pin : DATA_PINS) { + SetMode(pin, dir); + } } inline uint8_t RpiBus::GetDAT() @@ -425,8 +396,6 @@ inline void RpiBus::SetDAT(uint8_t dat) void RpiBus::CreateWorkTable(void) { - constexpr array pins = { PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP }; - array tblParity; // Create parity table @@ -457,7 +426,7 @@ void RpiBus::CreateWorkTable(void) } // Bit check - for (const int pin : pins) { + for (const int pin : DATA_PINS) { // Offset of the Function Select register for this pin (3 bits per pin) const int index = pin / 10; #if defined BOARD_STANDARD || defined BOARD_FULLSPEC @@ -490,7 +459,7 @@ void RpiBus::CreateWorkTable(void) // Create GPIO register information uint32_t gpclr = 0; uint32_t gpset = 0; - for (int j = 0; j < static_cast(pins.size()); j++) { + for (int j = 0; j < static_cast(DATA_PINS.size()); j++) { if (bits & 1) { gpset |= (1 << pins[j]); } else { diff --git a/cpp/buses/rpi_bus.h b/cpp/buses/rpi_bus.h index 3f38c07a..86e76be9 100644 --- a/cpp/buses/rpi_bus.h +++ b/cpp/buses/rpi_bus.h @@ -149,6 +149,9 @@ class RpiBus final : public Bus constexpr static array SIGNAL_TABLE = { PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP, PIN_SEL, PIN_ATN, PIN_RST, PIN_ACK, PIN_BSY, PIN_MSG, PIN_CD, PIN_IO, PIN_REQ }; + constexpr static array DATA_PINS = { PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, + PIN_DP }; + constexpr static int ARMT_CTRL = 2; constexpr static int ARMT_FREERUN = 8;