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

FT6206.h

Committer:
JackB
Date:
2015-03-23
Revision:
0:d146e986a07f
Child:
4:b9ff3c020e7f

File content as of revision 0:d146e986a07f:

/*************************************************** 
  This is a library for the Adafruit Capacitive Touch Screens

  ----> http://www.adafruit.com/products/1947
 
  Check out the links above for our tutorials and wiring diagrams
  This chipset uses I2C to communicate

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#ifndef FT6206_H
#define FT6206_H

#include "mbed.h"

#define FT6206_I2C_FREQUENCY      400000

#define FT6206_ADDR           0x38
#define FT6206_G_FT5201ID     0xA8
#define FT6206_REG_NUMTOUCHES 0x02

#define FT6206_NUM_X             0x33
#define FT6206_NUM_Y             0x34

#define FT6206_REG_MODE 0x00
#define FT6206_REG_CALIBRATE 0x02
#define FT6206_REG_WORKMODE 0x00
#define FT6206_REG_FACTORYMODE 0x40
#define FT6206_REG_THRESHHOLD 0x80
#define FT6206_REG_POINTRATE 0x88
#define FT6206_REG_FIRMVERS 0xA6
#define FT6206_REG_CHIPID 0xA3
#define FT6206_REG_VENDID 0xA8

// calibrated for Adafruit 2.8" ctp screen
#define FT6206_DEFAULT_THRESSHOLD 0x80

#define ILI9341_TFTWIDTH  320
#define ILI9341_TFTHEIGHT 240

class TS_Point {
 public:
    TS_Point(void);
    TS_Point(int16_t x, int16_t y, int16_t z);
    
    bool operator==(TS_Point);
    bool operator!=(TS_Point);
    
    int16_t x, y, z;
};

class FT6206 {
 public:

    FT6206(PinName sda, PinName scl, PinName interrupt);
  
    bool begin(uint8_t thresh = FT6206_DEFAULT_THRESSHOLD);  

    void writeRegister8(char reg, char val);
    char readRegister8(char reg);
    char dataReceived(void);

    void readData(uint16_t *x, uint16_t *y);
    
    bool touched(void);
    TS_Point getPoint(void);

 private:
    DigitalIn m_interrupt; 
    I2C m_i2c;
    int m_addr;
    char data[2];

    uint8_t touches;
    uint16_t touchX[2], touchY[2], touchID[2];

};

#endif