diff --git a/adafruit_matrixportal/graphics.py b/adafruit_matrixportal/graphics.py index 8a418b1..59b6f4f 100755 --- a/adafruit_matrixportal/graphics.py +++ b/adafruit_matrixportal/graphics.py @@ -38,12 +38,16 @@ class Graphics(GraphicsBase): :param default_bg: The path to your default background image file or a hex color. Defaults to 0x000000. - :param int width: The width of the display in Pixels. Defaults to 64. - :param int height: The height of the display in Pixels. Defaults to 32. + :param int width: The total width of the display(s) in Pixels. Defaults to 64. + :param int height: The total height of the display(s) in Pixels. Defaults to 32. :param int bit_depth: The number of bits per color channel. Defaults to 2. :param list alt_addr_pins: An alternate set of address pins to use. Defaults to None :param string color_order: A string containing the letter "R", "G", and "B" in the order you want. Defaults to "RGB" + :param bool Serpentine: Used when panels are arranged in a serpentine pattern rather + than a Z-pattern. Defaults to True. + :param int tiles_rows: Used to indicate the number of rows the panels are arranged in. + Defaults to 1. :param debug: Turn on debug print outs. Defaults to False. """ @@ -58,6 +62,8 @@ def __init__( bit_depth=2, alt_addr_pins=None, color_order="RGB", + serpentine=True, + tile_rows=1, debug=False ): @@ -67,6 +73,8 @@ def __init__( height=height, alt_addr_pins=alt_addr_pins, color_order=color_order, + serpentine=serpentine, + tile_rows=tile_rows, ) super().__init__(matrix.display, default_bg=default_bg, debug=debug) diff --git a/adafruit_matrixportal/matrix.py b/adafruit_matrixportal/matrix.py index 7f9728d..7c62573 100755 --- a/adafruit_matrixportal/matrix.py +++ b/adafruit_matrixportal/matrix.py @@ -47,14 +47,29 @@ class Matrix: :param list alt_addr_pins: An alternate set of address pins to use. Defaults to None :param string color_order: A string containing the letter "R", "G", and "B" in the order you want. Defaults to "RGB" - + :param int width: The total width of the display(s) in Pixels. Defaults to 64. + :param int height: The total height of the display(s) in Pixels. Defaults to 32. + :param bool Serpentine: Used when panels are arranged in a serpentine pattern rather + than a Z-pattern. Defaults to True. + :param int tiles_rows: Used to indicate the number of rows the panels are arranged in. + Defaults to 1. """ - # pylint: disable=too-few-public-methods,too-many-branches + # pylint: disable=too-few-public-methods,too-many-branches,too-many-statements,too-many-locals def __init__( - self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, color_order="RGB" + self, + *, + width=64, + height=32, + bit_depth=2, + alt_addr_pins=None, + color_order="RGB", + serpentine=True, + tile_rows=1 ): + panel_height = height // tile_rows + if not isinstance(color_order, str): raise ValueError("color_index should be a string") color_order = color_order.lower() @@ -67,9 +82,9 @@ def __init__( if "Matrix Portal M4" in os.uname().machine: # MatrixPortal M4 Board addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC] - if height > 16: + if panel_height > 16: addr_pins.append(board.MTX_ADDRD) - if height > 32: + if panel_height > 32: addr_pins.append(board.MTX_ADDRE) rgb_pins = [ board.MTX_R1, @@ -87,13 +102,13 @@ def __init__( if "nrf52" in os.uname().sysname: # nrf52840 Style Feather addr_pins = [board.D11, board.D5, board.D13] - if height > 16: + if panel_height > 16: addr_pins.append(board.D9) rgb_pins = [board.D6, board.A5, board.A1, board.A0, board.A4, board.D11] clock_pin = board.D12 else: addr_pins = [board.A5, board.A4, board.A3] - if height > 16: + if panel_height > 16: addr_pins.append(board.A2) rgb_pins = [ board.D6, @@ -124,23 +139,50 @@ def __init__( try: displayio.release_displays() - matrix = rgbmatrix.RGBMatrix( - width=width, - height=height, - bit_depth=bit_depth, - rgb_pins=( - rgb_pins[red_index], - rgb_pins[green_index], - rgb_pins[blue_index], - rgb_pins[red_index + 3], - rgb_pins[green_index + 3], - rgb_pins[blue_index + 3], - ), - addr_pins=addr_pins, - clock_pin=clock_pin, - latch_pin=latch_pin, - output_enable_pin=oe_pin, - ) + if tile_rows > 1: + matrix = rgbmatrix.RGBMatrix( + width=width, + height=height, + bit_depth=bit_depth, + rgb_pins=( + rgb_pins[red_index], + rgb_pins[green_index], + rgb_pins[blue_index], + rgb_pins[red_index + 3], + rgb_pins[green_index + 3], + rgb_pins[blue_index + 3], + ), + addr_pins=addr_pins, + clock_pin=clock_pin, + latch_pin=latch_pin, + output_enable_pin=oe_pin, + tile=tile_rows, + serpentine=serpentine, + ) + else: + matrix = rgbmatrix.RGBMatrix( + width=width, + height=height, + bit_depth=bit_depth, + rgb_pins=( + rgb_pins[red_index], + rgb_pins[green_index], + rgb_pins[blue_index], + rgb_pins[red_index + 3], + rgb_pins[green_index + 3], + rgb_pins[blue_index + 3], + ), + addr_pins=addr_pins, + clock_pin=clock_pin, + latch_pin=latch_pin, + output_enable_pin=oe_pin, + ) self.display = framebufferio.FramebufferDisplay(matrix) + except TypeError: + if tile_rows > 1: + raise RuntimeError( + "Make sure you are running CircuitPython 6.2.0.alpha-1 or later" + ) from TypeError + raise except ValueError: raise RuntimeError("Failed to initialize RGB Matrix") from ValueError diff --git a/adafruit_matrixportal/matrixportal.py b/adafruit_matrixportal/matrixportal.py index fdb19d5..0b12723 100755 --- a/adafruit_matrixportal/matrixportal.py +++ b/adafruit_matrixportal/matrixportal.py @@ -61,6 +61,12 @@ class MatrixPortal(PortalBase): :param string color_order: A string containing the letter "R", "G", and "B" in the order you want. Defaults to "RGB" :param debug: Turn on debug print outs. Defaults to False. + :param int width: The total width of the display(s) in Pixels. Defaults to 64. + :param int height: The total height of the display(s) in Pixels. Defaults to 32. + :param bool Serpentine: Used when panels are arranged in a serpentine pattern rather + than a Z-pattern. Defaults to True. + :param int tiles_rows: Used to indicate the number of rows the panels are arranged in. + Defaults to 1. """ @@ -83,6 +89,8 @@ def __init__( debug=False, width=64, height=32, + serpentine=True, + tile_rows=1, ): graphics = Graphics( @@ -92,6 +100,8 @@ def __init__( height=height, alt_addr_pins=alt_addr_pins, color_order=color_order, + serpentine=serpentine, + tile_rows=tile_rows, debug=debug, )