When we are writing input driver (touchpad / touchscreen) in Linux, we need to first initialize and set the maximum values for
- ABS_X and ABS_Y if we are writing single touch driver or
- ABS_MT_POSISION_X and ABS_MT_POSITION_Y if we are writing multitouch driver
These maximum values can be set inside driver using below API ( below is for multitouch, for single touch use ABS_X/ABS_Y )
input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, MAX_X, 0, 0)
input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, MAX_Y, 0, 0)
Before calling input_register_device in device driver, we need to fill additional fields in the input_dev struct for each absolute axis our device has. For example, If our device has the ABS_X axis:
input_dev.absmin[ABS_X] = 0;
input_dev.absmax[ABS_X] = 255;
input_dev.absfuzz[ABS_X] = 4;
input_dev.absflat[ABS_X] = 8;
Or, we can just use below API to set all 4 values using one API as,
input_set_abs_params(button_dev, ABS_X, 0, 255, 4, 8);
This setting would be appropriate for a touchscreen X axis, with the minimum of 0, maximum of 255 (which the joystick must be able to reach, no problem if it sometimes reports more, but it must be able to always reach the min and max values), with noise in the data up to +- 4, and with a center flat position of size 8. If we don’t need absfuzz and absflat, we can set them to zero, which mean that the thing is precise and always returns to exactly the center position (if it has any).
How to Identify Maximum Values for X & Y Axis ?
Ideally the maximum values for X & Y are the resolution of the touchscreen if we are implementing touch drivers or maximum values read from the sensor if we are implementing any custom driver.
In Android, we can get the screen resolution ( Max X and Max Y ) using below command,
$ adb shell wm size
Physical size: 1080x2160
So, we can initialize the driver with values as,
input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 1080, 0, 0)
input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 2160, 0, 0)
More details about Fuzz and Flat are as,
Dead-zone (flat value): Tiny values are reported as zero to reduce noise
Filtering (fuzz value): Tiny changes are not reported to reduce noise
which means, if we set fuzz as 8, then any change in value less than “fuzz” will be filtered out and event will not be sent.