Skip to content

Commit b33cd2a

Browse files
authored
Merge pull request #20 from rrottmann/master
Validated concat of bytes and fixed errors
2 parents 7882a95 + 58ff16a commit b33cd2a

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

adafruit_atecc/adafruit_atecc.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,14 @@
5454

5555

5656
def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
57-
int(i2c_addr, 16)
57+
int(hex(i2c_addr), 16)
5858
return i2c_addr << 1
5959

6060

6161
# Device Address
6262
_I2C_ADDR = 0x60
6363
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr(i2c_addr=_I2C_ADDR)
6464

65-
# TODO: Verify that _REG_ATECC_ADDR is still 0xC0
66-
# TODO: Remove assertion test afterwards
67-
assert _REG_ATECC_ADDR == 0xC0
68-
6965
_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1
7066

7167
# Version Registers
@@ -100,15 +96,6 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
10096
OP_WRITE: const(26),
10197
}
10298

103-
CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \
104-
\xc0\x00U\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\x00UU\xff\xff\x00\x00\x00\x00\x00\x003 \
109-
\x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \
110-
\x00<\x00<\x00<\x00\x1c\x00"
111-
11299
"""
113100
Configuration Zone Bytes
114101
@@ -132,7 +119,7 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
132119
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
133120
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
134121
"""
135-
CFG_TLS_HEX = bytes(
122+
CFG_TLS = bytes(
136123
bytearray.fromhex(
137124
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
138125
"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):
151138
)
152139
)
153140

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-
160141
# 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)
165146

166147

167148
class ATECC:

0 commit comments

Comments
 (0)