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,16 +178,25 @@ static void write_dr(uint8_t data) {
|
|||
}
|
||||
|
||||
|
||||
static void wait_ready() {
|
||||
while (read_ir() & _BV(7));
|
||||
static bool wait_ready() {
|
||||
// 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) {
|
||||
wait_ready();
|
||||
if (wait_ready()) {
|
||||
write_ir(command);
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
write_dr(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loop() {
|
||||
|
|
Loading…
Reference in a new issue