-
Notifications
You must be signed in to change notification settings - Fork 36
Add SPI (MCP23SXX) devices #41
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
504c58d
Add MCP23SXX files from https://github.com/romybompart/Adafruit_Circu…
Red-M b7d897a
Add composite support for MCP23SXX devices. This is currently untested.
Red-M 8b5cbd0
Fix up files as per pre-commit
Red-M f7dbc47
Remove unnecessary variables for mcp23xxx.py
Red-M 60640fd
Add documentation for the MCP23SXX devices.
Red-M e405072
Add the most basic of examples as an initial
Red-M 1ed36cf
Add baudrate to SPI devices, this cannot be set the same way as I2C b…
Red-M 91d2485
Fix documentation for new SPI devices.
Red-M a1a94ac
Add another example file for SPI devices.
Red-M b36aebe
More minor documentation changes.
Red-M e70de9f
Minor copyright fix.
Red-M 1bc647a
Fix import in mcp23s08 for mcp23sxx.
Red-M a3064ac
Add inverse polarity for MCP23S17
Red-M 7b76090
Fix README.rst as per suggestion.
Red-M e5d86da
Just force io_control to not accept turning the banks into multiple b…
Red-M 2c3af9c
Force `BANK` bit to 0 via suggested method.
Red-M 8f50b94
Add documentation on `BANK` bit ignored if being set to 1.
Red-M f8ddbe0
Fix docstring.
Red-M File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries | ||
# SPDX-FileCopyrightText: 2019 Carter Nelson | ||
# SPDX-FileCopyrightText: 2021 Red_M | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
`MCP23S08` | ||
==================================================== | ||
|
||
CircuitPython module for the MCP23S08 I2C I/O extenders. | ||
|
||
* Author(s): Tony DiCola, Romy Bompart (2020), Red_M (2021) | ||
""" | ||
|
||
from micropython import const | ||
from .mcp23sxx import MCP23SXX | ||
from .digital_inout import DigitalInOut | ||
|
||
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MCP23Sxx.git" | ||
|
||
_MCP23S08_ADDRESS = const(0x20) | ||
_MCP23S08_IODIR = const(0x00) | ||
_MCP23S08_IPOL = const(0x01) | ||
_MCP23S08_GPINTEN = const(0x02) | ||
_MCP23S08_DEFVAL = const(0x03) | ||
_MCP23S08_INTCON = const(0x04) | ||
_MCP23S08_IOCON = const(0x05) | ||
_MCP23S08_GPPU = const(0x06) | ||
_MCP23S08_INTF = const(0x07) | ||
_MCP23S08_INTCAP = const(0x08) | ||
_MCP23S08_GPIO = const(0x09) | ||
Red-M marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# pylint: disable=too-many-arguments | ||
class MCP23S08(MCP23SXX): | ||
"""Supports MCP23S08 instance on specified I2C bus and optionally | ||
at the specified I2C address. | ||
""" | ||
|
||
def __init__( | ||
self, spi, chip_select, address=_MCP23S08_ADDRESS, reset=True, baudrate=100000 | ||
): | ||
super().__init__(spi, address, chip_select, baudrate=baudrate) | ||
# For user information | ||
self.address = address | ||
if reset: | ||
# Reset to all inputs with no pull-ups and no inverted polarity. | ||
self.iodir = 0xFF | ||
self.gppu = 0x00 | ||
self._write_u8(_MCP23S08_IPOL, 0x00) | ||
|
||
@property | ||
def gpio(self): | ||
"""The raw GPIO output register. Each bit represents the | ||
output value of the associated pin (0 = low, 1 = high), assuming that | ||
pin has been configured as an output previously. | ||
""" | ||
return self._read_u8(_MCP23S08_GPIO) | ||
|
||
@gpio.setter | ||
def gpio(self, val): | ||
self._write_u8(_MCP23S08_GPIO, val) | ||
|
||
@property | ||
def iodir(self): | ||
"""The raw IODIR direction register. Each bit represents | ||
direction of a pin, either 1 for an input or 0 for an output mode. | ||
""" | ||
return self._read_u8(_MCP23S08_IODIR) | ||
|
||
@iodir.setter | ||
def iodir(self, val): | ||
self._write_u8(_MCP23S08_IODIR, val) | ||
|
||
@property | ||
def gppu(self): | ||
"""The raw GPPU pull-up register. Each bit represents | ||
if a pull-up is enabled on the specified pin (1 = pull-up enabled, | ||
0 = pull-up disabled). Note pull-down resistors are NOT supported! | ||
""" | ||
return self._read_u8(_MCP23S08_GPPU) | ||
|
||
@gppu.setter | ||
def gppu(self, val): | ||
self._write_u8(_MCP23S08_GPPU, val) | ||
|
||
def get_pin(self, pin): | ||
"""Convenience function to create an instance of the DigitalInOut class | ||
pointing at the specified pin of this MCP23S08 device. | ||
""" | ||
if not 0 <= pin <= 7: | ||
raise ValueError("Pin number must be 0-7.") | ||
return DigitalInOut(pin, self) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.