Add deadline on display status read

This commit is contained in:
Gregor Riepl 2021-03-09 11:52:38 +01:00
parent a35be5f149
commit 6b58fc2738

View file

@ -178,16 +178,25 @@ static void write_dr(uint8_t data) {
} }
static void wait_ready() { static bool wait_ready() {
while (read_ir() & _BV(7)); // if the busy flag never goes high, we'll run into a deadlock here.
// let's put a deadline on the wait loop.
for (uint8_t i = 0; i < 100; i++) {
// read_ir() takes about 500ns
if (read_ir() & _BV(7)) return true;
// wait 10us until the next status read
_delay_us(10 - 0.5);
}
return false;
} }
static void write_display(uint8_t command, const uint8_t *data, uint8_t length) { static void write_display(uint8_t command, const uint8_t *data, uint8_t length) {
wait_ready(); if (wait_ready()) {
write_ir(command); write_ir(command);
for (uint8_t i = 0; i < length; i++) { for (uint8_t i = 0; i < length; i++) {
write_dr(data[i]); write_dr(data[i]);
} }
}
} }
static void loop() { static void loop() {