Skip to content

Add adafruit_bus_device dependency #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions adafruit_is31fl3731/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import time
from micropython import const

from adafruit_bus_device.i2c_device import I2CDevice

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731.git"

Expand Down Expand Up @@ -85,47 +87,38 @@ class IS31FL3731:
The IS31FL3731 is an abstract class contain the main function related to this chip.
Each board needs to define width, height and pixel_addr.

:param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
:param address: the device address; defaults to 0x74
:param ~busio.I2C i2c: the connected i2c bus i2c_device
:param int address: the device address; defaults to 0x74
"""

width = 16
height = 9

def __init__(self, i2c, address=0x74, frames=None):
self.i2c = i2c
self.address = address
self.i2c_device = I2CDevice(i2c, address)
self._frame = None
self._init(frames=frames)

def _i2c_read_reg(self, reg, result):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function got changed by another recent PR and the changes will get need to get conflicts resolved with this one before it can get merged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FoamyGuy I should have just resolved the conflicts in the latest commit! For this, it's sufficient to just store self.i2c_device and use that in the other pertinent functions.

# Read a buffer of data from the specified 8-bit I2C register address.
# The provided result parameter will be filled to capacity with bytes
# of data read from the register.
while not self.i2c.try_lock():
pass
try:
self.i2c.writeto_then_readfrom(self.address, bytes([reg]), result)
with self.i2c_device as i2c:
i2c.write_then_readinto(bytes([reg]), result)
return result
finally:
self.i2c.unlock()
return None

def _i2c_write_block(self, data):
# Writes a contiguous block of data (bytearray) where the first byte
# is the starting I2C register address (register is not an argument).
while not self.i2c.try_lock():
pass
try:
self.i2c.writeto(self.address, data)
finally:
self.i2c.unlock()

def _i2c_write_reg(self, reg, data):
# Write a contiguous block of data (bytearray) starting at the
# specified I2C register address (register passed as argument).
self._i2c_write_block(bytes([reg]) + data)

def _i2c_write_block(self, data):
# Write a buffer of data (byte array) to the specified I2C register
# address.
with self.i2c_device as i2c:
i2c.write(data)

def _bank(self, bank=None):
if bank is None:
result = bytearray(1)
Expand Down Expand Up @@ -292,14 +285,10 @@ def fill(self, color=None, blink=None, frame=None):
if not 0 <= color <= 255:
raise ValueError("Color out of range")
data = bytearray([color] * 25) # Extra byte at front for address.
while not self.i2c.try_lock():
pass
try:
with self.i2c_device as i2c:
for row in range(6):
data[0] = _COLOR_OFFSET + row * 24
self.i2c.writeto(self.address, data)
finally:
self.i2c.unlock()
i2c.write(data)
if blink is not None:
data = bool(blink) * 0xFF
for col in range(18):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

Adafruit-Blinka
adafruit-circuitpython-framebuf
adafruit-circuitpython-busdevice
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=["Adafruit-Blinka"],
install_requires=[
"Adafruit-Blinka",
"adafruit-circuitpython-busdevice",
],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down