]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/_i2cdisplay.py
Bug fixes for SSD1306
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _i2cdisplay.py
index 26476599fa61acc0379b3d3b27c5b54163feb86d..e37eb8a659be5b584b28e71777f7b7131b571426 100644 (file)
@@ -23,7 +23,7 @@ displayio for Blinka
 import time
 import busio
 import digitalio
-import circuitpython_typing
+from circuitpython_typing import ReadableBuffer
 from ._constants import CHIP_SELECT_UNTOUCHED, DISPLAY_COMMAND
 
 __version__ = "0.0.0+auto.0"
@@ -53,6 +53,15 @@ class I2CDisplay:
         self._i2c = i2c_bus
         self._dev_addr = device_address
 
+    def __new__(cls, *args, **kwargs):
+        from . import (  # pylint: disable=import-outside-toplevel, cyclic-import
+            allocate_display_bus,
+        )
+
+        display_bus_instance = super().__new__(cls)
+        allocate_display_bus(display_bus_instance)
+        return display_bus_instance
+
     def _release(self):
         self.reset()
         self._i2c.deinit()
@@ -76,7 +85,7 @@ class I2CDisplay:
         while not self._i2c.try_lock():
             pass
 
-    def send(self, command: int, data: circuitpython_typing.ReadableBuffer) -> None:
+    def send(self, command: int, data: ReadableBuffer) -> None:
         """
         Sends the given command value followed by the full set of data. Display state,
         such as vertical scroll, set via ``send`` may or may not be reset once the code is
@@ -89,10 +98,9 @@ class I2CDisplay:
     def _send(
         self,
         data_type: int,
-        chip_select: int,
-        data: circuitpython_typing.ReadableBuffer,
+        _chip_select: int,  # Chip select behavior
+        data: ReadableBuffer,
     ):
-        # pylint: disable=unused-argument
         if data_type == DISPLAY_COMMAND:
             n = len(data)
             if n > 0:
@@ -101,12 +109,12 @@ class I2CDisplay:
                     command_bytes[2 * i] = 0x80
                     command_bytes[2 * i + 1] = data[i]
 
-                self._i2c.writeto(self._dev_addr, buffer=command_bytes, stop=True)
+                self._i2c.writeto(self._dev_addr, buffer=command_bytes)
         else:
             data_bytes = bytearray(len(data) + 1)
             data_bytes[0] = 0x40
             data_bytes[1:] = data
-            self._i2c.writeto(self._dev_addr, buffer=data_bytes, stop=True)
+            self._i2c.writeto(self._dev_addr, buffer=data_bytes)
 
     def _end_transaction(self) -> None:
         """Release the bus after sending data."""