Calibrate a touchscreen with tpcal.h

I’m currently work with a embedded linux and a touchscreen (display is send by linux frame buffer).
I use file properly adapted to execute tpcal.c. as stand alone. I can touch circles and see result near the screen borders.

I use evdev.h and fbdev.h drivers
I see that I need to adapt these lines in lv_drv_conf.h file to calibrate my device:

#  define EVDEV_CALIBRATE         1               /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
#  if EVDEV_CALIBRATE
#    define EVDEV_HOR_MIN   200                    /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
#    define EVDEV_HOR_MAX   3800
#    define EVDEV_VER_MIN   200
#    define EVDEV_VER_MAX   3800
#  endif  /*EVDEV_SCALE*/
#endif  /*USE_EVDEV*/

But:

  • I don’t understand how I can calculate correction?
  • I don’t understand how to write driver function
    xxx_set_cal_data (like tell in the appendix)
  • In the equation:
x_cal = ((x_act - x1_saved) * lcd_hor_res) / (x2_saved - x1_saved);
 - x_cal: the calibrated X coordinate
 - x_act: the currently measured X coordinate
 - x1_saved, x2_saved: The raw X coordinates saved as calibration data

x1_saved, x2_saved are from a precedent calibration? I don’t understand how to get then.

I hope the problem is clearly expressed. Thank you for your help.

Hi,

I were just talking about here.

I’ll clarify the description in the tpcal example.

1 Like

Hello,

OK, thank you for this response.

Have a nice day

Finally I doesn’t change my driver with a function but I adapt #define in lv_drv_conf.h file to have a good calibration.

This is my screen resolution

/* Horizontal and vertical resolution of the library.*/
#define LV_HOR_RES          (800)
#define LV_VER_RES          (480)

This is my adaptation

#  define EVDEV_CALIBRATE         1               /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
#  if EVDEV_CALIBRATE
#    define EVDEV_HOR_MIN   0                    /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
#    define EVDEV_HOR_MAX   4000
#    define EVDEV_VER_MIN   0
#    define EVDEV_VER_MAX   4000
#  endif  /*EVDEV_SCALE*/
#endif  /*USE_EVDEV*/
1 Like