Skip to content

Add constant_current_range selector for LED driving #6

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 1 commit into from
Jun 28, 2022
Merged
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
10 changes: 10 additions & 0 deletions adafruit_aw9523.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from adafruit_bus_device import i2c_device
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
from adafruit_register.i2c_bit import RWBit
from adafruit_register.i2c_bits import RWBits
from micropython import const

__version__ = "0.0.0-auto.0"
Expand All @@ -46,6 +47,12 @@

# pylint: disable=invalid-name

# constant_current_range options
AW9523_4_4_RANGE = const(0) # Full range: 0 - 37 mA (typical)
AW9523_3_4_RANGE = const(1) # 3/4 range: 0 - 27.8 mA
AW9523_2_4_RANGE = const(2) # 2/4 range: 0 - 18.5 mA
AW9523_1_4_RANGE = const(3) # 1/4 range: 0 - 9.3 mA


class AW9523:
"""CircuitPython helper class for using the AW9523 GPIO expander"""
Expand All @@ -67,6 +74,9 @@ class AW9523:
# Whether port 0 is push-pull
port0_push_pull = RWBit(_AW9523_REG_GCR, 4)

# 256-step constant-current range selector 'ISEL' - choice of 'full' (4/4), 3/4, 2/4, or 1/4.
constant_current_range = RWBits(2, _AW9523_REG_GCR, 0)

def __init__(self, i2c_bus, address=_AW9523_DEFAULT_ADDR, reset=True):
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
self._buffer = bytearray(2)
Expand Down