Skip to content

Commit

Permalink
update to allow diff i2c
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Oct 20, 2023
1 parent bfd72a8 commit 90fae75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 12 additions & 10 deletions Adafruit_FT6206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Adafruit_FT6206::Adafruit_FT6206() { touches = 0; }
@brief Setups the I2C interface and hardware, identifies if chip is found
@param thresh Optional threshhold-for-touch value, default is
FT6206_DEFAULT_THRESHOLD but you can try changing it if your screen is
too/not sensitive.
too/not sensitive. You can also try 0 to not change the threshold.
@param theWire Which I2C bus to use, defaults to &Wire
@returns True if an FT6206 is found, false on any failure
@returns True if an FT captouch is found, false on any failure
*/
/**************************************************************************/
bool Adafruit_FT6206::begin(uint8_t thresh, TwoWire *theWire) {
bool Adafruit_FT6206::begin(uint8_t thresh, TwoWire *theWire, uint8_t i2c_addr) {
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(FT62XX_ADDR, theWire);
i2c_dev = new Adafruit_I2CDevice(i2c_addr, theWire);
if (!i2c_dev->begin())
return false;

Expand All @@ -75,15 +75,16 @@ bool Adafruit_FT6206::begin(uint8_t thresh, TwoWire *theWire) {
}
#endif

// change threshhold to be higher/lower
writeRegister8(FT62XX_REG_THRESHHOLD, thresh);
// change threshhold to be higher/lower if desired
if (thresh != 0)
writeRegister8(FT62XX_REG_THRESHHOLD, thresh);

if (readRegister8(FT62XX_REG_VENDID) != FT62XX_VENDID) {
return false;
}
uint8_t id = readRegister8(FT62XX_REG_CHIPID);
if ((id != FT6206_CHIPID) && (id != FT6236_CHIPID) &&
(id != FT6236U_CHIPID)) {
(id != FT6236U_CHIPID) && (id != FT6336U_CHIPID)) {
return false;
}

Expand Down Expand Up @@ -139,14 +140,15 @@ void Adafruit_FT6206::readData(void) {
i2c_dev->write_then_read(&addr, 1, i2cdat, 16);

touches = i2cdat[0x02];
#ifdef FT6206_DEBUG
Serial.print("# Touches: ");
Serial.println(touches);
#endif
if ((touches > 2) || (touches == 0)) {
touches = 0;
}

#ifdef FT6206_DEBUG
Serial.print("# Touches: ");
Serial.println(touches);

for (uint8_t i = 0; i < 16; i++) {
Serial.print("0x");
Serial.print(i2cdat[i], HEX);
Expand Down
5 changes: 3 additions & 2 deletions Adafruit_FT6206.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Arduino.h"
#include <Adafruit_I2CDevice.h>

#define FT62XX_ADDR 0x38 //!< I2C address
#define FT62XX_DEFAULT_ADDR 0x38 //!< I2C address
#define FT62XX_G_FT5201ID 0xA8 //!< FocalTech's panel ID
#define FT62XX_REG_NUMTOUCHES 0x02 //!< Number of touch points

Expand All @@ -29,6 +29,7 @@
#define FT6206_CHIPID 0x06 //!< Chip selecting
#define FT6236_CHIPID 0x36 //!< Chip selecting
#define FT6236U_CHIPID 0x64 //!< Chip selecting
#define FT6336U_CHIPID 0x64 //!< Chip selecting

// calibrated for Adafruit 2.8" ctp screen
#define FT62XX_DEFAULT_THRESHOLD 128 //!< Default threshold for touch detection
Expand Down Expand Up @@ -62,7 +63,7 @@ class Adafruit_FT6206 {
public:
Adafruit_FT6206(void);
bool begin(uint8_t thresh = FT62XX_DEFAULT_THRESHOLD,
TwoWire *theWire = &Wire);
TwoWire *theWire = &Wire, uint8_t i2c_addr = FT62XX_DEFAULT_ADDR);
uint8_t touched(void);
TS_Point getPoint(uint8_t n = 0);

Expand Down

0 comments on commit 90fae75

Please sign in to comment.