]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/fake_mcp2221/i2c.py
blacken
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / fake_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 import random
6 from .fake_mcp2221 import mcp2221
7
8
9 class I2C:
10     """Custom I2C Class for MCP2221"""
11
12     def __init__(self, *, frequency=100000):
13         self._mcp2221 = mcp2221
14
15     def scan(self, address_list=None):
16         """Mocks an I2C scan.
17         If address_list is not provided, this function returns a list of 3 randomly generated I2C addresses from 0x0 to 0x79.
18         For a stimulus-driven test: If address_list is provided, this function returns the provided address_list.
19         """
20         if address_list == None:
21             # Generate a list of 3 randomly generated addresses from 0x0 to 0x79
22             address_list = []
23             for _ in range(3):
24                 address_list.append(random.randint(0x0, 0x79))
25             return address_list
26         return address_list
27
28     # pylint: disable=unused-argument
29     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
30         """Write data from the buffer to an address"""
31         pass
32
33     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
34         """Read data from an address and into the buffer"""
35         pass
36
37     def writeto_then_readfrom(
38         self,
39         address,
40         buffer_out,
41         buffer_in,
42         *,
43         out_start=0,
44         out_end=None,
45         in_start=0,
46         in_end=None,
47         stop=False,
48     ):
49         """Write data from buffer_out to an address and then
50         read data from an address and into buffer_in
51         """
52         pass
53
54     # pylint: enable=unused-argument