@@ -113,48 +113,28 @@ def __init__(self, i2c_bus, address=_REG_ATECC_DEVICE_ADDR, debug=False):
113
113
"""
114
114
self ._debug = debug
115
115
self ._i2cbuf = bytearray (12 )
116
- self ._i2c_bus = i2c_bus
117
- self ._i2c_device = None
118
- self .wakeup ()
119
- if not self ._i2c_device :
120
- self ._i2c_device = I2CDevice (self ._i2c_bus , address )
121
- self .idle ()
116
+ # don't probe, the device will NACK until woken up
117
+ self ._wake_device = I2CDevice (i2c_bus , 0x00 , probe = False )
118
+ self ._i2c_device = I2CDevice (i2c_bus , address , probe = False )
122
119
if (self .version () >> 8 ) not in (_ATECC_508_VER , _ATECC_608_VER ):
123
120
raise RuntimeError (
124
121
"Failed to find 608 or 508 chip. Please check your wiring."
125
122
)
126
123
127
124
def wakeup (self ):
128
- """Wakes up THE ATECC608A from sleep or idle modes.
129
- Returns True if device woke up from sleep/idle mode.
130
- """
131
- while not self ._i2c_bus .try_lock ():
132
- pass
133
- # check if it exists, first
134
- if 0x60 in self ._i2c_bus .scan ():
135
- self ._i2c_bus .unlock ()
136
- return
137
- zero_bits = bytearray (2 )
125
+ """Wakes up THE ATECC608A from sleep or idle modes."""
126
+ # This is a hack to generate the ATECC Wake condition, which is SDA
127
+ # held low for t > 60us (twlo). For an I2C clock freq of 100kHz, 8
128
+ # clock cycles will be 80us. This signal is generated by trying to
129
+ # address something at 0x00. It will fail, but the pattern should
130
+ # wake up the ATECC.
131
+ # pylint: disable=bare-except
138
132
try :
139
- self ._i2c_bus .writeto (0x0 , zero_bits )
140
- except OSError :
141
- pass # this may fail, that's ok - its just to wake up the chip!
142
- time .sleep (_TWLO_TIME )
143
- data = self ._i2c_bus .scan () # check for an i2c device
144
-
145
- try :
146
- if data [0 ] != 96 :
147
- raise TypeError ("ATECCx08 not found - please check your wiring!" )
148
- except IndexError as err :
149
- raise IndexError ("ATECCx08 not found - please check your wiring!" ) from err
150
- self ._i2c_bus .unlock ()
151
- if not self ._i2c_device :
152
- self ._i2c_device = I2CDevice (self ._i2c_bus , _REG_ATECC_DEVICE_ADDR )
153
- # check if we are ready to read from
154
- r = bytearray (1 )
155
- self ._get_response (r )
156
- if r [0 ] != 0x11 :
157
- raise RuntimeError ("Failed to wakeup" )
133
+ with self ._wake_device as i2c :
134
+ i2c .write (bytes ([0x00 ]))
135
+ except :
136
+ pass
137
+ time .sleep (0.001 )
158
138
159
139
def idle (self ):
160
140
"""Puts the chip into idle mode
0 commit comments