@@ -111,7 +111,6 @@ def const(x):
111
111
_ATTINY817_HW_ID_CODE = const (0x87 )
112
112
_ATTINY1616_HW_ID_CODE = const (0x88 )
113
113
_ATTINY1617_HW_ID_CODE = const (0x89 )
114
- _EEPROM_I2C_ADDR = const (0x3F )
115
114
116
115
_ENCODER_STATUS = const (0x00 )
117
116
_ENCODER_INTENSET = const (0x10 )
@@ -440,16 +439,32 @@ def disable_encoder_interrupt(self, encoder=0):
440
439
#
441
440
# return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA)
442
441
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
+
443
461
def set_i2c_addr (self , addr ):
444
462
"""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 )
449
464
450
465
def get_i2c_addr (self ):
451
466
"""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 () )
453
468
454
469
def eeprom_write8 (self , addr , val ):
455
470
"""Write a single byte directly to the device's EEPROM"""
0 commit comments