Skip to content

Commit

Permalink
Add array for data pins
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Mar 16, 2024
1 parent 15f0584 commit a86e42c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 46 deletions.
61 changes: 15 additions & 46 deletions cpp/buses/rpi_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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()
Expand Down Expand Up @@ -425,8 +396,6 @@ inline void RpiBus::SetDAT(uint8_t dat)

void RpiBus::CreateWorkTable(void)
{
constexpr array<int, 9> pins = { PIN_DT0, PIN_DT1, PIN_DT2, PIN_DT3, PIN_DT4, PIN_DT5, PIN_DT6, PIN_DT7, PIN_DP };

array<bool, 256> tblParity;

// Create parity table
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(pins.size()); j++) {
for (int j = 0; j < static_cast<int>(DATA_PINS.size()); j++) {
if (bits & 1) {
gpset |= (1 << pins[j]);
} else {
Expand Down
3 changes: 3 additions & 0 deletions cpp/buses/rpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class RpiBus final : public Bus
constexpr static array<int, 19> 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<int, 9> 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;

Expand Down

0 comments on commit a86e42c

Please sign in to comment.