initial commit
This commit is contained in:
@@ -0,0 +1,331 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2023 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file TouchDrvCST226.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#include "TouchDrvCST226.h"
|
||||
|
||||
TouchDrvCST226::TouchDrvCST226() : comm(nullptr), hal(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TouchDrvCST226::~TouchDrvCST226()
|
||||
{
|
||||
if (comm) {
|
||||
comm->deinit();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ARDUINO)
|
||||
bool TouchDrvCST226::begin(TwoWire &wire, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalArduino>(comm, hal, wire, addr, sda, scl)) {
|
||||
return false;
|
||||
}
|
||||
return initImpl();
|
||||
}
|
||||
#elif defined(ESP_PLATFORM)
|
||||
|
||||
#if defined(USEING_I2C_LEGACY)
|
||||
bool TouchDrvCST226::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, port_num, addr, sda, scl)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool TouchDrvCST226::begin(i2c_master_bus_handle_t handle, uint8_t addr)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, handle, addr)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif //USEING_I2C_LEGACY
|
||||
#endif //ARDUINO
|
||||
|
||||
bool TouchDrvCST226::begin(SensorCommCustom::CustomCallback callback,
|
||||
SensorCommCustomHal::CustomHalCallback hal_callback,
|
||||
uint8_t addr)
|
||||
{
|
||||
if (!beginCommCustomCallback<SensorCommCustom, SensorCommCustomHal>(COMM_CUSTOM,
|
||||
callback, hal_callback, addr, comm, hal)) {
|
||||
return false;
|
||||
}
|
||||
return initImpl();
|
||||
}
|
||||
|
||||
void TouchDrvCST226::reset()
|
||||
{
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OUTPUT);
|
||||
hal->digitalWrite(_rst, LOW);
|
||||
hal->delay(100);
|
||||
hal->digitalWrite(_rst, HIGH);
|
||||
hal->delay(100);
|
||||
} else {
|
||||
comm->writeRegister(0xD1, 0x0E);
|
||||
hal->delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TouchDrvCST226::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
|
||||
{
|
||||
static constexpr uint8_t statusReg = (0x00);
|
||||
static constexpr uint8_t bufferSize = (28);
|
||||
|
||||
uint8_t buffer[bufferSize];
|
||||
uint8_t index = 0;
|
||||
|
||||
if (comm->readRegister(statusReg, buffer, bufferSize) == -1) {
|
||||
return 0;
|
||||
}
|
||||
if (buffer[0] == 0x83 && buffer[1] == 0x17 && buffer[5] == 0x80) {
|
||||
if (_HButtonCallback) {
|
||||
_HButtonCallback(_userData);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buffer[6] != 0xAB)return 0;
|
||||
if (buffer[0] == 0xAB)return 0;
|
||||
if (buffer[5] == 0x80)return 0;
|
||||
|
||||
uint8_t numPoints = buffer[5] & 0x7F;
|
||||
|
||||
if (numPoints > 5 || !numPoints) {
|
||||
comm->writeRegister(0x00, 0xAB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
report.id[i] = buffer[index] >> 4;
|
||||
report.status[i] = buffer[index] & 0x0F;
|
||||
report.x[i] = (uint16_t)((buffer[index + 1] << 4) | ((buffer[index + 3] >> 4) & 0x0F));
|
||||
report.y[i] = (uint16_t)((buffer[index + 2] << 4) | (buffer[index + 3] & 0x0F));
|
||||
report.pressure[i] = buffer[index + 4];
|
||||
index = (i == 0) ? (index + 7) : (index + 5);
|
||||
}
|
||||
|
||||
updateXY(numPoints, report.x, report.y);
|
||||
|
||||
if (numPoints) {
|
||||
for (int i = 0; i < get_point; i++) {
|
||||
x_array[i] = report.x[i];
|
||||
y_array[i] = report.y[i];
|
||||
}
|
||||
}
|
||||
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
bool TouchDrvCST226::isPressed()
|
||||
{
|
||||
static uint32_t lastPulse = 0;
|
||||
if (_irq != -1) {
|
||||
int val = hal->digitalRead(_irq) == LOW;
|
||||
if (val) {
|
||||
//Filter low levels with intervals greater than 1000ms
|
||||
val = (hal->millis() - lastPulse > 1000) ? false : true;
|
||||
lastPulse = hal->millis();
|
||||
return val;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return getPoint(NULL, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
const char *TouchDrvCST226::getModelName()
|
||||
{
|
||||
return "CST226SE";
|
||||
}
|
||||
|
||||
void TouchDrvCST226::sleep()
|
||||
{
|
||||
comm->writeRegister(0xD1, 0x05);
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (_irq != -1) {
|
||||
hal->pinMode(_irq, OPEN_DRAIN);
|
||||
}
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OPEN_DRAIN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TouchDrvCST226::wakeup()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void TouchDrvCST226::idle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t TouchDrvCST226::getSupportTouchPoint()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
bool TouchDrvCST226::getResolution(int16_t *x, int16_t *y)
|
||||
{
|
||||
*x = _resX;
|
||||
*y = _resY;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TouchDrvCST226::setHomeButtonCallback(HomeButtonCallback cb, void *user_data)
|
||||
{
|
||||
_HButtonCallback = cb;
|
||||
_userData = user_data;
|
||||
}
|
||||
|
||||
void TouchDrvCST226::setGpioCallback(CustomMode mode_cb,
|
||||
CustomWrite write_cb,
|
||||
CustomRead read_cb)
|
||||
{
|
||||
SensorHalCustom::setCustomMode(mode_cb);
|
||||
SensorHalCustom::setCustomWrite(write_cb);
|
||||
SensorHalCustom::setCustomRead(read_cb);
|
||||
}
|
||||
|
||||
bool TouchDrvCST226::initImpl()
|
||||
{
|
||||
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OUTPUT);
|
||||
}
|
||||
|
||||
if (_irq != -1) {
|
||||
hal->pinMode(_irq, INPUT);
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
uint8_t buffer[8];
|
||||
// Enter Command mode
|
||||
comm->writeRegister(0xD1, 0x01);
|
||||
hal->delay(10);
|
||||
uint8_t write_buffer[2] = {0xD1, 0xFC};
|
||||
comm->writeThenRead(write_buffer, 2, buffer, 4);
|
||||
uint32_t checkcode = 0;
|
||||
checkcode = buffer[3];
|
||||
checkcode <<= 8;
|
||||
checkcode |= buffer[2];
|
||||
checkcode <<= 8;
|
||||
checkcode |= buffer[1];
|
||||
checkcode <<= 8;
|
||||
checkcode |= buffer[0];
|
||||
|
||||
log_i("Chip checkcode:0x%lx.", checkcode);
|
||||
|
||||
write_buffer[0] = {0xD1};
|
||||
write_buffer[1] = {0xF8};
|
||||
comm->writeThenRead(write_buffer, 2, buffer, 4);
|
||||
_resX = ( buffer[1] << 8) | buffer[0];
|
||||
_resY = ( buffer[3] << 8) | buffer[2];
|
||||
log_i("Chip resolution X:%u Y:%u", _resX, _resY);
|
||||
|
||||
write_buffer[0] = {0xD2};
|
||||
write_buffer[1] = {0x04};
|
||||
comm->writeThenRead(write_buffer, 2, buffer, 4);
|
||||
uint32_t chipType = buffer[3];
|
||||
chipType <<= 8;
|
||||
chipType |= buffer[2];
|
||||
|
||||
|
||||
uint32_t ProjectID = buffer[1];
|
||||
ProjectID <<= 8;
|
||||
ProjectID |= buffer[0];
|
||||
log_i("Chip type :0x%lx, ProjectID:0X%lx",
|
||||
chipType, ProjectID);
|
||||
|
||||
|
||||
|
||||
write_buffer[0] = {0xD2};
|
||||
write_buffer[1] = {0x08};
|
||||
comm->writeThenRead(write_buffer, 2, buffer, 8);
|
||||
|
||||
uint32_t fwVersion = buffer[3];
|
||||
fwVersion <<= 8;
|
||||
fwVersion |= buffer[2];
|
||||
fwVersion <<= 8;
|
||||
fwVersion |= buffer[1];
|
||||
fwVersion <<= 8;
|
||||
fwVersion |= buffer[0];
|
||||
|
||||
uint32_t checksum = buffer[7];
|
||||
checksum <<= 8;
|
||||
checksum |= buffer[6];
|
||||
checksum <<= 8;
|
||||
checksum |= buffer[5];
|
||||
checksum <<= 8;
|
||||
checksum |= buffer[4];
|
||||
|
||||
log_i("Chip ic version:0x%lx, checksum:0x%lx",
|
||||
fwVersion, checksum);
|
||||
|
||||
if (fwVersion == 0xA5A5A5A5) {
|
||||
log_e("Chip ic don't have firmware.");
|
||||
return false;
|
||||
}
|
||||
if ((checkcode & 0xffff0000) != 0xCACA0000) {
|
||||
log_e("Firmware info read error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chipType != CST226SE_CHIPTYPE) {
|
||||
log_e("Chip ID does not match, should be 0x%2X", CST226SE_CHIPTYPE);
|
||||
return false;
|
||||
}
|
||||
|
||||
_chipID = chipType;
|
||||
|
||||
// Exit Command mode
|
||||
comm->writeRegister(0xD1, 0x09);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2023 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file TouchDrvCST226.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "TouchDrvInterface.hpp"
|
||||
|
||||
#define CST226SE_SLAVE_ADDRESS (0x5A)
|
||||
|
||||
class TouchDrvCST226 : public TouchDrvInterface
|
||||
{
|
||||
public:
|
||||
|
||||
TouchDrvCST226();
|
||||
|
||||
~TouchDrvCST226();
|
||||
|
||||
#if defined(ARDUINO)
|
||||
bool begin(TwoWire &wire, uint8_t addr = CST226SE_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if defined(USEING_I2C_LEGACY)
|
||||
bool begin(i2c_port_t port_num, uint8_t addr = CST226SE_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#else
|
||||
bool begin(i2c_master_bus_handle_t handle, uint8_t addr = CST226SE_SLAVE_ADDRESS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
bool begin(SensorCommCustom::CustomCallback callback,
|
||||
SensorCommCustomHal::CustomHalCallback hal_callback,
|
||||
uint8_t addr = CST226SE_SLAVE_ADDRESS);
|
||||
|
||||
void reset();
|
||||
|
||||
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
|
||||
|
||||
bool isPressed();
|
||||
|
||||
const char *getModelName();
|
||||
|
||||
void sleep();
|
||||
|
||||
void wakeup();
|
||||
|
||||
void idle();
|
||||
|
||||
uint8_t getSupportTouchPoint();
|
||||
|
||||
bool getResolution(int16_t *x, int16_t *y);
|
||||
|
||||
void setHomeButtonCallback(HomeButtonCallback cb, void *user_data);
|
||||
|
||||
void setGpioCallback(CustomMode mode_cb,
|
||||
CustomWrite write_cb,
|
||||
CustomRead read_cb);
|
||||
|
||||
private:
|
||||
bool initImpl();
|
||||
protected:
|
||||
std::unique_ptr<SensorCommBase> comm;
|
||||
std::unique_ptr<SensorHal> hal;
|
||||
TouchData report;
|
||||
static constexpr uint8_t CST226SE_CHIPTYPE = (0xA8);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2023 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file TouchDrvCST816.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#include "TouchDrvCST816.h"
|
||||
|
||||
TouchDrvCST816::TouchDrvCST816() : comm(nullptr), hal(nullptr),
|
||||
_center_btn_x(0),
|
||||
_center_btn_y(0)
|
||||
{
|
||||
}
|
||||
|
||||
TouchDrvCST816::~TouchDrvCST816()
|
||||
{
|
||||
if (comm) {
|
||||
comm->deinit();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ARDUINO)
|
||||
bool TouchDrvCST816::begin(TwoWire &wire, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalArduino>(comm, hal, wire, addr, sda, scl)) {
|
||||
return false;
|
||||
}
|
||||
return initImpl();
|
||||
}
|
||||
#elif defined(ESP_PLATFORM)
|
||||
|
||||
#if defined(USEING_I2C_LEGACY)
|
||||
bool TouchDrvCST816::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, port_num, addr, sda, scl)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool TouchDrvCST816::begin(i2c_master_bus_handle_t handle, uint8_t addr)
|
||||
{
|
||||
if (!beginCommon<SensorCommI2C, HalEspIDF>(comm, hal, handle, addr)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif //USEING_I2C_LEGACY
|
||||
#endif //ARDUINO
|
||||
|
||||
bool TouchDrvCST816::begin(SensorCommCustom::CustomCallback callback,
|
||||
SensorCommCustomHal::CustomHalCallback hal_callback,
|
||||
uint8_t addr)
|
||||
{
|
||||
if (!beginCommCustomCallback<SensorCommCustom, SensorCommCustomHal>(COMM_CUSTOM,
|
||||
callback, hal_callback, addr, comm, hal)) {
|
||||
return false;
|
||||
}
|
||||
return initImpl();
|
||||
}
|
||||
|
||||
void TouchDrvCST816::reset()
|
||||
{
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OUTPUT);
|
||||
hal->digitalWrite(_rst, LOW);
|
||||
hal->delay(30);
|
||||
hal->digitalWrite(_rst, HIGH);
|
||||
hal->delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TouchDrvCST816::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
|
||||
{
|
||||
uint8_t buffer[13];
|
||||
if (comm->readRegister(CST8xx_REG_STATUS, buffer, 13) == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!buffer[2] || !x_array || !y_array || !get_point) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Some CST816T will return all 0xFF after turning off automatic sleep.
|
||||
if (buffer[2] == 0xFF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t numPoints = buffer[2] & 0x0F;
|
||||
|
||||
// CST816 only supports single touch
|
||||
if (numPoints > 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t tmp_x, tmp_y;
|
||||
|
||||
tmp_x = ((buffer[CST8xx_REG_XPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_XPOS_LOW]);
|
||||
tmp_y = ((buffer[CST8xx_REG_YPOS_HIGH] & 0x0F) << 8 | buffer[CST8xx_REG_YPOS_LOW]);
|
||||
|
||||
// Depends on touch screen firmware
|
||||
if (tmp_x == _center_btn_x && tmp_y == _center_btn_y && _HButtonCallback) {
|
||||
_HButtonCallback(_userData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
x_array[0] = tmp_x;
|
||||
y_array[0] = tmp_y;
|
||||
|
||||
updateXY(numPoints, x_array, y_array);
|
||||
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
bool TouchDrvCST816::isPressed()
|
||||
{
|
||||
static uint32_t lastPulse = 0;
|
||||
if (_irq != -1) {
|
||||
int val = hal->digitalRead(_irq) == LOW;
|
||||
if (val) {
|
||||
//Filter low levels with intervals greater than 1000ms
|
||||
val = (hal->millis() - lastPulse > 1000) ? false : true;
|
||||
lastPulse = hal->millis();
|
||||
return val;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return getPoint(NULL, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
const char *TouchDrvCST816::getModelName()
|
||||
{
|
||||
switch (_chipID) {
|
||||
case CST816S_CHIP_ID:
|
||||
return "CST816S";
|
||||
case CST816T_CHIP_ID:
|
||||
return "CST816T";
|
||||
case CST716_CHIP_ID:
|
||||
return "CST716";
|
||||
case CST820_CHIP_ID:
|
||||
return "CST820";
|
||||
case CST816D_CHIP_ID:
|
||||
return "CST816D";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "UNKNOW";
|
||||
}
|
||||
|
||||
void TouchDrvCST816::sleep()
|
||||
{
|
||||
comm->writeRegister(CST8xx_REG_SLEEP, 0x03);
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (_irq != -1) {
|
||||
hal->pinMode(_irq, OPEN_DRAIN);
|
||||
}
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OPEN_DRAIN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TouchDrvCST816::wakeup()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void TouchDrvCST816::idle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t TouchDrvCST816::getSupportTouchPoint()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool TouchDrvCST816::getResolution(int16_t *x, int16_t *y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void TouchDrvCST816::setHomeButtonCallback(HomeButtonCallback cb, void *user_data)
|
||||
{
|
||||
_HButtonCallback = cb;
|
||||
_userData = user_data;
|
||||
}
|
||||
|
||||
void TouchDrvCST816::setCenterButtonCoordinate(int16_t x, int16_t y)
|
||||
{
|
||||
_center_btn_x = x;
|
||||
_center_btn_y = y;
|
||||
}
|
||||
|
||||
|
||||
void TouchDrvCST816::disableAutoSleep()
|
||||
{
|
||||
switch (_chipID) {
|
||||
case CST816S_CHIP_ID:
|
||||
case CST816T_CHIP_ID:
|
||||
case CST820_CHIP_ID:
|
||||
case CST816D_CHIP_ID:
|
||||
reset();
|
||||
hal->delay(50);
|
||||
comm->writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x01);
|
||||
break;
|
||||
case CST716_CHIP_ID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchDrvCST816::enableAutoSleep()
|
||||
{
|
||||
switch (_chipID) {
|
||||
case CST816S_CHIP_ID:
|
||||
case CST816T_CHIP_ID:
|
||||
case CST820_CHIP_ID:
|
||||
case CST816D_CHIP_ID:
|
||||
reset();
|
||||
hal->delay(50);
|
||||
comm->writeRegister(CST8xx_REG_DIS_AUTOSLEEP, (uint8_t)0x00);
|
||||
break;
|
||||
case CST716_CHIP_ID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchDrvCST816::setGpioCallback(CustomMode mode_cb,
|
||||
CustomWrite write_cb,
|
||||
CustomRead read_cb)
|
||||
{
|
||||
SensorHalCustom::setCustomMode(mode_cb);
|
||||
SensorHalCustom::setCustomWrite(write_cb);
|
||||
SensorHalCustom::setCustomRead(read_cb);
|
||||
}
|
||||
|
||||
bool TouchDrvCST816::initImpl()
|
||||
{
|
||||
|
||||
if (_rst != -1) {
|
||||
hal->pinMode(_rst, OUTPUT);
|
||||
}
|
||||
|
||||
if (_irq != -1) {
|
||||
hal->pinMode(_irq, INPUT);
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
int chip_id = comm->readRegister(CST8xx_REG_CHIP_ID);
|
||||
log_i("Chip ID:0x%x", chip_id);
|
||||
|
||||
int version = comm->readRegister(CST8xx_REG_FW_VERSION);
|
||||
log_i("Version :0x%x", version);
|
||||
|
||||
// CST716 : 0x20
|
||||
// CST816S : 0xB4
|
||||
// CST816T : 0xB5
|
||||
// CST816D : 0xB6
|
||||
// CST226SE : A7 = 0X20
|
||||
if (chip_id != CST816S_CHIP_ID &&
|
||||
chip_id != CST816T_CHIP_ID &&
|
||||
chip_id != CST820_CHIP_ID &&
|
||||
chip_id != CST816D_CHIP_ID &&
|
||||
(chip_id != CST716_CHIP_ID || version == 0)) {
|
||||
log_e("Chip ID does not match, should be CST816S:0X%02X , CST816T:0X%02X , CST816D:0X%02X , CST820:0X%02X , CST716:0X%02X",
|
||||
CST816S_CHIP_ID, CST816T_CHIP_ID, CST816D_CHIP_ID, CST820_CHIP_ID, CST716_CHIP_ID);
|
||||
return false;
|
||||
}
|
||||
|
||||
_chipID = chip_id;
|
||||
|
||||
log_i("Touch type:%s", getModelName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2023 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file TouchDrvCST816.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "TouchDrvInterface.hpp"
|
||||
|
||||
#define CST816_SLAVE_ADDRESS 0x15
|
||||
|
||||
class TouchDrvCST816 : public TouchDrvInterface
|
||||
{
|
||||
public:
|
||||
TouchDrvCST816();
|
||||
|
||||
~TouchDrvCST816();
|
||||
|
||||
#if defined(ARDUINO)
|
||||
bool begin(TwoWire &wire, uint8_t address = CST816_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if defined(USEING_I2C_LEGACY)
|
||||
bool begin(i2c_port_t port_num, uint8_t addr = CST816_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#else
|
||||
bool begin(i2c_master_bus_handle_t handle, uint8_t addr = CST816_SLAVE_ADDRESS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool begin(SensorCommCustom::CustomCallback callback,
|
||||
SensorCommCustomHal::CustomHalCallback hal_callback,
|
||||
uint8_t addr = CST816_SLAVE_ADDRESS);
|
||||
|
||||
void reset();
|
||||
|
||||
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
|
||||
|
||||
bool isPressed();
|
||||
|
||||
const char *getModelName();
|
||||
|
||||
void sleep();
|
||||
|
||||
void wakeup();
|
||||
|
||||
void idle();
|
||||
|
||||
uint8_t getSupportTouchPoint();
|
||||
|
||||
bool getResolution(int16_t *x, int16_t *y);
|
||||
|
||||
void setCenterButtonCoordinate(int16_t x, int16_t y);
|
||||
|
||||
void setHomeButtonCallback(HomeButtonCallback cb, void *user_data);
|
||||
|
||||
void disableAutoSleep();
|
||||
|
||||
void enableAutoSleep();
|
||||
|
||||
void setGpioCallback(CustomMode mode_cb,
|
||||
CustomWrite write_cb,
|
||||
CustomRead read_cb);
|
||||
|
||||
private:
|
||||
bool initImpl();
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SensorCommBase> comm;
|
||||
std::unique_ptr<SensorHal> hal;
|
||||
|
||||
int16_t _center_btn_x;
|
||||
int16_t _center_btn_y;
|
||||
|
||||
static constexpr uint8_t CST8xx_REG_STATUS = (0x00);
|
||||
static constexpr uint8_t CST8xx_REG_XPOS_HIGH = (0x03);
|
||||
static constexpr uint8_t CST8xx_REG_XPOS_LOW = (0x04);
|
||||
static constexpr uint8_t CST8xx_REG_YPOS_HIGH = (0x05);
|
||||
static constexpr uint8_t CST8xx_REG_YPOS_LOW = (0x06);
|
||||
static constexpr uint8_t CST8xx_REG_DIS_AUTOSLEEP = (0xFE);
|
||||
static constexpr uint8_t CST8xx_REG_CHIP_ID = (0xA7);
|
||||
static constexpr uint8_t CST8xx_REG_FW_VERSION = (0xA9);
|
||||
static constexpr uint8_t CST8xx_REG_SLEEP = (0xE5);
|
||||
static constexpr uint8_t CST816S_CHIP_ID = (0xB4);
|
||||
static constexpr uint8_t CST816T_CHIP_ID = (0xB5);
|
||||
static constexpr uint8_t CST716_CHIP_ID = (0x20);
|
||||
static constexpr uint8_t CST820_CHIP_ID = (0xB7);
|
||||
static constexpr uint8_t CST816D_CHIP_ID = (0xB6);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2023 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file TouchDrvCST92xx.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2024-07-07
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "REG/CST9xxConstants.h"
|
||||
#include "TouchDrvInterface.hpp"
|
||||
|
||||
#define CST92XX_SLAVE_ADDRESS (0x5A)
|
||||
|
||||
class TouchDrvCST92xx : public TouchDrvInterface, public CST92xxConstants
|
||||
{
|
||||
public:
|
||||
|
||||
enum CST92_RunMode {
|
||||
CST92_MODE_NORMAL = (0x00),
|
||||
CST92_MODE_LOW_POWER = (0X01),
|
||||
CST92_MODE_DEEP_SLEEP = (0X02),
|
||||
CST92_MODE_WAKEUP = (0x03),
|
||||
CST92_MODE_DEBUG_DIFF = (0x04),
|
||||
CST92_MODE_DEBUG_RAWDATA = (0X05),
|
||||
CST92_MODE_FACTORY = (0x06),
|
||||
CST92_MODE_DEBUG_INFO = (0x07),
|
||||
CST92_MODE_UPDATE_FW = (0x08),
|
||||
CST92_MODE_FACTORY_HIGHDRV = (0x10),
|
||||
CST92_MODE_FACTORY_LOWDRV = (0x11),
|
||||
CST92_MODE_FACTORY_SHORT = (0x12),
|
||||
CST92_MODE_LPSCAN = (0x13),
|
||||
};
|
||||
|
||||
TouchDrvCST92xx();
|
||||
|
||||
~TouchDrvCST92xx();
|
||||
|
||||
#if defined(ARDUINO)
|
||||
bool begin(TwoWire &wire, uint8_t address = CST92XX_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if defined(USEING_I2C_LEGACY)
|
||||
bool begin(i2c_port_t port_num, uint8_t addr = CST92XX_SLAVE_ADDRESS, int sda = -1, int scl = -1);
|
||||
#else
|
||||
bool begin(i2c_master_bus_handle_t handle, uint8_t addr = CST92XX_SLAVE_ADDRESS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool begin(SensorCommCustom::CustomCallback callback,
|
||||
SensorCommCustomHal::CustomHalCallback hal_callback,
|
||||
uint8_t addr = CST92XX_SLAVE_ADDRESS);
|
||||
|
||||
void reset();
|
||||
|
||||
uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point);
|
||||
|
||||
bool isPressed();
|
||||
|
||||
const char *getModelName();
|
||||
|
||||
void sleep();
|
||||
|
||||
void wakeup();
|
||||
|
||||
void idle();
|
||||
|
||||
uint8_t getSupportTouchPoint();
|
||||
|
||||
bool getResolution(int16_t *x, int16_t *y);
|
||||
|
||||
void setCoverScreenCallback(HomeButtonCallback cb, void *user_data = NULL);
|
||||
|
||||
void setGpioCallback(CustomMode mode_cb,
|
||||
CustomWrite write_cb,
|
||||
CustomRead read_cb);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
bool setMode(uint8_t mode);
|
||||
bool enterBootloader();
|
||||
bool getAttribute();
|
||||
uint32_t readWordFromMem(uint8_t type, uint16_t mem_addr);
|
||||
void parseFingerData(uint8_t *data, cst9xx_point_t *point);
|
||||
uint32_t get_u32_from_ptr(const void *ptr);
|
||||
|
||||
|
||||
#if 0 /*DISABLE UPDATE FIRMWARE*/
|
||||
|
||||
struct {
|
||||
bool firmware_info_ok;
|
||||
uint32_t firmware_ic_type;
|
||||
uint32_t firmware_version;
|
||||
uint32_t firmware_checksum;
|
||||
uint32_t firmware_project_id;
|
||||
uint8_t tx_num;
|
||||
uint8_t rx_num;
|
||||
uint8_t key_num;
|
||||
} IC_firmware;
|
||||
|
||||
struct {
|
||||
bool ok;
|
||||
uint8_t *head_data;
|
||||
uint8_t *data;
|
||||
uint32_t checksum;
|
||||
uint32_t version;
|
||||
uint32_t project_id;
|
||||
uint32_t chip_type;
|
||||
} bin_data;
|
||||
|
||||
bool getFirmwareInfo(void);
|
||||
int16_t eraseMem(void);
|
||||
int16_t writeSRAM(uint8_t *buf, uint16_t len);
|
||||
int16_t writeMemPage(uint16_t addr, uint8_t *buf, uint16_t len) ;
|
||||
int16_t writeMemAll(void) ;
|
||||
int16_t calculateVerifyChecksum(void) ;
|
||||
int16_t upgradeFirmware(void);
|
||||
uint32_t verifyFirmware(uint8_t *pdata, uint16_t order);
|
||||
int16_t parseFirmware(void);
|
||||
int16_t upgradeFirmwareJudge(void);
|
||||
int16_t getFirmwareAddress(uint8_t data_seq, uint16_t data_len) ;
|
||||
int16_t updateFirmware(void);
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t getChipType();
|
||||
bool initImpl();
|
||||
|
||||
uint16_t chipType;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SensorCommBase> comm;
|
||||
std::unique_ptr<SensorHal> hal;
|
||||
|
||||
int _slave_addr;
|
||||
int16_t _center_btn_x;
|
||||
int16_t _center_btn_y;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user