Lines Matching +full:relative +full:- +full:axis
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
124 WSP_CLAMP(ptun->scale_factor, 1, 63); in wsp_runing_rangecheck()
125 WSP_CLAMP(ptun->z_factor, 1, 63); in wsp_runing_rangecheck()
126 WSP_CLAMP(ptun->z_invert, 0, 1); in wsp_runing_rangecheck()
127 WSP_CLAMP(ptun->pressure_touch_threshold, 1, 255); in wsp_runing_rangecheck()
128 WSP_CLAMP(ptun->pressure_untouch_threshold, 1, 255); in wsp_runing_rangecheck()
129 WSP_CLAMP(ptun->pressure_tap_threshold, 1, 255); in wsp_runing_rangecheck()
130 WSP_CLAMP(ptun->max_finger_area, 1, 2400); in wsp_runing_rangecheck()
131 WSP_CLAMP(ptun->max_double_tap_distance, 1, 16384); in wsp_runing_rangecheck()
132 WSP_CLAMP(ptun->scr_hor_threshold, 1, 255); in wsp_runing_rangecheck()
133 WSP_CLAMP(ptun->enable_single_tap_clicks, 0, 1); in wsp_runing_rangecheck()
134 WSP_CLAMP(ptun->enable_single_tap_movement, 0, 1); in wsp_runing_rangecheck()
140 &wsp_tuning.z_factor, 0, "Z-axis scale factor");
142 &wsp_tuning.z_invert, 0, "enable Z-axis inversion");
152 &wsp_tuning.max_double_tap_distance, 0, "maximum double-finger click distance");
171 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
174 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
176 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
184 uint8_t rel_x; /* relative x coordinate */
185 uint8_t rel_y; /* relative y coordinate */
197 /* trackpad finger data offsets, le16-aligned */
278 /* trackpad finger header - little endian */
293 /* trackpad finger structure - little endian */
298 int16_t rel_x; /* relative x coodinate */
299 int16_t rel_y; /* relative y coodinate */
300 int16_t tool_major; /* tool area, major axis */
301 int16_t tool_minor; /* tool area, minor axis */
303 int16_t touch_major; /* touch area, major axis */
304 int16_t touch_minor; /* touch area, minor axis */
342 /* device-specific parameters */
344 int snratio; /* signal-to-noise ratio */
350 /* device-specific configuration */
361 #define SN_PRESSURE 45 /* pressure signal-to-noise ratio */
362 #define SN_WIDTH 25 /* width signal-to-noise ratio */
363 #define SN_COORD 250 /* coordinate signal-to-noise ratio */
364 #define SN_ORIENT 10 /* orientation signal-to-noise ratio */
371 .x = { SN_COORD, -4824, 5342, 105 },
372 .y = { SN_COORD, -172, 5820, 75 },
374 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
380 .x = { SN_COORD, -4824, 4824, 105 },
381 .y = { SN_COORD, -172, 4290, 75 },
383 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
389 .x = { SN_COORD, -4460, 5166, 105 },
390 .y = { SN_COORD, -75, 6700, 75 },
392 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
398 .x = { SN_COORD, -4620, 5140, 105 },
399 .y = { SN_COORD, -150, 6600, 75 },
401 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
407 .x = { SN_COORD, -4616, 5112, 105 },
408 .y = { SN_COORD, -142, 5234, 75 },
410 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
416 .x = { SN_COORD, -4415, 5050, 105 },
417 .y = { SN_COORD, -55, 6680, 75 },
419 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
425 .x = { SN_COORD, -4620, 5140, 105 },
426 .y = { SN_COORD, -150, 6600, 75 },
428 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
434 .x = { SN_COORD, -4750, 5280, 105 },
435 .y = { SN_COORD, -150, 6730, 75 },
437 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
443 .x = { SN_COORD, -4620, 5140, 105 },
444 .y = { SN_COORD, -150, 6600, 75 },
446 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
452 .x = { SN_COORD, -4750, 5280, 105 },
453 .y = { SN_COORD, -150, 6730, 75 },
455 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
461 .x = { SN_COORD, -4750, 5280, 105 },
462 .y = { SN_COORD, -150, 6730, 75 },
464 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
470 .x = { SN_COORD, -4620, 5140, 105 },
471 .y = { SN_COORD, -150, 6600, 75 },
473 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
479 .x = { SN_COORD, -4828, 5345, 105 },
480 .y = { SN_COORD, -203, 6803, 75 },
482 -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 },
534 /* MacbookPro11,1-3 (unibody, June 2013) */
593 int dx_sum; /* x axis cumulative movement */
594 int dy_sum; /* y axis cumulative movement */
595 int dz_sum; /* z axis cumulative movement */
598 int dt_sum; /* T-axis cumulative movement */
599 int rdx; /* x axis remainder of divide by scale_factor */
600 int rdy; /* y axis remainder of divide by scale_factor */
601 int rdz; /* z axis remainder of divide by scale_factor */
676 const struct wsp_dev_params *params = sc->sc_params; in wsp_set_device_mode()
681 if (params->tp == wsp_tp + TYPE3) in wsp_set_device_mode()
684 err = usbd_req_get_report(sc->sc_usb_device, NULL, in wsp_set_device_mode()
685 mode_bytes, params->tp->um_size, params->tp->iface_index, in wsp_set_device_mode()
686 UHID_FEATURE_REPORT, params->tp->um_req_idx); in wsp_set_device_mode()
701 mode_bytes[params->tp->um_switch_idx] = in wsp_set_device_mode()
702 on ? params->tp->um_switch_on : params->tp->um_switch_off; in wsp_set_device_mode()
704 return (usbd_req_set_report(sc->sc_usb_device, NULL, in wsp_set_device_mode()
705 mode_bytes, params->tp->um_size, params->tp->iface_index, in wsp_set_device_mode()
706 UHID_FEATURE_REPORT, params->tp->um_req_idx)); in wsp_set_device_mode()
713 memset(&sc->sc_status, 0, sizeof(sc->sc_status)); in wsp_enable()
714 sc->sc_state |= WSP_ENABLED; in wsp_enable()
723 sc->sc_state &= ~WSP_ENABLED; in wsp_disable()
735 if (uaa->usb_mode != USB_MODE_HOST) in wsp_probe()
740 iface = usbd_get_iface(uaa->device, i); in wsp_probe()
743 id = iface->idesc; in wsp_probe()
745 (id->bInterfaceClass != UICLASS_HID) || in wsp_probe()
746 (id->bInterfaceProtocol != 0 && in wsp_probe()
747 id->bInterfaceProtocol != UIPROTO_MOUSE)) in wsp_probe()
752 if (uaa->info.bIfaceIndex != i) in wsp_probe()
772 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr, in wsp_attach()
773 &d_len, M_TEMP, uaa->info.bIfaceIndex); in wsp_attach()
777 sc->tp_datalen = hid_report_size_max(d_ptr, d_len, hid_input, in wsp_attach()
781 if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) { in wsp_attach()
783 "datalength: %d\n", sc->tp_datalen); in wsp_attach()
790 sc->sc_usb_device = uaa->device; in wsp_attach()
793 sc->sc_params = wsp_dev_params + USB_GET_DRIVER_INFO(uaa); in wsp_attach()
801 * reports to raw sensor data using vendor-specific USB in wsp_attach()
806 * During re-enumeration of the device we need to force the in wsp_attach()
822 mtx_init(&sc->sc_mutex, "wspmtx", NULL, MTX_DEF | MTX_RECURSE); in wsp_attach()
824 err = usbd_transfer_setup(uaa->device, in wsp_attach()
825 &uaa->info.bIfaceIndex, sc->sc_xfer, wsp_config, in wsp_attach()
826 WSP_N_TRANSFER, sc, &sc->sc_mutex); in wsp_attach()
831 if (usb_fifo_attach(sc->sc_usb_device, sc, &sc->sc_mutex, in wsp_attach()
832 &wsp_fifo_methods, &sc->sc_fifo, in wsp_attach()
833 device_get_unit(dev), -1, uaa->info.bIfaceIndex, in wsp_attach()
839 sc->sc_hw.buttons = 3; in wsp_attach()
840 sc->sc_hw.iftype = MOUSE_IF_USB; in wsp_attach()
841 sc->sc_hw.type = MOUSE_PAD; in wsp_attach()
842 sc->sc_hw.model = MOUSE_MODEL_GENERIC; in wsp_attach()
843 sc->sc_mode.protocol = MOUSE_PROTO_MSC; in wsp_attach()
844 sc->sc_mode.rate = -1; in wsp_attach()
845 sc->sc_mode.resolution = MOUSE_RES_UNKNOWN; in wsp_attach()
846 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE; in wsp_attach()
847 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK; in wsp_attach()
848 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC; in wsp_attach()
850 sc->sc_touch = WSP_UNTOUCH; in wsp_attach()
851 sc->scr_mode = WSP_SCR_NONE; in wsp_attach()
854 sc->sc_evdev = evdev_alloc(); in wsp_attach()
855 evdev_set_name(sc->sc_evdev, device_get_desc(dev)); in wsp_attach()
856 evdev_set_phys(sc->sc_evdev, device_get_nameunit(dev)); in wsp_attach()
857 evdev_set_id(sc->sc_evdev, BUS_USB, uaa->info.idVendor, in wsp_attach()
858 uaa->info.idProduct, 0); in wsp_attach()
859 evdev_set_serial(sc->sc_evdev, usb_get_serial(uaa->device)); in wsp_attach()
860 evdev_set_methods(sc->sc_evdev, sc, &wsp_evdev_methods); in wsp_attach()
861 evdev_support_prop(sc->sc_evdev, INPUT_PROP_POINTER); in wsp_attach()
862 evdev_support_event(sc->sc_evdev, EV_SYN); in wsp_attach()
863 evdev_support_event(sc->sc_evdev, EV_ABS); in wsp_attach()
864 evdev_support_event(sc->sc_evdev, EV_KEY); in wsp_attach()
868 ((param).max - (param).min) / (param).snratio, 0, \ in wsp_attach()
869 (param).size != 0 ? ((param).max - (param).min) / (param).size : 0); in wsp_attach()
872 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_X, sc->sc_params->x); in wsp_attach()
873 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_Y, sc->sc_params->y); in wsp_attach()
875 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_PRESSURE, sc->sc_params->p); in wsp_attach()
877 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MAJOR, sc->sc_params->w); in wsp_attach()
878 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MINOR, sc->sc_params->w); in wsp_attach()
880 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MAJOR, sc->sc_params->w); in wsp_attach()
881 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MINOR, sc->sc_params->w); in wsp_attach()
883 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_ORIENTATION, sc->sc_params->o); in wsp_attach()
885 evdev_support_key(sc->sc_evdev, BTN_LEFT); in wsp_attach()
886 if ((sc->sc_params->tp->caps & HAS_INTEGRATED_BUTTON) != 0) in wsp_attach()
887 evdev_support_prop(sc->sc_evdev, INPUT_PROP_BUTTONPAD); in wsp_attach()
889 evdev_support_abs(sc->sc_evdev, ABS_MT_SLOT, in wsp_attach()
890 0, MAX_FINGERS - 1, 0, 0, 0); in wsp_attach()
891 evdev_support_abs(sc->sc_evdev, ABS_MT_TRACKING_ID, in wsp_attach()
892 -1, MAX_FINGERS - 1, 0, 0, 0); in wsp_attach()
893 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_TRACK); in wsp_attach()
894 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_AUTOREL); in wsp_attach()
896 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_STCOMPAT); in wsp_attach()
898 err = evdev_register(sc->sc_evdev); in wsp_attach()
917 mtx_lock(&sc->sc_mutex); in wsp_detach()
918 if (sc->sc_state & WSP_ENABLED) in wsp_detach()
920 mtx_unlock(&sc->sc_mutex); in wsp_detach()
922 usb_fifo_detach(&sc->sc_fifo); in wsp_detach()
925 evdev_free(sc->sc_evdev); in wsp_detach()
928 usbd_transfer_unsetup(sc->sc_xfer, WSP_N_TRANSFER); in wsp_detach()
930 mtx_destroy(&sc->sc_mutex); in wsp_detach()
939 const struct wsp_dev_params *params = sc->sc_params; in wsp_intr_callback()
959 if (sc->dz_count == 0) in wsp_intr_callback()
960 sc->dz_count = WSP_DZ_MAX_COUNT; in wsp_intr_callback()
969 usbd_copy_out(pc, 0, sc->tp_data, len); in wsp_intr_callback()
971 if ((len < params->tp->offset + params->tp->fsize) || in wsp_intr_callback()
972 ((len - params->tp->offset) % params->tp->fsize) != 0) { in wsp_intr_callback()
974 len, sc->tp_data[0], sc->tp_data[1]); in wsp_intr_callback()
978 if (len < sc->tp_datalen) { in wsp_intr_callback()
980 memset(sc->tp_data + len, 0, sc->tp_datalen - len); in wsp_intr_callback()
983 if (params->tp != wsp_tp + TYPE1) { in wsp_intr_callback()
984 ibt = sc->tp_data[params->tp->button]; in wsp_intr_callback()
985 ntouch = sc->tp_data[params->tp->button - 1]; in wsp_intr_callback()
987 ntouch = (len - params->tp->offset) / params->tp->fsize; in wsp_intr_callback()
996 …f = (struct tp_finger *)(sc->tp_data + params->tp->offset + params->tp->delta + i * params->tp->fs… in wsp_intr_callback()
999 f->origin = le16toh((uint16_t)f->origin); in wsp_intr_callback()
1000 f->abs_x = le16toh((uint16_t)f->abs_x); in wsp_intr_callback()
1001 f->abs_y = le16toh((uint16_t)f->abs_y); in wsp_intr_callback()
1002 f->rel_x = le16toh((uint16_t)f->rel_x); in wsp_intr_callback()
1003 f->rel_y = le16toh((uint16_t)f->rel_y); in wsp_intr_callback()
1004 f->tool_major = le16toh((uint16_t)f->tool_major); in wsp_intr_callback()
1005 f->tool_minor = le16toh((uint16_t)f->tool_minor); in wsp_intr_callback()
1006 f->orientation = le16toh((uint16_t)f->orientation); in wsp_intr_callback()
1007 f->touch_major = le16toh((uint16_t)f->touch_major); in wsp_intr_callback()
1008 f->touch_minor = le16toh((uint16_t)f->touch_minor); in wsp_intr_callback()
1009 f->pressure = le16toh((uint16_t)f->pressure); in wsp_intr_callback()
1010 f->multi = le16toh((uint16_t)f->multi); in wsp_intr_callback()
1016 i, ibt, ntouch, f->origin, f->abs_x, f->abs_y, in wsp_intr_callback()
1017 f->rel_x, f->rel_y, f->tool_major, f->tool_minor, f->orientation, in wsp_intr_callback()
1018 f->touch_major, f->touch_minor, f->pressure, f->multi); in wsp_intr_callback()
1019 sc->pos_x[i] = f->abs_x; in wsp_intr_callback()
1020 sc->pos_y[i] = -f->abs_y; in wsp_intr_callback()
1021 sc->index[i] = f; in wsp_intr_callback()
1023 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE && f->touch_major != 0) { in wsp_intr_callback()
1026 .x = f->abs_x, in wsp_intr_callback()
1027 .y = params->y.min + params->y.max - f->abs_y, in wsp_intr_callback()
1028 .p = f->pressure, in wsp_intr_callback()
1029 .maj = f->touch_major << 1, in wsp_intr_callback()
1030 .min = f->touch_minor << 1, in wsp_intr_callback()
1031 .w_maj = f->tool_major << 1, in wsp_intr_callback()
1032 .w_min = f->tool_minor << 1, in wsp_intr_callback()
1033 .ori = params->o.max - f->orientation, in wsp_intr_callback()
1035 evdev_mt_push_slot(sc->sc_evdev, slot, &slot_data); in wsp_intr_callback()
1043 evdev_push_key(sc->sc_evdev, BTN_LEFT, ibt); in wsp_intr_callback()
1044 evdev_sync(sc->sc_evdev); in wsp_intr_callback()
1047 sc->sc_status.flags &= ~MOUSE_POSCHANGED; in wsp_intr_callback()
1048 sc->sc_status.flags &= ~MOUSE_STDBUTTONSCHANGED; in wsp_intr_callback()
1049 sc->sc_status.obutton = sc->sc_status.button; in wsp_intr_callback()
1050 sc->sc_status.button = 0; in wsp_intr_callback()
1053 sc->distance = max(sc->distance, max( in wsp_intr_callback()
1054 abs(sc->pos_x[0] - sc->pos_x[1]), in wsp_intr_callback()
1055 abs(sc->pos_y[0] - sc->pos_y[1]))); in wsp_intr_callback()
1059 if (params->tp->caps & HAS_INTEGRATED_BUTTON) { in wsp_intr_callback()
1062 sc->sc_status.button |= MOUSE_BUTTON1DOWN; in wsp_intr_callback()
1065 if (sc->distance < tun.max_double_tap_distance && abs(sc->dx_sum) < 5 && in wsp_intr_callback()
1066 abs(sc->dy_sum) < 5) in wsp_intr_callback()
1067 sc->sc_status.button |= MOUSE_BUTTON3DOWN; in wsp_intr_callback()
1069 sc->sc_status.button |= MOUSE_BUTTON1DOWN; in wsp_intr_callback()
1072 sc->sc_status.button |= MOUSE_BUTTON2DOWN; in wsp_intr_callback()
1078 sc->sc_status.button |= MOUSE_BUTTON1DOWN; in wsp_intr_callback()
1081 sc->ibtn = 1; in wsp_intr_callback()
1083 sc->intr_count++; in wsp_intr_callback()
1085 if (sc->ntaps < ntouch) { in wsp_intr_callback()
1088 if (sc->index[0]->touch_major > tun.pressure_tap_threshold && in wsp_intr_callback()
1089 sc->index[0]->tool_major <= tun.max_finger_area) in wsp_intr_callback()
1090 sc->ntaps = 1; in wsp_intr_callback()
1093 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-30 && in wsp_intr_callback()
1094 sc->index[1]->touch_major > tun.pressure_tap_threshold-30) in wsp_intr_callback()
1095 sc->ntaps = 2; in wsp_intr_callback()
1098 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-40 && in wsp_intr_callback()
1099 sc->index[1]->touch_major > tun.pressure_tap_threshold-40 && in wsp_intr_callback()
1100 sc->index[2]->touch_major > tun.pressure_tap_threshold-40) in wsp_intr_callback()
1101 sc->ntaps = 3; in wsp_intr_callback()
1108 if (sc->index[0]->touch_major < tun.pressure_untouch_threshold && in wsp_intr_callback()
1109 sc->sc_status.button == 0) { in wsp_intr_callback()
1110 sc->sc_touch = WSP_UNTOUCH; in wsp_intr_callback()
1111 if (sc->intr_count < WSP_TAP_MAX_COUNT && in wsp_intr_callback()
1112 sc->intr_count > WSP_TAP_THRESHOLD && in wsp_intr_callback()
1113 sc->ntaps && sc->ibtn == 0) { in wsp_intr_callback()
1115 * Add a pair of events (button-down and in wsp_intr_callback()
1116 * button-up). in wsp_intr_callback()
1118 switch (sc->ntaps) { in wsp_intr_callback()
1120 if (!(params->tp->caps & HAS_INTEGRATED_BUTTON) || tun.enable_single_tap_clicks) { in wsp_intr_callback()
1127 sc->dx_sum, sc->dy_sum); in wsp_intr_callback()
1128 if (sc->distance < tun.max_double_tap_distance && abs(sc->dx_sum) < 5 && in wsp_intr_callback()
1129 abs(sc->dy_sum) < 5) { in wsp_intr_callback()
1143 if ((sc->dt_sum / tun.scr_hor_threshold) != 0 && in wsp_intr_callback()
1144 sc->ntaps == 2 && sc->scr_mode == WSP_SCR_HOR) { in wsp_intr_callback()
1146 * translate T-axis into button presses in wsp_intr_callback()
1149 if (sc->dt_sum > 0) in wsp_intr_callback()
1151 else if (sc->dt_sum < 0) in wsp_intr_callback()
1154 sc->dz_count = WSP_DZ_MAX_COUNT; in wsp_intr_callback()
1155 sc->dz_sum = 0; in wsp_intr_callback()
1156 sc->intr_count = 0; in wsp_intr_callback()
1157 sc->ibtn = 0; in wsp_intr_callback()
1158 sc->ntaps = 0; in wsp_intr_callback()
1159 sc->finger = 0; in wsp_intr_callback()
1160 sc->distance = 0; in wsp_intr_callback()
1161 sc->dt_sum = 0; in wsp_intr_callback()
1162 sc->dx_sum = 0; in wsp_intr_callback()
1163 sc->dy_sum = 0; in wsp_intr_callback()
1164 sc->rdx = 0; in wsp_intr_callback()
1165 sc->rdy = 0; in wsp_intr_callback()
1166 sc->rdz = 0; in wsp_intr_callback()
1167 sc->scr_mode = WSP_SCR_NONE; in wsp_intr_callback()
1168 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold && in wsp_intr_callback()
1169 sc->sc_touch == WSP_UNTOUCH) { /* ignore first touch */ in wsp_intr_callback()
1170 sc->sc_touch = WSP_FIRST_TOUCH; in wsp_intr_callback()
1171 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold && in wsp_intr_callback()
1172 sc->sc_touch == WSP_FIRST_TOUCH) { /* ignore second touch */ in wsp_intr_callback()
1173 sc->sc_touch = WSP_SECOND_TOUCH; in wsp_intr_callback()
1175 sc->pre_pos_x[0], sc->pre_pos_y[0]); in wsp_intr_callback()
1177 if (sc->sc_touch == WSP_SECOND_TOUCH) in wsp_intr_callback()
1178 sc->sc_touch = WSP_TOUCHING; in wsp_intr_callback()
1181 sc->index[0]->touch_major >= tun.pressure_touch_threshold) { in wsp_intr_callback()
1182 dx = sc->pos_x[0] - sc->pre_pos_x[0]; in wsp_intr_callback()
1183 dy = sc->pos_y[0] - sc->pre_pos_y[0]; in wsp_intr_callback()
1186 if (tun.enable_single_tap_movement != 1 && sc->ibtn != 0 && sc->sc_status.button == 0) in wsp_intr_callback()
1190 if (sc->o_ntouch != ntouch) in wsp_intr_callback()
1194 if (ntouch == 1 && sc->index[0]->tool_major > tun.max_finger_area) in wsp_intr_callback()
1197 if (sc->ibtn != 0 && ntouch == 1 && in wsp_intr_callback()
1198 sc->intr_count < WSP_TAP_MAX_COUNT && in wsp_intr_callback()
1199 abs(sc->dx_sum) < 1 && abs(sc->dy_sum) < 1 ) in wsp_intr_callback()
1202 if (ntouch == 2 && sc->sc_status.button != 0) { in wsp_intr_callback()
1203 dx = sc->pos_x[sc->finger] - sc->pre_pos_x[sc->finger]; in wsp_intr_callback()
1204 dy = sc->pos_y[sc->finger] - sc->pre_pos_y[sc->finger]; in wsp_intr_callback()
1210 if (sc->index[0]->origin == 0 || sc->index[1]->origin == 0 || in wsp_intr_callback()
1211 sc->sc_status.obutton != sc->sc_status.button) { in wsp_intr_callback()
1213 sc->finger = 0; in wsp_intr_callback()
1215 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) < in wsp_intr_callback()
1216 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) && in wsp_intr_callback()
1217 sc->finger == 0) { in wsp_intr_callback()
1218 sc->sc_touch = WSP_SECOND_TOUCH; in wsp_intr_callback()
1220 sc->finger = 1; in wsp_intr_callback()
1222 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) >= in wsp_intr_callback()
1223 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) && in wsp_intr_callback()
1224 sc->finger == 1) { in wsp_intr_callback()
1225 sc->sc_touch = WSP_SECOND_TOUCH; in wsp_intr_callback()
1227 sc->finger = 0; in wsp_intr_callback()
1230 dx, dy, sc->finger); in wsp_intr_callback()
1232 if (sc->dz_count--) { in wsp_intr_callback()
1233 rdz = (dy + sc->rdz) % tun.scale_factor; in wsp_intr_callback()
1234 sc->dz_sum -= (dy + sc->rdz) / tun.scale_factor; in wsp_intr_callback()
1235 sc->rdz = rdz; in wsp_intr_callback()
1237 if ((sc->dz_sum / tun.z_factor) != 0) in wsp_intr_callback()
1238 sc->dz_count = 0; in wsp_intr_callback()
1240 rdx = (dx + sc->rdx) % tun.scale_factor; in wsp_intr_callback()
1241 dx = (dx + sc->rdx) / tun.scale_factor; in wsp_intr_callback()
1242 sc->rdx = rdx; in wsp_intr_callback()
1244 rdy = (dy + sc->rdy) % tun.scale_factor; in wsp_intr_callback()
1245 dy = (dy + sc->rdy) / tun.scale_factor; in wsp_intr_callback()
1246 sc->rdy = rdy; in wsp_intr_callback()
1248 sc->dx_sum += dx; in wsp_intr_callback()
1249 sc->dy_sum += dy; in wsp_intr_callback()
1251 if (ntouch == 2 && sc->sc_status.button == 0) { in wsp_intr_callback()
1252 if (sc->scr_mode == WSP_SCR_NONE && in wsp_intr_callback()
1253 abs(sc->dx_sum) + abs(sc->dy_sum) > tun.scr_hor_threshold) in wsp_intr_callback()
1254 sc->scr_mode = abs(sc->dx_sum) > in wsp_intr_callback()
1255 abs(sc->dy_sum) * 2 ? WSP_SCR_HOR : WSP_SCR_VER; in wsp_intr_callback()
1257 sc->scr_mode, sc->intr_count, sc->dx_sum, sc->dy_sum); in wsp_intr_callback()
1258 if (sc->scr_mode == WSP_SCR_HOR) in wsp_intr_callback()
1259 sc->dt_sum += dx; in wsp_intr_callback()
1261 sc->dt_sum = 0; in wsp_intr_callback()
1264 if (sc->dz_count == 0) in wsp_intr_callback()
1265 dz = (sc->dz_sum / tun.z_factor) * (tun.z_invert ? -1 : 1); in wsp_intr_callback()
1266 if (sc->scr_mode == WSP_SCR_HOR || sc->distance > tun.max_double_tap_distance) in wsp_intr_callback()
1271 if (sc->intr_count < WSP_TAP_MAX_COUNT && in wsp_intr_callback()
1275 sc->intr_count = WSP_TAP_MAX_COUNT; in wsp_intr_callback()
1277 sc->sc_status.flags |= MOUSE_POSCHANGED; in wsp_intr_callback()
1279 dx, dy, dz, sc->sc_touch, sc->sc_status.button); in wsp_intr_callback()
1280 sc->sc_status.dx += dx; in wsp_intr_callback()
1281 sc->sc_status.dy += dy; in wsp_intr_callback()
1282 sc->sc_status.dz += dz; in wsp_intr_callback()
1284 wsp_add_to_queue(sc, dx, -dy, dz, sc->sc_status.button); in wsp_intr_callback()
1285 if (sc->dz_count == 0) { in wsp_intr_callback()
1286 sc->dz_sum = 0; in wsp_intr_callback()
1287 sc->rdz = 0; in wsp_intr_callback()
1290 sc->pre_pos_x[0] = sc->pos_x[0]; in wsp_intr_callback()
1291 sc->pre_pos_y[0] = sc->pos_y[0]; in wsp_intr_callback()
1293 if (ntouch == 2 && sc->sc_status.button != 0) { in wsp_intr_callback()
1294 sc->pre_pos_x[sc->finger] = sc->pos_x[sc->finger]; in wsp_intr_callback()
1295 sc->pre_pos_y[sc->finger] = sc->pos_y[sc->finger]; in wsp_intr_callback()
1297 sc->o_ntouch = ntouch; in wsp_intr_callback()
1303 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) { in wsp_intr_callback()
1305 sc->tp_datalen); in wsp_intr_callback()
1328 dx = imax(dx, -256); in wsp_add_to_queue()
1330 dy = imax(dy, -256); in wsp_add_to_queue()
1332 dz = imax(dz, -128); in wsp_add_to_queue()
1343 buf[0] = sc->sc_mode.syncmask[1]; in wsp_add_to_queue()
1347 buf[3] = dx - (dx >> 1); in wsp_add_to_queue()
1348 buf[4] = dy - (dy >> 1); in wsp_add_to_queue()
1350 if (sc->sc_mode.level == 1) { in wsp_add_to_queue()
1352 buf[6] = dz - (dz >> 1);/* dz - (dz / 2) */ in wsp_add_to_queue()
1355 usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf, in wsp_add_to_queue()
1356 sc->sc_mode.packetsize, 1); in wsp_add_to_queue()
1363 usb_fifo_reset(sc->sc_fifo.fp[USB_FIFO_RX]); in wsp_reset_buf()
1372 rate = sc->sc_pollrate; in wsp_start_read()
1377 if ((rate > 0) && (sc->sc_xfer[WSP_INTR_DT] != NULL)) { in wsp_start_read()
1379 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]); in wsp_start_read()
1381 usbd_xfer_set_interval(sc->sc_xfer[WSP_INTR_DT], 1000 / rate); in wsp_start_read()
1383 sc->sc_pollrate = 0; in wsp_start_read()
1385 usbd_transfer_start(sc->sc_xfer[WSP_INTR_DT]); in wsp_start_read()
1391 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]); in wsp_stop_read()
1402 if (sc->sc_fflags & fflags) in wsp_open()
1411 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0) in wsp_open()
1419 sc->sc_fflags |= fflags & (FREAD | FWRITE); in wsp_open()
1430 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0) in wsp_close()
1436 sc->sc_fflags &= ~(fflags & (FREAD | FWRITE)); in wsp_close()
1453 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0) in wsp_fifo_stop_read()
1465 mtx_lock(&sc->sc_mutex); in wsp_ev_open()
1466 if (sc->sc_fflags == 0) in wsp_ev_open()
1470 sc->sc_state |= WSP_EVDEV_OPENED; in wsp_ev_open()
1472 mtx_unlock(&sc->sc_mutex); in wsp_ev_open()
1482 mtx_lock(&sc->sc_mutex); in wsp_ev_close()
1483 sc->sc_state &= ~WSP_EVDEV_OPENED; in wsp_ev_close()
1484 if (sc->sc_fflags == 0) in wsp_ev_close()
1486 mtx_unlock(&sc->sc_mutex); in wsp_ev_close()
1499 mtx_lock(&sc->sc_mutex); in wsp_ioctl()
1503 *(mousehw_t *)addr = sc->sc_hw; in wsp_ioctl()
1506 *(mousemode_t *)addr = sc->sc_mode; in wsp_ioctl()
1511 if (mode.level == -1) in wsp_ioctl()
1518 sc->sc_mode.level = mode.level; in wsp_ioctl()
1519 sc->sc_pollrate = mode.rate; in wsp_ioctl()
1520 sc->sc_hw.buttons = 3; in wsp_ioctl()
1522 if (sc->sc_mode.level == 0) { in wsp_ioctl()
1523 sc->sc_mode.protocol = MOUSE_PROTO_MSC; in wsp_ioctl()
1524 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE; in wsp_ioctl()
1525 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK; in wsp_ioctl()
1526 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC; in wsp_ioctl()
1527 } else if (sc->sc_mode.level == 1) { in wsp_ioctl()
1528 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE; in wsp_ioctl()
1529 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE; in wsp_ioctl()
1530 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK; in wsp_ioctl()
1531 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC; in wsp_ioctl()
1536 *(int *)addr = sc->sc_mode.level; in wsp_ioctl()
1543 sc->sc_mode.level = *(int *)addr; in wsp_ioctl()
1544 sc->sc_hw.buttons = 3; in wsp_ioctl()
1546 if (sc->sc_mode.level == 0) { in wsp_ioctl()
1547 sc->sc_mode.protocol = MOUSE_PROTO_MSC; in wsp_ioctl()
1548 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE; in wsp_ioctl()
1549 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK; in wsp_ioctl()
1550 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC; in wsp_ioctl()
1551 } else if (sc->sc_mode.level == 1) { in wsp_ioctl()
1552 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE; in wsp_ioctl()
1553 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE; in wsp_ioctl()
1554 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK; in wsp_ioctl()
1555 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC; in wsp_ioctl()
1562 *status = sc->sc_status; in wsp_ioctl()
1563 sc->sc_status.obutton = sc->sc_status.button; in wsp_ioctl()
1564 sc->sc_status.button = 0; in wsp_ioctl()
1565 sc->sc_status.dx = 0; in wsp_ioctl()
1566 sc->sc_status.dy = 0; in wsp_ioctl()
1567 sc->sc_status.dz = 0; in wsp_ioctl()
1569 if (status->dx || status->dy || status->dz) in wsp_ioctl()
1570 status->flags |= MOUSE_POSCHANGED; in wsp_ioctl()
1571 if (status->button != status->obutton) in wsp_ioctl()
1572 status->flags |= MOUSE_BUTTONSCHANGED; in wsp_ioctl()
1580 mtx_unlock(&sc->sc_mutex); in wsp_ioctl()