FT6206 Library for Adafruit 2.8" TFT Touch Shield for Arduino w/Capacitive Touch
Dependents: ArchPro_TFT ATT_AWS_IoT_demo_v06 ArchPro_TFT TermProject
Revision 11:9e1fc2233b0e, committed 2015-04-28
- Comitter:
- JackB
- Date:
- Tue Apr 28 21:12:26 2015 +0000
- Parent:
- 10:535d2140db2c
- Commit message:
- InterruptIn used, when touched
Changed in this revision
FT6206.cpp | Show annotated file Show diff for this revision Revisions of this file |
FT6206.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 535d2140db2c -r 9e1fc2233b0e FT6206.cpp --- a/FT6206.cpp Tue Mar 24 01:31:42 2015 +0000 +++ b/FT6206.cpp Tue Apr 28 21:12:26 2015 +0000 @@ -23,7 +23,8 @@ ----> http://www.adafruit.com/products/1947 This chipset uses I2C to communicate -Based on Arduino written by Limor Fried/Ladyada for Adafruit Industries. +Based on code by Limor Fried/Ladyada for Adafruit Industries. +MIT license, all text above must be included in any redistribution. On the shield, these jumpers were bridged: Int - #7 (default) @@ -101,8 +102,15 @@ { m_addr = (FT6206_ADDR << 1); m_i2c.frequency(FT6206_I2C_FREQUENCY); + m_interrupt.mode(PullUp); + m_interrupt.enable_irq(); + m_interrupt.fall(this, &FT6206::checkDataReceived); + init(); + +// tick.attach(this, &FT6206::checkDataReceived, 0.00001); // Every 10 us id data was received + } FT6206::~FT6206() @@ -118,19 +126,20 @@ bool FT6206::init(uint8_t threshhold) { // change threshhold to be higher/lower writeRegister8(FT6206_REG_THRESHHOLD, FT6206_DEFAULT_THRESSHOLD); +// writeRegister8(FT6206_REG_POINTRATE, 80); if (readRegister8(FT6206_REG_VENDID) != 17) return false; if (readRegister8(FT6206_REG_CHIPID) != 6) return false; -/* - printf("Vend ID: %d\n", readRegister8(FT6206_REG_VENDID)); - printf("Chip ID: %d\n", readRegister8(FT6206_REG_CHIPID)); - printf("Firm V: %d\n", readRegister8(FT6206_REG_FIRMVERS)); - printf("Rate Hz: %d\n", readRegister8(FT6206_REG_POINTRATE)); - printf("Thresh: %d\n", readRegister8(FT6206_REG_THRESHHOLD)); -*/ + +// printf("Vend ID: %d\n", readRegister8(FT6206_REG_VENDID)); +// printf("Chip ID: %d\n", readRegister8(FT6206_REG_CHIPID)); +// printf("Firm V: %d\n", readRegister8(FT6206_REG_FIRMVERS)); +// printf("Rate Hz: %d\n", readRegister8(FT6206_REG_POINTRATE)); +// printf("Thresh: %d\n", readRegister8(FT6206_REG_THRESHHOLD)); + // dump all registers /* for (int16_t i=0; i<0x20; i++) { @@ -147,12 +156,36 @@ return false; } +void FT6206::checkDataReceived(void) { + // InterruptIn pin used +// // Runs every 0.00001 Sec. in Ticker +// if (dataReceived()) { + DataReceived = true; +// } +} + +bool FT6206::getDataReceived(void) { + bool _DataReceived = DataReceived; + DataReceived = false; + return _DataReceived; +} + +void FT6206::waitScreenTapped(void) { + DataReceived = false; + while (!getDataReceived()) { + wait(0.01); + } +} + bool FT6206::getTouchPoint(TS_Point &p) { - if (dataReceived()) { +// if (touched()) { +// if (dataReceived()) { + if (getDataReceived()) { // Retrieve a point p = getPoint(); return true; } + p = clearPoint(); return false; } @@ -223,6 +256,11 @@ return TS_Point(x, y, 1); } +TS_Point FT6206::clearPoint(void) { + uint16_t x = 0, y = 0; + return TS_Point(x, y, 1); +} + char FT6206::readRegister8(char reg) { char val; m_i2c.write(m_addr, ®, 1);
diff -r 535d2140db2c -r 9e1fc2233b0e FT6206.h --- a/FT6206.h Tue Mar 24 01:31:42 2015 +0000 +++ b/FT6206.h Tue Apr 28 21:12:26 2015 +0000 @@ -23,7 +23,8 @@ ----> http://www.adafruit.com/products/1947 This chipset uses I2C to communicate -Based on Arduino written by Limor Fried/Ladyada for Adafruit Industries. +Based on code by Limor Fried/Ladyada for Adafruit Industries. +MIT license, all text above must be included in any redistribution. On the shield, these jumpers were bridged: Int - #7 (default) @@ -161,17 +162,31 @@ bool touched(void); TS_Point getPoint(void); + TS_Point clearPoint(void); + + void checkDataReceived(void); + + bool getDataReceived(void); + + void waitScreenTapped(void); bool getTouchPoint(TS_Point &p); + Ticker tick; + private: - DigitalIn m_interrupt; +// DigitalIn m_interrupt; + InterruptIn m_interrupt; + I2C m_i2c; int m_addr; char data[2]; uint8_t touches; uint16_t touchX[2], touchY[2], touchID[2]; + + bool DataReceived; + };