2525 EV_KEY, (c))
2626
2727struct ntrig_data {
28- __s32 x , y , id , w , h ;
29- bool reading_a_point , found_contact_id ;
28+ /* Incoming raw values for a single contact */
29+ __u16 x , y , w , h ;
30+ __u16 id ;
31+ __u8 confidence ;
32+
33+ bool reading_mt ;
34+ __u8 first_contact_confidence ;
35+
36+ __u8 mt_footer [4 ];
37+ __u8 mt_foot_count ;
3038};
3139
3240/*
@@ -39,8 +47,8 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
3947 struct hid_field * field , struct hid_usage * usage ,
4048 unsigned long * * bit , int * max )
4149{
42- /* No special mappings needed for the pen */
43- if (field -> application == HID_DG_PEN )
50+ /* No special mappings needed for the pen and single touch */
51+ if (field -> physical )
4452 return 0 ;
4553
4654 switch (usage -> hid & HID_USAGE_PAGE ) {
@@ -66,18 +74,12 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
6674 case HID_UP_DIGITIZER :
6775 switch (usage -> hid ) {
6876 /* we do not want to map these for now */
69- case HID_DG_CONTACTID : /* value is useless */
77+ case HID_DG_CONTACTID : /* Not trustworthy, squelch for now */
7078 case HID_DG_INPUTMODE :
7179 case HID_DG_DEVICEINDEX :
72- case HID_DG_CONTACTCOUNT :
7380 case HID_DG_CONTACTMAX :
7481 return -1 ;
7582
76- /* original mapping by Rafi Rubin */
77- case HID_DG_CONFIDENCE :
78- nt_map_key_clear (BTN_TOOL_DOUBLETAP );
79- return 1 ;
80-
8183 /* width/height mapped on TouchMajor/TouchMinor/Orientation */
8284 case HID_DG_WIDTH :
8385 hid_map_usage (hi , usage , bit , max ,
@@ -104,8 +106,8 @@ static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi,
104106 struct hid_field * field , struct hid_usage * usage ,
105107 unsigned long * * bit , int * max )
106108{
107- /* No special mappings needed for the pen */
108- if (field -> application == HID_DG_PEN )
109+ /* No special mappings needed for the pen and single touch */
110+ if (field -> physical )
109111 return 0 ;
110112
111113 if (usage -> type == EV_KEY || usage -> type == EV_REL
@@ -133,17 +135,24 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
133135
134136 if (hid -> claimed & HID_CLAIMED_INPUT ) {
135137 switch (usage -> hid ) {
138+ case 0xff000001 :
139+ /* Tag indicating the start of a multitouch group */
140+ nd -> reading_mt = 1 ;
141+ nd -> first_contact_confidence = 0 ;
142+ break ;
143+ case HID_DG_CONFIDENCE :
144+ nd -> confidence = value ;
145+ break ;
136146 case HID_GD_X :
137147 nd -> x = value ;
138- nd -> reading_a_point = 1 ;
148+ /* Clear the contact footer */
149+ nd -> mt_foot_count = 0 ;
139150 break ;
140151 case HID_GD_Y :
141152 nd -> y = value ;
142153 break ;
143154 case HID_DG_CONTACTID :
144155 nd -> id = value ;
145- /* we receive this only when in multitouch mode */
146- nd -> found_contact_id = 1 ;
147156 break ;
148157 case HID_DG_WIDTH :
149158 nd -> w = value ;
@@ -155,7 +164,7 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
155164 * report received in a finger event. We want
156165 * to emit a normal (X, Y) position
157166 */
158- if (!nd -> found_contact_id ) {
167+ if (!nd -> reading_mt ) {
159168 input_event (input , EV_ABS , ABS_X , nd -> x );
160169 input_event (input , EV_ABS , ABS_Y , nd -> y );
161170 }
@@ -167,10 +176,34 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
167176 * this usage tells if the contact point is real
168177 * or a placeholder
169178 */
170- if (!nd -> reading_a_point || value != 1 )
179+
180+ /* Shouldn't get more than 4 footer packets, so skip */
181+ if (nd -> mt_foot_count >= 4 )
182+ break ;
183+
184+ nd -> mt_footer [nd -> mt_foot_count ++ ] = value ;
185+
186+ /* if the footer isn't complete break */
187+ if (nd -> mt_foot_count != 4 )
188+ break ;
189+
190+ /* Pen activity signal, trigger end of touch. */
191+ if (nd -> mt_footer [2 ]) {
192+ nd -> confidence = 0 ;
193+ break ;
194+ }
195+
196+ /* If the contact was invalid */
197+ if (!(nd -> confidence && nd -> mt_footer [0 ])
198+ || nd -> w <= 250
199+ || nd -> h <= 190 ) {
200+ nd -> confidence = 0 ;
171201 break ;
202+ }
203+
172204 /* emit a normal (X, Y) for the first point only */
173205 if (nd -> id == 0 ) {
206+ nd -> first_contact_confidence = nd -> confidence ;
174207 input_event (input , EV_ABS , ABS_X , nd -> x );
175208 input_event (input , EV_ABS , ABS_Y , nd -> y );
176209 }
@@ -192,8 +225,39 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
192225 ABS_MT_TOUCH_MINOR , nd -> w );
193226 }
194227 input_mt_sync (field -> hidinput -> input );
195- nd -> reading_a_point = 0 ;
196- nd -> found_contact_id = 0 ;
228+ break ;
229+
230+ case HID_DG_CONTACTCOUNT : /* End of a multitouch group */
231+ if (!nd -> reading_mt )
232+ break ;
233+
234+ nd -> reading_mt = 0 ;
235+
236+ if (nd -> first_contact_confidence ) {
237+ switch (value ) {
238+ case 0 : /* for single touch devices */
239+ case 1 :
240+ input_report_key (input ,
241+ BTN_TOOL_DOUBLETAP , 1 );
242+ break ;
243+ case 2 :
244+ input_report_key (input ,
245+ BTN_TOOL_TRIPLETAP , 1 );
246+ break ;
247+ case 3 :
248+ default :
249+ input_report_key (input ,
250+ BTN_TOOL_QUADTAP , 1 );
251+ }
252+ input_report_key (input , BTN_TOUCH , 1 );
253+ } else {
254+ input_report_key (input ,
255+ BTN_TOOL_DOUBLETAP , 0 );
256+ input_report_key (input ,
257+ BTN_TOOL_TRIPLETAP , 0 );
258+ input_report_key (input ,
259+ BTN_TOOL_QUADTAP , 0 );
260+ }
197261 break ;
198262
199263 default :
@@ -224,8 +288,8 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
224288 dev_err (& hdev -> dev , "cannot allocate N-Trig data\n" );
225289 return - ENOMEM ;
226290 }
227- nd -> reading_a_point = 0 ;
228- nd -> found_contact_id = 0 ;
291+
292+ nd -> reading_mt = 0 ;
229293 hid_set_drvdata (hdev , nd );
230294
231295 ret = hid_parse (hdev );
@@ -248,6 +312,14 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
248312 input -> name = "N-Trig Pen" ;
249313 break ;
250314 case HID_DG_TOUCHSCREEN :
315+ __clear_bit (BTN_TOOL_PEN , input -> keybit );
316+ /*
317+ * A little something special to enable
318+ * two and three finger taps.
319+ */
320+ __set_bit (BTN_TOOL_DOUBLETAP , input -> keybit );
321+ __set_bit (BTN_TOOL_TRIPLETAP , input -> keybit );
322+ __set_bit (BTN_TOOL_QUADTAP , input -> keybit );
251323 /*
252324 * The physical touchscreen (single touch)
253325 * input has a value for physical, whereas
0 commit comments