[cst816] Fix CST826 & CST836 (#12260)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
jsmarion
2025-12-03 14:35:14 -05:00
committed by GitHub
parent a24ba26068
commit 03aaa66f8e
2 changed files with 42 additions and 24 deletions

View File

@@ -9,27 +9,40 @@ void CST816Touchscreen::continue_setup_() {
this->interrupt_pin_->setup();
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
}
if (this->read_byte(REG_CHIP_ID, &this->chip_id_)) {
switch (this->chip_id_) {
case CST820_CHIP_ID:
case CST826_CHIP_ID:
case CST716_CHIP_ID:
case CST816S_CHIP_ID:
case CST816D_CHIP_ID:
case CST816T_CHIP_ID:
break;
default:
if (!this->read_byte(REG_CHIP_ID, &this->chip_id_) && !this->skip_probe_) {
this->status_set_error(LOG_STR("Failed to read chip ID"));
this->mark_failed();
return;
}
// CST826/CST836 return 0 for chip ID, need to read from factory ID register
if (this->chip_id_ == 0) {
if (!this->read_byte(REG_FACTORY_ID, &this->chip_id_) && !this->skip_probe_) {
this->status_set_error(LOG_STR("Failed to read chip ID"));
this->mark_failed();
return;
}
}
switch (this->chip_id_) {
case CST716_CHIP_ID:
case CST816S_CHIP_ID:
case CST816D_CHIP_ID:
case CST816T_CHIP_ID:
case CST820_CHIP_ID:
case CST826_CHIP_ID:
case CST836_CHIP_ID:
break;
default:
if (!this->skip_probe_) {
ESP_LOGE(TAG, "Unknown chip ID: 0x%02X", this->chip_id_);
this->status_set_error(LOG_STR("Unknown chip ID"));
this->mark_failed();
return;
}
this->write_byte(REG_IRQ_CTL, IRQ_EN_MOTION);
} else if (!this->skip_probe_) {
this->status_set_error(LOG_STR("Failed to read chip id"));
this->mark_failed();
return;
}
}
this->write_byte(REG_IRQ_CTL, IRQ_EN_MOTION);
if (this->x_raw_max_ == this->x_raw_min_) {
this->x_raw_max_ = this->display_->get_native_width();
}
@@ -80,11 +93,8 @@ void CST816Touchscreen::dump_config() {
this->x_raw_min_, this->x_raw_max_, this->y_raw_min_, this->y_raw_max_);
const char *name;
switch (this->chip_id_) {
case CST820_CHIP_ID:
name = "CST820";
break;
case CST826_CHIP_ID:
name = "CST826";
case CST716_CHIP_ID:
name = "CST716";
break;
case CST816S_CHIP_ID:
name = "CST816S";
@@ -92,12 +102,18 @@ void CST816Touchscreen::dump_config() {
case CST816D_CHIP_ID:
name = "CST816D";
break;
case CST716_CHIP_ID:
name = "CST716";
break;
case CST816T_CHIP_ID:
name = "CST816T";
break;
case CST820_CHIP_ID:
name = "CST820";
break;
case CST826_CHIP_ID:
name = "CST826";
break;
case CST836_CHIP_ID:
name = "CST836";
break;
default:
name = "Unknown";
break;

View File

@@ -19,12 +19,14 @@ static const uint8_t REG_YPOS_HIGH = 0x05;
static const uint8_t REG_YPOS_LOW = 0x06;
static const uint8_t REG_DIS_AUTOSLEEP = 0xFE;
static const uint8_t REG_CHIP_ID = 0xA7;
static const uint8_t REG_FACTORY_ID = 0xAA;
static const uint8_t REG_FW_VERSION = 0xA9;
static const uint8_t REG_SLEEP = 0xE5;
static const uint8_t REG_IRQ_CTL = 0xFA;
static const uint8_t IRQ_EN_MOTION = 0x70;
static const uint8_t CST826_CHIP_ID = 0x11;
static const uint8_t CST836_CHIP_ID = 0x13;
static const uint8_t CST820_CHIP_ID = 0xB7;
static const uint8_t CST816S_CHIP_ID = 0xB4;
static const uint8_t CST816D_CHIP_ID = 0xB6;