Skip to content

Commit 4d9addf

Browse files
committed
- Added documentation for config bytes
- Added documentation for i2c config byte 16 - Added I2C address variable used to derive config byte 16 - Added I2C address to config byte 16 of CFG_TLS - Modified representation of CFG_TLS
1 parent be7dd75 commit 4d9addf

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

adafruit_atecc/adafruit_atecc.py

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,20 @@
5252
__version__ = "0.0.0-auto.0"
5353
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ATECC.git"
5454

55+
56+
def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
57+
int(i2c_addr, 16)
58+
return i2c_addr << 1
59+
60+
5561
# Device Address
56-
_REG_ATECC_ADDR = const(0xC0)
62+
_I2C_ADDR = 0x60
63+
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr(i2c_addr=_I2C_ADDR)
64+
65+
# TODO: Verify that _REG_ATECC_ADDR is still 0xC0
66+
# TODO: Remove assertion test afterwards
67+
assert _REG_ATECC_ADDR == 0xC0
68+
5769
_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1
5870

5971
# Version Registers
@@ -88,7 +100,6 @@
88100
OP_WRITE: const(26),
89101
}
90102

91-
92103
CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \
93104
\xc0\x00U\x00\x83 \x87 \x87 \x87/\x87/\x8f\x8f\x9f\x8f\xaf \
94105
\x8f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \
@@ -98,6 +109,58 @@
98109
\x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \
99110
\x00<\x00<\x00<\x00\x1c\x00"
100111

112+
"""
113+
Serial Number (Bytes 0-3 and 8-12), Revision Number (Bytes 4-7)
114+
AES Enable (Byte 13), I2C Enable (Byte 14), Reserved (Byte 15)
115+
I2C Address (Byte 16), Reserved (Byte 17); Count Match (Byte 18)
116+
Chi Mode (Byte 19), Slot Config (Bytes 20-51)
117+
Counter 0 (Bytes 52-59), Counter 1 (Bytes 60-67)
118+
Use Lock (Byte 68), Volatile Key Permission (Byte 69)
119+
Secure Boot (Bytes 70-71), KDF (Bytes 72-74)
120+
Reserved (Bytes 75-83), User Extra (Bytes 84-85)
121+
Lock Config (Bytes 86-89), Chip Options (Bytes 90-91)
122+
X509 (Bytes 92-95), Key Config (Bytes 96-127)
123+
"""
124+
CFG_TLS_HEX = bytes(
125+
bytearray.fromhex(
126+
'01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00'
127+
'20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55'
128+
'00 83 20 87 20 87 20 87 2f 87 2f 8f 8f 9f 8f af'
129+
'20 20 20 20 20 20 20 20 20 20 20 20 20 8f 00 00'
130+
'00 00 00 00 00 00 00 00 00 00 00 00 20 20 20 20'
131+
'20 20 20 20 20 20 20 20 20 af 8f ff ff ff ff 00'
132+
'00 00 00 ff ff ff ff 00 20 20 20 20 20 20 20 20'
133+
'20 20 20 20 20 00 00 00 ff ff ff ff ff ff ff ff'
134+
'ff ff ff ff 20 20 20 20 20 20 20 20 20 20 20 20'
135+
'20 ff ff ff ff 00 00 55 55 ff ff 00 00 00 00 00'
136+
'00 33 20 20 20 20 20 20 20 20 20 20 20 20 20 00'
137+
'33 00 33 00 33 00 33 00 1c 00 1c 00 1c 00 3c 00'
138+
'3c 00 3c 00 3c 20 20 20 20 20 20 20 20 20 20 20'
139+
'20 20 00 3c 00 3c 00 3c 00 1c 00'
140+
)
141+
)
142+
143+
# TODO: Verify that both representations are identical
144+
# TODO: Decide whether to use alternate representation of config bytes
145+
# TODO: Remove assertion tests
146+
assert CFG_TLS == CFG_TLS_HEX
147+
assert bytearray(CFG_TLS)[16] == 0x20 #
148+
149+
"""I2C Config
150+
HEX DEC BIN Description
151+
Byte 14: C0 192 1100 0000
152+
^xxx xxxx Bit 0 (MSB): 0:Single Wire, 1:I2C; Bit 1-7: Set by Microchip
153+
Byte 16: C0 192 0010 0000 Default 7 bit I2C Address: 0xC0>>1: 0x60 ATECC608A-MAHDA
154+
Byte 16: 6A 106 0010 0000 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
155+
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
156+
"""
157+
158+
# Convert I2C address to config byte 16 and update CFG_TLS
159+
_CFG_BYTES = bytearray(CFG_TLS)
160+
_CFG_BYTE_16 = hex(_I2C_ADDR << 1)
161+
_CFG_BYTES[16] = ord(_CFG_BYTE_16)
162+
CFG_TLS = bytes(_CFG_BYTES)
163+
101164

102165
class ATECC:
103166
"""
@@ -254,7 +317,7 @@ def nonce(self, data, mode=0, zero=0x0000):
254317
time.sleep(1 / 1000)
255318
if mode == 0x03:
256319
assert (
257-
calculated_nonce[0] == 0x00
320+
calculated_nonce[0] == 0x00
258321
), "Incorrectly calculated nonce in pass-thru mode"
259322
self.idle()
260323
return calculated_nonce
@@ -424,7 +487,7 @@ def write_config(self, data):
424487
if i == 84:
425488
# can't write
426489
continue
427-
self._write(0, i // 4, data[i : i + 4])
490+
self._write(0, i // 4, data[i: i + 4])
428491

429492
def _write(self, zone, address, buffer):
430493
self.wakeup()

0 commit comments

Comments
 (0)