Skip to content

Commit b040cc5

Browse files
committed
issi evb pixel mapping
1 parent ae7efa8 commit b040cc5

File tree

2 files changed

+83
-30
lines changed

2 files changed

+83
-30
lines changed

adafruit_is31fl3741/__init__.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,28 @@ def page(self, p):
131131

132132

133133

134-
def __getitem__(self, key):
135-
print(key)
134+
def __getitem__(self, led):
135+
if not 0 <= led <= 350:
136+
raise ValueError("LED must be 0 ~ 350")
137+
if led < 180:
138+
self.page = 0
139+
self._buf[0] = led
140+
else:
141+
self.page = 1
142+
self._buf[0] = led - 180
143+
144+
with self.i2c_device as i2c:
145+
i2c.write_then_readinto(self._buf, self._buf,
146+
out_start=0, out_end=1,
147+
in_start=1, in_end=2)
148+
return self._buf[1]
136149

137150
def __setitem__(self, led, pwm):
138151
if not 0 <= led <= 350:
139152
raise ValueError("LED must be 0 ~ 350")
140153
if not 0 <= pwm <= 255:
141154
raise ValueError("PWM must be 0 ~ 255")
142-
print(led, pwm)
155+
#print(led, pwm)
143156

144157
if led < 180:
145158
self.page = 0
@@ -150,16 +163,13 @@ def __setitem__(self, led, pwm):
150163
self._buf[1] = pwm
151164
with self.i2c_device as i2c:
152165
i2c.write(self._buf)
153-
154-
155-
156-
157166

158167
# This function must be replaced for each board
159168
@staticmethod
160-
def pixel_addr(x, y):
169+
def pixel_addrs(x, y):
161170
"""Calulate the offset into the device array for x,y pixel"""
162-
return x + y * 16
171+
raise NotImplementedError("Supported in subclasses only")
172+
163173

164174
# pylint: disable-msg=too-many-arguments
165175
def pixel(self, x, y, color=None):
@@ -174,24 +184,20 @@ def pixel(self, x, y, color=None):
174184
return None
175185
if not 0 <= y <= self.height:
176186
return None
177-
pixel = self.pixel_addr(x, y)
178-
if color is None and blink is None:
179-
return self._register(self._frame, pixel)
180-
if frame is None:
181-
frame = self._frame
182-
if color is not None:
183-
if not 0 <= color <= 255:
184-
raise ValueError("Color out of range")
185-
self._register(frame, _COLOR_OFFSET + pixel, color)
186-
if blink is not None:
187-
addr, bit = divmod(pixel, 8)
188-
bits = self._register(frame, _BLINK_OFFSET + addr)
189-
if blink:
190-
bits |= 1 << bit
191-
else:
192-
bits &= ~(1 << bit)
193-
self._register(frame, _BLINK_OFFSET + addr, bits)
194-
return None
187+
addrs = self.pixel_addrs(x, y)
188+
print(addrs)
189+
if color is not None: # set the color
190+
self[addrs[0]] = (color >> 16) & 0xFF
191+
self[addrs[1]] = (color >> 8) & 0xFF
192+
self[addrs[2]] = color & 0xFF
193+
return None
194+
# we want to fetch the color
195+
color = self[addrs[0]]
196+
color <<= 8
197+
color |= self[addrs[1]]
198+
color <<= 8
199+
color |= self[addrs[2]]
200+
return color
195201

196202
# pylint: enable-msg=too-many-arguments
197203

@@ -203,8 +209,8 @@ def image(self, img, blink=None, frame=None):
203209
:param blink: True to blink
204210
:param frame: the frame to set the image
205211
"""
206-
if img.mode != "L":
207-
raise ValueError("Image must be in mode L.")
212+
if img.mode != "RGB":
213+
raise ValueError("Image must be in mode RGB.")
208214
imwidth, imheight = img.size
209215
if imwidth != self.width or imheight != self.height:
210216
raise ValueError(
@@ -218,4 +224,4 @@ def image(self, img, blink=None, frame=None):
218224
# Iterate through the pixels
219225
for x in range(self.width): # yes this double loop is slow,
220226
for y in range(self.height): # but these displays are small!
221-
self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)
227+
self.pixel(x, y, pixels[(x, y)])

adafruit_is31fl3741/issi_evb.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_is31fl3741.issi_evb`
7+
====================================================
8+
9+
CircuitPython driver for the IS31FL3741 ISSI Eval Board
10+
11+
12+
* Author(s): ladyada
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Hardware:**
18+
19+
* `ISSI IS31FL3741 eval board
20+
<https://www.digikey.com/en/products/detail/issi-integrated-silicon-solution-inc/IS31FL3741-QFLS4-EB/10243951>`_
21+
22+
**Software and Dependencies:**
23+
24+
* Adafruit CircuitPython firmware for the supported boards:
25+
https://github.com/adafruit/circuitpython/releases
26+
27+
"""
28+
29+
# imports
30+
from . import IS31FL3741
31+
32+
33+
class ISSI_EVB(IS31FL3741):
34+
"""Supports the ISSI IS31FL3741 eval board"""
35+
36+
width = 13
37+
height = 9
38+
39+
@staticmethod
40+
def pixel_addrs(x, y):
41+
"""Calulate the RGB offsets into the device array for x,y pixel"""
42+
if x > 9:
43+
offset = (x + 80 + y * 3) * 3
44+
else:
45+
offset = (x + y * 10) * 3
46+
47+
return (offset+2, offset+1, offset)

0 commit comments

Comments
 (0)