Skip to content

Commit fa0aad9

Browse files
authored
Merge pull request #6 from rtyley/add-constant-current-range-selector
Add `constant_current_range` selector for LED driving
2 parents fa1e1dd + 792c2b0 commit fa0aad9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

adafruit_aw9523.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from adafruit_bus_device import i2c_device
3030
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
3131
from adafruit_register.i2c_bit import RWBit
32+
from adafruit_register.i2c_bits import RWBits
3233
from micropython import const
3334

3435
__version__ = "0.0.0-auto.0"
@@ -46,6 +47,12 @@
4647

4748
# pylint: disable=invalid-name
4849

50+
# constant_current_range options
51+
AW9523_4_4_RANGE = const(0) # Full range: 0 - 37 mA (typical)
52+
AW9523_3_4_RANGE = const(1) # 3/4 range: 0 - 27.8 mA
53+
AW9523_2_4_RANGE = const(2) # 2/4 range: 0 - 18.5 mA
54+
AW9523_1_4_RANGE = const(3) # 1/4 range: 0 - 9.3 mA
55+
4956

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

77+
# 256-step constant-current range selector 'ISEL' - choice of 'full' (4/4), 3/4, 2/4, or 1/4.
78+
constant_current_range = RWBits(2, _AW9523_REG_GCR, 0)
79+
7080
def __init__(self, i2c_bus, address=_AW9523_DEFAULT_ADDR, reset=True):
7181
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
7282
self._buffer = bytearray(2)

0 commit comments

Comments
 (0)