[SOLVED] FT5x06 Event Flag Put Up

Comments

3 comments

  • Michael_L

    You would detect the end of a contact with the Put Up event as you have mentioned.  The touch event code is the upper 4 bits of the register that holds the upper 4 bits of the x coordinate of the touch point.  This can be seen on page 4 of the FT5x06 Registers document on our website, or here:

    https://support.newhavendisplay.com/hc/en-us/articles/4410042626839-FT5x06-Registers

    You must be reading back these values quickly because the Put Down and Put Up events are only valid for less than a tenth of a second.  I have tested this for you with my Arduino and have posted the code below:

    //---------------------------------------------------------
    /*
    CTP_Register_Test_mega.ino
    Program for writing/reading to/from Newhaven Display Capacitive Touch Panel with FocalTech FT5x06 controller
    Please refer to the below URLs for the touch panel controller documentation:
    http://www.newhavendisplay.com/app_notes/FT5x06.pdf
    http://www.newhavendisplay.com/app_notes/FT5x06_registers.pdf

    (c)2014 Mike LaVine - Newhaven Display International, LLC.

            This program is free software; you can redistribute it and/or modify
            it under the terms of the GNU General Public License as published by
            the Free Software Foundation; either version 2 of the License, or
            (at your option) any later version.

            This program is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public License for more details.
    */
    //---------------------------------------------------------
    #include <Wire.h>

    int WAKE = 14;    //WAKE signal is connected to digital pin 14 on the Arduino Mega2560
    int INT = 15;     //INT signal is connected to digital pin 15 on the Arduino Mega2560

    //SDA line is connected to digital pin 20 (SDA) on the Arduino Mega2560
    //SCL line is connected to digital pin 21 (SCL) on the Arduino Mega2560

    unsigned char dummy, gesture, numpoints, t1xh, t1xl, t1yh, t1yl;
    unsigned char x, read1, read2, read3, read4;
    unsigned int t1x, t1y;

    const char slave = 0x38;    //slave address of 0x70 shifted over 1 bit

    void init_CTP()
    {
    digitalWrite(WAKE, HIGH);
            delay(100);
    digitalWrite(INT, HIGH);
    delay(100);
            digitalWrite(WAKE, LOW);
            delay(200);
            digitalWrite(WAKE, HIGH);
            delay(200);
    }

    void i2c_write(char addr, unsigned char reg, unsigned char i2cwrite)
    {
      Wire.beginTransmission(addr);
      Wire.write(reg);
      Wire.write(i2cwrite);
      Wire.endTransmission();
    }
         
    void i2c_read(char addr, unsigned char reg)                  //function for reading a specified register
    {
      unsigned char x;
      Wire.beginTransmission(addr);
      Wire.write(reg);
      Wire.endTransmission();
      Wire.requestFrom(addr, 1);
      while(Wire.available())
      {
        x = Wire.read();
        Serial.println(x, DEC);
      }
    }

    void i2c_read4times(char addr, unsigned char reg)           //function for reading 4 registers in a row, starting from specified register
    {
      unsigned char x;
      Wire.beginTransmission(addr);
      Wire.write(reg);
      Wire.endTransmission();
      Wire.requestFrom(addr, 4);
      while(Wire.available())
      {
        read1 = Wire.read();
        read2 = Wire.read();
        read3 = Wire.read();
        read4 = Wire.read();
      }
    }
    /*****************************************************/
    /*****************************************************/
    void setup()
    {
            pinMode(WAKE, OUTPUT);
            pinMode(INT, INPUT);
            init_CTP();
            Wire.begin();
            Serial.begin(9600);       
    }
    void loop()
    {
        //i2c_write(slave, 0x80, 0x30);
       
        while((digitalRead(INT)) == LOW)
        {
            i2c_read4times(slave, 0x00);
            dummy = read1;                               //dummy read
            gesture = read2;                             //which gesture register read
            numpoints = read3;                           //how many touch points register read
            t1xh = read4;                                //upper 8 bits of X-axis touch location
            i2c_read4times(slave, 0x04);
            t1xl = read1;                                //lower 8 bits of X-axis touch location
            t1yh = read2;                                //upper 8 bits of Y-axis touch location
            t1yl = read3;                                //lower 8 bits of X-axis touch location
            dummy = read4;                               //dummy read
            t1x = t1xl | (t1xh << 8);                    //get the 16 bit X-axis touch location
            t1y = t1yl | (t1yh << 8);                    //get the 16 bit Y-axis touch location*/
           
           
           
            i2c_read4times(slave, 0x80);
            dummy = read1;
           
        //****************************************************************************//
        //  UNCOMMENT THE LINE BELOW THAT YOU WANT TO BE SHOWN ON THE SERIAL MONITOR  //
        //****************************************************************************//
           
            //Serial.println(gesture, HEX);delay(1);    //show gesture value
            //Serial.println(numpoints, HEX);delay(25);  //show how many touch points
            //Serial.println(t1x, HEX);delay(25);        //show 16 bit X-axis touch location
            //Serial.println(t1y, HEX);delay(25);        //show 16 bit Y-axis touch location
            //Serial.println(dummy, DEC);delay(25);
            Serial.println(t1xh, HEX);delay(25);       
           
            //delays are only used here to slow down scrolling in the serial monitor
            //********************************************************************//
        }   
    }
    0
  • PaulVdBergh

    Hi Michael,

    Thanks for your reply.

    Since I'm not confident with arduino boards and their framework, I'll give you some more info on the subject at hand.

    I'm developing on an Atmel SAM4sXplained Pro board (ATSAM4SD32C - Cortex M4) using bare metal gcc/g++.

    first, when the FT5x06 raises the INT pin (by pulling it to low level), this code reads the registers:

    m_pTwi->Read(FT5X06_TWI_ADDRESS, 0, 1, 3, (uint8_t*)&m_TouchData);
    if(m_TouchData.TDStatus & 0x0F)
    {
    m_pTwi->Read(FT5X06_TWI_ADDRESS, 3, 1, ((m_TouchData.TDStatus) & 0x0F) * 6, (uint8_t*)&m_TouchData.TouchPoints);
    (new SPg_TouchEvent(&m_TouchData, NULL))->InsertEvent();
    }

    The latency from the FT lowering the INT pin until reaching this code is approx. 160µS and m_pTwi->read is defined as

    void Read(const uint8_t& devAddr, const uint32_t& internalAddress, const uint8_t& internalAddressSize, uint16_t count, uint8_t* buffer);

    The above code reads the actual touchdata for the number of touchpositions indicated in TD_STATUS.

    The touchdata is then forwarded (via a messaging system) to this routine, decoding each touchposition :

    void SPg_GUI::OnTouch(uint32_t value, void* pointer)
    {
    SPg_FT5X06::Data* pTouchData = (SPg_FT5X06::Data*)pointer;
    if(pTouchData)
    {
    for(uint8_t i = 0; i < (pTouchData->TDStatus & 0x0F); i++)
    {
    SPg_FT5X06::TouchPointData TouchPoint = pTouchData->TouchPoints[i];
    SPg_Point location((((TouchPoint.Touch1_XH & 0x0F) * 0x100) + TouchPoint.Touch1_XL), (((TouchPoint.Touch1_YH & 0x0F) * 0x100) + TouchPoint.Touch1_YL));
    m_pTFT->DrawPixel(location, SPg_Color::BRIGHTGREEN);

    switch(TouchPoint.Touch1_XH >> 6)
    {
    case 0: // Put Down
    {
    m_pMainFrame->FindTopmostFrameAt(location)->OnTouchDown(location);
    break;
    }

    case 1: // Put Up
    {
    m_pMainFrame->FindTopmostFrameAt(location)->OnTouchUp(location);
    break;
    }

    case 2: // Contact
    {
    m_pMainFrame->FindTopmostFrameAt(location)->OnTouchContact(location);
    break;
    }

    default: // Reserved
    {
    __BKPT();
    }
    }
    }
    }
    }

    Well, I receive 'Put Down' events and 'Contact' events, but never a 'Put Up' event...

    What am I doing wrong?

    Thanks

    0
  • PaulVdBergh

    OK, found my mistake : the 'Put Up' event is send with NbrOfTouchpoints set to zero.  Since I had a loop counting from zero up to the number of touchpoints I always missed the PutUp events....

    0

Please sign in to leave a comment.