From 4e7e6314131123a8a7cf37769605f89fe7e19b7d Mon Sep 17 00:00:00 2001 From: David Dudas Date: Sat, 17 Jan 2026 12:27:33 +0100 Subject: [PATCH 1/2] Add support for 0xb4 chip ID too --- api_drivers/common_api_drivers/indev/cst816s.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api_drivers/common_api_drivers/indev/cst816s.py b/api_drivers/common_api_drivers/indev/cst816s.py index 64255ac8..ea209e9c 100644 --- a/api_drivers/common_api_drivers/indev/cst816s.py +++ b/api_drivers/common_api_drivers/indev/cst816s.py @@ -40,8 +40,10 @@ _BPC1L = const(0xB3) _ChipID = const(0xA7) -_ChipIDValue = const(0xB5) -_ChipIDValue2 = const(0xB6) +_ChipIDValue = const(0xB4) +_ChipIDValue2 = const(0xB5) +_ChipIDValue3 = const(0xB6) +_ExpectedChipIDs = (_ChipIDValue, _ChipIDValue2, _ChipIDValue3) _ProjID = const(0xA8) _FwVersion = const(0xA9) @@ -206,8 +208,8 @@ 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 chip_id not in _ExpectedChipIDs: + raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {", ".join(hex(v) for v in _ExpectedChipIDs)}') self._write_reg(_IrqCtl, _EnTouch | _EnChange) From d1e0db45675fdf74a083d76f6f077e9e5d342c63 Mon Sep 17 00:00:00 2001 From: David Dudas Date: Tue, 20 Jan 2026 19:02:02 +0100 Subject: [PATCH 2/2] CST816S chip ID is a constructor parameter and do an instance check on passed arguments int and tuple are accepted --- .../common_api_drivers/indev/cst816s.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/api_drivers/common_api_drivers/indev/cst816s.py b/api_drivers/common_api_drivers/indev/cst816s.py index ea209e9c..fd0c6cd2 100644 --- a/api_drivers/common_api_drivers/indev/cst816s.py +++ b/api_drivers/common_api_drivers/indev/cst816s.py @@ -40,10 +40,8 @@ _BPC1L = const(0xB3) _ChipID = const(0xA7) -_ChipIDValue = const(0xB4) -_ChipIDValue2 = const(0xB5) -_ChipIDValue3 = const(0xB6) -_ExpectedChipIDs = (_ChipIDValue, _ChipIDValue2, _ChipIDValue3) +# Known chip IDs for CST816S +_ExpectedChipIDs = (const(0xB4), const(0xB5), const(0xB6)) _ProjID = const(0xA8) _FwVersion = const(0xA9) @@ -175,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) @@ -207,9 +206,15 @@ def __init__( self._read_reg(_FwVersion) print('FW Version:', hex(self._rx_buf[0])) - - if chip_id not in _ExpectedChipIDs: - raise RuntimeError(f'Incorrect chip id: {hex(chip_id)}, expected: {", ".join(hex(v) for v in _ExpectedChipIDs)}') + + 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') self._write_reg(_IrqCtl, _EnTouch | _EnChange)