BRT Community

General Category => Discussion - EVE => Topic started by: madhusudan.jadhav on November 10, 2020, 06:28:59 AM

Title: REG_TOUCH_RZ giving output 32627 without touching
Post by: madhusudan.jadhav on November 10, 2020, 06:28:59 AM
Hi there,
 I am using matrix orbital EVE2-70A TPR tft display for my industrial project. when i run the calibration file i found without touch the calibration getting over and without touch REG_TOUCH_RZ I am getting 32627 it means display got touch. Please see the code below.
void Calibrate_Manual(uint16_t Width, uint16_t Height, uint16_t V_Offset, uint16_t H_Offset)
{
  uint32_t displayX[3], displayY[3];
  uint32_t touchX[3], touchY[3];
  uint32_t touchValue = 0, storedValue = 0;
  int32_t tmp, k;
  int32_t TransMatrix[6];
  uint8_t count = 0;
  char num[2];
  uint8_t touch_lock = 1;
  uint32_t touchness=0;

  // These values determine where your calibration points will be drawn on your display
  displayX[0] = (Width * 0.15) + H_Offset;
  displayY[0] = (Height * 0.15) + V_Offset;

  displayX[1] = (Width * 0.85) + H_Offset;
  displayY[1] = (Height / 2) + V_Offset;

  displayX[2] = (Width / 2) + H_Offset;
  displayY[2] = (Height * 0.85) + V_Offset;

  while (count < 3)
  {
  //  Send_CMD(CMD_DLSTART);
  //  Send_CMD(CLEAR_COLOR_RGB(64, 64, 64));
  //  Send_CMD(CLEAR(1,1,1));
     API_LIB_BeginCoProList();
    API_CMD_DLSTART();                                                      // Tell co-processor to create new Display List
                API_CLEAR_COLOR_RGB(64, 64, 64);                                     // Specify color to clear screen to
                API_CLEAR(1,1,1);
    // Draw Calibration Point on screen
    API_COLOR_RGB(255, 0, 0);
    API_POINT_SIZE(20 * 16);
    API_BEGIN(FTPOINTS);
    API_VERTEX2F((uint32_t)(displayX[count]) * 16, (uint32_t)((displayY[count])) * 16);

    API_COLOR_RGB(255, 255, 255);
    API_CMD_TEXT((Width / 2) + H_Offset, (Height / 3) + V_Offset, 27, OPT_CENTER, "Calibrating");
    API_CMD_TEXT((Width / 2) + H_Offset, (Height / 2) + V_Offset, 27, OPT_CENTER, "Please tap the dots");
    num[0] = count + 0x31; num[1] = 0;                                            // null terminated string of one character
    API_CMD_TEXT(displayX[count], displayY[count], 27, OPT_CENTER, num);
    API_END();
    API_DISPLAY();
    API_CMD_SWAP();
                                                           // Swap buffers in EVE to make this list active
                          API_LIB_EndCoProList();                                                 // Finish the co-processor list burst write
                        API_LIB_AwaitCoProEmpty();      // wait here until the coprocessor has read and executed every pending command.

    while(1)
    {

       SEGGER_RTT_printf(0,"%stouchvalue =%d\r\n",RTT_CTRL_BG_BRIGHT_GREEN,EVE_MemRead32(REG_TOUCH_RZ) & 0x7fff,RTT_CTRL_RESET);
      touchValue = EVE_MemRead32(REG_TOUCH_DIRECT_XY);    // Read for any new touch tag inputs

      if(touchValue > 1877868500){
      SEGGER_RTT_printf(0,"%stouchmatrix =%d\r\n",RTT_CTRL_BG_BRIGHT_GREEN,touchValue,RTT_CTRL_RESET);}
      if(touch_lock)
      {
        if(touchValue & 0x80000000) // check if we have no touch
          {
            touch_lock = 0;
          }
      }
      else
      {
        if (!(touchValue & 0x80000000)) // check if a touch is detected
          {
           touchValue = EVE_MemRead32(REG_TOUCH_DIRECT_XY);
            touchX[count] = (touchValue>>16) & 0x03FF;   // Raw Touchscreen Y coordinate
            touchY[count] = touchValue & 0x03FF;      // Raw Touchscreen Y coordinate
            touch_lock = 1;
            count++;
            break; // leave while(1)
          }
      }
    }
  }

  k = ((touchX[0] - touchX[2]) * (touchY[1] - touchY[2])) - ((touchX[1] - touchX[2]) * (touchY[0] - touchY[2]));

  tmp = (((displayX[0] - displayX[2]) * (touchY[1] - touchY[2])) - ((displayX[1] - displayX[2])*(touchY[0] - touchY[2])));
  TransMatrix[0] = CalcCoef(tmp, k);

  tmp = (((touchX[0] - touchX[2]) * (displayX[1] - displayX[2])) - ((displayX[0] - displayX[2])*(touchX[1] - touchX[2])));
  TransMatrix[1] = CalcCoef(tmp, k);

  tmp = ((touchY[0] * (((touchX[2] * displayX[1]) - (touchX[1] * displayX[2])))) + (touchY[1] * (((touchX[0] * displayX[2]) - (touchX[2] * displayX[0])))) + (touchY[2] * (((touchX[1] * displayX[0]) - (touchX[0] * displayX[1])))));
  TransMatrix[2] = CalcCoef(tmp, k);

  tmp = (((displayY[0] - displayY[2]) * (touchY[1] - touchY[2])) - ((displayY[1] - displayY[2])*(touchY[0] - touchY[2])));
  TransMatrix[3] = CalcCoef(tmp, k);

  tmp = (((touchX[0] - touchX[2]) * (displayY[1] - displayY[2])) - ((displayY[0] - displayY[2])*(touchX[1] - touchX[2])));
  TransMatrix[4] = CalcCoef(tmp, k);

  tmp = ((touchY[0] * (((touchX[2] * displayY[1]) - (touchX[1] * displayY[2])))) + (touchY[1] * (((touchX[0] * displayY[2]) - (touchX[2] * displayY[0])))) + (touchY[2] * (((touchX[1] * displayY[0]) - (touchX[0] * displayY[1])))));
  TransMatrix[5] = CalcCoef(tmp, k);

  count = 0;
  do
  {
     EVE_MemWrite32(REG_TOUCH_TRANSFORM_A + (count * 4), TransMatrix[count]);  // Write to Eve config registers

//    uint16_t ValH = TransMatrix[count] >> 16;
//    uint16_t ValL = TransMatrix[count] & 0xFFFF;
//    Log("TM%d: 0x%04x %04x\n", count, ValH, ValL);

    count++;
  }while(count < 6);
}
Title: Re: REG_TOUCH_RZ giving output 32627 without touching
Post by: Rudolph on November 10, 2020, 07:03:40 PM
I do not have a resistive touch display that I could test this with.
It looks like you used my version of EVE_calibrate_manual() that I mostly copied from the EVE2-Library by Matrix Orbital and that you modified for your own rewrite which looks kind of the early one from FTDI.

This function is meant to be used with special displays that are cut from larger panels, like the EVE2-38A.
For any normal normal shaped display that is using its full range of pixels for the viewing area I would recommend using the builtin calibration command: CMD_CALIBRATE.

Sure, you still need to put it in a display-list but the math is done by the FT81x itself.
Code: [Select]
EVE_cmd_dl(CMD_DLSTART);
EVE_cmd_dl(DL_CLEAR_RGB | WHITE);
EVE_cmd_dl(DL_CLEAR | CLR_COL | CLR_STN | CLR_TAG);
EVE_color_rgb(BLACK);
EVE_cmd_text((EVE_HSIZE/2), 50, 26, EVE_OPT_CENTER, "Please tap on the dot.");
EVE_cmd_calibrate();
EVE_cmd_dl(DL_DISPLAY);
EVE_cmd_dl(CMD_SWAP);
EVE_cmd_execute();

And after that you can read the touch transformation values from the module and for example save it in the host-controller.
Or display them / print then out over serial in order to use these as constants in your code.
Title: Re: REG_TOUCH_RZ giving output 32627 without touching
Post by: madhusudan.jadhav on November 12, 2020, 11:44:45 AM
Ok understood, I put the app_calibrate its working values are as below,

DATAOUT =52605
DATAOUT =232
DATAOUT =33926
DATAOUT =-195
DATAOUT =-33436
DATAOUT =32024056
 now after i run one page code. but tag values are not coming when i touch the buttons.
Title: Re: REG_TOUCH_RZ giving output 32627 without touching
Post by: madhusudan.jadhav on November 20, 2020, 10:12:33 AM
is that touchscreen got faulty?
Title: Re: REG_TOUCH_RZ giving output 32627 without touching
Post by: Matrix Orbital on November 20, 2020, 09:26:52 PM
To verify that the hardware is working properly please run this demo

https://github.com/MatrixOrbital/Basic-EVE-Demo
Title: Re: REG_TOUCH_RZ giving output 32627 without touching
Post by: darkjezter on November 25, 2020, 10:14:09 PM
According to the datasheet, and my use of the 816 with resistive panels... 32767 is what REG_TOUCH_RZ is supposed to read when there is no touch.

It falls toward zero in response to increasing touch pressure.