mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Add FT6336U
This commit is contained in:
parent
124a979569
commit
7625d688be
38
lib/FT6336U/.gitignore
vendored
Normal file
38
lib/FT6336U/.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# VS Code Setting
|
||||
.vscode/
|
||||
|
||||
# Build Folder
|
||||
build/
|
21
lib/FT6336U/LICENSE
Normal file
21
lib/FT6336U/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 aselectroworks
|
||||
|
||||
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.
|
5
lib/FT6336U/README.md
Normal file
5
lib/FT6336U/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# FT6336U Library
|
||||
FocalTech FT6336U (Self-Capacitive Touch Panel Controller) library for Arduino.
|
||||
|
||||
## License
|
||||
This code is released under the MIT License. Please see [LICENSE](https://github.com/aselectroworks/Arduino-FT6336U/blob/master/LICENSE) for the full text.
|
40
lib/FT6336U/examples/ReadTouchParam/ReadTouchParam.ino
Normal file
40
lib/FT6336U/examples/ReadTouchParam/ReadTouchParam.ino
Normal file
@ -0,0 +1,40 @@
|
||||
#include "FT6336U.h"
|
||||
|
||||
#define I2C_SDA 22
|
||||
#define I2C_SCL 23
|
||||
#define RST_N_PIN 21
|
||||
#define INT_N_PIN 34
|
||||
|
||||
FT6336U ft6336u(I2C_SDA, I2C_SCL, RST_N_PIN, INT_N_PIN);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
ft6336u.begin();
|
||||
|
||||
Serial.print("FT6336U Firmware Version: ");
|
||||
Serial.println(ft6336u.read_firmware_id());
|
||||
Serial.print("FT6336U Device Mode: ");
|
||||
Serial.println(ft6336u.read_device_mode());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if(digitalRead(INT_N_PIN) != -1) {
|
||||
Serial.print("FT6336U TD Status: ");
|
||||
Serial.println(ft6336u.read_td_status());
|
||||
Serial.print("FT6336U Touch Event/ID 1: (");
|
||||
Serial.print(ft6336u.read_touch1_event()); Serial.print(" / "); Serial.print(ft6336u.read_touch1_id()); Serial.println(")");
|
||||
Serial.print("FT6336U Touch Position 1: (");
|
||||
Serial.print(ft6336u.read_touch1_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch1_y()); Serial.println(")");
|
||||
Serial.print("FT6336U Touch Weight/MISC 1: (");
|
||||
Serial.print(ft6336u.read_touch1_weight()); Serial.print(" / "); Serial.print(ft6336u.read_touch1_misc()); Serial.println(")");
|
||||
Serial.print("FT6336U Touch Event/ID 2: (");
|
||||
Serial.print(ft6336u.read_touch2_event()); Serial.print(" / "); Serial.print(ft6336u.read_touch2_id()); Serial.println(")");
|
||||
Serial.print("FT6336U Touch Position 2: (");
|
||||
Serial.print(ft6336u.read_touch2_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch2_y()); Serial.println(")");
|
||||
Serial.print("FT6336U Touch Weight/MISC 2: (");
|
||||
Serial.print(ft6336u.read_touch2_weight()); Serial.print(" / "); Serial.print(ft6336u.read_touch2_misc()); Serial.println(")");
|
||||
}
|
||||
|
||||
}
|
||||
|
57
lib/FT6336U/examples/ScanMultiTouch/ScanMultiTouch.ino
Normal file
57
lib/FT6336U/examples/ScanMultiTouch/ScanMultiTouch.ino
Normal file
@ -0,0 +1,57 @@
|
||||
#include "FT6336U.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define I2C_SDA 22
|
||||
#define I2C_SCL 23
|
||||
#define RST_N_PIN 21
|
||||
#define INT_N_PIN 34
|
||||
|
||||
FT6336U ft6336u(I2C_SDA, I2C_SCL, RST_N_PIN, INT_N_PIN);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
ft6336u.begin();
|
||||
|
||||
// ft6336u.write_device_mode(factory_mode);
|
||||
Serial.print("FT6336U Device Mode: ");
|
||||
Serial.println(ft6336u.read_device_mode());
|
||||
Serial.print("FT6336U Threshold: 0x");
|
||||
Serial.println(ft6336u.read_touch_threshold(), HEX);
|
||||
Serial.print("FT6336U Filter Coefficient: 0x");
|
||||
Serial.println(ft6336u.read_filter_coefficient(), HEX);
|
||||
Serial.print("FT6336U Control Mode: 0x");
|
||||
Serial.println(ft6336u.read_ctrl_mode(), HEX);
|
||||
Serial.print("FT6336U Time Period for enter to Monitor Mode: 0x");
|
||||
Serial.println(ft6336u.read_time_period_enter_monitor(), HEX);
|
||||
Serial.print("FT6336U Active Rate: 0x");
|
||||
Serial.println(ft6336u.read_active_rate(), HEX);
|
||||
Serial.print("FT6336U Monitor Rate: 0x");
|
||||
Serial.println(ft6336u.read_monitor_rate(), HEX);
|
||||
|
||||
Serial.print("FT6336U LIB Ver: 0x");
|
||||
Serial.println(ft6336u.read_library_version(), HEX);
|
||||
Serial.print("FT6336U Chip ID: 0x");
|
||||
Serial.println(ft6336u.read_chip_id(), HEX);
|
||||
Serial.print("FT6336U G Mode: 0x");
|
||||
Serial.println(ft6336u.read_g_mode(), HEX);
|
||||
Serial.print("FT6336U POWER Mode: 0x");
|
||||
Serial.println(ft6336u.read_pwrmode(), HEX);
|
||||
Serial.print("FT6336U Firm ID: 0x");
|
||||
Serial.println(ft6336u.read_firmware_id(), HEX);
|
||||
Serial.print("FT6336U Focal Tehc ID: 0x");
|
||||
Serial.println(ft6336u.read_focaltech_id(), HEX);
|
||||
Serial.print("FT6336U Release Code ID: 0x");
|
||||
Serial.println(ft6336u.read_release_code_id(), HEX);
|
||||
Serial.print("FT6336U State: 0x");
|
||||
Serial.println(ft6336u.read_state(), HEX);
|
||||
|
||||
}
|
||||
|
||||
FT6336U_TouchPointType tp;
|
||||
void loop() {
|
||||
tp = ft6336u.scan();
|
||||
char tempString[128];
|
||||
sprintf(tempString, "FT6336U TD Count %d / TD1 (%d, %4d, %4d) / TD2 (%d, %4d, %4d)\r", tp.touch_count, tp.tp[0].status, tp.tp[0].x, tp.tp[0].y, tp.tp[1].status, tp.tp[1].x, tp.tp[1].y);
|
||||
Serial.print(tempString);
|
||||
}
|
10
lib/FT6336U/library.properties
Normal file
10
lib/FT6336U/library.properties
Normal file
@ -0,0 +1,10 @@
|
||||
name=FT6336U CTP Controller
|
||||
version=1.0.2
|
||||
author=Atsushi Sasaki
|
||||
maintainer=Atsushi Sasaki
|
||||
sentence=Arduino FT6336U CTP Controller library
|
||||
paragraph=Arduino FT6336U CTP Controller library
|
||||
category=Sensors
|
||||
url=
|
||||
architectures=*
|
||||
includes=FT6336U.h
|
271
lib/FT6336U/src/FT6336U.cpp
Normal file
271
lib/FT6336U/src/FT6336U.cpp
Normal file
@ -0,0 +1,271 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file FT6336U.cpp
|
||||
Author: Atsushi Sasaki (https://github.com/aselectroworks)
|
||||
License: MIT (see LICENSE)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "FT6336U.h"
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
FT6336U::FT6336U(uint8_t rst_n, uint8_t int_n)
|
||||
: rst_n(rst_n), int_n(int_n) {
|
||||
}
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
FT6336U::FT6336U(int8_t sda, int8_t scl, uint8_t rst_n, uint8_t int_n)
|
||||
: sda(sda), scl(scl), rst_n(rst_n), int_n(int_n) {
|
||||
}
|
||||
#endif
|
||||
FT6336U::~FT6336U() {
|
||||
}
|
||||
|
||||
|
||||
void FT6336U::begin(void) {
|
||||
// Initialize I2C
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
if(sda != -1 && scl != -1) {
|
||||
Wire.begin(sda, scl);
|
||||
}
|
||||
else {
|
||||
Wire.begin();
|
||||
}
|
||||
#else
|
||||
Wire.begin();
|
||||
#endif
|
||||
// Int Pin Configuration
|
||||
pinMode(int_n, INPUT);
|
||||
// Reset Pin Configuration
|
||||
pinMode(rst_n, OUTPUT);
|
||||
digitalWrite(rst_n, LOW);
|
||||
delay(10);
|
||||
digitalWrite(rst_n, HIGH);
|
||||
delay(500);
|
||||
}
|
||||
uint8_t FT6336U::read_device_mode(void) {
|
||||
return (readByte(FT6336U_ADDR_DEVICE_MODE) & 0x70) >> 4;
|
||||
}
|
||||
void FT6336U::write_device_mode(DEVICE_MODE_Enum mode) {
|
||||
writeByte(FT6336U_ADDR_DEVICE_MODE, (mode & 0x07) << 4);
|
||||
}
|
||||
uint8_t FT6336U::read_gesture_id(void) {
|
||||
return readByte(FT6336U_ADDR_GESTURE_ID);
|
||||
}
|
||||
uint8_t FT6336U::read_td_status(void) {
|
||||
return readByte(FT6336U_ADDR_TD_STATUS);
|
||||
}
|
||||
uint8_t FT6336U::read_touch_number(void) {
|
||||
return readByte(FT6336U_ADDR_TD_STATUS) & 0x0F;
|
||||
}
|
||||
// Touch 1 functions
|
||||
uint16_t FT6336U::read_touch1_x(void) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = readByte(FT6336U_ADDR_TOUCH1_X);
|
||||
read_buf[1] = readByte(FT6336U_ADDR_TOUCH1_X + 1);
|
||||
return ((read_buf[0] & 0x0f) << 8) | read_buf[1];
|
||||
}
|
||||
uint16_t FT6336U::read_touch1_y(void) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = readByte(FT6336U_ADDR_TOUCH1_Y);
|
||||
read_buf[1] = readByte(FT6336U_ADDR_TOUCH1_Y + 1);
|
||||
return ((read_buf[0] & 0x0f) << 8) | read_buf[1];
|
||||
}
|
||||
uint8_t FT6336U::read_touch1_event(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH1_EVENT) >> 6;
|
||||
}
|
||||
uint8_t FT6336U::read_touch1_id(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH1_ID) >> 4;
|
||||
}
|
||||
uint8_t FT6336U::read_touch1_weight(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH1_WEIGHT);
|
||||
}
|
||||
uint8_t FT6336U::read_touch1_misc(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH1_MISC) >> 4;
|
||||
}
|
||||
// Touch 2 functions
|
||||
uint16_t FT6336U::read_touch2_x(void) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = readByte(FT6336U_ADDR_TOUCH2_X);
|
||||
read_buf[1] = readByte(FT6336U_ADDR_TOUCH2_X + 1);
|
||||
return ((read_buf[0] & 0x0f) << 8) | read_buf[1];
|
||||
}
|
||||
uint16_t FT6336U::read_touch2_y(void) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = readByte(FT6336U_ADDR_TOUCH2_Y);
|
||||
read_buf[1] = readByte(FT6336U_ADDR_TOUCH2_Y + 1);
|
||||
return ((read_buf[0] & 0x0f) << 8) | read_buf[1];
|
||||
}
|
||||
uint8_t FT6336U::read_touch2_event(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH2_EVENT) >> 6;
|
||||
}
|
||||
uint8_t FT6336U::read_touch2_id(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH2_ID) >> 4;
|
||||
}
|
||||
uint8_t FT6336U::read_touch2_weight(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH2_WEIGHT);
|
||||
}
|
||||
uint8_t FT6336U::read_touch2_misc(void) {
|
||||
return readByte(FT6336U_ADDR_TOUCH2_MISC) >> 4;
|
||||
}
|
||||
|
||||
// Mode Parameter Register
|
||||
uint8_t FT6336U::read_touch_threshold(void) {
|
||||
return readByte(FT6336U_ADDR_THRESHOLD);
|
||||
}
|
||||
uint8_t FT6336U::read_filter_coefficient(void) {
|
||||
return readByte(FT6336U_ADDR_FILTER_COE);
|
||||
}
|
||||
uint8_t FT6336U::read_ctrl_mode(void) {
|
||||
return readByte(FT6336U_ADDR_CTRL);
|
||||
}
|
||||
void FT6336U::write_ctrl_mode(CTRL_MODE_Enum mode) {
|
||||
writeByte(FT6336U_ADDR_CTRL, mode);
|
||||
}
|
||||
uint8_t FT6336U::read_time_period_enter_monitor(void) {
|
||||
return readByte(FT6336U_ADDR_TIME_ENTER_MONITOR);
|
||||
}
|
||||
uint8_t FT6336U::read_active_rate(void) {
|
||||
return readByte(FT6336U_ADDR_ACTIVE_MODE_RATE);
|
||||
}
|
||||
uint8_t FT6336U::read_monitor_rate(void) {
|
||||
return readByte(FT6336U_ADDR_MONITOR_MODE_RATE);
|
||||
}
|
||||
|
||||
// Gesture Parameters
|
||||
uint8_t FT6336U::read_radian_value(void) {
|
||||
return readByte(FT6336U_ADDR_RADIAN_VALUE);
|
||||
}
|
||||
void FT6336U::write_radian_value(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_RADIAN_VALUE, val);
|
||||
}
|
||||
uint8_t FT6336U::read_offset_left_right(void) {
|
||||
return readByte(FT6336U_ADDR_OFFSET_LEFT_RIGHT);
|
||||
}
|
||||
void FT6336U::write_offset_left_right(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_OFFSET_LEFT_RIGHT, val);
|
||||
}
|
||||
uint8_t FT6336U::read_offset_up_down(void) {
|
||||
return readByte(FT6336U_ADDR_OFFSET_UP_DOWN);
|
||||
}
|
||||
void FT6336U::write_offset_up_down(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_OFFSET_UP_DOWN, val);
|
||||
}
|
||||
uint8_t FT6336U::read_distance_left_right(void) {
|
||||
return readByte(FT6336U_ADDR_DISTANCE_LEFT_RIGHT);
|
||||
}
|
||||
void FT6336U::write_distance_left_right(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_DISTANCE_LEFT_RIGHT, val);
|
||||
}
|
||||
uint8_t FT6336U::read_distance_up_down(void) {
|
||||
return readByte(FT6336U_ADDR_DISTANCE_UP_DOWN);
|
||||
}
|
||||
void FT6336U::write_distance_up_down(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_DISTANCE_UP_DOWN, val);
|
||||
}
|
||||
uint8_t FT6336U::read_distance_zoom(void) {
|
||||
return readByte(FT6336U_ADDR_DISTANCE_ZOOM);
|
||||
}
|
||||
void FT6336U::write_distance_zoom(uint8_t val) {
|
||||
writeByte(FT6336U_ADDR_DISTANCE_ZOOM, val);
|
||||
}
|
||||
|
||||
|
||||
// System Information
|
||||
uint16_t FT6336U::read_library_version(void) {
|
||||
uint8_t read_buf[2];
|
||||
read_buf[0] = readByte(FT6336U_ADDR_LIBRARY_VERSION_H);
|
||||
read_buf[1] = readByte(FT6336U_ADDR_LIBRARY_VERSION_L);
|
||||
return ((read_buf[0] & 0x0f) << 8) | read_buf[1];
|
||||
}
|
||||
uint8_t FT6336U::read_chip_id(void) {
|
||||
return readByte(FT6336U_ADDR_CHIP_ID);
|
||||
}
|
||||
uint8_t FT6336U::read_g_mode(void) {
|
||||
return readByte(FT6336U_ADDR_G_MODE);
|
||||
}
|
||||
void FT6336U::write_g_mode(G_MODE_Enum mode){
|
||||
writeByte(FT6336U_ADDR_G_MODE, mode);
|
||||
}
|
||||
uint8_t FT6336U::read_pwrmode(void) {
|
||||
return readByte(FT6336U_ADDR_POWER_MODE);
|
||||
}
|
||||
uint8_t FT6336U::read_firmware_id(void) {
|
||||
return readByte(FT6336U_ADDR_FIRMARE_ID);
|
||||
}
|
||||
uint8_t FT6336U::read_focaltech_id(void) {
|
||||
return readByte(FT6336U_ADDR_FOCALTECH_ID);
|
||||
}
|
||||
uint8_t FT6336U::read_release_code_id(void) {
|
||||
return readByte(FT6336U_ADDR_RELEASE_CODE_ID);
|
||||
}
|
||||
uint8_t FT6336U::read_state(void) {
|
||||
return readByte(FT6336U_ADDR_STATE);
|
||||
}
|
||||
|
||||
|
||||
//coordinate diagram(FPC downwards)
|
||||
////y ////////////////////264x176
|
||||
//
|
||||
//
|
||||
//x
|
||||
//
|
||||
//
|
||||
FT6336U_TouchPointType FT6336U::scan(void){
|
||||
touchPoint.touch_count = read_td_status();
|
||||
|
||||
if(touchPoint.touch_count == 0) {
|
||||
touchPoint.tp[0].status = release;
|
||||
touchPoint.tp[1].status = release;
|
||||
}
|
||||
else if(touchPoint.touch_count == 1) {
|
||||
uint8_t id1 = read_touch1_id(); // id1 = 0 or 1
|
||||
touchPoint.tp[id1].status = (touchPoint.tp[id1].status == release) ? touch : stream;
|
||||
touchPoint.tp[id1].x = read_touch1_x();
|
||||
touchPoint.tp[id1].y = read_touch1_y();
|
||||
touchPoint.tp[~id1 & 0x01].status = release;
|
||||
}
|
||||
else {
|
||||
uint8_t id1 = read_touch1_id(); // id1 = 0 or 1
|
||||
touchPoint.tp[id1].status = (touchPoint.tp[id1].status == release) ? touch : stream;
|
||||
touchPoint.tp[id1].x = read_touch1_x();
|
||||
touchPoint.tp[id1].y = read_touch1_y();
|
||||
uint8_t id2 = read_touch2_id(); // id2 = 0 or 1(~id1 & 0x01)
|
||||
touchPoint.tp[id2].status = (touchPoint.tp[id2].status == release) ? touch : stream;
|
||||
touchPoint.tp[id2].x = read_touch2_x();
|
||||
touchPoint.tp[id2].y = read_touch2_y();
|
||||
}
|
||||
|
||||
return touchPoint;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Private Function
|
||||
uint8_t FT6336U::readByte(uint8_t addr) {
|
||||
uint8_t rdData = 0;
|
||||
uint8_t rdDataCount;
|
||||
do {
|
||||
Wire.beginTransmission(I2C_ADDR_FT6336U);
|
||||
Wire.write(addr);
|
||||
Wire.endTransmission(false); // Restart
|
||||
delay(10);
|
||||
rdDataCount = Wire.requestFrom(I2C_ADDR_FT6336U, 1);
|
||||
} while(rdDataCount == 0);
|
||||
while(Wire.available()) {
|
||||
rdData = Wire.read();
|
||||
}
|
||||
return rdData;
|
||||
|
||||
}
|
||||
void FT6336U::writeByte(uint8_t addr, uint8_t data) {
|
||||
DEBUG_PRINTLN("")
|
||||
DEBUG_PRINT("writeI2C reg 0x")
|
||||
DEBUG_PRINT(addr, HEX)
|
||||
DEBUG_PRINT(" -> 0x") DEBUG_PRINTLN(data, HEX)
|
||||
|
||||
Wire.beginTransmission(I2C_ADDR_FT6336U);
|
||||
Wire.write(addr);
|
||||
Wire.write(data);
|
||||
Wire.endTransmission();
|
||||
}
|
201
lib/FT6336U/src/FT6336U.h
Normal file
201
lib/FT6336U/src/FT6336U.h
Normal file
@ -0,0 +1,201 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file FT6336U.h
|
||||
Author: Atsushi Sasaki(https://github.com/aselectroworks)
|
||||
License: MIT (see LICENSE)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _FT6336U_H
|
||||
#define _FT6336U_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#define I2C_ADDR_FT6336U 0x48
|
||||
|
||||
// Touch Parameter
|
||||
#define FT6336U_PRES_DOWN 0x2
|
||||
#define FT6336U_COORD_UD 0x1
|
||||
|
||||
// Registers
|
||||
#define FT6336U_ADDR_DEVICE_MODE 0x00
|
||||
typedef enum {
|
||||
working_mode = 0b000,
|
||||
factory_mode = 0b100,
|
||||
} DEVICE_MODE_Enum;
|
||||
#define FT6336U_ADDR_GESTURE_ID 0x01
|
||||
#define FT6336U_ADDR_TD_STATUS 0x02
|
||||
|
||||
#define FT6336U_ADDR_TOUCH1_EVENT 0x03
|
||||
#define FT6336U_ADDR_TOUCH1_ID 0x05
|
||||
#define FT6336U_ADDR_TOUCH1_X 0x03
|
||||
#define FT6336U_ADDR_TOUCH1_Y 0x05
|
||||
#define FT6336U_ADDR_TOUCH1_WEIGHT 0x07
|
||||
#define FT6336U_ADDR_TOUCH1_MISC 0x08
|
||||
|
||||
#define FT6336U_ADDR_TOUCH2_EVENT 0x09
|
||||
#define FT6336U_ADDR_TOUCH2_ID 0x0B
|
||||
#define FT6336U_ADDR_TOUCH2_X 0x09
|
||||
#define FT6336U_ADDR_TOUCH2_Y 0x0B
|
||||
#define FT6336U_ADDR_TOUCH2_WEIGHT 0x0D
|
||||
#define FT6336U_ADDR_TOUCH2_MISC 0x0E
|
||||
|
||||
#define FT6336U_ADDR_THRESHOLD 0x80
|
||||
#define FT6336U_ADDR_FILTER_COE 0x85
|
||||
#define FT6336U_ADDR_CTRL 0x86
|
||||
typedef enum {
|
||||
keep_active_mode = 0,
|
||||
switch_to_monitor_mode = 1,
|
||||
} CTRL_MODE_Enum;
|
||||
#define FT6336U_ADDR_TIME_ENTER_MONITOR 0x87
|
||||
#define FT6336U_ADDR_ACTIVE_MODE_RATE 0x88
|
||||
#define FT6336U_ADDR_MONITOR_MODE_RATE 0x89
|
||||
|
||||
#define FT6336U_ADDR_RADIAN_VALUE 0x91
|
||||
#define FT6336U_ADDR_OFFSET_LEFT_RIGHT 0x92
|
||||
#define FT6336U_ADDR_OFFSET_UP_DOWN 0x93
|
||||
#define FT6336U_ADDR_DISTANCE_LEFT_RIGHT 0x94
|
||||
#define FT6336U_ADDR_DISTANCE_UP_DOWN 0x95
|
||||
#define FT6336U_ADDR_DISTANCE_ZOOM 0x96
|
||||
|
||||
#define FT6336U_ADDR_LIBRARY_VERSION_H 0xA1
|
||||
#define FT6336U_ADDR_LIBRARY_VERSION_L 0xA2
|
||||
#define FT6336U_ADDR_CHIP_ID 0xA3
|
||||
#define FT6336U_ADDR_G_MODE 0xA4
|
||||
typedef enum {
|
||||
pollingMode = 0,
|
||||
triggerMode = 1,
|
||||
} G_MODE_Enum;
|
||||
#define FT6336U_ADDR_POWER_MODE 0xA5
|
||||
#define FT6336U_ADDR_FIRMARE_ID 0xA6
|
||||
#define FT6336U_ADDR_FOCALTECH_ID 0xA8
|
||||
#define FT6336U_ADDR_RELEASE_CODE_ID 0xAF
|
||||
#define FT6336U_ADDR_STATE 0xBC
|
||||
|
||||
// Function Specific Type
|
||||
typedef enum {
|
||||
touch = 0,
|
||||
stream,
|
||||
release,
|
||||
} TouchStatusEnum;
|
||||
typedef struct {
|
||||
TouchStatusEnum status;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
} TouchPointType;
|
||||
typedef struct {
|
||||
uint8_t touch_count;
|
||||
TouchPointType tp[2];
|
||||
} FT6336U_TouchPointType;
|
||||
|
||||
|
||||
// Uncomment to enable debug messages
|
||||
//#define FT6336U_DEBUG
|
||||
|
||||
// Define where debug output will be printed
|
||||
#define DEBUG_PRINTER Serial
|
||||
|
||||
// Setup debug printing macros
|
||||
#ifdef FT6336U_DEBUG
|
||||
#define DEBUG_PRINT(...) \
|
||||
{ \
|
||||
DEBUG_PRINTER.print(__VA_ARGS__); \
|
||||
}
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{ \
|
||||
DEBUG_PRINTER.println(__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DEBUG_PRINT(...) \
|
||||
{ \
|
||||
}
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{ \
|
||||
}
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief FT6336U I2C CTP controller driver
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class FT6336U
|
||||
{
|
||||
public:
|
||||
FT6336U(uint8_t rst_n, uint8_t int_n);
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
FT6336U(int8_t sda, int8_t scl, uint8_t rst_n, uint8_t int_n);
|
||||
#endif
|
||||
virtual ~FT6336U();
|
||||
|
||||
void begin(void);
|
||||
|
||||
uint8_t read_device_mode(void);
|
||||
void write_device_mode(DEVICE_MODE_Enum);
|
||||
uint8_t read_gesture_id(void);
|
||||
uint8_t read_td_status(void);
|
||||
uint8_t read_touch_number(void);
|
||||
uint16_t read_touch1_x(void);
|
||||
uint16_t read_touch1_y(void);
|
||||
uint8_t read_touch1_event(void);
|
||||
uint8_t read_touch1_id(void);
|
||||
uint8_t read_touch1_weight(void);
|
||||
uint8_t read_touch1_misc(void);
|
||||
uint16_t read_touch2_x(void);
|
||||
uint16_t read_touch2_y(void);
|
||||
uint8_t read_touch2_event(void);
|
||||
uint8_t read_touch2_id(void);
|
||||
uint8_t read_touch2_weight(void);
|
||||
uint8_t read_touch2_misc(void);
|
||||
|
||||
// Mode Parameter Register
|
||||
uint8_t read_touch_threshold(void);
|
||||
uint8_t read_filter_coefficient(void);
|
||||
uint8_t read_ctrl_mode(void);
|
||||
void write_ctrl_mode(CTRL_MODE_Enum mode);
|
||||
uint8_t read_time_period_enter_monitor(void);
|
||||
uint8_t read_active_rate(void);
|
||||
uint8_t read_monitor_rate(void);
|
||||
|
||||
// Gestrue Parameter Register
|
||||
uint8_t read_radian_value(void);
|
||||
void write_radian_value(uint8_t val);
|
||||
uint8_t read_offset_left_right(void);
|
||||
void write_offset_left_right(uint8_t val);
|
||||
uint8_t read_offset_up_down(void);
|
||||
void write_offset_up_down(uint8_t val);
|
||||
uint8_t read_distance_left_right(void);
|
||||
void write_distance_left_right(uint8_t val);
|
||||
uint8_t read_distance_up_down(void);
|
||||
void write_distance_up_down(uint8_t val);
|
||||
uint8_t read_distance_zoom(void);
|
||||
void write_distance_zoom(uint8_t val);
|
||||
|
||||
// System Information
|
||||
uint16_t read_library_version(void);
|
||||
uint8_t read_chip_id(void);
|
||||
uint8_t read_g_mode(void);
|
||||
void write_g_mode(G_MODE_Enum mode);
|
||||
uint8_t read_pwrmode(void);
|
||||
uint8_t read_firmware_id(void);
|
||||
uint8_t read_focaltech_id(void);
|
||||
uint8_t read_release_code_id(void);
|
||||
uint8_t read_state(void);
|
||||
|
||||
// Scan Function
|
||||
FT6336U_TouchPointType scan(void);
|
||||
|
||||
private:
|
||||
int8_t sda = -1;
|
||||
int8_t scl = -1;
|
||||
uint8_t rst_n = -1;
|
||||
uint8_t int_n = -1;
|
||||
|
||||
uint8_t readByte(uint8_t addr);
|
||||
void writeByte(uint8_t addr, uint8_t data);
|
||||
|
||||
FT6336U_TouchPointType touchPoint;
|
||||
};
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3) && defined(HASP_USE_ARDUINOGFX)
|
||||
|
||||
#include "Arduino_PCA9535SWSPI/Arduino_PCA9535SWSPI.h"
|
||||
#include "Arduino_PCA9535SWSPI.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "hasplib.h"
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "Arduino_RGBPanel_mod.h"
|
||||
#include "Arduino_RGB_Display_mod.h"
|
||||
#include "Arduino_PCA9535SWSPI/Arduino_PCA9535SWSPI.h"
|
||||
#include "Arduino_PCA9535SWSPI.h"
|
||||
|
||||
namespace dev {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user