Added missing lib https://github.com/Xinyuan-LilyGO/T-Deck/issues/47
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
*
|
||||
* @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 TouchClassCST226.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#include "TouchClassCST226.h"
|
||||
|
||||
#define CST2xx_REG_STATUS (0x00)
|
||||
#define CST226SE_BUFFER_NUM (28)
|
||||
|
||||
#if defined(ARDUINO)
|
||||
TouchClassCST226::TouchClassCST226()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TouchClassCST226::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl)
|
||||
{
|
||||
return SensorCommon::begin(wire, address, sda, scl);
|
||||
}
|
||||
|
||||
#elif defined(ESP_PLATFORM)
|
||||
|
||||
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
|
||||
bool TouchClassCST226::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
|
||||
{
|
||||
return SensorCommon::begin(i2c_dev_bus_handle, addr);
|
||||
}
|
||||
#else
|
||||
bool TouchClassCST226::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
return SensorCommon::begin(port_num, addr, sda, scl);
|
||||
}
|
||||
#endif //ESP_IDF_VERSION
|
||||
|
||||
#endif //ARDUINO
|
||||
|
||||
|
||||
bool TouchClassCST226::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
|
||||
{
|
||||
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
|
||||
}
|
||||
|
||||
void TouchClassCST226::reset()
|
||||
{
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OUTPUT);
|
||||
this->setGpioLevel(__rst, LOW);
|
||||
delay(100);
|
||||
this->setGpioLevel(__rst, HIGH);
|
||||
delay(100);
|
||||
} else {
|
||||
writeRegister(0xD1, 0x0E);
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TouchClassCST226::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
|
||||
{
|
||||
uint8_t buffer[CST226SE_BUFFER_NUM];
|
||||
uint8_t index = 0;
|
||||
|
||||
if (readRegister(CST2xx_REG_STATUS, buffer, CST226SE_BUFFER_NUM) == DEV_WIRE_ERR) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOG_PORT
|
||||
LOG_PORT.print("RAW:");
|
||||
for (int i = 0; i < CST226SE_BUFFER_NUM; ++i) {
|
||||
LOG_PORT.printf("%02X,", buffer[i]);
|
||||
}
|
||||
LOG_PORT.println();
|
||||
#endif
|
||||
|
||||
if (buffer[0] == 0x83 && buffer[1] == 0x17 && buffer[5] == 0x80) {
|
||||
if (__homeButtonCb) {
|
||||
__homeButtonCb(__userData);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buffer[6] != 0xAB)return 0;
|
||||
if (buffer[0] == 0xAB)return 0;
|
||||
if (buffer[5] == 0x80)return 0;
|
||||
|
||||
uint8_t point = buffer[5] & 0x7F;
|
||||
if (point > 5 || !point) {
|
||||
writeRegister(0x00, 0xAB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < point; 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(point, report.x, report.y);
|
||||
|
||||
#ifdef LOG_PORT
|
||||
for (int i = 0; i < point; i++) {
|
||||
LOG_PORT.printf("[%d]-X:%u Y:%u P:%u sta:%u ", report.id[i], report.x[i], report.y[i], report.pressure[i], report.status[i]);
|
||||
}
|
||||
LOG_PORT.println();
|
||||
#endif
|
||||
|
||||
if (point) {
|
||||
for (int i = 0; i < get_point; i++) {
|
||||
x_array[i] = report.x[i];
|
||||
y_array[i] = report.y[i];
|
||||
}
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
bool TouchClassCST226::isPressed()
|
||||
{
|
||||
static uint32_t lastPulse = 0;
|
||||
if (__irq != SENSOR_PIN_NONE) {
|
||||
int val = this->getGpioLevel(__irq) == LOW;
|
||||
if (val) {
|
||||
//Filter low levels with intervals greater than 1000ms
|
||||
val = (millis() - lastPulse > 1000) ? false : true;
|
||||
lastPulse = millis();
|
||||
return val;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return getPoint(NULL, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
const char *TouchClassCST226::getModelName()
|
||||
{
|
||||
return "CST226SE";
|
||||
}
|
||||
|
||||
void TouchClassCST226::sleep()
|
||||
{
|
||||
writeRegister(0xD1, 0x05);
|
||||
#ifdef ESP32
|
||||
if (__irq != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__irq, OPEN_DRAIN);
|
||||
}
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OPEN_DRAIN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TouchClassCST226::wakeup()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void TouchClassCST226::idle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t TouchClassCST226::getSupportTouchPoint()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
bool TouchClassCST226::getResolution(int16_t *x, int16_t *y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void TouchClassCST226::setHomeButtonCallback(home_button_callback_t cb, void *user_data)
|
||||
{
|
||||
__homeButtonCb = cb;
|
||||
__userData = user_data;
|
||||
}
|
||||
|
||||
void TouchClassCST226::setGpioCallback(gpio_mode_fptr_t mode_cb,
|
||||
gpio_write_fptr_t write_cb,
|
||||
gpio_read_fptr_t read_cb)
|
||||
{
|
||||
SensorCommon::setGpioModeCallback(mode_cb);
|
||||
SensorCommon::setGpioWriteCallback(write_cb);
|
||||
SensorCommon::setGpioReadCallback(read_cb);
|
||||
}
|
||||
|
||||
bool TouchClassCST226::initImpl()
|
||||
{
|
||||
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OUTPUT);
|
||||
}
|
||||
|
||||
if (__irq != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__irq, INPUT);
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
uint8_t buffer[8];
|
||||
// Enter Command mode
|
||||
writeRegister(0xD1, 0x01);
|
||||
delay(10);
|
||||
uint8_t write_buffer[2] = {0xD1, 0xFC};
|
||||
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.\r\n", checkcode);
|
||||
|
||||
write_buffer[0] = {0xD1};
|
||||
write_buffer[1] = {0xF8};
|
||||
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\r\n", __resX, __resY);
|
||||
|
||||
write_buffer[0] = {0xD2};
|
||||
write_buffer[1] = {0x04};
|
||||
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\r\n",
|
||||
chipType, ProjectID);
|
||||
|
||||
|
||||
|
||||
write_buffer[0] = {0xD2};
|
||||
write_buffer[1] = {0x08};
|
||||
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\n",
|
||||
fwVersion, checksum);
|
||||
|
||||
if (fwVersion == 0xA5A5A5A5) {
|
||||
log_i("Chip ic don't have firmware. \n");
|
||||
return false;
|
||||
}
|
||||
if ((checkcode & 0xffff0000) != 0xCACA0000) {
|
||||
log_i("Firmware info read error .\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
__chipID = chipType;
|
||||
|
||||
// Exit Command mode
|
||||
writeRegister(0xD1, 0x09);
|
||||
return true;
|
||||
}
|
||||
|
||||
int TouchClassCST226::getReadMaskImpl()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
*
|
||||
* @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 TouchClassCST226.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../TouchDrvInterface.hpp"
|
||||
#include "../SensorCommon.tpp"
|
||||
|
||||
class TouchClassCST226 : public TouchDrvInterface,
|
||||
public SensorCommon<TouchClassCST226>
|
||||
{
|
||||
friend class SensorCommon<TouchClassCST226>;
|
||||
|
||||
public:
|
||||
|
||||
#if defined(ARDUINO)
|
||||
TouchClassCST226();
|
||||
|
||||
bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl);
|
||||
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
|
||||
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr);
|
||||
#else
|
||||
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl);
|
||||
#endif //ESP_IDF_VERSION
|
||||
|
||||
#endif
|
||||
|
||||
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback);
|
||||
|
||||
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(home_button_callback_t cb, void *user_data);
|
||||
|
||||
void setGpioCallback(gpio_mode_fptr_t mode_cb,
|
||||
gpio_write_fptr_t write_cb,
|
||||
gpio_read_fptr_t read_cb);
|
||||
|
||||
private:
|
||||
bool initImpl();
|
||||
int getReadMaskImpl();
|
||||
protected:
|
||||
TouchData report;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
/**
|
||||
*
|
||||
* @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 TouchClassCST816.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#include "TouchClassCST816.h"
|
||||
|
||||
#define CST8xx_REG_STATUS (0x00)
|
||||
#define CST8xx_REG_XPOS_HIGH (0x03)
|
||||
#define CST8xx_REG_XPOS_LOW (0x04)
|
||||
#define CST8xx_REG_YPOS_HIGH (0x05)
|
||||
#define CST8xx_REG_YPOS_LOW (0x06)
|
||||
#define CST8xx_REG_DIS_AUTOSLEEP (0xFE)
|
||||
#define CST8xx_REG_CHIP_ID (0xA7)
|
||||
#define CST8xx_REG_FW_VERSION (0xA9)
|
||||
#define CST8xx_REG_SLEEP (0xE5)
|
||||
|
||||
#define CST816S_CHIP_ID (0xB4)
|
||||
#define CST816T_CHIP_ID (0xB5)
|
||||
#define CST716_CHIP_ID (0x20)
|
||||
#define CST820_CHIP_ID (0xB7)
|
||||
#define CST816D_CHIP_ID (0xB6)
|
||||
|
||||
#if defined(ARDUINO)
|
||||
TouchClassCST816::TouchClassCST816():
|
||||
__center_btn_x(0),
|
||||
__center_btn_y(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool TouchClassCST816::begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl)
|
||||
{
|
||||
return SensorCommon::begin(wire, address, sda, scl);
|
||||
}
|
||||
|
||||
#elif defined(ESP_PLATFORM)
|
||||
|
||||
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
|
||||
bool TouchClassCST816::begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
|
||||
{
|
||||
return SensorCommon::begin(i2c_dev_bus_handle, addr);
|
||||
}
|
||||
#else
|
||||
bool TouchClassCST816::begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
|
||||
{
|
||||
return SensorCommon::begin(port_num, addr, sda, scl);
|
||||
}
|
||||
|
||||
#endif //ESP_IDF_VERSION
|
||||
#endif //ARDUINO
|
||||
|
||||
bool TouchClassCST816::begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
|
||||
{
|
||||
return SensorCommon::begin(addr, readRegCallback, writeRegCallback);
|
||||
}
|
||||
|
||||
void TouchClassCST816::reset()
|
||||
{
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OUTPUT);
|
||||
this->setGpioLevel(__rst, LOW);
|
||||
delay(30);
|
||||
this->setGpioLevel(__rst, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TouchClassCST816::getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point)
|
||||
{
|
||||
uint8_t buffer[13];
|
||||
if (readRegister(CST8xx_REG_STATUS, buffer, 13) == DEV_WIRE_ERR) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Only suitable for AMOLED 1.91 inch
|
||||
// RAW:00,00,01,80,78,02,58,00,00,FF,FF,FF,FF,
|
||||
// if (buffer[2] == 0x01 && buffer[3] == 0x80 && buffer[4] == 0x78 && buffer[5] == 0x02 && buffer[6] == 0x58) {
|
||||
// if (__homeButtonCb) {
|
||||
// __homeButtonCb(__userData);
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
uint8_t point = buffer[2] & 0x0F;
|
||||
|
||||
// CST816 only supports single touch
|
||||
if (point > 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOG_PORT
|
||||
LOG_PORT.print("RAW:");
|
||||
for (int i = 0; i < 13; ++i) {
|
||||
LOG_PORT.printf("%02X,", buffer[i]);
|
||||
}
|
||||
LOG_PORT.println();
|
||||
#endif
|
||||
|
||||
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 && __homeButtonCb) {
|
||||
__homeButtonCb(__userData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if (get_point == 2) {
|
||||
// x_array[1] = ((buffer[((uint8_t)0x09)] & 0x0F) << 8 | buffer[((uint8_t)0x10)]);
|
||||
// y_array[1] = ((buffer[((uint8_t)0x11)] & 0x0F) << 8 | buffer[((uint8_t)0x12)]);
|
||||
// }
|
||||
|
||||
x_array[0] = tmp_x;
|
||||
y_array[0] = tmp_y;
|
||||
|
||||
#ifdef LOG_PORT
|
||||
for (int i = 0; i < point; i++) {
|
||||
LOG_PORT.printf("[%d] --> X:%d Y:%d \n", i, x_array[i], y_array[i]);
|
||||
}
|
||||
#endif
|
||||
updateXY(point, x_array, y_array);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
bool TouchClassCST816::isPressed()
|
||||
{
|
||||
static uint32_t lastPulse = 0;
|
||||
if (__irq != SENSOR_PIN_NONE) {
|
||||
int val = this->getGpioLevel(__irq) == LOW;
|
||||
if (val) {
|
||||
//Filter low levels with intervals greater than 1000ms
|
||||
val = (millis() - lastPulse > 1000) ? false : true;
|
||||
lastPulse = millis();
|
||||
return val;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return getPoint(NULL, NULL, 1);
|
||||
}
|
||||
|
||||
|
||||
const char *TouchClassCST816::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 "UNKONW";
|
||||
}
|
||||
|
||||
void TouchClassCST816::sleep()
|
||||
{
|
||||
writeRegister(CST8xx_REG_SLEEP, 0x03);
|
||||
#ifdef ESP32
|
||||
if (__irq != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__irq, OPEN_DRAIN);
|
||||
}
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OPEN_DRAIN);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void TouchClassCST816::wakeup()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void TouchClassCST816::idle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t TouchClassCST816::getSupportTouchPoint()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool TouchClassCST816::getResolution(int16_t *x, int16_t *y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void TouchClassCST816::setHomeButtonCallback(home_button_callback_t cb, void *user_data)
|
||||
{
|
||||
__homeButtonCb = cb;
|
||||
__userData = user_data;
|
||||
}
|
||||
|
||||
void TouchClassCST816::setCenterButtonCoordinate(int16_t x, int16_t y)
|
||||
{
|
||||
__center_btn_x = x;
|
||||
__center_btn_y = y;
|
||||
}
|
||||
|
||||
|
||||
void TouchClassCST816::disableAutoSleep()
|
||||
{
|
||||
switch (__chipID) {
|
||||
case CST816S_CHIP_ID:
|
||||
case CST816T_CHIP_ID:
|
||||
case CST820_CHIP_ID:
|
||||
case CST816D_CHIP_ID:
|
||||
reset();
|
||||
delay(50);
|
||||
writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x01);
|
||||
break;
|
||||
case CST716_CHIP_ID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchClassCST816::enableAutoSleep()
|
||||
{
|
||||
switch (__chipID) {
|
||||
case CST816S_CHIP_ID:
|
||||
case CST816T_CHIP_ID:
|
||||
case CST820_CHIP_ID:
|
||||
case CST816D_CHIP_ID:
|
||||
reset();
|
||||
delay(50);
|
||||
writeRegister(CST8xx_REG_DIS_AUTOSLEEP, 0x00);
|
||||
break;
|
||||
case CST716_CHIP_ID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchClassCST816::setGpioCallback(gpio_mode_fptr_t mode_cb,
|
||||
gpio_write_fptr_t write_cb,
|
||||
gpio_read_fptr_t read_cb)
|
||||
{
|
||||
SensorCommon::setGpioModeCallback(mode_cb);
|
||||
SensorCommon::setGpioWriteCallback(write_cb);
|
||||
SensorCommon::setGpioReadCallback(read_cb);
|
||||
}
|
||||
|
||||
bool TouchClassCST816::initImpl()
|
||||
{
|
||||
|
||||
if (__rst != SENSOR_PIN_NONE) {
|
||||
this->setGpioMode(__rst, OUTPUT);
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
int chip_id = readRegister(CST8xx_REG_CHIP_ID);
|
||||
log_i("Chip ID:0x%x\n", chip_id);
|
||||
|
||||
int version = readRegister(CST8xx_REG_FW_VERSION);
|
||||
log_i("Version :0x%x\n", 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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
__chipID = chip_id;
|
||||
|
||||
log_i("Touch type:%s\n", getModelName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int TouchClassCST816::getReadMaskImpl()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
*
|
||||
* @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 TouchClassCST816.h
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2023-10-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../TouchDrvInterface.hpp"
|
||||
#include "../SensorCommon.tpp"
|
||||
#include "../SensorLib.h"
|
||||
|
||||
class TouchClassCST816 : public TouchDrvInterface,
|
||||
public SensorCommon<TouchClassCST816>
|
||||
{
|
||||
friend class SensorCommon<TouchClassCST816>;
|
||||
|
||||
public:
|
||||
|
||||
#if defined(ARDUINO)
|
||||
TouchClassCST816();
|
||||
|
||||
bool begin(PLATFORM_WIRE_TYPE &wire, uint8_t address, int sda, int scl);
|
||||
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if ((ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API))
|
||||
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr);
|
||||
#else
|
||||
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl);
|
||||
#endif //ESP_IDF_VERSION
|
||||
#endif
|
||||
|
||||
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback);
|
||||
|
||||
|
||||
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(home_button_callback_t cb, void *user_data);
|
||||
|
||||
void disableAutoSleep();
|
||||
|
||||
void enableAutoSleep();
|
||||
|
||||
void setGpioCallback(gpio_mode_fptr_t mode_cb,
|
||||
gpio_write_fptr_t write_cb,
|
||||
gpio_read_fptr_t read_cb);
|
||||
|
||||
private:
|
||||
bool initImpl();
|
||||
int getReadMaskImpl();
|
||||
|
||||
protected:
|
||||
int16_t __center_btn_x;
|
||||
int16_t __center_btn_y;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user