Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set clock polarity in software SPI implementations #1224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cppsrc/U8x8lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
uint8_t i, b;
uint8_t *data;
uint8_t takeover_edge = u8x8_GetSPIClockPhase(u8x8);
uint8_t clock_polarity = u8x8_GetSPIClockPolarity(u8x8);
//uint8_t not_takeover_edge = 1 - takeover_edge;

/* the following static vars are recalculated in U8X8_MSG_BYTE_START_TRANSFER */
Expand Down Expand Up @@ -431,6 +432,9 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
*arduino_clock_port |= arduino_clock_mask;
*arduino_clock_port &= arduino_clock_n_mask;
}
if (clock_polarity == 1) {
*arduino_clock_port |= arduino_clock_mask;
}
}
else
#endif
Expand All @@ -446,6 +450,9 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
b <<= 1;
*arduino_clock_port &= arduino_clock_n_mask;
}
if (clock_polarity == 1) {
*arduino_clock_port |= arduino_clock_mask;
}
}
SREG = SREG_backup;
}
Expand All @@ -468,6 +475,9 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
*arduino_clock_port &= arduino_clock_n_mask;
*arduino_clock_port |= arduino_clock_mask;
}
if (clock_polarity == 1) {
*arduino_clock_port |= arduino_clock_mask;
}
}
else
#endif
Expand All @@ -483,6 +493,9 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
b <<= 1;
*arduino_clock_port |= arduino_clock_mask;
}
if (clock_polarity == 1) {
*arduino_clock_port |= arduino_clock_mask;
}
}
SREG = SREG_backup;
}
Expand Down Expand Up @@ -517,6 +530,10 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
arduino_data_port = portOutputRegister(digitalPinToPort(u8x8->pins[U8X8_PIN_SPI_DATA]));
arduino_data_mask = digitalPinToBitMask(u8x8->pins[U8X8_PIN_SPI_DATA]);
arduino_data_n_mask = ~arduino_data_mask;

if (clock_polarity == 1) {
*arduino_clock_port |= arduino_clock_mask;
}

break;
case U8X8_MSG_BYTE_END_TRANSFER:
Expand Down