From: brentru Date: Fri, 29 Mar 2024 15:18:48 +0000 (-0400) Subject: fake i2c device scan, allow stimulus X-Git-Tag: 8.39.0^2~11 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/0e0e0f1a1ef91a20236627aaf4cf82df03f9a836?ds=inline fake i2c device scan, allow stimulus --- diff --git a/src/adafruit_blinka/microcontroller/fake_mcp2221/i2c.py b/src/adafruit_blinka/microcontroller/fake_mcp2221/i2c.py index 9b55c68..5f28051 100644 --- a/src/adafruit_blinka/microcontroller/fake_mcp2221/i2c.py +++ b/src/adafruit_blinka/microcontroller/fake_mcp2221/i2c.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT """I2C Class for MCP2221""" +import random from .fake_mcp2221 import mcp2221 @@ -10,21 +11,28 @@ class I2C: def __init__(self, *, frequency=100000): self._mcp2221 = mcp2221 - # self._mcp2221._i2c_configure(frequency) - def scan(self): - """Perform an I2C Device Scan""" - # TODO: We need to fake an I2C scan here - return self._mcp2221.i2c_scan() + def scan(self, address_list = None): + """Mocks an I2C scan. + If address_list is not provided, this function returns a list of 3 randomly generated I2C addresses from 0x0 to 0x79. + For a stimulus-driven test: If address_list is provided, this function returns the provided address_list. + """ + if address_list == None: + # Generate a list of 3 randomly generated addresses from 0x0 to 0x79 + address_list = [] + for _ in range(3): + address_list.append(random.randint(0x0, 0x79)) + return address_list + return address_list # pylint: disable=unused-argument def writeto(self, address, buffer, *, start=0, end=None, stop=True): """Write data from the buffer to an address""" - #self._mcp2221.i2c_writeto(address, buffer, start=start, end=end) + pass def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True): """Read data from an address and into the buffer""" - #self._mcp2221.i2c_readfrom_into(address, buffer, start=start, end=end) + pass def writeto_then_readfrom( self, @@ -41,17 +49,6 @@ class I2C: """Write data from buffer_out to an address and then read data from an address and into buffer_in """ - - """ - self._mcp2221.i2c_writeto_then_readfrom( - address, - buffer_out, - buffer_in, - out_start=out_start, - out_end=out_end, - in_start=in_start, - in_end=in_end, - ) - """ + pass # pylint: enable=unused-argument \ No newline at end of file