Files
clawdmeter/firmware/src/boards/waveshare_amoled_216_c6/touch.cpp
T
Jerome TayandClaude Opus 4.8 9375bd6d66 fix(c6): drive AMOLED-2.16 C6 panel as CO5300, side-USB orientation
platformio.ini and the board files labelled the Waveshare
ESP32-C6-Touch-AMOLED-2.16 as an SH8601 panel, when it actually uses a
CO5300 (per the official spec) -- the same controller as the S3
AMOLED-2.16. It still rendered because display.cpp grafted CO5300-style
manufacturer registers (a 0xFE page-switch writing the 0x19/0x1C
driving-voltage registers) onto the Arduino_SH8601 class, and both
controllers speak standard MIPI DCS for pixel writes.

Rebase onto Arduino_CO5300 (matching the S3 AMOLED-2.16 sibling) and keep
only the page-0x20 panel-driving registers (0x19/0x1C) the class init
omits; everything else (0xC4/0x36/0x53/0x51/0x63/0x29) is now covered by
Arduino_CO5300::begin().

Adopt the CO5300 rotation-0 default (MADCTL 0x00) instead of the old forced
0x30 transpose, orienting the board with the USB port on the side (the
preferred desk orientation). Touch axis mapping is re-derived and tap-tested
on hardware to match: swap=false, mirror=(false,false).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-08 21:37:34 +08:00

57 lines
1.8 KiB
C++

#include "../../hal/touch_hal.h"
#include "board.h"
#include <Arduino.h>
#include <Wire.h>
#include <TouchDrvCSTXXX.hpp>
static TouchDrvCST92xx touch;
static volatile bool touch_data_ready = false;
static volatile bool touch_pressed = false;
static volatile uint16_t touch_x = 0;
static volatile uint16_t touch_y = 0;
static void IRAM_ATTR touch_isr(void) {
touch_data_ready = true;
}
void touch_hal_init(void) {
touch.setPins(TP_RST, TP_INT);
if (!touch.begin(Wire, CST9220_ADDR, IIC_SDA, IIC_SCL)) {
Serial.println("Touch init failed");
return;
}
touch.setMaxCoordinates(LCD_WIDTH, LCD_HEIGHT);
// C6 2.16 panel mapping. The original values (swap=true, mirrorX=true)
// were calibrated to the old display orientation that force-wrote MADCTL
// 0x30 (MV transpose + ML). The display now runs at the CO5300 class
// default (MADCTL 0x00 — USB-port-on-the-side orientation), so the touch
// mapping is re-derived to match. SensorLib applies swap then mirror
// (TouchDrvInterface::updateXY); tap-tested on C6 hardware, the raw
// CST9217 coordinates map straight through in this orientation — no swap,
// no mirror.
touch.setSwapXY(false);
touch.setMirrorXY(false, false);
pinMode(TP_INT, INPUT_PULLUP);
attachInterrupt(TP_INT, touch_isr, FALLING);
Serial.println("Touch init OK");
}
void touch_hal_read(uint16_t* x, uint16_t* y, bool* pressed) {
if (touch_data_ready) {
touch_data_ready = false;
int16_t tx[5], ty[5];
uint8_t n = touch.getPoint(tx, ty, touch.getSupportTouchPoint());
if (n > 0) {
touch_pressed = true;
touch_x = (uint16_t)tx[0];
touch_y = (uint16_t)ty[0];
} else {
touch_pressed = false;
}
}
*x = touch_x;
*y = touch_y;
*pressed = touch_pressed;
}