Skip to content

Commit 3c68121

Browse files
committed
Cleanup and clarification in doc strings.
1 parent aeb708b commit 3c68121

File tree

8 files changed

+81
-75
lines changed

8 files changed

+81
-75
lines changed

examples/i2c_expanders_simpletest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
#
44
# SPDX-License-Identifier: Unlicense
55

6+
# Make sure to change the code based on the expander type you are using.
7+
68
import time
79
import board
810
import digitalio
11+
12+
# Change this if you are not using a PCAL9555
913
from i2c_expanders.PCAL9555 import PCAL9555
1014

1115
# To use default I2C bus (most boards)
@@ -15,6 +19,7 @@
1519
PCAL9555_Address = 0x20
1620

1721
# Initialize the device and get pins
22+
# Change this if you are not using a PCAL9555
1823
IOEXP1_dev = PCAL9555.PCAL9555(i2c, address=PCAL9555_Address)
1924
pin0 = IOEXP1_dev.get_pin(0)
2025
pin1 = IOEXP1_dev.get_pin(1)

i2c_expanders/PCA9554.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626
Use this class if you are using a PCA9554 or compatible expander. This class is also used
2727
as the base class for the PCAL9554 expander.
2828
29-
There are likely other devices that use this same command set and can be used with this class.
30-
Where I find them, I will probably make a separate class name to make it obvious what devices are
31-
supported. A list of other devices that should be compatible is below.
29+
Required library files (.py or their .mpy equivalent):
30+
31+
* PCA9554.py
32+
* i2c_expander.py
33+
* digital_inout.py
34+
* helpers.py
3235
3336
Compatible Devices
3437
3538
* PCA9554
3639
* PCA9538
37-
* TODO
3840
39-
Note: Some devices have the same command set and register, but different i2c addresses and register
40-
defaults. These devices should work fine with this class, but make sure the addresses are set right
41-
when initializing them.
41+
These are devices I have specifically tested and know work. There appear to be a lot more devices
42+
with similar naming schemes that use the same register map. These should also be compatible, but
43+
make sure you check the i2c address and default register state.
4244
4345
Heavily based on the code written by Tony DiCola for the MCP230xx library.
4446
@@ -63,8 +65,8 @@
6365

6466

6567
class PCA9554(I2c_Expander):
66-
"""Supports PCA9554 instance on specified I2C bus and optionally
67-
at the specified I2C address.
68+
"""The class for the PCA9554 expander. Instantiate one of these for each expander on the bus.
69+
Make sure you get the address right.
6870
"""
6971

7072
def __init__(self, i2c, address=_PCA9554_DEFAULT_ADDRESS, reset=True):

i2c_expanders/PCA9555.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,37 @@
2525
Use this class if you are using a PCA9555 or compatible expander. This class is also used
2626
as the base class for the PCAL9555 expander.
2727
28-
There are likely other devices that use this same command set and can be used with this class.
29-
Where I find them, I will probably make a separate class name to make it obvious what devices are
30-
supported. A list of other devices that should be compatible is below.
28+
Required library files (.py or their .mpy equivalent):
29+
30+
* PCA9555.py
31+
* i2c_expander.py
32+
* digital_inout.py
33+
* helpers.py
3134
3235
Compatible Devices
3336
3437
* PCA9555
35-
* TODO
38+
39+
These are devices I have specifically tested and know work. There appear to be a lot more devices
40+
with similar naming schemes that use the same register map. These should also be compatible, but
41+
make sure you check the i2c address and default register state.
3642
3743
Heavily based on the code written by Tony DiCola for the MCP230xx library.
3844
3945
* Author(s): Pat Satyshur
4046
"""
4147

42-
# DriveMode: PUSH_PULL vs OPEN_DRAIN
43-
# Pull: Pull.Up vs Pull.DOWN vs None
44-
# TODO: Handle interrupts in here somewhere
48+
from micropython import const
4549

46-
from micropython import (
47-
const,
48-
) # TODO: What does const get me in this situation? Can I remove it?
4950
from i2c_expanders.i2c_expander import I2c_Expander
5051
from i2c_expanders.helpers import _enable_bit, Capability
5152

52-
# from i2c_expanders.digital_inout import _enable_bit
53-
5453
__version__ = "0.0.0+auto.0"
5554
__repo__ = "https://github.com/ilikecake/CircuitPython_I2C_Expanders.git"
5655

57-
# TODO: this will probably change based on the device used.
58-
# Not sure how to deal with this. Maybe remove the default and
59-
# force the user to specify the address?
56+
# This is the default address for the PCA9555 with all addr pins grounded.
57+
_PCA9555_DEFAULT_ADDRESS = const(0x20)
6058

61-
_PCA9555_ADDRESS = const(0x20)
6259
_PCA9555_INPUT0 = const(0x00) # Input register 0
6360
_PCA9555_INPUT1 = const(0x01) # Input register 1
6461
_PCA9555_OUTPUT0 = const(0x02) # Output register 0
@@ -70,11 +67,11 @@
7067

7168

7269
class PCA9555(I2c_Expander):
73-
"""Supports PCA9555 instance on specified I2C bus and optionally
74-
at the specified I2C address.
70+
"""The class for the PCA9555 expander. Instantiate one of these for each expander on the bus.
71+
Make sure you get the address right.
7572
"""
7673

77-
def __init__(self, i2c, address=_PCA9555_ADDRESS, reset=True):
74+
def __init__(self, i2c, address=_PCA9555_DEFAULT_ADDRESS, reset=True):
7875
super().__init__(i2c, address)
7976
self._maxpins = 15
8077
self._capability = _enable_bit(0x00, Capability.INVERT_POL)

i2c_expanders/PCAL9554.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@
2626
* Latching interrupt option
2727
* Per bank push-pull/open drain pin setup.
2828
29-
There are likely other devices that use this same command set and can be used with this class.
30-
Where I find them, I will probably make a separate class name to make it obvious what devices are
31-
supported. A list of other devices that should be compatible is below.
29+
Required library files (.py or their .mpy equivalent):
30+
31+
* PCAL9554.py
32+
* PCA9554.py
33+
* i2c_expander.py
34+
* digital_inout.py
35+
* helpers.py
3236
3337
Compatible Devices
3438
3539
* PCAL9554
3640
* PCAL9538
37-
* TODO
3841
39-
Note: Some devices have the same command set and register, but different i2c addresses and register
40-
defaults. These devices should work fine with this class, but make sure the addresses are set right
41-
when initializing them.
42+
These are devices I have specifically tested and know work. There appear to be a lot more devices
43+
with similar naming schemes that use the same register map. These should also be compatible, but
44+
make sure you check the i2c address and default register state.
4245
4346
:Note: By default if an (non-latched) interrupt enabled pin changes state, but changes back before
4447
the GPIO state register is read, the interrupt state will be cleared. Setting the interrupt
@@ -61,21 +64,17 @@
6164
# are still unused.
6265
# pylint: disable=unused-import
6366
from micropython import const
64-
import digitalio # import DigitalInOut #TODO: Do i need this??
67+
import digitalio
6568

6669
from i2c_expanders.PCA9554 import PCA9554
67-
from i2c_expanders.helpers import (
68-
Capability,
69-
_get_bit,
70-
_enable_bit,
71-
_clear_bit,
72-
)
70+
from i2c_expanders.helpers import Capability, _get_bit, _enable_bit, _clear_bit
71+
7372

7473
__version__ = "0.0.0+auto.0"
7574
__repo__ = "https://github.com/ilikecake/CircuitPython_I2C_Expanders.git"
7675

77-
# TODO: Probably don't want this here.
78-
_PCAL9554_ADDRESS = const(0x27)
76+
# This is the default address for the PCA9554 with all addr pins grounded.
77+
_PCAL9554_DEFAULT_ADDRESS = const(0x20)
7978

8079
_PCAL9554_OUTPUT_DRIVE_1 = const(0x40)
8180
_PCAL9554_OUTPUT_DRIVE_2 = const(0x41)
@@ -88,11 +87,11 @@
8887

8988

9089
class PCAL9554(PCA9554):
91-
"""Supports PCAL9554 instance on specified I2C bus and optionally
92-
at the specified I2C address.
90+
"""The class for the PCAL9554 expander. Instantiate one of these for each expander on the bus.
91+
Make sure you get the address right.
9392
"""
9493

95-
def __init__(self, i2c, address=_PCAL9554_ADDRESS, reset=True):
94+
def __init__(self, i2c, address=_PCAL9554_DEFAULT_ADDRESS, reset=True):
9695
super().__init__(
9796
i2c, address, False
9897
) # This initializes the PCA9554 compatible registers.

i2c_expanders/PCAL9555.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@
2828
* Latching interrupt option
2929
* Per bank push-pull/open drain pin setup.
3030
31-
There are likely other devices that use this same command set and can be used with this class.
32-
Where I find them, I will probably make a separate class name to make it obvious what devices are
33-
supported. A list of other devices that should be compatible is below.
31+
Required library files (.py or their .mpy equivalent):
32+
33+
* PCAL9555.py
34+
* PCA9555.py
35+
* i2c_expander.py
36+
* digital_inout.py
37+
* helpers.py
38+
39+
Compatible Devices
40+
41+
* PCAL9555
42+
43+
These are devices I have specifically tested and know work. There appear to be a lot more devices
44+
with similar naming schemes that use the same register map. These should also be compatible, but
45+
make sure you check the i2c address and default register state.
3446
3547
:Note: By default if an (non-latched) interrupt enabled pin changes state, but changes back before
3648
the GPIO state register is read, the interrupt state will be cleared. Setting the interrupt
@@ -44,18 +56,6 @@
4456
the input register is read before the pin state changes back to the original value, both
4557
state changes will cause an interrupt.
4658
47-
Required library files:
48-
* PCAL9555.py
49-
* PCA9555.py
50-
* i2c_expander.py
51-
* digital_inout.py
52-
* helpers.py
53-
54-
Compatible Devices
55-
56-
* PCAL9555
57-
* TODO
58-
5959
Heavily based on the code written by Tony DiCola for the MCP230xx library.
6060
6161
* Author(s): Pat Satyshur
@@ -70,7 +70,7 @@
7070
__version__ = "0.0.0+auto.0"
7171
__repo__ = "https://github.com/ilikecake/CircuitPython_I2C_Expanders.git"
7272

73-
# This is the default address for the PCA9554 with all addr pins grounded.
73+
# This is the default address for the PCAL9555 with all addr pins grounded.
7474
_PCAL9555_DEFAULT_ADDRESS = const(0x20)
7575

7676
# Registers specific to the PCAL9555 devices. This device also inherits the registers
@@ -112,8 +112,8 @@ class DriveStrength: # pylint: disable=too-few-public-methods
112112

113113

114114
class PCAL9555(PCA9555):
115-
"""PACL9555 is a compatible with all PCA9555 functions and definitions. All functions
116-
from the PCA9555 work without updates. The PCAL device added capability is defined below.
115+
"""The class for the PCAL9555 expander. Instantiate one of these for each expander on the bus.
116+
Make sure you get the address right.
117117
"""
118118

119119
def __init__(self, i2c, address=_PCAL9555_DEFAULT_ADDRESS, reset=True):

i2c_expanders/digital_inout.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@
2424

2525
class DigitalInOut:
2626
"""The interface is exactly the same as the digitalio.DigitalInOut
27-
class. However Some devices do not support pull up/down resistors
28-
or setting the pin to open drain.
27+
class. However Some devices do not support pull up/down resistors
28+
or setting the pin to open drain.
29+
30+
:param pin_number: The pin number. Starts at zero.
31+
:type pin_number: int
32+
33+
:param ioexpander_class: The I2c expander class object.
34+
:type ioexpander_class: gpio class object
2935
3036
Exceptions will be thrown when attempting to set unsupported configurations.
3137
"""
3238

3339
def __init__(self, pin_number, ioexpander_class):
34-
"""Specify the pin number of the expander and pass the class object.
35-
Pin numbers start a 0.
36-
"""
3740
self._pin = pin_number
3841
self._ioexp = ioexpander_class
3942

43+
# TODO: Not sure if this is still true. Can't we just use the same arguments as the 'real'
44+
# DigitalInout class expects, and then not use the ones we don't need? Leaving it along for now.
45+
#
4046
# kwargs in switch functions below are _necessary_ for compatibility
4147
# with DigitalInout class (which allows specifying pull, etc. which
4248
# is unused by this class). Do not remove them, instead turn off pylint

i2c_expanders/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515

16+
# TODO: Look at this later, it does not look right.
1617
class Capability: # pylint: disable=too-few-public-methods
1718
"""IO Expander Capability
1819
A one in the corresponding bit position below indicates

i2c_expanders/i2c_expander.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
# pylint: disable=too-few-public-methods
2727
class I2c_Expander:
2828
"""Base class for I2C GPIO expander devices. This class has basic read and write functions that
29-
are common to all i2c expanders. This class should never be used directly
30-
31-
:param maxpins: Number of pins in the expander. Starts at 0.
32-
:type maxpins: interger
33-
29+
are common to all i2c expanders. This class should never be used directly.
3430
"""
3531

3632
def __init__(self, bus_device, address):

0 commit comments

Comments
 (0)