Update eeprom_i2c.py

allow to override addr and max_chips_count
pull/19/head
Rinaldi Jandrinata 2023-10-13 20:52:26 +07:00 zatwierdzone przez GitHub
rodzic 4003fcef44
commit b80fde066f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 3 dodań i 3 usunięć

Wyświetl plik

@ -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.")