diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-03-06 13:45:48 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-03-06 13:45:48 -0500 |
| commit | c854f6617a0b343333635fe0cc91419daff7cdd5 (patch) | |
| tree | e784d33bdf651927f5ea71029327ce966ae83c49 /shared-module | |
| parent | 2eaa98ad7103ea4a03fc10fbcee7d2ec7a045a70 (diff) | |
check display-bus transaction status and act accordingly
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/displayio/Display.c | 16 | ||||
| -rw-r--r-- | shared-module/displayio/__init__.c | 6 |
2 files changed, 18 insertions, 4 deletions
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 95c5cdfec..2f2ba0665 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -69,7 +69,11 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->bus = bus; uint32_t i = 0; - self->begin_transaction(self->bus); + while (!self->begin_transaction(self->bus)) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP ; +#endif + } while (i < init_sequence_len) { uint8_t *cmd = init_sequence + i; uint8_t data_size = *(cmd + 1); @@ -198,9 +202,14 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, return ok; } -void displayio_display_start_region_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { +// This routine is meant to be called as a background task. If it cannot acquire the display bus, +// it will return false immediately to indicate it didn't do anything. +bool displayio_display_start_region_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { // TODO(tannewt): Handle displays with single byte bounds. - self->begin_transaction(self->bus); + if (!self->begin_transaction(self->bus)) { + // Could not acquire the bus; give up. + return false; + } uint16_t data[2]; self->send(self->bus, true, &self->set_column_command, 1); data[0] = __builtin_bswap16(x0 + self->colstart); @@ -211,6 +220,7 @@ void displayio_display_start_region_update(displayio_display_obj_t* self, uint16 data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); self->send(self->bus, false, (uint8_t*) data, 4); self->send(self->bus, true, &self->write_ram_command, 1); + return true; } void displayio_display_finish_region_update(displayio_display_obj_t* self) { diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 79014fb5a..58a6ce471 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -60,7 +60,11 @@ void displayio_refresh_displays(void) { if (display->transpose_xy) { swap(&c1, &r1); } - displayio_display_start_region_update(display, c0, r0, c1, r1); + // Someone else is holding the bus used to talk to the display, + // so skip update for now. + if (!displayio_display_start_region_update(display, c0, r0, c1, r1)) { + return; + } uint16_t x0 = 0; uint16_t x1 = display->width - 1; |
