Snapshot: full project state

This commit is contained in:
2026-10-06 23:43:26 -07:00
commit c1f5e0ff42
15 changed files with 2816 additions and 0 deletions

126
include/touch_ft6336.h Normal file
View File

@@ -0,0 +1,126 @@
#ifndef TOUCH_FT6336_H
#define TOUCH_FT6336_H
#include <Wire.h>
#include "board_config.h"
// FT6336 Capacitive Touch Controller
class TouchFT6336 {
public:
struct TouchPoint {
uint16_t x;
uint16_t y;
uint8_t pressure;
bool pressed;
};
// Initialize I2C touch controller
static bool begin() {
// Hardware reset (active low)
pinMode(TOUCH_RST, OUTPUT);
digitalWrite(TOUCH_RST, LOW);
delay(10);
digitalWrite(TOUCH_RST, HIGH);
delay(300);
pinMode(TOUCH_INT, INPUT_PULLUP);
Wire.begin(TOUCH_SDA, TOUCH_SCL, 400000);
delay(100);
// Verify FT6336 is present (chip ID reg 0xA3 = 0x64 on FT6336G)
uint8_t chipID = readReg(0xA3);
Serial.printf("[Touch] Chip ID: 0x%02X\n", chipID);
if (chipID == 0x00 || chipID == 0xFF) {
return false; // Not responding
}
// Reset to defaults
writeReg(0xFC, 0x01);
delay(300);
// Set to normal mode, threshold
writeReg(0x80, 0x00); // Normal mode
writeReg(0x88, 40); // Touch threshold
return true;
}
// Read touch point (single finger)
static TouchPoint readTouch() {
TouchPoint tp = {0, 0, 0, false};
Wire.beginTransmission(TOUCH_ADDR);
Wire.write(0x02);
if (Wire.endTransmission() != 0) return tp;
// Read 5 bytes: status + X/Y coordinates
if (Wire.requestFrom((uint8_t)TOUCH_ADDR, (uint8_t)5) != 5) {
return tp;
}
uint8_t status = Wire.read();
uint8_t x_hi = Wire.read();
uint8_t x_lo = Wire.read();
uint8_t y_hi = Wire.read();
uint8_t y_lo = Wire.read();
// Extract touch count (bits 3-0)
uint8_t touch_count = status & 0x0F;
if (touch_count > 0) {
tp.pressed = true;
tp.x = ((x_hi & 0x0F) << 8) | x_lo;
tp.y = ((y_hi & 0x0F) << 8) | y_lo;
tp.pressure = 255; // Capacitive doesn't have pressure, default max
}
return tp;
}
// Calibrate touch (4-point corners)
static void calibrate() {
// FT6336 typically doesn't need manual calibration
// It auto-calibrates on startup
// If needed, implement 4-point calibration here
}
// Get firmware version
static uint8_t getFirmwareVersion() {
return readReg(0xA6);
}
// Power modes
static void setPowerMode(uint8_t mode) {
// 0 = Active, 1 = Monitor, 3 = Sleep
writeReg(0xA5, mode);
}
static void sleep() {
setPowerMode(3);
}
static void wakeup() {
setPowerMode(0);
delay(50);
}
private:
static uint8_t readReg(uint8_t reg) {
Wire.beginTransmission(TOUCH_ADDR);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom((uint8_t)TOUCH_ADDR, (uint8_t)1);
return Wire.read();
}
static void writeReg(uint8_t reg, uint8_t value) {
Wire.beginTransmission(TOUCH_ADDR);
Wire.write(reg);
Wire.write(value);
Wire.endTransmission();
}
};
#endif // TOUCH_FT6336_H