Add deadline on display status read
This commit is contained in:
parent
a35be5f149
commit
6b58fc2738
1 changed files with 15 additions and 6 deletions
|
@ -178,17 +178,26 @@ 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() {
|
||||||
// Check for new messages
|
// Check for new messages
|
||||||
|
|
Loading…
Reference in a new issue