Skip to content

Commit

Permalink
test1
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Nov 18, 2024
1 parent 44aa605 commit 69e8563
Show file tree
Hide file tree
Showing 28 changed files with 2,863 additions and 2 deletions.
18 changes: 18 additions & 0 deletions lib/TouchLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.12.4)

if(NOT ESP_PLATFORM)
project(TouchLib HOMEPAGE_URL https://github.com/mmMicky/TouchLib)
endif()

set(TOUCH_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

if(ESP_PLATFORM)

file(GLOB_RECURSE SOURCES ${TOUCH_ROOT_DIR}/src/*.cpp
${TOUCH_ROOT_DIR}/src/*.tpp )

idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS "src/."
PRIV_REQUIRES )

endif()
21 changes: 21 additions & 0 deletions lib/TouchLib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Micky

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.
2 changes: 2 additions & 0 deletions lib/TouchLib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TouchLib
In order to integrate the touch driver, let the touch interface be unified. (The following chips are currently supported. CST328, CST816, CST820, GT911, FT3267, FT5x06)
94 changes: 94 additions & 0 deletions lib/TouchLib/example/demo/demo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#define TOUCH_MODULES_GT911
//#define TOUCH_MODULES_CST_SELF
//#define TOUCH_MODULES_CST_MUTUAL
//#define TOUCH_MODULES_ZTW622
//#define TOUCH_MODULES_L58
//#define TOUCH_MODULES_FT3267
//#define TOUCH_MODULES_FT5x06

#include "Arduino.h"
#include "TouchLib.h"
#include "Wire.h"

#define PIN_IIC_SCL 48
#define PIN_IIC_SDA 8
#define PIN_TOUCH_INT 1
#define PIN_TOUCH_RES 2

#define TOUCH_READ_FROM_INTERRNUPT 0

TouchLib touch(Wire, PIN_IIC_SDA, PIN_IIC_SCL, GT911_SLAVE_ADDRESS2);

void scan_i2c_device(TwoWire &i2c)
{
Serial.println("Scanning for I2C devices ...");
Serial.print(" ");
for (int i = 0; i < 0x10; i++)
{
Serial.printf("0x%02X|", i);
}
uint8_t error;
for (int j = 0; j < 0x80; j += 0x10)
{
Serial.println();
Serial.printf("0x%02X |", j);
for (int i = 0; i < 0x10; i++)
{
Wire.beginTransmission(i | j);
error = Wire.endTransmission();
if (error == 0)
Serial.printf("0x%02X|", i | j);
else
Serial.print(" -- |");
}
}
Serial.println();
}

bool get_int = false;
void setup()
{
Serial.begin(115200);
Serial.println("Hello T-Display-S3");
pinMode(PIN_TOUCH_RES, OUTPUT);
digitalWrite(PIN_TOUCH_RES, 0);
delay(200);
digitalWrite(PIN_TOUCH_RES, 1);
delay(200);
Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL);
scan_i2c_device(Wire);

touch.init();
#if (TOUCH_READ_FROM_INTERRNUPT)
attachInterrupt(
PIN_TOUCH_INT,
[]
{
get_int = 1;
Serial.println("get_int");
},
CHANGE);
#endif
}

void loop()
{
delay(5);
#if (TOUCH_READ_FROM_INTERRNUPT)
if (get_int)
{
get_int = 0;
touch.read();
#else
if (touch.read())
{
#endif
uint8_t n = touch.getPointNum();
Serial.printf("getPointNum: %d ", n);
for (uint8_t i = 0; i < n; i++)
{
TP_Point t = touch.getPoint(i);
Serial.printf("[%d] point x: %d point y: %d \r\n", i, t.x, t.y);
}
}
}
17 changes: 17 additions & 0 deletions lib/TouchLib/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#######################################
# Syntax Coloring Map For TouchLib By Micky
# github:https://github.com/mmMicky
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################
TouchLib KEYWORD1
TouchLibCSTSelf KEYWORD1
TouchLibCSTMutual KEYWORD1
TouchLibGT911 KEYWORD1
TouchLibZTW622 KEYWORD1
TouchLibFT3267 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
30 changes: 30 additions & 0 deletions lib/TouchLib/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "TouchLib",
"version": "0.0.2",
"description": "Integrated touch driver (CST328, CST816, CST820, GT911, FT3267, FT5x06)",
"keywords": "TouchLib",
"authors": [{
"name": "mmMicky",
"url": "https://github.com/mmMicky",
"maintainer": true
}],
"repository": {
"type": "git",
"url": "https://github.com/mmMicky/TouchLib.git"
},
"homepage": "https://github.com/mmMicky/TouchLib",
"export": {
"include": [
"LICENSE",
"library.json",
"library.properties",
"README.md",
"keywords.txt",
"src/*",
"examples/*"
]
},
"frameworks": ["arduino", "espidf"],
"platforms": "esp32",
"headers": "TouchLib.h"
}
11 changes: 11 additions & 0 deletions lib/TouchLib/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=TouchLib
version=0.0.2
author=Micky
maintainer=Micky
sentence=ESP32
paragraph=Integrated touch driver (CST328, CST816, CST820, GT911, FT3267, FT5x06).
category=Integrated touch driver (CST328, CST816, CST820, GT911, FT3267, FT5x06)
url=https://github.com/mmMicky/TouchLib
architectures=*
includes=TouchLib.h

148 changes: 148 additions & 0 deletions lib/TouchLib/src/ModulesCSTMutual.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**
*
* @license MIT License
*
* Copyright (c) 2022 micky
*
* 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 TouchLibCSTMutual.tpp
* @author Micky ([email protected])
* @date 2022-10-24
*
*/

#if defined(ARDUINO)
#include <Arduino.h>
#endif
#include "REG/CSTMutualConstants.h"
#include "TouchLibCommon.tpp"
#include "TouchLibInterface.hpp"

class TouchLibCSTMutual : public TouchLibCommon<TouchLibCSTMutual>, public TouchLibInterface
{
friend class TouchLibCommon<TouchLibCSTMutual>;

public:
#if defined(ARDUINO)
TouchLibCSTMutual(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = CTS328_SLAVE_ADDRESS, int rst = -1)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
__rst = rst;
}
#endif

TouchLibCSTMutual()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = SDA;
__scl = SCL;
__rst = -1;
#endif
__addr = CTS328_SLAVE_ADDRESS;
}

~TouchLibCSTMutual()
{
log_i("~TouchLibCSTMutual");
deinit();
}

bool init() { return begin(); }

void deinit() { end(); }

bool enableSleep() { return this->writeRegister((uint8_t)(CHIP_DEEP_SLEEP_REG >> 8), (uint8_t)(CHIP_DEEP_SLEEP_REG & 0xFF)); }

bool read()
{
this->readRegister(MODE_NORMAL_0_REG, raw_data, sizeof(raw_data));
this->writeRegister(MODE_NORMAL_0_REG, (uint8_t)0xAB); // sync signal
// return raw_data[MODE_NORMAL_6_REG & 0xFF] == 0XAB ? 1 : 0;
return ((raw_data[MODE_NORMAL_5_REG & 0xff] & 0x0f) != 0 ? 1 : 0);
}

uint8_t getPointNum() { return raw_data[MODE_NORMAL_5_REG & 0xff] & 0x0f; }

TP_Point getPoint(uint8_t n)
{
TP_Point t;
switch (n)
{
case 0:
t.state = raw_data[MODE_NORMAL_0_REG & 0xFF] & 0xF;
t.x = COMBINE_H8L4_H(MODE_NORMAL_1_REG, MODE_NORMAL_3_REG);
t.y = COMBINE_H8L4_L(MODE_NORMAL_2_REG, MODE_NORMAL_3_REG);
t.pressure = raw_data[MODE_NORMAL_4_REG & 0xF];
break;
case 1:
t.state = raw_data[MODE_NORMAL_7_REG & 0xFF] & 0xF;
t.x = COMBINE_H8L4_H(MODE_NORMAL_8_REG, MODE_NORMAL_10_REG);
t.y = COMBINE_H8L4_L(MODE_NORMAL_9_REG, MODE_NORMAL_10_REG);
t.pressure = raw_data[MODE_NORMAL_11_REG & 0xF];
break;
case 2:
t.state = raw_data[MODE_NORMAL_12_REG & 0xFF] & 0xF;
t.x = COMBINE_H8L4_H(MODE_NORMAL_13_REG, MODE_NORMAL_15_REG);
t.y = COMBINE_H8L4_L(MODE_NORMAL_14_REG, MODE_NORMAL_15_REG);
t.pressure = raw_data[MODE_NORMAL_16_REG & 0xF];
break;
case 3:
t.state = raw_data[MODE_NORMAL_17_REG & 0xFF] & 0xF;
t.x = COMBINE_H8L4_H(MODE_NORMAL_18_REG, MODE_NORMAL_20_REG);
t.y = COMBINE_H8L4_L(MODE_NORMAL_19_REG, MODE_NORMAL_20_REG);
t.pressure = raw_data[MODE_NORMAL_21_REG & 0xF];
break;
case 4:
t.state = raw_data[MODE_NORMAL_22_REG & 0xFF] & 0xF;
t.x = COMBINE_H8L4_H(MODE_NORMAL_23_REG, MODE_NORMAL_25_REG);
t.y = COMBINE_H8L4_L(MODE_NORMAL_24_REG, MODE_NORMAL_25_REG);
t.pressure = raw_data[MODE_NORMAL_26_REG & 0xF];
break;
default:
log_i("The parameter range of getPoint is between 0 and 4.");
break;
}
t.id = n;

if (rotation == 0)
{
}
else if (rotation == 1)
{
uint16_t tmp = t.x;
t.x = t.y;
t.y = tmp;
}
return t;
}

void setRotation(uint8_t r) { rotation = r % 4; }

uint8_t getRotation() { return rotation; }

protected:
bool initImpl() { return true; }
uint8_t raw_data[27] = {0};
uint8_t rotation = 0;
};
Loading

0 comments on commit 69e8563

Please sign in to comment.