-
Notifications
You must be signed in to change notification settings - Fork 44
/
wcmUSB.c
1986 lines (1746 loc) · 59.9 KB
/
wcmUSB.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 1995-2002 by Frederic Lepied, France. <Lepied@XFree86.org>
* Copyright 2002-2013 by Ping Cheng, Wacom. <pingc@wacom.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xf86Wacom.h"
#include <asm/types.h>
#include <linux/input.h>
#include <sys/utsname.h>
#include <linux/version.h>
#define MAX_USB_EVENTS 32
typedef struct {
int wcmLastToolSerial;
int wcmDeviceType;
Bool wcmPenTouch;
Bool wcmUseMT;
int wcmMTChannel;
int wcmEventCnt;
struct input_event wcmEvents[MAX_USB_EVENTS];
uint32_t wcmEventFlags; /* event types received in this frame */
int nbuttons; /* total number of buttons */
int npadkeys; /* number of pad keys in the above array */
int padkey_code[WCM_MAX_BUTTONS];/* hardware codes for buttons */
int lastChannel;
} wcmUSBData;
static Bool usbDetect(InputInfoPtr);
static Bool usbWcmInit(InputInfoPtr pDev, char* id, size_t id_len, float *version);
static int usbProbeKeys(InputInfoPtr pInfo);
static int usbStart(InputInfoPtr pInfo);
static void usbInitProtocol5(WacomCommonPtr common, const char* id,
float version);
static void usbInitProtocol4(WacomCommonPtr common, const char* id,
float version);
int usbWcmGetRanges(InputInfoPtr pInfo);
static int usbParse(InputInfoPtr pInfo, const unsigned char* data, int len);
static int usbDetectConfig(InputInfoPtr pInfo);
static void usbParseEvent(InputInfoPtr pInfo,
const struct input_event* event);
static void usbParseSynEvent(InputInfoPtr pInfo,
const struct input_event *event);
static void usbParseMscEvent(InputInfoPtr pInfo,
const struct input_event *event);
static void usbDispatchEvents(InputInfoPtr pInfo);
static int usbChooseChannel(WacomCommonPtr common, int device_type, unsigned int serial);
WacomDeviceClass gWacomUSBDevice =
{
usbDetect,
NULL, /* no USB-specific options */
usbWcmInit,
usbProbeKeys
};
#define DEFINE_MODEL(mname, identifier, protocol) \
static struct _WacomModel mname = \
{ \
.name = identifier, \
.Initialize = usbInitProtocol##protocol,\
.GetResolution = NULL, \
.GetRanges = usbWcmGetRanges, \
.Start = usbStart, \
.Parse = usbParse, \
.DetectConfig = usbDetectConfig, \
}
DEFINE_MODEL(usbUnknown, "Unknown USB", 5);
DEFINE_MODEL(usbPenPartner, "USB PenPartner", 4);
DEFINE_MODEL(usbGraphire, "USB Graphire", 4);
DEFINE_MODEL(usbGraphire2, "USB Graphire2", 4);
DEFINE_MODEL(usbGraphire3, "USB Graphire3", 4);
DEFINE_MODEL(usbGraphire4, "USB Graphire4", 4);
DEFINE_MODEL(usbBamboo, "USB Bamboo", 4);
DEFINE_MODEL(usbBamboo1, "USB Bamboo1", 4);
DEFINE_MODEL(usbBambooFun, "USB BambooFun", 4);
DEFINE_MODEL(usbCintiq, "USB PL/Cintiq/DTU", 4);
DEFINE_MODEL(usbCintiqPartner, "USB CintiqPartner", 4);
DEFINE_MODEL(usbIntuos, "USB Intuos1", 5);
DEFINE_MODEL(usbIntuos2, "USB Intuos2", 5);
DEFINE_MODEL(usbIntuos3, "USB Intuos3", 5);
DEFINE_MODEL(usbIntuos4, "USB Intuos4", 5);
DEFINE_MODEL(usbIntuos5, "USB Intuos5", 5);
DEFINE_MODEL(usbIntuosPro, "USB Intuos Pro", 5);
DEFINE_MODEL(usbVolito, "USB Volito", 4);
DEFINE_MODEL(usbVolito2, "USB Volito2", 4);
DEFINE_MODEL(usbCintiqV5, "USB CintiqV5", 5);
DEFINE_MODEL(usbTabletPC, "USB TabletPC", 4);
/*****************************************************************************
* usbDetect --
* Test if the attached device is USB.
****************************************************************************/
static Bool usbDetect(InputInfoPtr pInfo)
{
int version;
int err;
#ifdef DEBUG
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
DBG(1, priv, "\n");
#endif
SYSCALL(err = ioctl(pInfo->fd, EVIOCGVERSION, &version));
if (err < 0)
{
xf86Msg(X_ERROR, "%s: usbDetect: can not ioctl version\n", pInfo->name);
return 0;
}
return 1;
}
/*****************************************************************************
* usbStart --
****************************************************************************/
static int
usbStart(InputInfoPtr pInfo)
{
int err;
if (xf86CheckBoolOption(pInfo->options, "GrabDevice", 0))
{
/* Try to grab the event device so that data don't leak to /dev/input/mice */
SYSCALL(err = ioctl(pInfo->fd, EVIOCGRAB, (pointer)1));
/* this is called for all tools, so all but the first one fails with
* EBUSY */
if (err < 0 && errno != EBUSY)
xf86Msg(X_ERROR, "%s: Wacom X driver can't grab event device (%s)\n",
pInfo->name, strerror(errno));
}
return Success;
}
/* Key codes used to mark tablet buttons -- must be in sync
* with the keycode array in wacom kernel drivers.
*/
static unsigned short padkey_codes [] = {
BTN_0, BTN_1, BTN_2, BTN_3, BTN_4,
BTN_5, BTN_6, BTN_7, BTN_8, BTN_9,
BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
BTN_BASE, BTN_BASE2, BTN_BASE3,
BTN_BASE4, BTN_BASE5, BTN_BASE6,
BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_SELECT
};
/* Fixed mapped stylus and mouse buttons */
#define WCM_USB_MAX_MOUSE_BUTTONS 5
#define WCM_USB_MAX_STYLUS_BUTTONS 4
static unsigned short mouse_codes [] = {
BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, BTN_BACK, BTN_FORWARD,
BTN_SIDE, BTN_EXTRA
};
static struct WacomModelDesc
{
const unsigned int vendor_id;
const unsigned int model_id;
int yRes; /* tablet Y resolution in units/meter */
int xRes; /* tablet X resolution in units/meter */
WacomModelPtr model;
const char *name;
} WacomModelDesc [] =
{
{ WACOM_VENDOR_ID, 0x00, 39370, 39370, &usbPenPartner, "PenPartner" },
{ WACOM_VENDOR_ID, 0x10, 80000, 80000, &usbGraphire, "Graphire" },
{ WACOM_VENDOR_ID, 0x11, 80000, 80000, &usbGraphire2, "Graphire2 4x5" },
{ WACOM_VENDOR_ID, 0x12, 80000, 80000, &usbGraphire2, "Graphire2 5x7" },
{ WACOM_VENDOR_ID, 0x13, 80000, 80000, &usbGraphire3, "Graphire3 4x5" },
{ WACOM_VENDOR_ID, 0x14, 80000, 80000, &usbGraphire3, "Graphire3 6x8" },
{ WACOM_VENDOR_ID, 0x15, 80000, 80000, &usbGraphire4, "Graphire4 4x5" },
{ WACOM_VENDOR_ID, 0x16, 80000, 80000, &usbGraphire4, "Graphire4 6x8" },
{ WACOM_VENDOR_ID, 0x17, 100000, 100000, &usbBambooFun, "BambooFun 4x5" },
{ WACOM_VENDOR_ID, 0x18, 100000, 100000, &usbBambooFun, "BambooFun 6x8" },
{ WACOM_VENDOR_ID, 0x19, 80000, 80000, &usbBamboo1, "Bamboo1 Medium" },
{ WACOM_VENDOR_ID, 0x81, 80000, 80000, &usbGraphire4, "Graphire4 6x8 BlueTooth" },
{ WACOM_VENDOR_ID, 0xD1, 100000, 100000, &usbBamboo, "CTL-460" },
{ WACOM_VENDOR_ID, 0xD4, 100000, 100000, &usbBamboo, "CTH-461" },
{ WACOM_VENDOR_ID, 0xD3, 100000, 100000, &usbBamboo, "CTL-660" },
{ WACOM_VENDOR_ID, 0xD2, 100000, 100000, &usbBamboo, "CTL-461/S" },
{ WACOM_VENDOR_ID, 0xD0, 100000, 100000, &usbBamboo, "Bamboo Touch" },
{ WACOM_VENDOR_ID, 0xD6, 100000, 100000, &usbBamboo, "CTH-460/K" },
{ WACOM_VENDOR_ID, 0xD7, 100000, 100000, &usbBamboo, "CTH-461/S" },
{ WACOM_VENDOR_ID, 0xD8, 100000, 100000, &usbBamboo, "CTH-661/S1" },
{ WACOM_VENDOR_ID, 0xDA, 100000, 100000, &usbBamboo, "CTH-461/L" },
{ WACOM_VENDOR_ID, 0xDB, 100000, 100000, &usbBamboo, "CTH-661/L" },
{ WACOM_VENDOR_ID, 0x20, 100000, 100000, &usbIntuos, "Intuos 4x5" },
{ WACOM_VENDOR_ID, 0x21, 100000, 100000, &usbIntuos, "Intuos 6x8" },
{ WACOM_VENDOR_ID, 0x22, 100000, 100000, &usbIntuos, "Intuos 9x12" },
{ WACOM_VENDOR_ID, 0x23, 100000, 100000, &usbIntuos, "Intuos 12x12" },
{ WACOM_VENDOR_ID, 0x24, 100000, 100000, &usbIntuos, "Intuos 12x18" },
{ WACOM_VENDOR_ID, 0x03, 20000, 20000, &usbCintiqPartner, "PTU600" },
{ WACOM_VENDOR_ID, 0x30, 20000, 20000, &usbCintiq, "PL400" },
{ WACOM_VENDOR_ID, 0x31, 20000, 20000, &usbCintiq, "PL500" },
{ WACOM_VENDOR_ID, 0x32, 20000, 20000, &usbCintiq, "PL600" },
{ WACOM_VENDOR_ID, 0x33, 20000, 20000, &usbCintiq, "PL600SX" },
{ WACOM_VENDOR_ID, 0x34, 20000, 20000, &usbCintiq, "PL550" },
{ WACOM_VENDOR_ID, 0x35, 20000, 20000, &usbCintiq, "PL800" },
{ WACOM_VENDOR_ID, 0x37, 20000, 20000, &usbCintiq, "PL700" },
{ WACOM_VENDOR_ID, 0x38, 20000, 20000, &usbCintiq, "PL510" },
{ WACOM_VENDOR_ID, 0x39, 20000, 20000, &usbCintiq, "PL710" },
{ WACOM_VENDOR_ID, 0x3A, 20000, 20000, &usbCintiq, "DTI520" },
{ WACOM_VENDOR_ID, 0xC0, 20000, 20000, &usbCintiq, "DTF720" },
{ WACOM_VENDOR_ID, 0xC2, 20000, 20000, &usbCintiq, "DTF720a" },
{ WACOM_VENDOR_ID, 0xC4, 20000, 20000, &usbCintiq, "DTF521" },
{ WACOM_VENDOR_ID, 0xC7, 100000, 100000, &usbCintiq, "DTU1931" },
{ WACOM_VENDOR_ID, 0xCE, 100000, 100000, &usbCintiq, "DTU2231" },
{ WACOM_VENDOR_ID, 0xF0, 100000, 100000, &usbCintiq, "DTU1631" },
{ WACOM_VENDOR_ID, 0x35a, 100000, 100000, &usbCintiq, "DTH1152" },
{ WACOM_VENDOR_ID, 0x368, 100000, 100000, &usbCintiq, "DTH1152" }, /* Touch */
{ WACOM_VENDOR_ID, 0x382, 100000, 100000, &usbCintiq, "DTK2451" },
{ WACOM_VENDOR_ID, 0x37D, 100000, 100000, &usbCintiq, "DTH2452" },
{ WACOM_VENDOR_ID, 0x37E, 100000, 100000, &usbCintiq, "DTH2452" }, /* Touch */
{ WACOM_VENDOR_ID, 0x41, 100000, 100000, &usbIntuos2, "Intuos2 4x5" },
{ WACOM_VENDOR_ID, 0x42, 100000, 100000, &usbIntuos2, "Intuos2 6x8" },
{ WACOM_VENDOR_ID, 0x43, 100000, 100000, &usbIntuos2, "Intuos2 9x12" },
{ WACOM_VENDOR_ID, 0x44, 100000, 100000, &usbIntuos2, "Intuos2 12x12" },
{ WACOM_VENDOR_ID, 0x45, 100000, 100000, &usbIntuos2, "Intuos2 12x18" },
{ WACOM_VENDOR_ID, 0x47, 100000, 100000, &usbIntuos2, "Intuos2 6x8 " },
{ WACOM_VENDOR_ID, 0x60, 50000, 50000, &usbVolito, "Volito" },
{ WACOM_VENDOR_ID, 0x61, 50000, 50000, &usbVolito2, "PenStation" },
{ WACOM_VENDOR_ID, 0x62, 50000, 50000, &usbVolito2, "Volito2 4x5" },
{ WACOM_VENDOR_ID, 0x63, 50000, 50000, &usbVolito2, "Volito2 2x3" },
{ WACOM_VENDOR_ID, 0x64, 50000, 50000, &usbVolito2, "PenPartner2" },
{ WACOM_VENDOR_ID, 0x65, 100000, 100000, &usbBamboo, "Bamboo" },
{ WACOM_VENDOR_ID, 0x69, 39842, 39842, &usbBamboo1, "Bamboo1" },
{ WACOM_VENDOR_ID, 0x6A, 100000, 100000, &usbBamboo1, "Bamboo1 4x6" },
{ WACOM_VENDOR_ID, 0x6B, 100000, 100000, &usbBamboo1, "Bamboo1 5x8" },
{ WACOM_VENDOR_ID, 0xB0, 200000, 200000, &usbIntuos3, "Intuos3 4x5" },
{ WACOM_VENDOR_ID, 0xB1, 200000, 200000, &usbIntuos3, "Intuos3 6x8" },
{ WACOM_VENDOR_ID, 0xB2, 200000, 200000, &usbIntuos3, "Intuos3 9x12" },
{ WACOM_VENDOR_ID, 0xB3, 200000, 200000, &usbIntuos3, "Intuos3 12x12" },
{ WACOM_VENDOR_ID, 0xB4, 200000, 200000, &usbIntuos3, "Intuos3 12x19" },
{ WACOM_VENDOR_ID, 0xB5, 200000, 200000, &usbIntuos3, "Intuos3 6x11" },
{ WACOM_VENDOR_ID, 0xB7, 200000, 200000, &usbIntuos3, "Intuos3 4x6" },
{ WACOM_VENDOR_ID, 0xB8, 200000, 200000, &usbIntuos4, "Intuos4 4x6" },
{ WACOM_VENDOR_ID, 0xB9, 200000, 200000, &usbIntuos4, "Intuos4 6x9" },
{ WACOM_VENDOR_ID, 0xBA, 200000, 200000, &usbIntuos4, "Intuos4 8x13" },
{ WACOM_VENDOR_ID, 0xBB, 200000, 200000, &usbIntuos4, "Intuos4 12x19" },
{ WACOM_VENDOR_ID, 0xBC, 200000, 200000, &usbIntuos4, "Intuos4 WL USB Endpoint" },
{ WACOM_VENDOR_ID, 0xBD, 200000, 200000, &usbIntuos4, "Intuos4 WL Bluetooth Endpoint"},
{ WACOM_VENDOR_ID, 0x26, 200000, 200000, &usbIntuos5, "Intuos5 touch S" },
{ WACOM_VENDOR_ID, 0x27, 200000, 200000, &usbIntuos5, "Intuos5 touch M" },
{ WACOM_VENDOR_ID, 0x28, 200000, 200000, &usbIntuos5, "Intuos5 touch L" },
{ WACOM_VENDOR_ID, 0x29, 200000, 200000, &usbIntuos5, "Intuos5 S" },
{ WACOM_VENDOR_ID, 0x2A, 200000, 200000, &usbIntuos5, "Intuos5 M" },
{ WACOM_VENDOR_ID, 0x314,200000, 200000, &usbIntuosPro, "Intuos Pro S" },
{ WACOM_VENDOR_ID, 0x315,200000, 200000, &usbIntuosPro, "Intuos Pro M" },
{ WACOM_VENDOR_ID, 0x317,200000, 200000, &usbIntuosPro, "Intuos Pro L" },
{ WACOM_VENDOR_ID, 0x3F, 200000, 200000, &usbCintiqV5, "Cintiq 21UX" },
{ WACOM_VENDOR_ID, 0xC5, 200000, 200000, &usbCintiqV5, "Cintiq 20WSX" },
{ WACOM_VENDOR_ID, 0xC6, 200000, 200000, &usbCintiqV5, "Cintiq 12WX" },
{ WACOM_VENDOR_ID, 0xCC, 200000, 200000, &usbCintiqV5, "Cintiq 21UX2" },
{ WACOM_VENDOR_ID, 0xF4, 200000, 200000, &usbCintiqV5, "Cintiq 24HD" },
{ WACOM_VENDOR_ID, 0xFA, 200000, 200000, &usbCintiqV5, "Cintiq 22HD" },
{ WACOM_VENDOR_ID, 0xF8, 200000, 200000, &usbCintiqV5, "Cintiq 24HD touch (EMR digitizer)" },
{ WACOM_VENDOR_ID, 0x304,200000, 200000, &usbCintiqV5, "Cintiq 13HD" },
{ WACOM_VENDOR_ID, 0x57, 200000, 200000, &usbCintiqV5, "DTK2241" },
{ WACOM_VENDOR_ID, 0x59, 200000, 200000, &usbCintiqV5, "DTH2242" },
{ WACOM_VENDOR_ID, 0x5B, 200000, 200000, &usbCintiqV5, "Cintiq 22HDT" },
{ WACOM_VENDOR_ID, 0x32B, 200000, 200000, &usbCintiqV5, "Cintiq 27QHDT" },
{ WACOM_VENDOR_ID, 0x32C, 200000, 200000, &usbCintiqV5, "Cintiq 27QHDT" }, /* Touch */
{ WACOM_VENDOR_ID, 0x34A, 200000, 200000, &usbCintiqV5, "Mobilestudio Pro 13" }, /* Touch */
{ WACOM_VENDOR_ID, 0x34B, 200000, 200000, &usbCintiqV5, "MobileStudio Pro 16" }, /* Touch */
{ WACOM_VENDOR_ID, 0x34D, 200000, 200000, &usbCintiqV5, "MobileStudio Pro 13" },
{ WACOM_VENDOR_ID, 0x34E, 200000, 200000, &usbCintiqV5, "MobileStudio Pro 16" },
{ WACOM_VENDOR_ID, 0x34F, 200000, 200000, &usbCintiqV5, "Cintiq 13 FHD Pro" },
{ WACOM_VENDOR_ID, 0x350, 200000, 200000, &usbCintiqV5, "Cintiq 16 UHD Pro" },
{ WACOM_VENDOR_ID, 0x351, 200000, 200000, &usbCintiqV5, "Cintiq Pro 24" },
{ WACOM_VENDOR_ID, 0x352, 200000, 200000, &usbCintiqV5, "Cintiq Pro 32" },
{ WACOM_VENDOR_ID, 0x353, 200000, 200000, &usbCintiqV5, "Cintiq 13 FHD Pro" }, /* Touch */
{ WACOM_VENDOR_ID, 0x354, 200000, 200000, &usbCintiqV5, "Cintiq 16 UHD Pro" }, /* Touch */
{ WACOM_VENDOR_ID, 0x355, 200000, 200000, &usbCintiqV5, "Cintiq Pro 24" }, /* Touch */
{ WACOM_VENDOR_ID, 0x356, 200000, 200000, &usbCintiqV5, "Cintiq Pro 32" }, /* Touch */
{ WACOM_VENDOR_ID, 0x37C, 200000, 200000, &usbCintiqV5, "Cintiq Pro 24" }, /* Pen-only model */
{ WACOM_VENDOR_ID, 0x90, 100000, 100000, &usbTabletPC, "TabletPC 0x90" },
{ WACOM_VENDOR_ID, 0x93, 100000, 100000, &usbTabletPC, "TabletPC 0x93" },
{ WACOM_VENDOR_ID, 0x97, 100000, 100000, &usbTabletPC, "TabletPC 0x97" },
{ WACOM_VENDOR_ID, 0x9A, 100000, 100000, &usbTabletPC, "TabletPC 0x9A" },
{ WACOM_VENDOR_ID, 0x9F, 100000, 100000, &usbTabletPC, "CapPlus 0x9F" },
{ WACOM_VENDOR_ID, 0xE2, 100000, 100000, &usbTabletPC, "TabletPC 0xE2" },
{ WACOM_VENDOR_ID, 0xE3, 100000, 100000, &usbTabletPC, "TabletPC 0xE3" },
{ WACOM_VENDOR_ID, 0xE5, 100000, 100000, &usbTabletPC, "TabletPC 0xE5" },
{ WACOM_VENDOR_ID, 0xE6, 100000, 100000, &usbTabletPC, "TabletPC 0xE6" },
{ WACOM_VENDOR_ID, 0xEC, 100000, 100000, &usbTabletPC, "TabletPC 0xEC" },
{ WACOM_VENDOR_ID, 0xED, 100000, 100000, &usbTabletPC, "TabletPC 0xED" },
{ WACOM_VENDOR_ID, 0xEF, 100000, 100000, &usbTabletPC, "TabletPC 0xEF" },
{ WACOM_VENDOR_ID, 0x100,100000, 100000, &usbTabletPC, "TabletPC 0x100" },
{ WACOM_VENDOR_ID, 0x101,100000, 100000, &usbTabletPC, "TabletPC 0x101" },
{ WACOM_VENDOR_ID, 0x10D,100000, 100000, &usbTabletPC, "TabletPC 0x10D" },
{ WACOM_VENDOR_ID, 0x116,100000, 100000, &usbTabletPC, "TabletPC 0x116" },
{ WACOM_VENDOR_ID, 0x12C,100000, 100000, &usbTabletPC, "TabletPC 0x12C" },
{ WACOM_VENDOR_ID, 0x4001,100000, 100000, &usbTabletPC, "TabletPC 0x4001" },
{ WACOM_VENDOR_ID, 0x4004,100000, 100000, &usbTabletPC, "TabletPC 0x4004" },
{ WACOM_VENDOR_ID, 0x5000,100000, 100000, &usbTabletPC, "TabletPC 0x5000" },
{ WACOM_VENDOR_ID, 0x5002,100000, 100000, &usbTabletPC, "TabletPC 0x5002" },
/* IDs from Waltop's driver, available http://www.waltop.com.tw/download.asp?lv=0&id=2.
Accessed 8 Apr 2010, driver release date 2009/08/11, fork of linuxwacom 0.8.4.
Some more info would be nice for the ID's below... */
{ WALTOP_VENDOR_ID, 0x24, 80000, 80000, &usbGraphire, NULL },
{ WALTOP_VENDOR_ID, 0x25, 80000, 80000, &usbGraphire2, NULL },
{ WALTOP_VENDOR_ID, 0x26, 80000, 80000, &usbGraphire2, NULL },
{ WALTOP_VENDOR_ID, 0x27, 80000, 80000, &usbGraphire3, NULL },
{ WALTOP_VENDOR_ID, 0x28, 80000, 80000, &usbGraphire3, NULL },
{ WALTOP_VENDOR_ID, 0x30, 80000, 80000, &usbGraphire4, NULL },
{ WALTOP_VENDOR_ID, 0x31, 80000, 80000, &usbGraphire4, NULL },
{ WALTOP_VENDOR_ID, 0x32, 100000, 100000, &usbBambooFun, NULL },
{ WALTOP_VENDOR_ID, 0x33, 100000, 100000, &usbBambooFun, NULL },
{ WALTOP_VENDOR_ID, 0x34, 80000, 80000, &usbBamboo1, NULL },
{ WALTOP_VENDOR_ID, 0x35, 80000, 80000, &usbGraphire4, NULL },
{ WALTOP_VENDOR_ID, 0x36, 80000, 80000, &usbGraphire4, NULL },
{ WALTOP_VENDOR_ID, 0x37, 80000, 80000, &usbGraphire4, NULL },
{ WALTOP_VENDOR_ID, 0x38, 100000, 100000, &usbBambooFun, NULL },
{ WALTOP_VENDOR_ID, 0x39, 100000, 100000, &usbBambooFun, NULL },
{ WALTOP_VENDOR_ID, 0x51, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x52, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x53, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x54, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x55, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x56, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x57, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x58, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x500, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x501, 100000, 100000, &usbBamboo, NULL },
{ WALTOP_VENDOR_ID, 0x502, 200000, 200000, &usbIntuos4, NULL },
{ WALTOP_VENDOR_ID, 0x503, 200000, 200000, &usbIntuos4, NULL },
/* N-Trig devices */
{ NTRIG_VENDOR_ID, 0x01, 44173, 36772, &usbTabletPC, NULL },
/* Add in Lenovo W700 Palmrest digitizer */
{ LENOVO_VENDOR_ID, 0x6004, 100000, 100000, &usbTabletPC, NULL } /* Pen-only */
};
void usbListModels(void)
{
int i;
char *usbnames[ARRAY_SIZE(WacomModelDesc)] = {0};
SymTabRec models[ARRAY_SIZE(WacomModelDesc) + 1];
for (i = 0; i < ARRAY_SIZE(WacomModelDesc); i++)
{
struct WacomModelDesc *m = &WacomModelDesc[i];
models[i].token = i;
if (m->name)
models[i].name = m->name;
else {
/* SymTabRec has a const char *name so we can't free
without compiler warnings. keep allocated stuff
in separate array.
*/
usbnames[i] = malloc(64);
if (!usbnames[i]) {
/* if malloc fails, xf86PrintChipsets() terminates
here because models->name is NULL. then again,
malloc failed, so the rest is academic. */
models[i].name = NULL;
break;
}
sprintf(usbnames[i], "usb:%04x:%04x", m->vendor_id, m->model_id);
models[i].name = usbnames[i];
}
}
models[ARRAY_SIZE(models) - 1].name = NULL;
xf86PrintChipsets("wacom",
"Driver for Wacom graphics tablets",
models);
for (i = 0; i < ARRAY_SIZE(usbnames); i++)
free(usbnames[i]);
}
static Bool usbWcmInit(InputInfoPtr pInfo, char* id, size_t id_len, float *version)
{
int i;
struct input_id sID;
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
wcmUSBData *usbdata;
DBG(1, priv, "initializing USB tablet\n");
/* fetch vendor, product, and model name */
if (ioctl(pInfo->fd, EVIOCGID, &sID) == -1 ||
ioctl(pInfo->fd, EVIOCGNAME(id_len), id) == -1) {
xf86Msg(X_ERROR, "%s: failed to ioctl ID or name.\n",
pInfo->name);
return !Success;
}
if (!common->private &&
!(common->private = calloc(1, sizeof(wcmUSBData))))
{
xf86Msg(X_ERROR, "%s: unable to alloc event queue.\n",
pInfo->name);
return !Success;
}
usbdata = common->private;
*version = 0.0;
for (i = 0; i < ARRAY_SIZE(WacomModelDesc); i++)
{
if (sID.vendor == WacomModelDesc[i].vendor_id &&
sID.product == WacomModelDesc [i].model_id)
{
common->wcmModel = WacomModelDesc [i].model;
common->wcmResolX = WacomModelDesc [i].xRes;
common->wcmResolY = WacomModelDesc [i].yRes;
}
}
if (!common->wcmModel)
{
common->wcmModel = &usbUnknown;
common->wcmResolX = common->wcmResolY = 1016;
}
/* Find out supported button codes. */
usbdata->npadkeys = 0;
for (i = 0; i < ARRAY_SIZE(padkey_codes); i++)
if (ISBITSET (common->wcmKeys, padkey_codes [i]))
usbdata->padkey_code [usbdata->npadkeys++] = padkey_codes [i];
if (usbdata->npadkeys == 0) {
/* If no pad keys were detected, entertain the possibility that any
* mouse buttons which exist may belong to the pad (e.g. Graphire4).
* If we're wrong, this will over-state the capabilities of the pad
* but that shouldn't actually cause problems.
*/
for (i = ARRAY_SIZE(mouse_codes) - 1; i > 0; i--)
if (ISBITSET(common->wcmKeys, mouse_codes[i]))
break;
/* Make sure room for fixed map mouse buttons. This
* means mappings may overlap with padkey_codes[].
*/
if (i != 0)
usbdata->npadkeys = WCM_USB_MAX_MOUSE_BUTTONS;
}
/* nbuttons tracks maximum buttons on all tools (stylus/mouse).
*
* Mouse support left, middle, right, side, and extra side button.
* Stylus support tip and 3 stylus buttons.
*/
if (ISBITSET (common->wcmKeys, BTN_TOOL_MOUSE))
usbdata->nbuttons = WCM_USB_MAX_MOUSE_BUTTONS;
else
usbdata->nbuttons = WCM_USB_MAX_STYLUS_BUTTONS;
return Success;
}
static void usbInitProtocol5(WacomCommonPtr common, const char* id,
float version)
{
common->wcmProtocolLevel = WCM_PROTOCOL_5;
common->wcmPktLength = sizeof(struct input_event);
common->wcmCursorProxoutDistDefault = PROXOUT_INTUOS_DISTANCE;
/* tilt enabled */
common->wcmFlags |= TILT_ENABLED_FLAG;
}
static void usbInitProtocol4(WacomCommonPtr common, const char* id,
float version)
{
common->wcmProtocolLevel = WCM_PROTOCOL_4;
common->wcmPktLength = sizeof(struct input_event);
common->wcmCursorProxoutDistDefault = PROXOUT_GRAPHIRE_DISTANCE;
/* tilt disabled */
common->wcmFlags &= ~TILT_ENABLED_FLAG;
}
/* Initialize fixed PAD channel's state to in proximity.
*
* Some, but not all, Wacom protocol 4/5 devices are always in proximity.
* Because of evdev filtering, there will never be a BTN_TOOL_FINGER
* sent to initialize state.
* Generic protocol devices never send anything to help initialize PAD
* device as well.
* This helps those 2 cases and does not hurt the cases where kernel
* driver sends out-of-proximity event for PAD since PAD is always on
* its own channel, PAD_CHANNEL.
*/
static void usbWcmInitPadState(InputInfoPtr pInfo)
{
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
WacomDeviceState *ds;
int channel = PAD_CHANNEL;
DBG(6, common, "Initializing PAD channel %d\n", channel);
ds = &common->wcmChannel[channel].work;
ds->proximity = 1;
ds->device_type = PAD_ID;
ds->device_id = PAD_DEVICE_ID;
ds->serial_num = channel;
}
int usbWcmGetRanges(InputInfoPtr pInfo)
{
struct input_absinfo absinfo;
unsigned long ev[NBITS(EV_MAX)] = {0};
unsigned long abs[NBITS(ABS_MAX)] = {0};
unsigned long sw[NBITS(SW_MAX)] = {0};
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
wcmUSBData* private = common->private;
int is_touch = IsTouch(priv);
/* Devices such as Bamboo P&T may have Pad data reported in the same
* packet as Touch. It's normal for Pad to be called first but logic
* requires it to act the same as Touch.
*/
if (ISBITSET(common->wcmKeys, BTN_TOOL_DOUBLETAP)
&& ISBITSET(common->wcmKeys, BTN_FORWARD))
is_touch = 1;
if (ioctl(pInfo->fd, EVIOCGBIT(0 /*EV*/, sizeof(ev)), ev) < 0)
{
xf86Msg(X_ERROR, "%s: unable to ioctl event bits.\n", pInfo->name);
return !Success;
}
if (!ISBITSET(ev,EV_ABS))
{
/* may be an expresskey only interface */
if (ISBITSET(common->wcmKeys, BTN_FORWARD) ||
ISBITSET(common->wcmKeys, BTN_0))
goto pad_init;
xf86Msg(X_ERROR, "%s: no abs bits.\n", pInfo->name);
return !Success;
}
/* absolute values */
if (ioctl(pInfo->fd, EVIOCGBIT(EV_ABS, sizeof(abs)), abs) < 0)
{
xf86Msg(X_ERROR, "%s: unable to ioctl max values.\n", pInfo->name);
return !Success;
}
/* max x */
if (ioctl(pInfo->fd, EVIOCGABS(ABS_X), &absinfo) < 0)
{
/* may be a PAD only interface */
if (ISBITSET(common->wcmKeys, BTN_FORWARD) ||
ISBITSET(common->wcmKeys, BTN_0))
goto pad_init;
xf86Msg(X_ERROR, "%s: unable to ioctl xmax value.\n", pInfo->name);
return !Success;
}
if (absinfo.maximum <= 0)
{
xf86Msg(X_ERROR, "%s: xmax value is %d, expected > 0.\n",
pInfo->name, absinfo.maximum);
return !Success;
}
if (!is_touch)
{
common->wcmMinX = absinfo.minimum;
common->wcmMaxX = absinfo.maximum;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
if (absinfo.resolution > 0)
common->wcmResolX = absinfo.resolution * 1000;
#endif
}
else
{
common->wcmMaxTouchX = absinfo.maximum;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
if (absinfo.resolution > 0)
common->wcmTouchResolX = absinfo.resolution * 1000;
#endif
}
/* max y */
if (ioctl(pInfo->fd, EVIOCGABS(ABS_Y), &absinfo) < 0)
{
xf86Msg(X_ERROR, "%s: unable to ioctl ymax value.\n", pInfo->name);
return !Success;
}
if (absinfo.maximum <= 0)
{
xf86Msg(X_ERROR, "%s: ymax value is %d, expected > 0.\n",
pInfo->name, absinfo.maximum);
return !Success;
}
if (!is_touch)
{
common->wcmMinY = absinfo.minimum;
common->wcmMaxY = absinfo.maximum;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
if (absinfo.resolution > 0)
common->wcmResolY = absinfo.resolution * 1000;
#endif
}
else
{
common->wcmMaxTouchY = absinfo.maximum;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
if (absinfo.resolution > 0)
common->wcmTouchResolY = absinfo.resolution * 1000;
#endif
}
/* max finger strip X for tablets with Expresskeys
* or physical X for touch devices in hundredths of a mm */
if (ISBITSET(abs, ABS_RX) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_RX), &absinfo))
{
if (is_touch)
common->wcmTouchResolX =
(int)(((double)common->wcmMaxTouchX * 100000.0
/ (double)absinfo.maximum) + 0.5);
else
common->wcmMaxStripX = absinfo.maximum;
}
/* max touchring value for standalone pad tools */
common->wcmMinRing = 0;
common->wcmMaxRing = 71;
if (!ISBITSET(ev,EV_MSC) && ISBITSET(abs, ABS_WHEEL) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_WHEEL), &absinfo))
{
common->wcmMinRing = absinfo.minimum;
common->wcmMaxRing = absinfo.maximum;
}
/* X tilt range */
if (ISBITSET(abs, ABS_TILT_X) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_TILT_X), &absinfo))
{
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
/* If resolution is specified */
if (absinfo.resolution > 0)
{
/* Assume the range is centered on zero */
common->wcmTiltOffX = 0;
/* Convert to resolution expected by applications */
common->wcmTiltFactX = TILT_RES /
(double)absinfo.resolution;
}
else
#endif
{
/*
* Center the reported range on zero to support
* kernel drivers still reporting non-zero-centered
* values.
*/
common->wcmTiltOffX = - (absinfo.minimum +
absinfo.maximum) / 2;
/*
* Assume reported resolution is the one expected by
* applications
*/
common->wcmTiltFactX = 1.0;
}
common->wcmTiltMinX = round((absinfo.minimum +
common->wcmTiltOffX) *
common->wcmTiltFactX);
common->wcmTiltMaxX = round((absinfo.maximum +
common->wcmTiltOffX) *
common->wcmTiltFactX);
}
/* Y tilt range */
if (ISBITSET(abs, ABS_TILT_Y) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_TILT_Y), &absinfo))
{
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
/* If resolution is specified */
if (absinfo.resolution > 0)
{
/* Assume the range is centered on zero */
common->wcmTiltOffY = 0;
/* Convert to resolution expected by applications */
common->wcmTiltFactY = TILT_RES /
(double)absinfo.resolution;
}
else
#endif
{
/*
* Center the reported range on zero to support
* kernel drivers still reporting non-zero-centered
* values.
*/
common->wcmTiltOffY = - (absinfo.minimum +
absinfo.maximum) / 2;
/*
* Assume reported resolution is the one expected by
* applications
*/
common->wcmTiltFactY = 1.0;
}
common->wcmTiltMinY = round((absinfo.minimum +
common->wcmTiltOffY) *
common->wcmTiltFactY);
common->wcmTiltMaxY = round((absinfo.maximum +
common->wcmTiltOffY) *
common->wcmTiltFactY);
}
/* max finger strip Y for tablets with Expresskeys
* or physical Y for touch devices in hundredths of a mm */
if (ISBITSET(abs, ABS_RY) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_RY), &absinfo))
{
if (is_touch)
common->wcmTouchResolY =
(int)(((double)common->wcmMaxTouchY * 100000.0
/ (double)absinfo.maximum) + 0.5);
else
common->wcmMaxStripY = absinfo.maximum;
}
/* max z cannot be configured */
if (ISBITSET(abs, ABS_PRESSURE) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_PRESSURE), &absinfo))
common->wcmMaxZ = absinfo.maximum;
/* max distance */
if (ISBITSET(abs, ABS_DISTANCE) &&
!ioctl(pInfo->fd, EVIOCGABS(ABS_DISTANCE), &absinfo))
common->wcmMaxDist = absinfo.maximum;
if (ISBITSET(abs, ABS_MT_SLOT))
{
private->wcmUseMT = 1;
if (!ioctl(pInfo->fd, EVIOCGABS(ABS_MT_SLOT), &absinfo))
common->wcmMaxContacts = absinfo.maximum + 1;
/* pen and MT on the same logical port */
if (ISBITSET(common->wcmKeys, BTN_TOOL_PEN))
private->wcmPenTouch = TRUE;
}
/* A generic protocol device does not report ABS_MISC event */
if (!ISBITSET(abs, ABS_MISC))
common->wcmProtocolLevel = WCM_PROTOCOL_GENERIC;
if (ioctl(pInfo->fd, EVIOCGBIT(EV_SW, sizeof(sw)), sw) < 0)
{
xf86Msg(X_ERROR, "%s: unable to ioctl sw bits.\n", pInfo->name);
return 0;
}
else if (ISBITSET(sw, SW_MUTE_DEVICE))
{
common->wcmHasHWTouchSwitch = TRUE;
memset(sw, 0, sizeof(sw));
if (ioctl(pInfo->fd, EVIOCGSW(sizeof(sw)), sw) < 0)
xf86Msg(X_ERROR, "%s: unable to ioctl sw state.\n", pInfo->name);
if (ISBITSET(sw, SW_MUTE_DEVICE))
common->wcmHWTouchSwitchState = 0;
else
common->wcmHWTouchSwitchState = 1;
}
pad_init:
usbWcmInitPadState(pInfo);
return Success;
}
static int usbDetectConfig(InputInfoPtr pInfo)
{
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
wcmUSBData *usbdata = common->private;
DBG(10, common, "\n");
if (IsPad (priv))
priv->nbuttons = usbdata->npadkeys;
else
priv->nbuttons = usbdata->nbuttons;
if (!common->wcmCursorProxoutDist)
common->wcmCursorProxoutDist
= common->wcmCursorProxoutDistDefault;
return TRUE;
}
static int usbParse(InputInfoPtr pInfo, const unsigned char* data, int len)
{
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
struct input_event event;
if (len < sizeof(struct input_event))
return 0;
memcpy(&event, data, sizeof(event));
usbParseEvent(pInfo, &event);
return common->wcmPktLength;
}
/**
* Returns a serial number for the provided device_type and serial, as
* through it came from from a Protocol 5 device.
*
* Protocol 5 serial numbers will be returned unchanged. Otherwise,
* anonymous tools (from Protocol 4 and Generic Protocol) will have
* serial numbers of: -1 (pad), 1 (pen/1st finger), 2 (2nd finger),
* etc.
*
* @param[in] device_type Type of device (e.g. STYLUS_ID, TOUCH_ID, PAD_ID)
* @param[in] serial Serial number of device
* @return Serial number of device as through from Protocol 5
*/
static int protocol5Serial(int device_type, unsigned int serial) {
if (!serial) {
/* Generic Protocol does not send serial numbers */
return device_type == PAD_ID ? -1 : 1;
}
else if (serial == 0xf0) {
/* Protocol 4 uses the expected anonymous serial
* numbers, but has the wrong PAD serial number.
* This could cause problem if 0xf0 is ever used
* for a Protocol 5 serial number, but isn't a
* problem as yet.
*/
return -1;
}
else {
/* Protocol 5 FTW */
return serial;
}
}
/**
* Find an appropriate channel to track the specified tool's state in.
* If the tool is already in proximity, the channel currently being used
* to store its state will be returned. Otherwise, an arbitrary available
* channel will be cleaned and returned. Up to MAX_CHANNEL tools can be
* tracked concurrently by driver.
*
* @param[in] common
* @param[in] device_type Type of tool (e.g. STYLUS_ID, TOUCH_ID, PAD_ID)
* @param[in] serial Serial number of tool
* @return Channel number to track the tool's state
*/
static int usbChooseChannel(WacomCommonPtr common, int device_type, unsigned int serial)
{
/* figure out the channel to use based on serial number */
int i, channel = -1;
/* force events from PAD device to PAD_CHANNEL */
if (serial == -1)
channel = PAD_CHANNEL;
/* find existing channel */
if (channel < 0)
{
for (i=0; i<MAX_CHANNELS; i++)
{
if (common->wcmChannel[i].work.proximity &&
common->wcmChannel[i].work.device_type == device_type &&
common->wcmChannel[i].work.serial_num == serial)
{
channel = i;
break;
}
}
}
/* find and clean an empty channel */
if (channel < 0)
{
for (i=0; i<MAX_CHANNELS; i++)
{
if (i == PAD_CHANNEL)
continue;
if (!common->wcmChannel[i].work.proximity &&
!common->wcmChannel[i].valid.state.proximity)
{
channel = i;
memset(&common->wcmChannel[channel],0, sizeof(WacomChannel));
break;
}
}
}
/* fresh out of channels */
if (channel < 0)
{
/* This should never happen in normal use.
* Let's start over again. Force prox-out for all channels.
*/
for (i=0; i<MAX_CHANNELS; i++)
{
if (i == PAD_CHANNEL)
continue;
if (common->wcmChannel[i].work.proximity &&
(common->wcmChannel[i].work.serial_num != -1))
{
common->wcmChannel[i].work.proximity = 0;
/* dispatch event */
wcmEvent(common, i, &common->wcmChannel[i].work);
DBG(2, common, "free channels: dropping %u\n",
common->wcmChannel[i].work.serial_num);
}
}
DBG(1, common, "device with serial number: %u"
" at %d: Exceeded channel count; ignoring the events.\n",
serial, (int)GetTimeInMillis());
}
return channel;
}
static inline void
usbResetEventCounter(wcmUSBData *private)
{
private->wcmEventCnt = 0;
private->wcmEventFlags = 0;
}
static void usbParseEvent(InputInfoPtr pInfo,
const struct input_event* event)
{
WacomDevicePtr priv = (WacomDevicePtr)pInfo->private;
WacomCommonPtr common = priv->common;
wcmUSBData* private = common->private;
DBG(10, common, "\n");
/* store events until we receive a SYN_REPORT */
/* space left? bail if not. */
if (private->wcmEventCnt >= ARRAY_SIZE(private->wcmEvents))
{
LogMessageVerbSigSafe(X_ERROR, 0, "%s: usbParse: Exceeded event queue (%d) \n",
pInfo->name, private->wcmEventCnt);
usbResetEventCounter(private);