From b80fde066fba06bd4a21f63f66275136e4dd6d0a Mon Sep 17 00:00:00 2001 From: Rinaldi Jandrinata <48564964+puppet13th@users.noreply.github.com> Date: Fri, 13 Oct 2023 20:52:26 +0700 Subject: [PATCH] Update eeprom_i2c.py allow to override addr and max_chips_count --- eeprom/i2c/eeprom_i2c.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eeprom/i2c/eeprom_i2c.py b/eeprom/i2c/eeprom_i2c.py index cf16bcb..26a19e2 100644 --- a/eeprom/i2c/eeprom_i2c.py +++ b/eeprom/i2c/eeprom_i2c.py @@ -19,7 +19,7 @@ T24C32 = const(4096) # 4KiB 32Kbits # Logical EEPROM device consists of 1-8 physical chips. Chips must all be the # same size, and must have contiguous addresses. class EEPROM(BlockDevice): - def __init__(self, i2c, chip_size=T24C512, verbose=True, block_size=9): + def __init__(self, i2c, chip_size=T24C512, verbose=True, block_size=9, addr=_ADDR, max_chips_count=_MAX_CHIPS_COUNT): self._i2c = i2c if chip_size not in (T24C32, T24C64, T24C128, T24C256, T24C512): print("Warning: possible unsupported chip. Size:", chip_size) @@ -31,9 +31,9 @@ class EEPROM(BlockDevice): self._addrbuf = bytearray(2) # Memory offset into current chip # Check for a valid hardware configuration - def scan(self, verbose, chip_size): + def scan(self, verbose, chip_size, addr, max_chips_count): devices = self._i2c.scan() # All devices on I2C bus - eeproms = [d for d in devices if _ADDR <= d < _ADDR + _MAX_CHIPS_COUNT] # EEPROM chips + eeproms = [d for d in devices if addr <= d < addr + max_chips_count] # EEPROM chips nchips = len(eeproms) if nchips == 0: raise RuntimeError("EEPROM not found.")