Native helper commit

This commit is contained in:
gamblor21 2021-12-10 17:42:04 -06:00
parent ff768ed8a5
commit b123bd767e
4 changed files with 1741 additions and 0 deletions

View file

@ -0,0 +1,164 @@
# SPDX-FileCopyrightText: 2016 Damien P. George
# SPDX-FileCopyrightText: 2017 Scott Shawcroft for Adafruit Industries
# SPDX-FileCopyrightText: 2019 Carter Nelson
# SPDX-FileCopyrightText: 2019 Rose Hooper
# SPDX-FileCopyrightText: 2021 Mark Komus
#
# SPDX-License-Identifier: MIT
"""
`is31fl3741` - IS31FL3741 driver
====================================================
* Author(s): Mark Komus, Damien P. George, Scott Shawcroft, Carter Nelson, Rose Hooper
"""
# pylint: disable=ungrouped-imports
import sys
from is31fl3741 import is31fl3741_write, is31fl3741_init
try:
import adafruit_pixelbuf
except ImportError:
try:
import _pixelbuf as adafruit_pixelbuf
except ImportError:
import adafruit_pypixelbuf as adafruit_pixelbuf
try:
# Used only for typing
from typing import Optional, Type
from types import TracebackType
except ImportError:
pass
__version__ = "0.0.0-auto.0"
#__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3741.git"
# Pixel color order constants
BGR = "BGR"
"""Blue Green Red"""
RGB = "RGB"
"""Red Green Blue"""
GRB = "GRB"
"""Green Red Blue"""
RGBW = "RGBW"
"""Red Green Blue White"""
GRBW = "GRBW"
"""Green Red Blue White"""
class IS31FL3741_PixelBuf(adafruit_pixelbuf.PixelBuf):
"""
A sequence of LEDs controlled by an IS31FL3741 driver.
:param ~busio.I2C i2c: the I2C bus to output with
:param ~int addr: the I2C address of the IS31FL3741 device
:param ~Tuple[int, ...] mapping: map the pixels in the buffer to the order addressed by the driver chip
:param int n: The number of neopixels in the chain
:param int bpp: Bytes per pixel. 3 for RGB and 4 for RGBW pixels.
:param float brightness: Brightness of the pixels between 0.0 and 1.0 where 1.0 is full
brightness
:param bool auto_write: True if the neopixels should immediately change when set. If False,
`show` must be called explicitly.
:param str pixel_order: Set the pixel color channel order. GRBW is set by default.
Example for Circuit Playground Express:
.. code-block:: python
import neopixel
from board import *
RED = 0x100000 # (0x10, 0, 0) also works
pixels = neopixel.NeoPixel(NEOPIXEL, 10)
for i in range(len(pixels)):
pixels[i] = RED
.. py:method:: NeoPixel.show()
Shows the new colors on the pixels themselves if they haven't already
been autowritten.
The colors may or may not be showing after this function returns because
it may be done asynchronously.
.. py:method:: NeoPixel.fill(color)
Colors all pixels the given ***color***.
.. py:attribute:: brightness
Overall brightness of the pixel (0 to 1.0)
"""
def __init__(
self,
i2c: busio.I2C,
mapping: tuple,
n: int,
*,
addr: int = 0x30,
bpp: int = 3,
brightness: float = 1.0,
auto_write: bool = True,
pixel_order: str = None,
init: bool = True
):
if not pixel_order:
pixel_order = BGR if bpp == 3 else GRBW
elif isinstance(pixel_order, tuple):
order_list = [RGBW[order] for order in pixel_order]
pixel_order = "".join(order_list)
super().__init__(
n, brightness=brightness, byteorder=pixel_order, auto_write=auto_write
)
self.i2c = i2c
self.addr = addr
if type(mapping) is not tuple:
raise AttributeError("Mapping must be a tuple")
self.mapping = mapping
if init is True:
is31fl3741_init(i2c=self.i2c, addr=self.addr)
def deinit(self) -> None:
"""Blank out the NeoPixels and release the pin."""
self.fill(0)
self.show()
def __enter__(self):
return self
def __exit__(
self,
exception_type: Optional[Type[BaseException]],
exception_value: Optional[BaseException],
traceback: Optional[TracebackType],
):
self.deinit()
def __repr__(self):
return "[" + ", ".join([str(x) for x in self]) + "]"
@property
def n(self) -> int:
"""
The number of LEDs in the chain (read-only)
"""
return len(self)
def write(self) -> None:
""".. deprecated: 1.0.0
Use ``show`` instead. It matches Micro:Bit and Arduino APIs."""
self.show()
def _transmit(self, buffer: bytearray) -> None:
is31fl3741_write(i2c=self.i2c, addr=self.addr, mapping=self.mapping, buffer=buffer)

View file

@ -0,0 +1,304 @@
# SPDX-FileCopyrightText: 2021 Mark Komus
# SPDX-License-Identifier: MIT
# Maps to link IS31FL3741 LEDs to pixels
# Full LED glasses
glassesmatrix_ledmap = (
65535, 65535, 65535, # (0,0) (clipped, corner)
10, 8, 9, # (0,1) / right ring pixel 20
13, 11, 12, # (0,2) / 19
16, 14, 15, # (0,3) / 18
4, 2, 3, # (0,4) / 17
217, 215, 216, # (1,0) / right ring pixel #21
220, 218, 219, # (1,1)
223, 221, 222, # (1,2)
226, 224, 225, # (1,3)
214, 212, 213, # (1,4)
187, 185, 186, # (2,0)
190, 188, 189, # (2,1)
193, 191, 192, # (2,2)
196, 194, 195, # (2,3)
184, 182, 183, # (2,4)
37, 35, 36, # (3,0)
40, 38, 39, # (3,1)
43, 41, 42, # (3,2)
46, 44, 45, # (3,3)
34, 32, 33, # (3,4)
67, 65, 66, # (4,0)
70, 68, 69, # (4,1)
73, 71, 72, # (4,2)
76, 74, 75, # (4,3)
64, 62, 63, # (4,4)
97, 95, 96, # (5,0)
100, 98, 99, # (5,1)
103, 101, 102, # (5,2)
106, 104, 105, # (5,3)
94, 92, 93, # (5,4)
127, 125, 126, # (6,0) / right ring pixel 3
130, 128, 129, # (6,1)
133, 131, 132, # (6,2)
136, 134, 135, # (6,3)
124, 122, 123, # (6,4)
157, 155, 156, # (7,0)
160, 158, 159, # (7,1)
163, 161, 162, # (7,2) / right ring pixel 5
166, 164, 165, # (7,3) / 6
244, 242, 243, # (7,4) / 7
247, 245, 246, # (8,0)
250, 248, 249, # (8,1)
253, 251, 252, # (8,2)
256, 254, 255, # (8,3)
65535, 65535, 65535, # (8,4) (clipped, nose bridge)
345, 347, 346, # (9,0)
342, 344, 343, # (9,1)
267, 269, 268, # (9,2)
263, 265, 264, # (9,3)
65535, 65535, 65535, # (9,4) (clipped, nose bridge)
336, 338, 337, # (10,0)
333, 335, 334, # (10,1)
237, 239, 238, # (10,2) / left ring pixel 19
233, 235, 234, # (10,3) / 18
348, 262, 349, # (10,4) / 17
327, 329, 328, # (11,0) / left ring pixel 21
324, 326, 325, # (11,1)
207, 209, 208, # (11,2)
203, 205, 204, # (11,3)
330, 202, 331, # (11,4)
318, 320, 319, # (12,0)
315, 317, 316, # (12,1)
177, 179, 178, # (12,2)
173, 175, 174, # (12,3)
321, 172, 322, # (12,4)
309, 311, 310, # (13,0)
306, 308, 307, # (13,1)
147, 149, 148, # (13,2)
143, 145, 144, # (13,3)
312, 142, 313, # (13,4)
300, 302, 301, # (14,0)
297, 299, 298, # (14,1)
117, 119, 118, # (14,2)
113, 115, 114, # (14,3)
303, 112, 304, # (14,4)
291, 293, 292, # (15,0)
288, 290, 289, # (15,1)
87, 89, 88, # (15,2)
83, 85, 84, # (15,3)
294, 82, 295, # (15,4)
282, 284, 283, # (16,0) / left ring pixel 3
279, 281, 280, # (16,1)
57, 59, 58, # (16,2)
53, 55, 54, # (16,3)
285, 52, 286, # (16,4)
65535, 65535, 65535, # (17,0) (clipped, corner)
270, 272, 271, # (17,1) / left ring pixel 4
27, 29, 28, # (17,2) / 5
23, 25, 24, # (17,3) / 6
276, 22, 277, # (17,4) / 7
)
# LED glasses but excluding LEDs shared with the eye rings
glassesmatrix_ledmap_no_ring = (
65535, 65535, 65535, # (0,0) (clipped, corner)
65535, 65535, 65535, # (0,1) / right ring pixel 20
65535, 65535, 65535, # (0,2) / 19
65535, 65535, 65535, # (0,3) / 18
65535, 65535, 65535, # (0,4) / 17
65535, 65535, 65535, # (1,0) / right ring pixel #21
220, 218, 219, # (1,1)
223, 221, 222, # (1,2)
226, 224, 225, # (1,3)
214, 212, 213, # (1,4)
187, 185, 186, # (2,0)
190, 188, 189, # (2,1)
193, 191, 192, # (2,2)
196, 194, 195, # (2,3)
184, 182, 183, # (2,4)
37, 35, 36, # (3,0)
40, 38, 39, # (3,1)
43, 41, 42, # (3,2)
46, 44, 45, # (3,3)
34, 32, 33, # (3,4)
67, 65, 66, # (4,0)
70, 68, 69, # (4,1)
73, 71, 72, # (4,2)
76, 74, 75, # (4,3)
64, 62, 63, # (4,4)
97, 95, 96, # (5,0)
100, 98, 99, # (5,1)
103, 101, 102, # (5,2)
106, 104, 105, # (5,3)
94, 92, 93, # (5,4)
127, 125, 126, # (6,0) / right ring pixel 3
130, 128, 129, # (6,1)
133, 131, 132, # (6,2)
136, 134, 135, # (6,3)
124, 122, 123, # (6,4)
157, 155, 156, # (7,0)
160, 158, 159, # (7,1)
163, 161, 162, # (7,2) / right ring pixel 5
166, 164, 165, # (7,3) / 6
244, 242, 243, # (7,4) / 7
247, 245, 246, # (8,0)
250, 248, 249, # (8,1)
253, 251, 252, # (8,2)
256, 254, 255, # (8,3)
65535, 65535, 65535, # (8,4) (clipped, nose bridge)
345, 347, 346, # (9,0)
342, 344, 343, # (9,1)
267, 269, 268, # (9,2)
263, 265, 264, # (9,3)
65535, 65535, 65535, # (9,4) (clipped, nose bridge)
336, 338, 337, # (10,0)
333, 335, 334, # (10,1)
237, 239, 238, # (10,2) / left ring pixel 19
233, 235, 234, # (10,3) / 18
348, 262, 349, # (10,4) / 17
327, 329, 328, # (11,0) / left ring pixel 21
324, 326, 325, # (11,1)
207, 209, 208, # (11,2)
203, 205, 204, # (11,3)
330, 202, 331, # (11,4)
318, 320, 319, # (12,0)
315, 317, 316, # (12,1)
177, 179, 178, # (12,2)
173, 175, 174, # (12,3)
321, 172, 322, # (12,4)
309, 311, 310, # (13,0)
306, 308, 307, # (13,1)
147, 149, 148, # (13,2)
143, 145, 144, # (13,3)
312, 142, 313, # (13,4)
300, 302, 301, # (14,0)
297, 299, 298, # (14,1)
117, 119, 118, # (14,2)
113, 115, 114, # (14,3)
303, 112, 304, # (14,4)
291, 293, 292, # (15,0)
288, 290, 289, # (15,1)
87, 89, 88, # (15,2)
83, 85, 84, # (15,3)
294, 82, 295, # (15,4)
65535, 65535, 65535, # (16,0) / left ring pixel 3
279, 281, 280, # (16,1)
57, 59, 58, # (16,2)
53, 55, 54, # (16,3)
285, 52, 286, # (16,4)
65535, 65535, 65535, # (17,0) (clipped, corner)
65535, 65535, 65535, # (17,1) / left ring pixel 4
65535, 65535, 65535, # (17,2) / 5
65535, 65535, 65535, # (17,3) / 6
65535, 65535, 65535, # (17,4) / 7
)
# Left LED glasses eye ring
left_ring_map = (
341, 210, 211, # 0
332, 180, 181, # 1
323, 150, 151, # 2
127, 125, 126, # 3
154, 152, 153, # 4
163, 161, 162, # 5
166, 164, 165, # 6
244, 242, 243, # 7
259, 257, 258, # 8
169, 167, 168, # 9
139, 137, 138, # 10
109, 107, 108, # 11
79, 77, 78, # 12
49, 47, 48, # 13
199, 197, 198, # 14
229, 227, 228, # 15
19, 17, 18, # 16
4, 2, 3, # 17
16, 14, 15, # 18
13, 11, 12, # 19
10, 8, 9, # 20
217, 215, 216, # 21
7, 5, 6, # 22
350, 240, 241, # 23
)
# Left LED glasses eye ring excluding inner LEDs shared with the display
left_ring_map_no_inner = (
341, 210, 211, # 0
332, 180, 181, # 1
323, 150, 151, # 2
65535, 65535, 65535, # 3
65535, 65535, 65535, # 4
65535, 65535, 65535, # 5
65535, 65535, 65535, # 6
65535, 65535, 65535, # 7
259, 257, 258, # 8
169, 167, 168, # 9
139, 137, 138, # 10
109, 107, 108, # 11
79, 77, 78, # 12
49, 47, 48, # 13
199, 197, 198, # 14
229, 227, 228, # 15
19, 17, 18, # 16
4, 2, 3, # 17
16, 14, 15, # 18
13, 11, 12, # 19
10, 8, 9, # 20
217, 215, 216, # 21
7, 5, 6, # 22
350, 240, 241, # 23
)
# Right LED glasses eye ring
right_ring_map = (
287, 30, 31, # 0
278, 0, 1, # 1
273, 275, 274, # 2
282, 284, 283, # 3
270, 272, 271, # 4
27, 29, 28, # 5
23, 25, 24, # 6
276, 22, 277, # 7
20, 26, 21, # 8
50, 56, 51, # 9
80, 86, 81, # 10
110, 116, 111, # 11
140, 146, 141, # 12
170, 176, 171, # 13
200, 206, 201, # 14
230, 236, 231, # 15
260, 266, 261, # 16
348, 262, 349, # 17
233, 235, 234, # 18
237, 239, 238, # 19
339, 232, 340, # 20
327, 329, 328, # 21
305, 90, 91, # 22
296, 60, 61, # 23
)
# Right LED glasses eye ring excluding inner LEDs shared with the display
right_ring_map_no_inner = (
287, 30, 31, # 0
278, 0, 1, # 1
273, 275, 274, # 2
282, 284, 283, # 3
270, 272, 271, # 4
27, 29, 28, # 5
23, 25, 24, # 6
276, 22, 277, # 7
20, 26, 21, # 8
50, 56, 51, # 9
80, 86, 81, # 10
110, 116, 111, # 11
140, 146, 141, # 12
170, 176, 171, # 13
200, 206, 201, # 14
230, 236, 231, # 15
260, 266, 261, # 16
65535, 65535, 65535, # 17
65535, 65535, 65535, # 18
65535, 65535, 65535, # 19
65535, 65535, 65535, # 20
65535, 65535, 65535, # 21
305, 90, 91, # 22
296, 60, 61, # 23
)

View file

@ -0,0 +1,61 @@
# SPDX-FileCopyrightText: 2021 Mark Komus
# SPDX-License-Identifier: MIT
import is31fl3741
import displayio
import framebufferio
import board
import busio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
from adafruit_is31fl3741.is31fl3741_PixelBuf import IS31FL3741_PixelBuf
from adafruit_is31fl3741.led_glasses_map import glassesmatrix_ledmap, glassesmatrix_ledmap_no_ring, left_ring_map_no_inner, right_ring_map_no_inner
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.chase import Chase
# Release any existing displays
displayio.release_displays()
# Create our own I2C bus with a 1Mhz frequency for faster updates
i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000)
# Initialize the IS31FL3741 displayio display
is31 = is31fl3741.IS31FL3741(width=54, height=15, i2c=i2c, scale=True, gamma=True, mapping=glassesmatrix_ledmap_no_ring)
display = framebufferio.FramebufferDisplay(is31, auto_refresh=True)
# Turn the brightness down
is31.brightness = 0.1
# Create pixel buffers for each eye. Init is False as the display setup initialized the chip
eye_left = IS31FL3741_PixelBuf(i2c, left_ring_map_no_inner, 24, init=False, auto_write=False)
eye_right = IS31FL3741_PixelBuf(i2c, right_ring_map_no_inner, 24, init=False, auto_write=False)
# Create a different animation for each eye ring
chase = Chase(eye_left, speed=0.05, color=(0,0,150), size=8, spacing=4)
comet = Comet(eye_right, speed=0.01, color=(0,0,150), tail_length=10, bounce=False)
# Create text to scroll across the display
font = bitmap_font.load_font("scrolly.bdf")
text = "HELLO FROM CIRCUITPYTHON ON NATIVE DISPLAYIO"
color = (255,210,0)
text_area = label.Label(font, text=text, color=color)
# Set the text location
text_width = text_area.bounding_box[2]
text_area.x = display.width
text_area.y = 8
# Add the text label to the display
group = displayio.Group()
group.append(text_area)
display.show(group)
# Scroll the text and update the animations
x = display.width
while True:
x = x - 1
text_area.x = x
if x == -text_width:
x = display.width
chase.animate()
comet.animate()

1212
examples/scrolly.bdf Normal file

File diff suppressed because it is too large Load diff