- "Meaning" of the new EEPROM constructor parameter `page_size` changed from

the size itself to the binary logarithm of the size.
- Default value of this parameter changed from None to 7, to match the
  behaviour of the constructor in its previous form, as discussed in the PR.
- Dictionary _PAGE_SIZES removed.
- Documentation updated.
pull/22/head
Abel Deuring 2024-01-06 16:07:04 +01:00
rodzic 208b3089bb
commit 6399f9f6d3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7A404F866F0DAED0
2 zmienionych plików z 4 dodań i 19 usunięć

Wyświetl plik

@ -132,6 +132,7 @@ Arguments:
is `2**block_size` so is 512 bytes by default.
5. `addr` override base address for first chip
6. `max_chips_count` override max_chips_count
7. `page_size=7` The binary logarithm of the page size of the EEPROMs, i.e., the page size in bytes is `2 ** page_size`. The page size may vary between chips from different manufacturers even for the same storage size. Note that specifying a too large value will most likely lead to data corruption in write operations. Look up the correct value for your setup in the chip's datasheet.
With `addr` and `max_chips_count` override, it's possible to make multiple
configuration

Wyświetl plik

@ -16,18 +16,10 @@ T24C128 = const(16384) # 16KiB 128Kbits
T24C64 = const(8192) # 8KiB 64Kbits
T24C32 = const(4096) # 4KiB 32Kbits
_PAGE_SIZES = {
T24C32: const(0x20),
T24C64: const(0x20),
T24C128: const(0x40),
T24C256: const(0x40),
T24C512: const(0x80),
}
# 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, addr=_ADDR, max_chips_count=_MAX_CHIPS_COUNT, page_size=None):
def __init__(self, i2c, chip_size=T24C512, verbose=True, block_size=9, addr=_ADDR, max_chips_count=_MAX_CHIPS_COUNT, page_size=7):
self._i2c = i2c
if chip_size not in (T24C32, T24C64, T24C128, T24C256, T24C512):
print("Warning: possible unsupported chip. Size:", chip_size)
@ -37,16 +29,8 @@ class EEPROM(BlockDevice):
self._i2c_addr = 0 # I2C address of current chip
self._buf1 = bytearray(1)
self._addrbuf = bytearray(2) # Memory offset into current chip
if page_size is None:
if chip_size not in _PAGE_SIZES:
raise ValueError(
f'The page size for chip size {chip_size} is not known.'
'Please specify it in the parameter page_size')
self._page_mask = ~(_PAGE_SIZES[chip_size] - 1)
self._page_size = _PAGE_SIZES[chip_size]
else:
self._page_mask = ~(page_size - 1)
self._page_size = page_size
self._page_size = 2 ** page_size
self._page_mask = ~(self._page_size - 1)
# Check for a valid hardware configuration
def scan(self, verbose, chip_size, addr, max_chips_count):