mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Swap out FT5206 for FT6336U
This commit is contained in:
parent
bab84898e0
commit
b8bdcaf710
@ -125,7 +125,7 @@ typedef int16_t lv_coord_t;
|
||||
|
||||
/* Input device read period in milliseconds */
|
||||
#ifndef LV_INDEV_DEF_READ_PERIOD
|
||||
#define LV_INDEV_DEF_READ_PERIOD 20
|
||||
#define LV_INDEV_DEF_READ_PERIOD 20 /*[ms]*/
|
||||
#endif
|
||||
|
||||
/* Drag threshold in pixels */
|
||||
|
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 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.
|
@ -1,2 +0,0 @@
|
||||
FT5206 Library
|
||||
=====================================
|
@ -1,29 +0,0 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For FT5206 Library By lewis He
|
||||
# github:https://github.com/lewisxhe
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
TP_Point KEYWORD1
|
||||
FT5206_Class KEYWORD1
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
begin KEYWORD2
|
||||
adjustTheshold KEYWORD2
|
||||
getPoint KEYWORD2
|
||||
enterSleepMode KEYWORD2
|
||||
enterMonitorMode KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
@ -1,10 +0,0 @@
|
||||
name=FT5206_Library
|
||||
version=1.0.0
|
||||
author=Lewis He
|
||||
maintainer=Lewis He <lewishe@outlook.com>
|
||||
sentence=Arduino library for FT5206 chip.
|
||||
paragraph=Arduino library for FT5206 chip. Tested with ESP32
|
||||
category=Communication
|
||||
url=https://github.com/lewisxhe/FT5206_Library
|
||||
architectures=*
|
||||
architectures=esp32
|
@ -1,108 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 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.
|
||||
|
||||
FT5206.cpp - Arduino library for FT5206 chip.
|
||||
Created by Lewis on April 17, 2019.
|
||||
github:https://github.com/lewisxhe/FT5206_Library
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////
|
||||
#include "FT5206.h"
|
||||
|
||||
int FT5206_Class::begin(TwoWire &port, uint8_t addr)
|
||||
{
|
||||
_i2cPort = &port;
|
||||
_address = addr;
|
||||
uint8_t val;
|
||||
_readByte(FT5206_VENDID_REG, 1, &val);
|
||||
//Serial.printf("vend id %d\n",val );
|
||||
if (val != FT5206_VENDID) {
|
||||
// return false;
|
||||
}
|
||||
_readByte(FT5206_CHIPID_REG, 1, &val);
|
||||
//Serial.printf("chip id %d\n",val );
|
||||
if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID) && (val != FT5316_CHIPID) ) {
|
||||
return false;
|
||||
}
|
||||
_init = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// valid touching detect threshold.
|
||||
void FT5206_Class::adjustTheshold(uint8_t thresh)
|
||||
{
|
||||
if (!_init)return;
|
||||
_writeByte(FT5206_THRESHHOLD_REG, 1, &thresh);
|
||||
}
|
||||
|
||||
TP_Point FT5206_Class::getPoint(uint8_t num)
|
||||
{
|
||||
if (!_init) return TP_Point(0, 0);
|
||||
_readRegister();
|
||||
if ((_touches == 0) || (num > 1)) {
|
||||
return TP_Point(0, 0);
|
||||
} else {
|
||||
return TP_Point(_x[num], _y[num]);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FT5206_Class::touched()
|
||||
{
|
||||
if (!_init)return 0;
|
||||
uint8_t val = 0;
|
||||
_readByte(FT5206_TOUCHES_REG,1,&val);
|
||||
return val > 2 ? 0: val;
|
||||
}
|
||||
|
||||
void FT5206_Class::enterSleepMode()
|
||||
{
|
||||
if (!_init)return;
|
||||
uint8_t val = FT5206_SLEEP_IN;
|
||||
_writeByte(FT5206_POWER_REG, 1, &val);
|
||||
}
|
||||
|
||||
void FT5206_Class::enterMonitorMode()
|
||||
{
|
||||
if (!_init)return;
|
||||
uint8_t val = FT5206_MONITOR;
|
||||
_writeByte(FT5206_POWER_REG, 1, &val);
|
||||
}
|
||||
|
||||
void FT5206_Class::_readRegister()
|
||||
{
|
||||
_readByte(DEVIDE_MODE, 16, _data);
|
||||
_touches = _data[TD_STATUS];
|
||||
if ((_touches > 2) || (_touches == 0)) {
|
||||
_touches = 0;
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
_x[i] = _data[TOUCH1_XH + i * 6] & 0x0F;
|
||||
_x[i] <<= 8;
|
||||
_x[i] |= _data[TOUCH1_XL + i * 6];
|
||||
_y[i] = _data[TOUCH1_YH + i * 6] & 0x0F;
|
||||
_y[i] <<= 8;
|
||||
_y[i] |= _data[TOUCH1_YL + i * 6];
|
||||
_id[i] = _data[TOUCH1_YH + i * 6] >> 4;
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 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.
|
||||
|
||||
FT5206.h - Arduino library for FT5206 chip.
|
||||
Created by Lewis on April 17, 2019.
|
||||
github:https://github.com/lewisxhe/FT5206_Library
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#define FT5206_SLAVE_ADDRESS (0x38)
|
||||
#define FT5206_MODE_REG (0x00)
|
||||
#define FT5206_TOUCHES_REG (0x02)
|
||||
#define FT5206_VENDID_REG (0xA8)
|
||||
#define FT5206_CHIPID_REG (0xA3)
|
||||
#define FT5206_THRESHHOLD_REG (0x80)
|
||||
#define FT5206_POWER_REG (0x87)
|
||||
|
||||
#define FT5206_MONITOR (0x01)
|
||||
#define FT5206_SLEEP_IN (0x03)
|
||||
|
||||
#define FT5206_VENDID 0x11
|
||||
#define FT6206_CHIPID 0x06
|
||||
#define FT6236_CHIPID 0x36
|
||||
#define FT6236U_CHIPID 0x64
|
||||
#define FT5206U_CHIPID 0x64
|
||||
|
||||
#define FT5316_CHIPID 0x0a
|
||||
|
||||
#define DEVIDE_MODE 0x00
|
||||
#define TD_STATUS 0x02
|
||||
#define TOUCH1_XH 0x03
|
||||
#define TOUCH1_XL 0x04
|
||||
#define TOUCH1_YH 0x05
|
||||
#define TOUCH1_YL 0x06
|
||||
|
||||
class TP_Point
|
||||
{
|
||||
public:
|
||||
TP_Point(void)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
TP_Point(int16_t _x, int16_t _y)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
};
|
||||
|
||||
|
||||
class FT5206_Class
|
||||
{
|
||||
public:
|
||||
FT5206_Class() {};
|
||||
int begin(TwoWire &port = Wire, uint8_t addr = FT5206_SLAVE_ADDRESS);
|
||||
// valid touching detect threshold.
|
||||
void adjustTheshold(uint8_t thresh);
|
||||
TP_Point getPoint(uint8_t num = 0);
|
||||
uint8_t touched();
|
||||
void enterSleepMode();
|
||||
void enterMonitorMode();
|
||||
private:
|
||||
void _readRegister();
|
||||
int _readByte(uint8_t reg, uint8_t nbytes, uint8_t *data)
|
||||
{
|
||||
_i2cPort->beginTransmission(_address);
|
||||
_i2cPort->write(reg);
|
||||
_i2cPort->endTransmission();
|
||||
_i2cPort->requestFrom(_address, nbytes);
|
||||
uint8_t index = 0;
|
||||
while (_i2cPort->available())
|
||||
data[index++] = _i2cPort->read();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _writeByte(uint8_t reg, uint8_t nbytes, uint8_t *data)
|
||||
{
|
||||
_i2cPort->beginTransmission(_address);
|
||||
_i2cPort->write(reg);
|
||||
for (uint8_t i = 0; i < nbytes; i++) {
|
||||
_i2cPort->write(data[i]);
|
||||
}
|
||||
_i2cPort->endTransmission();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t _address;
|
||||
uint8_t _data[16];
|
||||
uint16_t _x[2];
|
||||
uint16_t _y[2];
|
||||
uint16_t _id[2];
|
||||
uint8_t _touches = 0;
|
||||
bool _init = false;
|
||||
TwoWire *_i2cPort;
|
||||
};
|
@ -102,6 +102,7 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY)
|
||||
touched = Touch_getXY(&normal_x, &normal_y, false);
|
||||
|
||||
#elif TOUCH_DRIVER == 5206
|
||||
// WARNING : this library is slooow !! use 6336 instead
|
||||
touched = FT5206_getXY(&normal_x, &normal_y, false); // no debug
|
||||
|
||||
#elif TOUCH_DRIVER == 6336
|
||||
|
@ -1,32 +1,34 @@
|
||||
#if TOUCH_DRIVER == 5206
|
||||
|
||||
#include <Wire.h>
|
||||
#include "FT5206.h"
|
||||
#include "ArduinoLog.h"
|
||||
#include <Wire.h>
|
||||
#include "focaltech.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
#include "hasp_drv_ft5206.h"
|
||||
#include "hasp_drv_ft5206.h"
|
||||
|
||||
#define RST_PIN (TOUCH_RST) // -1 if pin is connected to VCC else set pin number
|
||||
#define RST_PIN (TOUCH_RST) // -1 if pin is connected to VCC else set pin number
|
||||
|
||||
FT5206_Class * touchpanel;
|
||||
FocalTech_Class* touchpanel;
|
||||
|
||||
// Read touch points
|
||||
bool FT5206_getXY(int16_t * touchX, int16_t * touchY, bool debug)
|
||||
bool FT5206_getXY(int16_t* touchX, int16_t* touchY, bool debug)
|
||||
{
|
||||
if(!touchpanel->touched()) return false;
|
||||
if(!touchpanel->getTouched()) return false;
|
||||
|
||||
TP_Point tp = touchpanel->getPoint(0);
|
||||
*touchX = tp.x;
|
||||
*touchY = tp.y;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
bool res = touchpanel->getPoint(x, y);
|
||||
*touchX = x;
|
||||
*touchY = y;
|
||||
|
||||
if(debug) {
|
||||
LOG_VERBOSE(TAG_DRVR, F("FT5206 touched x: %d y: %d\n"), tp.x, tp.y);
|
||||
LOG_VERBOSE(TAG_DRVR, F("FT5206 touched x: %d y: %d\n"), *touchX, *touchY);
|
||||
}
|
||||
|
||||
return true;
|
||||
return res;
|
||||
}
|
||||
|
||||
void scan(TwoWire & i2c)
|
||||
void scan(TwoWire& i2c)
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
@ -70,7 +72,7 @@ void FT5206_init()
|
||||
|
||||
Wire1.begin(TOUCH_SDA, TOUCH_SCL, TOUCH_FREQUENCY);
|
||||
scan(Wire1);
|
||||
touchpanel = new FT5206_Class();
|
||||
touchpanel = new FocalTech_Class();
|
||||
|
||||
if(touchpanel->begin(Wire1, FT5206_address)) {
|
||||
LOG_INFO(TAG_DRVR, F("FT5206 touch driver started"));
|
||||
|
@ -28,7 +28,7 @@ build_flags =
|
||||
-D TFT_MOSI=23 ; FCP pin6 SDA
|
||||
-D TFT_MISO=25 ; FCP pin7 SDO
|
||||
-D TFT_BCKL=5
|
||||
-D TOUCH_DRIVER=5206
|
||||
-D TOUCH_DRIVER=6336 ; FT5206 is too slow, 6336U works 6x faster
|
||||
-D TOUCH_SDA=4
|
||||
-D TOUCH_SCL=0
|
||||
-D TOUCH_IRQ=-1 ; not connected
|
||||
@ -46,7 +46,8 @@ build_flags =
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
${esp32.lib_deps}
|
||||
;git+https://github.com/lvgl/lvgl_esp32_drivers.git
|
||||
; FT6336U is 6x faster then FocalTech Library
|
||||
;git+https://github.com/lewisxhe/FocalTech_Library.git
|
||||
git+https://github.com/aselectroworks/Arduino-FT6336U.git
|
||||
|
||||
lib_ignore =
|
||||
|
Loading…
x
Reference in New Issue
Block a user