From: Melissa LeBlanc-Williams Date: Thu, 28 Sep 2023 22:49:42 +0000 (-0700) Subject: Remove debug code + add bus free X-Git-Tag: 1.0.0^2~5 X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/commitdiff_plain/b6c1453b93053cbf2fb6aae6f09fdb8f9b9e4345 Remove debug code + add bus free --- diff --git a/displayio/_display.py b/displayio/_display.py index f2d02cf..8551f8c 100644 --- a/displayio/_display.py +++ b/displayio/_display.py @@ -338,7 +338,7 @@ class Display: def _refresh_area(self, area) -> bool: """Loop through dirty areas and redraw that area.""" - # pylint: disable=too-many-locals + # pylint: disable=too-many-locals, too-many-branches clipped = Area() # Clip the area to the display by overlapping the areas. @@ -404,6 +404,11 @@ class Display: buffer = memoryview(bytearray([0] * (buffer_size * 4))) mask = memoryview(bytearray([0] * mask_length)) self._core.fill_area(subrectangle, mask, buffer) + + # Can't acquire display bus; skip the rest of the data. + if not self._core.bus_free(): + return False + self._core.begin_transaction() self._send_pixels(buffer[:subrectangle_size_bytes]) self._core.end_transaction() diff --git a/displayio/_displaycore.py b/displayio/_displaycore.py index 96c47a8..76a5d18 100644 --- a/displayio/_displaycore.py +++ b/displayio/_displaycore.py @@ -101,6 +101,7 @@ class _DisplayCore: if bus: if isinstance(bus, (FourWire, I2CDisplay, ParallelBus)): self._bus_reset = bus.reset + self._bus_free = bus._free self._begin_transaction = bus._begin_transaction self._send = bus._send self._end_transaction = bus._end_transaction @@ -376,12 +377,14 @@ class _DisplayCore: """ Send the data to the current bus """ - print(len(data)) - if isinstance(data, memoryview): - data = data.tobytes() - print(data) self._send(data_type, chip_select, data) + def bus_free(self) -> bool: + """ + Check if the bus is free + """ + return self._bus_free() + def begin_transaction(self) -> bool: """ Begin Bus Transaction diff --git a/displayio/_fourwire.py b/displayio/_fourwire.py index c343e65..61be810 100644 --- a/displayio/_fourwire.py +++ b/displayio/_fourwire.py @@ -132,6 +132,13 @@ class FourWire: else: self._spi.write(data) + def _free(self) -> bool: + """Attempt to free the bus and return False if busy""" + if not self._spi.try_lock(): + return False + self._spi.unlock() + return True + def _begin_transaction(self) -> bool: """Begin the SPI transaction by locking, configuring, and setting Chip Select""" if not self._spi.try_lock(): diff --git a/displayio/_i2cdisplay.py b/displayio/_i2cdisplay.py index 7ec9467..9611fb0 100644 --- a/displayio/_i2cdisplay.py +++ b/displayio/_i2cdisplay.py @@ -80,10 +80,6 @@ class I2CDisplay: time.sleep(0.0001) self._reset.value = True - def _begin_transaction(self) -> bool: - """Lock the bus before sending data.""" - return self._i2c.try_lock() - def send(self, command: int, data: ReadableBuffer) -> None: """ Sends the given command value followed by the full set of data. Display state, @@ -129,6 +125,17 @@ class I2CDisplay: ) from error raise error + def _free(self) -> bool: + """Attempt to free the bus and return False if busy""" + if not self._i2c.try_lock(): + return False + self._i2c.unlock() + return True + + def _begin_transaction(self) -> bool: + """Lock the bus before sending data.""" + return self._i2c.try_lock() + def _end_transaction(self) -> None: """Release the bus after sending data.""" self._i2c.unlock() diff --git a/paralleldisplay.py b/paralleldisplay.py index 8cfa87e..4e828cc 100644 --- a/paralleldisplay.py +++ b/paralleldisplay.py @@ -77,9 +77,11 @@ class ParallelBus: ) -> None: pass + def _free(self) -> bool: + """Attempt to free the bus and return False if busy""" + def _begin_transaction(self) -> bool: - # pylint: disable=no-self-use - return True + pass def _end_transaction(self) -> None: pass