Skip to content

Commit f58dea6

Browse files
committed
update eeprom i2c addr for attiny
1 parent c43206f commit f58dea6

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def const(x):
111111
_ATTINY817_HW_ID_CODE = const(0x87)
112112
_ATTINY1616_HW_ID_CODE = const(0x88)
113113
_ATTINY1617_HW_ID_CODE = const(0x89)
114-
_EEPROM_I2C_ADDR = const(0x3F)
115114

116115
_ENCODER_STATUS = const(0x00)
117116
_ENCODER_INTENSET = const(0x10)
@@ -440,16 +439,36 @@ def disable_encoder_interrupt(self, encoder=0):
440439
#
441440
# return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA)
442441

442+
443+
def _get_eeprom_i2c_addr(self):
444+
""" Return the EEPROM address used to store I2C address."""
445+
chip_id = self.chip_id
446+
if chip_id in (
447+
_ATTINY806_HW_ID_CODE,
448+
_ATTINY807_HW_ID_CODE,
449+
_ATTINY816_HW_ID_CODE,
450+
_ATTINY817_HW_ID_CODE,
451+
):
452+
return 0x7F
453+
elif chip_id in (
454+
_ATTINY1616_HW_ID_CODE,
455+
_ATTINY1617_HW_ID_CODE,
456+
):
457+
return 0xFF
458+
elif chip_id in (
459+
_SAMD09_HW_ID_CODE,
460+
):
461+
return 0x3F
462+
else:
463+
raise RuntimeError("Unknown chip id", hex(chip_id))
464+
443465
def set_i2c_addr(self, addr):
444466
"""Store a new address in the device's EEPROM and reboot it."""
445-
self.eeprom_write8(_EEPROM_I2C_ADDR, addr)
446-
time.sleep(0.250)
447-
self.i2c_device.device_address = addr
448-
self.sw_reset()
467+
self.eeprom_write8(self._get_eeprom_i2c_addr(), addr)
449468

450469
def get_i2c_addr(self):
451470
"""Return the device's I2C address stored in its EEPROM"""
452-
return self.read8(_EEPROM_BASE, _EEPROM_I2C_ADDR)
471+
return self.read8(_EEPROM_BASE, self._get_eeprom_i2c_addr())
453472

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

0 commit comments

Comments
 (0)