Skip to content

Commit a3064ac

Browse files
committed
Add inverse polarity for MCP23S17
1 parent 1bc647a commit a3064ac

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

adafruit_mcp230xx/mcp23s17.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_MCP23S17_IODIRA = const(0x00)
2525
_MCP23S17_IODIRB = const(0x01)
2626
_MCP23S17_IPOLA = const(0x02)
27+
_MCP23S17_IPOLB = const(0x03)
2728
_MCP23S17_GPINTENA = const(0x04)
2829
_MCP23S17_DEFVALA = const(0x06)
2930
_MCP23S17_INTCONA = const(0x08)
@@ -38,6 +39,7 @@
3839
_MCP23S17_INTCAPB = const(0x11)
3940

4041
# pylint: disable=too-many-arguments
42+
# pylint: disable=too-many-public-methods
4143
class MCP23S17(MCP23SXX):
4244
"""Supports MCP23S17 instance on specified SPI bus and optionally
4345
at the specified SPI address.
@@ -165,9 +167,46 @@ def get_pin(self, pin):
165167
"""Convenience function to create an instance of the DigitalInOut class
166168
pointing at the specified pin of this MCP23S17 device.
167169
"""
168-
assert 0 <= pin <= 15
170+
if not 0 <= pin <= 15:
171+
raise ValueError("Pin number must be 0-15.")
169172
return DigitalInOut(pin, self)
170173

174+
@property
175+
def ipol(self):
176+
"""The raw IPOL output register. Each bit represents the
177+
polarity value of the associated pin (0 = normal, 1 = inverted), assuming that
178+
pin has been configured as an input previously.
179+
"""
180+
return self._read_u16le(_MCP23S17_IPOLA)
181+
182+
@ipol.setter
183+
def ipol(self, val):
184+
self._write_u16le(_MCP23S17_IPOLA, val)
185+
186+
@property
187+
def ipola(self):
188+
"""The raw IPOL A output register. Each bit represents the
189+
polarity value of the associated pin (0 = normal, 1 = inverted), assuming that
190+
pin has been configured as an input previously.
191+
"""
192+
return self._read_u8(_MCP23S17_IPOLA)
193+
194+
@ipola.setter
195+
def ipola(self, val):
196+
self._write_u8(_MCP23S17_IPOLA, val)
197+
198+
@property
199+
def ipolb(self):
200+
"""The raw IPOL B output register. Each bit represents the
201+
polarity value of the associated pin (0 = normal, 1 = inverted), assuming that
202+
pin has been configured as an input previously.
203+
"""
204+
return self._read_u8(_MCP23S17_IPOLB)
205+
206+
@ipolb.setter
207+
def ipolb(self, val):
208+
self._write_u8(_MCP23S17_IPOLB, val)
209+
171210
@property
172211
def interrupt_configuration(self):
173212
"""The raw INTCON interrupt control register. The INTCON register

0 commit comments

Comments
 (0)