Analog Touch screen Hardware routines implementation location

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Analog Touch screen Hardware routines implementation location

    Hi there,

    I am trying to get the touch screen to work following emwin manual:
    Implementing the hardware routines
    The first step of implementing a touch screen should be filling the hardware routines
    with code. These routines are:
    GUI_TOUCH_X_ActivateX(), GUI_TOUCH_X_ActivateY()
    GUI_TOUCH_X_MeasureX(), GUI_TOUCH_X_MeasureY()
    I have made the hardware implementations of the above routines and when i call them directly i can print on screen the x and y values of the touch.

    However i never understood where to put those routines in order emwin to "know" what are the implementations.

    GUI_TOUCH_GetState() never returns a value.

    I have tried to implement inside LCDConf.c, at a separete file GUI_TOUCH_X.c, GUI_TOUCH_X_Analog.c etc.
    Nothing worked.

    Am i missing sth here?

    Can you please provide an "official" example with the code structure as it supposed to be?

    Any help would be very appreciated!

    Thanks a lot in advance.
  • Hi,

    You have to put those routines somewhere in your code. Either you create a new touch related file or besides the LCD configuration in LCDConf.c.

    If those functions are present you have to call GUI_TOUCH_Exec(). Within GUI_TOUCH_Exec() the functions GUI_TOUCH_X_ActivateX(), GUI_TOUCH_X_ActivateY(), GUI_TOUCH_X_Measure() and GUI_TOUCH_X_MeasureY() are getting called to receive the touch coordinates.

    Here is an example on how it could be done. The function _ExecTouch() is a separate task, but could also be called from within a super loop.

    C Source Code

    1. /*********************************************************************
    2. *
    3. * GUI_TOUCH_X_ActivateX
    4. * GUI_TOUCH_X_ActivateY
    5. * GUI_TOUCH_X_MeasureX
    6. * GUI_TOUCH_X_MeasureY
    7. */
    8. void GUI_TOUCH_X_ActivateX(void) {}
    9. void GUI_TOUCH_X_ActivateY(void) {}
    10. int GUI_TOUCH_X_MeasureX (void) { return _xPos; }
    11. int GUI_TOUCH_X_MeasureY (void) {
    12. int xPos, yPos, SwapXY;
    13. U32 xVal, yVal;
    14. _RequestValues(&xVal, &yVal);
    15. SwapXY = LCD_GetSwapXY();
    16. if (SwapXY) {
    17. xPos = yVal;
    18. yPos = xVal;
    19. } else {
    20. xPos = xVal;
    21. yPos = yVal;
    22. }
    23. if (xVal > 4000) {
    24. volatile int temp=0;
    25. }
    26. _xPos = xPos;
    27. return yPos;
    28. }
    29. /*********************************************************************
    30. *
    31. * _ExecTouch
    32. */
    33. static void _ExecTouch(void) {
    34. int xSize, ySize;
    35. int MirrorX, MirrorY, SwapXY;
    36. MirrorX = LCD_GetMirrorX();
    37. MirrorY = LCD_GetMirrorY();
    38. SwapXY = LCD_GetSwapXY();
    39. xSize = LCD_GetXSize();
    40. ySize = LCD_GetYSize();
    41. #if 0
    42. //
    43. // Works fine with all orientations and without GUI_TOUCH_SetOrientation
    44. //
    45. if (((SwapXY == 1) && (MirrorY == 1)) || ((SwapXY == 0) && (MirrorX == 1))) {
    46. GUI_TOUCH_Calibrate(0, 0, xSize - 1, 3880, 180);
    47. } else {
    48. GUI_TOUCH_Calibrate(0, 0, xSize - 1, 180, 3880);
    49. }
    50. if (((SwapXY == 1) && (MirrorX == 1)) || ((SwapXY == 0) && (MirrorY == 1))) {
    51. GUI_TOUCH_Calibrate(1, 0, ySize - 1, 3880, 180);
    52. } else {
    53. GUI_TOUCH_Calibrate(1, 0, ySize - 1, 180, 3880);
    54. }
    55. #else
    56. //
    57. // Works fine with all orientations and with GUI_TOUCH_SetOrientation
    58. //
    59. GUI_TOUCH_SetOrientation(GUI_MIRROR_X * MirrorX + GUI_MIRROR_Y * MirrorY + GUI_SWAP_XY * SwapXY);
    60. GUI_TOUCH_Calibrate(0, 0, xSize - 1, 180, 3880);
    61. GUI_TOUCH_Calibrate(1, 0, ySize - 1, 180, 3880);
    62. #endif
    63. while (1) {
    64. OS_Delay(10);
    65. GUI_TOUCH_Exec();
    66. }
    67. }
    Display All


    Regards
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thanks a lot for your reply!

    The issue was from ili9341 part. ILI9341 0x36 register configures screen orientation (mirror x, mirror y, swapxy etc).

    If i change setting in ili9341 registers screen orientation changes accordingly.

    I have done the calibration part correctly finding the min and max x, y values.

    If i change orientation from emwin with GUI_TOUCH_SetOrientation() with parameter GUI_MIRROR_Y or GUI_MIRROR_X etc nothing happens.

    Why is that?