]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/mcp2221/i2c.py
Merge pull request #593 from makermelissa/main
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / mcp2221 / i2c.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2 #
3 # SPDX-License-Identifier: MIT
4 """I2C Class for MCP2221"""
5 from .mcp2221 import mcp2221
6
7
8 class I2C:
9     """Custom I2C Class for MCP2221"""
10
11     def __init__(self, *, frequency=100000):
12         self._mcp2221 = mcp2221
13         self._mcp2221._i2c_configure(frequency)
14
15     def scan(self):
16         """Perform an I2C Device Scan"""
17         return self._mcp2221.i2c_scan()
18
19     # pylint: disable=unused-argument
20     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
21         """Write data from the buffer to an address"""
22         self._mcp2221.i2c_writeto(address, buffer, start=start, end=end)
23
24     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
25         """Read data from an address and into the buffer"""
26         self._mcp2221.i2c_readfrom_into(address, buffer, start=start, end=end)
27
28     def writeto_then_readfrom(
29         self,
30         address,
31         buffer_out,
32         buffer_in,
33         *,
34         out_start=0,
35         out_end=None,
36         in_start=0,
37         in_end=None,
38         stop=False,
39     ):
40         """Write data from buffer_out to an address and then
41         read data from an address and into buffer_in
42         """
43         self._mcp2221.i2c_writeto_then_readfrom(
44             address,
45             buffer_out,
46             buffer_in,
47             out_start=out_start,
48             out_end=out_end,
49             in_start=in_start,
50             in_end=in_end,
51         )
52
53     # pylint: enable=unused-argument