Skip to content

Add support to CST816 chips with different register for chip ID #2

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 1 commit into from
Mar 31, 2025
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
21 changes: 14 additions & 7 deletions adafruit_cst8xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
_CST_REG_TOUCHDATA = const(0x03)
_CST_REG_SLEEP = const(0xA5)
_CST_REG_FIRMVERS = const(0xA6)
_CST_REG_CHIPID_816 = const(0xA7)
_CST_REG_MODID = const(0xA8)
_CST_REG_PROJID = const(0xA9)
_CST_REG_CHIPTYPE = const(0xAA)
Expand Down Expand Up @@ -77,14 +78,20 @@ def __init__(self, i2c, address=_CST_DEFAULT_I2C_ADDR, debug=False, irq_pin=None

chip_data = self._read(_CST_REG_FIRMVERS, 6) # don't wait for IRQ
# print("chip_data: {%x}".format(chip_data))
fw_version, _, _, chip_type = struct.unpack("<HBBH", chip_data)
print("fw_version: {:02X}, chip_type: {:02X}".format(fw_version, chip_type))

if chip_type not in (_CHIP_ID_CST826,):
raise RuntimeError("Did not find CST8XX chip")

if debug:
print("Firmware vers %04X" % int(fw_version))
fw_version, _, _, chip_type = struct.unpack("<HBBH", chip_data)
print("fw_version: {:02X}, chip_type: {:02X}".format(fw_version, chip_type))

if chip_data[1] in (_CHIP_ID_CST816S, _CHIP_ID_CST816T, _CHIP_ID_CST816D):
# this is a CST816x
if debug:
print("CST816 chip found")
elif chip_data[5] in (_CHIP_ID_CST826,):
# this is a CST826
if debug:
print("CST826 chip found")
else:
raise RuntimeError("Did not find supported CST8XX chip")

@property
def touched(self) -> int:
Expand Down