]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Remove debug code + add bus free
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Thu, 28 Sep 2023 22:49:42 +0000 (15:49 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Thu, 28 Sep 2023 22:49:42 +0000 (15:49 -0700)
displayio/_display.py
displayio/_displaycore.py
displayio/_fourwire.py
displayio/_i2cdisplay.py
paralleldisplay.py

index f2d02cfd4cadf90746aca796def6be7f44bba76d..8551f8c87fded9cea51a104f207a773995c698ca 100644 (file)
@@ -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()
index 96c47a83a2e8e7a62744abbdae0d71eb982dac51..76a5d18a1871e085e8ca65fd8fa2b3ffa4560c7a 100644 (file)
@@ -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
index c343e6511a407cdb39c1abfc5df58097b95da4ea..61be810d45303555fa45291437e38c1e64967b8d 100644 (file)
@@ -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():
index 7ec9467e8479865f2af63e4ab9c9fc60c1389369..9611fb09187a687351c308a3cbb07097997b8eca 100644 (file)
@@ -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()
index 8cfa87eaa9e01e7ffad68a90655e0a2f94c1a717..4e828cce49253a4a89cb07b8a5f088c6099df624 100644 (file)
@@ -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