X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/0d243252f0fb3a3e200df404884e3cc7d872ee13..HEAD:/displayio/_displaycore.py diff --git a/displayio/_displaycore.py b/displayio/_displaycore.py index 3126b87..286f903 100644 --- a/displayio/_displaycore.py +++ b/displayio/_displaycore.py @@ -24,14 +24,14 @@ __repo__ = "https://github.com/adafruit/Adafruit_Blinka_Displayio.git" import time import struct -import circuitpython_typing -from paralleldisplay import ParallelBus -from ._fourwire import FourWire +from circuitpython_typing import WriteableBuffer, ReadableBuffer +from paralleldisplaybus import ParallelBus +from fourwire import FourWire +from i2cdisplaybus import I2CDisplayBus +from busdisplay._displaybus import _DisplayBus from ._group import Group -from ._i2cdisplay import I2CDisplay from ._structs import ColorspaceStruct, TransformStruct from ._area import Area -from ._displaybus import _DisplayBus from ._helpers import bswap16 from ._constants import ( CHIP_SELECT_UNTOUCHED, @@ -99,8 +99,9 @@ class _DisplayCore: self.last_refresh = 0 if bus: - if isinstance(bus, (FourWire, I2CDisplay, ParallelBus)): + if isinstance(bus, (FourWire, I2CDisplayBus, 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 @@ -117,16 +118,13 @@ class _DisplayCore: self.rotation = rotation self.transform = TransformStruct() + self.set_rotation(rotation) + def set_rotation(self, rotation: int) -> None: """ Sets the rotation of the display as an int in degrees. """ # pylint: disable=protected-access, too-many-branches - transposed = self.rotation in (90, 270) - will_be_transposed = rotation in (90, 270) - if transposed != will_be_transposed: - self.width, self.height = self.height, self.width - height = self.height width = self.width @@ -175,28 +173,14 @@ class _DisplayCore: self.transform.y = height self.transform.dy = -1 - if self.current_group is not None: - self.current_group._update_transform(self.transform) - - def show(self, root_group: Group) -> bool: - # pylint: disable=protected-access - + def set_root_group(self, root_group: Group) -> bool: """ Switches to displaying the given group of layers. When group is `None`, the default CircuitPython terminal will be shown. :param Optional[displayio.Group] root_group: The group to show. """ - - """ - # TODO: Implement Supervisor - if root_group is None: - circuitpython_splash = _Supervisor().circuitpython_splash - if not circuitpython_splash._in_group: - root_group = circuitpython_splash - elif self.current_group == circuitpython_splash: - return True - """ + # pylint: disable=protected-access if root_group == self.current_group: return True @@ -248,8 +232,8 @@ class _DisplayCore: def fill_area( self, area: Area, - mask: circuitpython_typing.WriteableBuffer, - buffer: circuitpython_typing.WriteableBuffer, + mask: WriteableBuffer, + buffer: WriteableBuffer, ) -> bool: """Call the current group's fill area function""" if self.current_group is not None: @@ -258,21 +242,6 @@ class _DisplayCore: ) return False - """ - def _clip(self, rectangle): - if self._core.rotation in (90, 270): - width, height = self._core.height, self._core.width - else: - width, height = self._core.width, self._core.height - - rectangle.x1 = max(rectangle.x1, 0) - rectangle.y1 = max(rectangle.y1, 0) - rectangle.x2 = min(rectangle.x2, width) - rectangle.y2 = min(rectangle.y2, height) - - return rectangle - """ - def clip_area(self, area: Area, clipped: Area) -> bool: """Shrink the area to the region shared by the two areas""" @@ -280,7 +249,8 @@ class _DisplayCore: if not overlaps: return False - # Expand the area if we have multiple pixels per byte and we need to byte align the bounds + # Expand the area if we have multiple pixels per byte and we need to byte + # align the bounds if self.colorspace.depth < 8: pixels_per_byte = ( 8 // self.colorspace.depth * self.colorspace.bytes_per_cell @@ -308,12 +278,11 @@ class _DisplayCore: if self.colorspace.depth < 8: pixels_per_byte = 8 // self.colorspace.depth if self.colorspace.pixels_in_byte_share_row: - region_x1 /= pixels_per_byte * self.colorspace.bytes_per_cell - region_x2 /= pixels_per_byte * self.colorspace.bytes_per_cell + region_x1 //= pixels_per_byte * self.colorspace.bytes_per_cell + region_x2 //= pixels_per_byte * self.colorspace.bytes_per_cell else: - region_y1 /= pixels_per_byte * self.colorspace.bytes_per_cell - region_y2 /= pixels_per_byte * self.colorspace.bytes_per_cell - + region_y1 //= pixels_per_byte * self.colorspace.bytes_per_cell + region_y2 //= pixels_per_byte * self.colorspace.bytes_per_cell region_x2 -= 1 region_y2 -= 1 @@ -323,27 +292,21 @@ class _DisplayCore: # Set column self.begin_transaction() + data = bytearray([self.column_command]) data_type = DISPLAY_DATA if not self.data_as_commands: - self.send( - DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([self.column_command]) - ) + self.send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data) + data = bytearray(0) else: data_type = DISPLAY_COMMAND - """ - self._core.send( - DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command]) + data - ) - self._core.send(DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, data) - """ if self.ram_width < 0x100: # Single Byte Bounds - data = struct.pack(">BB", region_x1, region_x2) + data += struct.pack(">BB", region_x1, region_x2) else: if self.address_little_endian: region_x1 = bswap16(region_x1) region_x2 = bswap16(region_x2) - data = struct.pack(">HH", region_x1, region_x2) + data += struct.pack(">HH", region_x1, region_x2) # Quirk for SH1107 "SH1107_addressing" # Column lower command = 0x00, Column upper command = 0x10 @@ -368,17 +331,18 @@ class _DisplayCore: # Set row self.begin_transaction() + data = bytearray([self.row_command]) if not self.data_as_commands: - self.send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([self.row_command])) - - if self.ram_width < 0x100: # Single Byte Bounds - data = struct.pack(">BB", region_y1, region_y2) + self.send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data) + data = bytearray(0) + if self.ram_height < 0x100: # Single Byte Bounds + data += struct.pack(">BB", region_y1, region_y2) else: if self.address_little_endian: region_y1 = bswap16(region_y1) region_y2 = bswap16(region_y2) - data = struct.pack(">HH", region_y1, region_y2) + data += struct.pack(">HH", region_y1, region_y2) # Quirk for SH1107 "SH1107_addressing" # Page address command = 0xB0 @@ -397,42 +361,28 @@ class _DisplayCore: self.send(DISPLAY_DATA, chip_select, data[: len(data) // 2]) self.end_transaction() - """ - img = self._buffer.convert("RGB").crop(astuple(area)) - img = img.rotate(360 - self._core.rotation, expand=True) - - display_area = self._apply_rotation(area) - - img = img.crop(astuple(display_area)) - - data = numpy.array(img).astype("uint16") - color = ( - ((data[:, :, 0] & 0xF8) << 8) - | ((data[:, :, 1] & 0xFC) << 3) - | (data[:, :, 2] >> 3) - ) - - pixels = bytes( - numpy.dstack(((color >> 8) & 0xFF, color & 0xFF)).flatten().tolist() - ) - """ - def send( self, data_type: int, chip_select: int, - data: circuitpython_typing.ReadableBuffer, + data: ReadableBuffer, ) -> None: """ Send the data to the current bus """ self._send(data_type, chip_select, data) - def begin_transaction(self) -> None: + def bus_free(self) -> bool: + """ + Check if the bus is free + """ + return self._bus_free() + + def begin_transaction(self) -> bool: """ Begin Bus Transaction """ - self._begin_transaction() + return self._begin_transaction() def end_transaction(self) -> None: """