@@ -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,36 @@ def disable_encoder_interrupt(self, encoder=0):
440
439
#
441
440
# return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA)
442
441
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
+
443
465
def set_i2c_addr (self , addr ):
444
466
"""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 )
449
468
450
469
def get_i2c_addr (self ):
451
470
"""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 () )
453
472
454
473
def eeprom_write8 (self , addr , val ):
455
474
"""Write a single byte directly to the device's EEPROM"""
0 commit comments