Skip to content

Validated concat of bytes and fixed errors #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions adafruit_atecc/adafruit_atecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,14 @@


def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
int(i2c_addr, 16)
int(hex(i2c_addr), 16)
return i2c_addr << 1


# Device Address
_I2C_ADDR = 0x60
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr(i2c_addr=_I2C_ADDR)

# TODO: Verify that _REG_ATECC_ADDR is still 0xC0
# TODO: Remove assertion test afterwards
assert _REG_ATECC_ADDR == 0xC0

_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1

# Version Registers
Expand Down Expand Up @@ -100,15 +96,6 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
OP_WRITE: const(26),
}

CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \
\xc0\x00U\x00\x83 \x87 \x87 \x87/\x87/\x8f\x8f\x9f\x8f\xaf \
\x8f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \
\xaf\x8f\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00 \
\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \
\xff\xff\xff\xff\x00\x00UU\xff\xff\x00\x00\x00\x00\x00\x003 \
\x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \
\x00<\x00<\x00<\x00\x1c\x00"

"""
Configuration Zone Bytes

Expand All @@ -132,7 +119,7 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
"""
CFG_TLS_HEX = bytes(
CFG_TLS = bytes(
bytearray.fromhex(
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
"20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55"
Expand All @@ -151,17 +138,11 @@ def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
)
)

# TODO: Verify that both representations are identical
# TODO: Decide whether to use alternate representation of config bytes
# TODO: Remove assertion tests
assert CFG_TLS == CFG_TLS_HEX
assert bytearray(CFG_TLS)[16] == 0x20

# Convert I2C address to config byte 16 and update CFG_TLS
_CFG_BYTES = bytearray(CFG_TLS)
_CFG_BYTE_16 = hex(_I2C_ADDR << 1)
_CFG_BYTES[16] = ord(_CFG_BYTE_16)
CFG_TLS = bytes(_CFG_BYTES)
_CFG_BYTES_LIST = list(bytearray(CFG_TLS))
_CFG_BYTE_16 = bytes(bytearray.fromhex(hex(_I2C_ADDR << 1).replace("0x", "")))
_CFG_BYTES_LIST_MOD = _CFG_BYTES_LIST[0:16] + list(_CFG_BYTE_16) + _CFG_BYTES_LIST[17:]
CFG_TLS = bytes(_CFG_BYTES_LIST_MOD)


class ATECC:
Expand Down