Skip to content
Open
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
19 changes: 13 additions & 6 deletions api_drivers/common_api_drivers/indev/cst816s.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
_BPC1L = const(0xB3)

_ChipID = const(0xA7)
_ChipIDValue = const(0xB5)
_ChipIDValue2 = const(0xB6)
# Known chip IDs for CST816S
_ExpectedChipIDs = (const(0xB4), const(0xB5), const(0xB6))

_ProjID = const(0xA8)
_FwVersion = const(0xA9)
Expand Down Expand Up @@ -173,7 +173,8 @@ def __init__(
reset_pin=None,
touch_cal=None,
startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._0, # NOQA
debug=False
debug=False,
valid_ids=_ExpectedChipIDs
):
self._tx_buf = bytearray(2)
self._tx_mv = memoryview(self._tx_buf)
Expand Down Expand Up @@ -205,9 +206,15 @@ def __init__(

self._read_reg(_FwVersion)
print('FW Version:', hex(self._rx_buf[0]))

if chip_id not in (_ChipIDValue, _ChipIDValue2):
raise RuntimeError(f'Incorrect chip id ({hex(_ChipIDValue)})')

if type(valid_ids) == int:
if chip_id != valid_ids:
raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {hex(valid_ids)}')
elif type(valid_ids) == tuple:
if chip_id not in valid_ids:
raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {", ".join(hex(v) for v in valid_ids)}')
else:
raise RuntimeError(f'Expected chip id needs to be int or tuple')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if isinstance(valid_ids, (list, tuple)):
            if chip_id not in valid_ids:
                raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {", ".join(hex(v) for v in valid_ids)}')
        elif chip_id != valid_ids:
                raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {hex(valid_ids)}')

That should be all that needs to be added.


self._write_reg(_IrqCtl, _EnTouch | _EnChange)

Expand Down
Loading