54
54
55
55
56
56
def _convert_i2c_addr_to_atecc_addr (i2c_addr = 0x60 ):
57
- int (i2c_addr , 16 )
57
+ int (hex ( i2c_addr ) , 16 )
58
58
return i2c_addr << 1
59
59
60
60
61
61
# Device Address
62
62
_I2C_ADDR = 0x60
63
63
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr (i2c_addr = _I2C_ADDR )
64
64
65
- # TODO: Verify that _REG_ATECC_ADDR is still 0xC0
66
- # TODO: Remove assertion test afterwards
67
- assert _REG_ATECC_ADDR == 0xC0
68
-
69
65
_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1
70
66
71
67
# Version Registers
@@ -100,15 +96,6 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
100
96
OP_WRITE : const (26 ),
101
97
}
102
98
103
- CFG_TLS = b"\x01 #\x00 \x00 \x00 \x00 P\x00 \x00 \x00 \x00 \x00 \x00 \xc0 q\x00 \
104
- \xc0 \x00 U\x00 \x83 \x87 \x87 \x87 /\x87 /\x8f \x8f \x9f \x8f \xaf \
105
- \x8f \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \
106
- \xaf \x8f \xff \xff \xff \xff \x00 \x00 \x00 \x00 \xff \xff \xff \xff \x00 \
107
- \x00 \x00 \x00 \xff \xff \xff \xff \xff \xff \xff \xff \xff \xff \xff \xff \
108
- \xff \xff \xff \xff \x00 \x00 UU\xff \xff \x00 \x00 \x00 \x00 \x00 \x00 3 \
109
- \x00 3\x00 3\x00 3\x00 3\x00 \x1c \x00 \x1c \x00 \x1c \x00 <\x00 <\x00 <\x00 < \
110
- \x00 <\x00 <\x00 <\x00 \x1c \x00 "
111
-
112
99
"""
113
100
Configuration Zone Bytes
114
101
@@ -132,7 +119,7 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
132
119
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
133
120
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
134
121
"""
135
- CFG_TLS_HEX = bytes (
122
+ CFG_TLS = bytes (
136
123
bytearray .fromhex (
137
124
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
138
125
"20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55"
@@ -151,17 +138,11 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
151
138
)
152
139
)
153
140
154
- # TODO: Verify that both representations are identical
155
- # TODO: Decide whether to use alternate representation of config bytes
156
- # TODO: Remove assertion tests
157
- assert CFG_TLS == CFG_TLS_HEX
158
- assert bytearray (CFG_TLS )[16 ] == 0x20
159
-
160
141
# Convert I2C address to config byte 16 and update CFG_TLS
161
- _CFG_BYTES = bytearray (CFG_TLS )
162
- _CFG_BYTE_16 = hex (_I2C_ADDR << 1 )
163
- _CFG_BYTES [ 16 ] = ord (_CFG_BYTE_16 )
164
- CFG_TLS = bytes (_CFG_BYTES )
142
+ _CFG_BYTES_LIST = list ( bytearray (CFG_TLS ) )
143
+ _CFG_BYTE_16 = bytes ( bytearray . fromhex ( hex (_I2C_ADDR << 1 ). replace ( "0x" , "" )) )
144
+ _CFG_BYTES_LIST_MOD = _CFG_BYTES_LIST [ 0 : 16 ] + list (_CFG_BYTE_16 ) + _CFG_BYTES_LIST [ 17 :]
145
+ CFG_TLS = bytes (_CFG_BYTES_LIST_MOD )
165
146
166
147
167
148
class ATECC :
0 commit comments