35 static unsigned short keycode_kore[] = {
70 #define MASCHINE_BUTTONS (42)
71 #define MASCHINE_BUTTON(X) ((X) + BTN_MISC)
72 #define MASCHINE_PADS (16)
73 #define MASCHINE_PAD(X) ((X) + ABS_PRESSURE)
75 static unsigned short keycode_maschine[] = {
125 #define KONTROLX1_INPUTS (40)
126 #define KONTROLS4_BUTTONS (12 * 8)
127 #define KONTROLS4_AXIS (46)
129 #define KONTROLS4_BUTTON(X) ((X) + BTN_MISC)
130 #define KONTROLS4_ABS(X) ((X) + ABS_HAT0X)
132 #define DEG90 (range / 2)
133 #define DEG180 (range)
134 #define DEG270 (DEG90 + DEG180)
135 #define DEG360 (DEG180 * 2)
136 #define HIGH_PEAK (268)
137 #define LOW_PEAK (-7)
143 static unsigned int decode_erp(
unsigned char a,
unsigned char b)
145 int weight_a, weight_b;
151 weight_b =
abs(mid_value - a) - (range / 2 - 100) / 2;
159 weight_a = 100 - weight_b;
163 pos_b = b - LOW_PEAK +
DEG270;
180 ret = pos_a * weight_a + pos_b * weight_b;
203 int axis,
const unsigned char *
buf,
206 input_report_abs(dev->input_dev, axis,
207 (buf[offset * 2] << 8) | buf[offset * 2 + 1]);
211 const unsigned char *
buf,
214 struct input_dev *input_dev = dev->input_dev;
216 switch (dev->
chip.usb_id) {
218 snd_caiaq_input_report_abs(dev,
ABS_X, buf, 2);
219 snd_caiaq_input_report_abs(dev,
ABS_Y, buf, 0);
220 snd_caiaq_input_report_abs(dev,
ABS_Z, buf, 1);
225 snd_caiaq_input_report_abs(dev,
ABS_X, buf, 0);
226 snd_caiaq_input_report_abs(dev,
ABS_Y, buf, 1);
227 snd_caiaq_input_report_abs(dev,
ABS_Z, buf, 2);
230 snd_caiaq_input_report_abs(dev,
ABS_HAT0X, buf, 4);
231 snd_caiaq_input_report_abs(dev,
ABS_HAT0Y, buf, 2);
232 snd_caiaq_input_report_abs(dev,
ABS_HAT1X, buf, 6);
233 snd_caiaq_input_report_abs(dev,
ABS_HAT1Y, buf, 1);
234 snd_caiaq_input_report_abs(dev,
ABS_HAT2X, buf, 7);
235 snd_caiaq_input_report_abs(dev,
ABS_HAT2Y, buf, 0);
236 snd_caiaq_input_report_abs(dev,
ABS_HAT3X, buf, 5);
237 snd_caiaq_input_report_abs(dev,
ABS_HAT3Y, buf, 3);
241 input_sync(input_dev);
245 const char *buf,
unsigned int len)
247 struct input_dev *input_dev = dev->input_dev;
250 switch (dev->
chip.usb_id) {
252 i = decode_erp(buf[0], buf[1]);
253 input_report_abs(input_dev,
ABS_X, i);
254 input_sync(input_dev);
258 i = decode_erp(buf[7], buf[5]);
259 input_report_abs(input_dev,
ABS_HAT0X, i);
260 i = decode_erp(buf[12], buf[14]);
261 input_report_abs(input_dev,
ABS_HAT0Y, i);
262 i = decode_erp(buf[15], buf[13]);
263 input_report_abs(input_dev,
ABS_HAT1X, i);
264 i = decode_erp(buf[0], buf[2]);
265 input_report_abs(input_dev,
ABS_HAT1Y, i);
266 i = decode_erp(buf[3], buf[1]);
267 input_report_abs(input_dev,
ABS_HAT2X, i);
268 i = decode_erp(buf[8], buf[10]);
269 input_report_abs(input_dev,
ABS_HAT2Y, i);
270 i = decode_erp(buf[11], buf[9]);
271 input_report_abs(input_dev,
ABS_HAT3X, i);
272 i = decode_erp(buf[4], buf[6]);
273 input_report_abs(input_dev,
ABS_HAT3Y, i);
274 input_sync(input_dev);
279 input_report_abs(input_dev,
ABS_HAT0X, decode_erp(buf[21], buf[20]));
280 input_report_abs(input_dev,
ABS_HAT0Y, decode_erp(buf[15], buf[14]));
281 input_report_abs(input_dev,
ABS_HAT1X, decode_erp(buf[9], buf[8]));
282 input_report_abs(input_dev,
ABS_HAT1Y, decode_erp(buf[3], buf[2]));
285 input_report_abs(input_dev,
ABS_HAT2X, decode_erp(buf[19], buf[18]));
286 input_report_abs(input_dev,
ABS_HAT2Y, decode_erp(buf[13], buf[12]));
287 input_report_abs(input_dev,
ABS_HAT3X, decode_erp(buf[7], buf[6]));
288 input_report_abs(input_dev,
ABS_HAT3Y, decode_erp(buf[1], buf[0]));
291 input_report_abs(input_dev,
ABS_RX, decode_erp(buf[17], buf[16]));
293 input_report_abs(input_dev,
ABS_RY, decode_erp(buf[11], buf[10]));
295 input_report_abs(input_dev,
ABS_RZ, decode_erp(buf[5], buf[4]));
297 input_sync(input_dev);
303 unsigned char *buf,
unsigned int len)
305 struct input_dev *input_dev = dev->input_dev;
306 unsigned short *
keycode = input_dev->keycode;
313 for (i = 0; i < len; i++)
316 for (i = 0; i < input_dev->keycodemax && i < len * 8; i++)
317 input_report_key(input_dev, keycode[i],
318 buf[i / 8] & (1 << (i % 8)));
320 switch (dev->
chip.usb_id) {
323 input_report_abs(dev->input_dev,
ABS_MISC, 255 - buf[4]);
327 input_report_abs(dev->input_dev,
ABS_X, buf[5] & 0xf);
328 input_report_abs(dev->input_dev,
ABS_Y, buf[5] >> 4);
329 input_report_abs(dev->input_dev,
ABS_Z, buf[6] & 0xf);
330 input_report_abs(dev->input_dev,
ABS_MISC, buf[6] >> 4);
334 input_sync(input_dev);
337 #define TKS4_MSGBLOCK_SIZE 16
340 const unsigned char *buf,
344 unsigned int i, block_id = (buf[0] << 8) | buf[1];
351 (buf[4 + (i / 8)] >> (i % 8)) & 1);
356 input_report_abs(dev->input_dev,
KONTROLS4_ABS(36), buf[9] | ((buf[8] & 0x3) << 8));
358 input_report_abs(dev->input_dev,
KONTROLS4_ABS(37), buf[13] | ((buf[12] & 0x3) << 8));
361 input_report_abs(dev->input_dev,
KONTROLS4_ABS(38), buf[3] & 0xf);
362 input_report_abs(dev->input_dev,
KONTROLS4_ABS(39), buf[4] >> 4);
363 input_report_abs(dev->input_dev,
KONTROLS4_ABS(40), buf[4] & 0xf);
364 input_report_abs(dev->input_dev,
KONTROLS4_ABS(41), buf[5] >> 4);
365 input_report_abs(dev->input_dev,
KONTROLS4_ABS(42), buf[5] & 0xf);
366 input_report_abs(dev->input_dev,
KONTROLS4_ABS(43), buf[6] >> 4);
367 input_report_abs(dev->input_dev,
KONTROLS4_ABS(44), buf[6] & 0xf);
368 input_report_abs(dev->input_dev,
KONTROLS4_ABS(45), buf[7] >> 4);
369 input_report_abs(dev->input_dev,
KONTROLS4_ABS(46), buf[7] & 0xf);
469 debug(
"%s(): bogus block (id %d)\n",
478 input_sync(dev->input_dev);
481 #define MASCHINE_MSGBLOCK_SIZE 2
484 const unsigned char *buf,
487 unsigned int i, pad_id;
491 pressure =
be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
492 pad_id = pressure >> 12;
494 input_report_abs(dev->input_dev,
MASCHINE_PAD(pad_id), pressure & 0xfff);
497 input_sync(dev->input_dev);
500 static void snd_usb_caiaq_ep4_reply_dispatch(
struct urb *
urb)
503 unsigned char *buf = urb->transfer_buffer;
506 if (urb->status || !dev || urb != dev->ep4_in_urb)
509 switch (dev->
chip.usb_id) {
511 if (urb->actual_length < 24)
515 snd_caiaq_input_read_io(dev, buf + 1, 7);
518 snd_caiaq_input_read_analog(dev, buf + 8, 16);
523 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
530 snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length);
535 dev->ep4_in_urb->actual_length = 0;
538 log(
"unable to submit urb. OOM!?\n");
541 static int snd_usb_caiaq_input_open(
struct input_dev *
idev)
548 switch (dev->
chip.usb_id) {
560 static void snd_usb_caiaq_input_close(
struct input_dev *idev)
567 switch (dev->
chip.usb_id) {
580 if (!dev->input_dev || len < 1)
585 snd_caiaq_input_read_analog(dev, buf + 1, len - 1);
588 snd_caiaq_input_read_erp(dev, buf + 1, len - 1);
591 snd_caiaq_input_read_io(dev, buf + 1, len - 1);
598 struct usb_device *usb_dev = dev->
chip.dev;
599 struct input_dev *
input;
602 input = input_allocate_device();
606 usb_make_path(usb_dev, dev->phys,
sizeof(dev->phys));
607 strlcat(dev->phys,
"/input0",
sizeof(dev->phys));
610 input->phys = dev->phys;
611 usb_to_input_id(usb_dev, &input->id);
612 input->dev.parent = &usb_dev->dev;
614 input_set_drvdata(input, dev);
616 switch (dev->
chip.usb_id) {
621 BUILD_BUG_ON(
sizeof(dev->keycode) <
sizeof(keycode_rk2));
622 memcpy(dev->keycode, keycode_rk2,
sizeof(keycode_rk2));
624 input_set_abs_params(input,
ABS_X, 0, 4096, 0, 10);
625 input_set_abs_params(input,
ABS_Y, 0, 4096, 0, 10);
626 input_set_abs_params(input,
ABS_Z, 0, 4096, 0, 10);
633 BUILD_BUG_ON(
sizeof(dev->keycode) <
sizeof(keycode_rk3));
634 memcpy(dev->keycode, keycode_rk3,
sizeof(keycode_rk3));
636 input_set_abs_params(input,
ABS_X, 0, 1024, 0, 10);
637 input_set_abs_params(input,
ABS_Y, 0, 1024, 0, 10);
638 input_set_abs_params(input,
ABS_Z, 0, 1024, 0, 10);
644 BUILD_BUG_ON(
sizeof(dev->keycode) <
sizeof(keycode_ak1));
645 memcpy(dev->keycode, keycode_ak1,
sizeof(keycode_ak1));
647 input_set_abs_params(input,
ABS_X, 0, 999, 0, 10);
660 BUILD_BUG_ON(
sizeof(dev->keycode) <
sizeof(keycode_kore));
661 memcpy(dev->keycode, keycode_kore,
sizeof(keycode_kore));
663 input_set_abs_params(input,
ABS_HAT0X, 0, 999, 0, 10);
664 input_set_abs_params(input,
ABS_HAT0Y, 0, 999, 0, 10);
665 input_set_abs_params(input,
ABS_HAT1X, 0, 999, 0, 10);
666 input_set_abs_params(input,
ABS_HAT1Y, 0, 999, 0, 10);
667 input_set_abs_params(input,
ABS_HAT2X, 0, 999, 0, 10);
668 input_set_abs_params(input,
ABS_HAT2Y, 0, 999, 0, 10);
669 input_set_abs_params(input,
ABS_HAT3X, 0, 999, 0, 10);
670 input_set_abs_params(input,
ABS_HAT3Y, 0, 999, 0, 10);
671 input_set_abs_params(input,
ABS_X, 0, 4096, 0, 10);
672 input_set_abs_params(input,
ABS_Y, 0, 4096, 0, 10);
673 input_set_abs_params(input,
ABS_Z, 0, 4096, 0, 10);
674 input_set_abs_params(input,
ABS_MISC, 0, 255, 0, 1);
689 input->keycodemax = KONTROLX1_INPUTS;
692 input_set_abs_params(input,
ABS_HAT0X, 0, 4096, 0, 10);
693 input_set_abs_params(input,
ABS_HAT0Y, 0, 4096, 0, 10);
694 input_set_abs_params(input,
ABS_HAT1X, 0, 4096, 0, 10);
695 input_set_abs_params(input,
ABS_HAT1Y, 0, 4096, 0, 10);
696 input_set_abs_params(input,
ABS_HAT2X, 0, 4096, 0, 10);
697 input_set_abs_params(input,
ABS_HAT2Y, 0, 4096, 0, 10);
698 input_set_abs_params(input,
ABS_HAT3X, 0, 4096, 0, 10);
699 input_set_abs_params(input,
ABS_HAT3Y, 0, 4096, 0, 10);
702 input_set_abs_params(input,
ABS_X, 0, 0xf, 0, 1);
703 input_set_abs_params(input,
ABS_Y, 0, 0xf, 0, 1);
704 input_set_abs_params(input,
ABS_Z, 0, 0xf, 0, 1);
705 input_set_abs_params(input,
ABS_MISC, 0, 0xf, 0, 1);
708 if (!dev->ep4_in_urb) {
713 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
714 usb_rcvbulkpipe(usb_dev, 0x4),
716 snd_usb_caiaq_ep4_reply_dispatch, dev);
735 for (i = 0; i < 36; i++)
736 input_set_abs_params(input,
KONTROLS4_ABS(i), 0, 0xfff, 0, 10);
739 input_set_abs_params(input,
KONTROLS4_ABS(36), 0, 0x3ff, 0, 1);
740 input_set_abs_params(input,
KONTROLS4_ABS(37), 0, 0x3ff, 0, 1);
743 for (i = 0; i < 9; i++)
744 input_set_abs_params(input,
KONTROLS4_ABS(38+i), 0, 0xf, 0, 1);
747 if (!dev->ep4_in_urb) {
752 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
753 usb_rcvbulkpipe(usb_dev, 0x4),
755 snd_usb_caiaq_ep4_reply_dispatch, dev);
770 BUILD_BUG_ON(
sizeof(dev->keycode) <
sizeof(keycode_maschine));
771 memcpy(dev->keycode, keycode_maschine,
sizeof(keycode_maschine));
772 input->keycodemax =
ARRAY_SIZE(keycode_maschine);
776 input_set_abs_params(input,
MASCHINE_PAD(i), 0, 0xfff, 5, 10);
779 input_set_abs_params(input,
ABS_HAT0X, 0, 999, 0, 10);
780 input_set_abs_params(input,
ABS_HAT0Y, 0, 999, 0, 10);
781 input_set_abs_params(input,
ABS_HAT1X, 0, 999, 0, 10);
782 input_set_abs_params(input,
ABS_HAT1Y, 0, 999, 0, 10);
783 input_set_abs_params(input,
ABS_HAT2X, 0, 999, 0, 10);
784 input_set_abs_params(input,
ABS_HAT2Y, 0, 999, 0, 10);
785 input_set_abs_params(input,
ABS_HAT3X, 0, 999, 0, 10);
786 input_set_abs_params(input,
ABS_HAT3Y, 0, 999, 0, 10);
787 input_set_abs_params(input,
ABS_RX, 0, 999, 0, 10);
788 input_set_abs_params(input,
ABS_RY, 0, 999, 0, 10);
789 input_set_abs_params(input,
ABS_RZ, 0, 999, 0, 10);
792 if (!dev->ep4_in_urb) {
797 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
798 usb_rcvbulkpipe(usb_dev, 0x4),
800 snd_usb_caiaq_ep4_reply_dispatch, dev);
810 input->open = snd_usb_caiaq_input_open;
811 input->close = snd_usb_caiaq_input_close;
812 input->keycode = dev->keycode;
813 input->keycodesize =
sizeof(
unsigned short);
814 for (i = 0; i < input->keycodemax; i++)
815 __set_bit(dev->keycode[i], input->keybit);
817 dev->input_dev =
input;
819 ret = input_register_device(input);
826 input_free_device(input);
827 dev->input_dev =
NULL;
833 if (!dev || !dev->input_dev)
838 dev->ep4_in_urb =
NULL;
840 input_unregister_device(dev->input_dev);
841 dev->input_dev =
NULL;