Skip to content

Update EEPROM I2C addr for ATtiny seesaw variants #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def const(x):
_ATTINY817_HW_ID_CODE = const(0x87)
_ATTINY1616_HW_ID_CODE = const(0x88)
_ATTINY1617_HW_ID_CODE = const(0x89)
_EEPROM_I2C_ADDR = const(0x3F)

_ENCODER_STATUS = const(0x00)
_ENCODER_INTENSET = const(0x10)
Expand Down Expand Up @@ -440,16 +439,32 @@ def disable_encoder_interrupt(self, encoder=0):
#
# return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA)

def _get_eeprom_i2c_addr(self):
"""Return the EEPROM address used to store I2C address."""
chip_id = self.chip_id
if chip_id in (
_ATTINY806_HW_ID_CODE,
_ATTINY807_HW_ID_CODE,
_ATTINY816_HW_ID_CODE,
_ATTINY817_HW_ID_CODE,
):
return 0x7F
if chip_id in (
_ATTINY1616_HW_ID_CODE,
_ATTINY1617_HW_ID_CODE,
):
return 0xFF
if chip_id in (_SAMD09_HW_ID_CODE,):
return 0x3F
return None

def set_i2c_addr(self, addr):
"""Store a new address in the device's EEPROM and reboot it."""
self.eeprom_write8(_EEPROM_I2C_ADDR, addr)
time.sleep(0.250)
self.i2c_device.device_address = addr
self.sw_reset()
self.eeprom_write8(self._get_eeprom_i2c_addr(), addr)

def get_i2c_addr(self):
"""Return the device's I2C address stored in its EEPROM"""
return self.read8(_EEPROM_BASE, _EEPROM_I2C_ADDR)
return self.read8(_EEPROM_BASE, self._get_eeprom_i2c_addr())

def eeprom_write8(self, addr, val):
"""Write a single byte directly to the device's EEPROM"""
Expand Down