Skip to content

Commit 503dfa1

Browse files
authored
Merge pull request #123 from caternuson/eeprom_i2c_addr
Update EEPROM I2C addr for ATtiny seesaw variants
2 parents c43206f + 3443b3c commit 503dfa1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 21 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,32 @@ def disable_encoder_interrupt(self, encoder=0):
440439
#
441440
# return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA)
442441

442+
def _get_eeprom_i2c_addr(self):
443+
"""Return the EEPROM address used to store I2C address."""
444+
chip_id = self.chip_id
445+
if chip_id in (
446+
_ATTINY806_HW_ID_CODE,
447+
_ATTINY807_HW_ID_CODE,
448+
_ATTINY816_HW_ID_CODE,
449+
_ATTINY817_HW_ID_CODE,
450+
):
451+
return 0x7F
452+
if chip_id in (
453+
_ATTINY1616_HW_ID_CODE,
454+
_ATTINY1617_HW_ID_CODE,
455+
):
456+
return 0xFF
457+
if chip_id in (_SAMD09_HW_ID_CODE,):
458+
return 0x3F
459+
return None
460+
443461
def set_i2c_addr(self, addr):
444462
"""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()
463+
self.eeprom_write8(self._get_eeprom_i2c_addr(), addr)
449464

450465
def get_i2c_addr(self):
451466
"""Return the device's I2C address stored in its EEPROM"""
452-
return self.read8(_EEPROM_BASE, _EEPROM_I2C_ADDR)
467+
return self.read8(_EEPROM_BASE, self._get_eeprom_i2c_addr())
453468

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

0 commit comments

Comments
 (0)