Lines Matching +full:x +full:- +full:axis

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
69 #define WSP_CLAMP(x,low,high) do { \
70 if ((x) < (low)) \
71 (x) = (low); \
72 else if ((x) > (high)) \
73 (x) = (high); \
124 WSP_CLAMP(ptun->scale_factor, 1, 63);
125 WSP_CLAMP(ptun->z_factor, 1, 63);
126 WSP_CLAMP(ptun->z_invert, 0, 1);
127 WSP_CLAMP(ptun->pressure_touch_threshold, 1, 255);
128 WSP_CLAMP(ptun->pressure_untouch_threshold, 1, 255);
129 WSP_CLAMP(ptun->pressure_tap_threshold, 1, 255);
130 WSP_CLAMP(ptun->max_finger_area, 1, 2400);
131 WSP_CLAMP(ptun->max_double_tap_distance, 1, 16384);
132 WSP_CLAMP(ptun->scr_hor_threshold, 1, 255);
133 WSP_CLAMP(ptun->enable_single_tap_clicks, 0, 1);
134 WSP_CLAMP(ptun->enable_single_tap_movement, 0, 1);
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 */
197 /* trackpad finger data offsets, le16-aligned */
278 /* trackpad finger header - little endian */
293 /* trackpad finger structure - little endian */
296 int16_t abs_x; /* absolute x coodinate */
298 int16_t rel_x; /* relative x 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 */
355 struct wsp_param x; /* horizontal limits */
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;
681 if (params->tp == wsp_tp + TYPE3)
684 err = usbd_req_get_report(sc->sc_usb_device, NULL,
685 mode_bytes, params->tp->um_size, params->tp->iface_index,
686 UHID_FEATURE_REPORT, params->tp->um_req_idx);
701 mode_bytes[params->tp->um_switch_idx] =
702 on ? params->tp->um_switch_on : params->tp->um_switch_off;
704 return (usbd_req_set_report(sc->sc_usb_device, NULL,
705 mode_bytes, params->tp->um_size, params->tp->iface_index,
706 UHID_FEATURE_REPORT, params->tp->um_req_idx));
713 memset(&sc->sc_status, 0, sizeof(sc->sc_status));
714 sc->sc_state |= WSP_ENABLED;
723 sc->sc_state &= ~WSP_ENABLED;
735 if (uaa->usb_mode != USB_MODE_HOST)
740 iface = usbd_get_iface(uaa->device, i);
743 id = iface->idesc;
745 (id->bInterfaceClass != UICLASS_HID) ||
746 (id->bInterfaceProtocol != 0 &&
747 id->bInterfaceProtocol != UIPROTO_MOUSE))
752 if (uaa->info.bIfaceIndex != i)
772 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr,
773 &d_len, M_TEMP, uaa->info.bIfaceIndex);
777 sc->tp_datalen = hid_report_size_max(d_ptr, d_len, hid_input,
781 if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
783 "datalength: %d\n", sc->tp_datalen);
790 sc->sc_usb_device = uaa->device;
793 sc->sc_params = wsp_dev_params + USB_GET_DRIVER_INFO(uaa);
801 * reports to raw sensor data using vendor-specific USB
806 * During re-enumeration of the device we need to force the
822 mtx_init(&sc->sc_mutex, "wspmtx", NULL, MTX_DEF | MTX_RECURSE);
824 err = usbd_transfer_setup(uaa->device,
825 &uaa->info.bIfaceIndex, sc->sc_xfer, wsp_config,
826 WSP_N_TRANSFER, sc, &sc->sc_mutex);
831 if (usb_fifo_attach(sc->sc_usb_device, sc, &sc->sc_mutex,
832 &wsp_fifo_methods, &sc->sc_fifo,
833 device_get_unit(dev), -1, uaa->info.bIfaceIndex,
839 sc->sc_hw.buttons = 3;
840 sc->sc_hw.iftype = MOUSE_IF_USB;
841 sc->sc_hw.type = MOUSE_PAD;
842 sc->sc_hw.model = MOUSE_MODEL_GENERIC;
843 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
844 sc->sc_mode.rate = -1;
845 sc->sc_mode.resolution = MOUSE_RES_UNKNOWN;
846 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
847 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
848 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
850 sc->sc_touch = WSP_UNTOUCH;
851 sc->scr_mode = WSP_SCR_NONE;
854 sc->sc_evdev = evdev_alloc();
855 evdev_set_name(sc->sc_evdev, device_get_desc(dev));
856 evdev_set_phys(sc->sc_evdev, device_get_nameunit(dev));
857 evdev_set_id(sc->sc_evdev, BUS_USB, uaa->info.idVendor,
858 uaa->info.idProduct, 0);
859 evdev_set_serial(sc->sc_evdev, usb_get_serial(uaa->device));
860 evdev_set_methods(sc->sc_evdev, sc, &wsp_evdev_methods);
861 evdev_support_prop(sc->sc_evdev, INPUT_PROP_POINTER);
862 evdev_support_event(sc->sc_evdev, EV_SYN);
863 evdev_support_event(sc->sc_evdev, EV_ABS);
864 evdev_support_event(sc->sc_evdev, EV_KEY);
868 ((param).max - (param).min) / (param).snratio, 0, \
869 (param).size != 0 ? ((param).max - (param).min) / (param).size : 0);
872 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_X, sc->sc_params->x);
873 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_POSITION_Y, sc->sc_params->y);
875 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_PRESSURE, sc->sc_params->p);
877 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MAJOR, sc->sc_params->w);
878 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_TOUCH_MINOR, sc->sc_params->w);
880 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MAJOR, sc->sc_params->w);
881 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_WIDTH_MINOR, sc->sc_params->w);
883 WSP_SUPPORT_ABS(sc->sc_evdev, ABS_MT_ORIENTATION, sc->sc_params->o);
885 evdev_support_key(sc->sc_evdev, BTN_LEFT);
886 if ((sc->sc_params->tp->caps & HAS_INTEGRATED_BUTTON) != 0)
887 evdev_support_prop(sc->sc_evdev, INPUT_PROP_BUTTONPAD);
889 evdev_support_abs(sc->sc_evdev, ABS_MT_SLOT,
890 0, MAX_FINGERS - 1, 0, 0, 0);
891 evdev_support_abs(sc->sc_evdev, ABS_MT_TRACKING_ID,
892 -1, MAX_FINGERS - 1, 0, 0, 0);
893 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_TRACK);
894 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_AUTOREL);
896 evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_STCOMPAT);
898 err = evdev_register(sc->sc_evdev);
917 mtx_lock(&sc->sc_mutex);
918 if (sc->sc_state & WSP_ENABLED)
920 mtx_unlock(&sc->sc_mutex);
922 usb_fifo_detach(&sc->sc_fifo);
925 evdev_free(sc->sc_evdev);
928 usbd_transfer_unsetup(sc->sc_xfer, WSP_N_TRANSFER);
930 mtx_destroy(&sc->sc_mutex);
939 const struct wsp_dev_params *params = sc->sc_params;
959 if (sc->dz_count == 0)
960 sc->dz_count = WSP_DZ_MAX_COUNT;
969 usbd_copy_out(pc, 0, sc->tp_data, len);
971 if ((len < params->tp->offset + params->tp->fsize) ||
972 ((len - params->tp->offset) % params->tp->fsize) != 0) {
973 DPRINTFN(WSP_LLEVEL_INFO, "Invalid length: %d, %x, %x\n",
974 len, sc->tp_data[0], sc->tp_data[1]);
978 if (len < sc->tp_datalen) {
980 memset(sc->tp_data + len, 0, sc->tp_datalen - len);
983 if (params->tp != wsp_tp + TYPE1) {
984 ibt = sc->tp_data[params->tp->button];
985 ntouch = sc->tp_data[params->tp->button - 1];
987 ntouch = (len - params->tp->offset) / params->tp->fsize;
996 f = (struct tp_finger *)(sc->tp_data + params->tp->offset + params->tp->delta + i * params->tp->fsize);
999 f->origin = le16toh((uint16_t)f->origin);
1000 f->abs_x = le16toh((uint16_t)f->abs_x);
1001 f->abs_y = le16toh((uint16_t)f->abs_y);
1002 f->rel_x = le16toh((uint16_t)f->rel_x);
1003 f->rel_y = le16toh((uint16_t)f->rel_y);
1004 f->tool_major = le16toh((uint16_t)f->tool_major);
1005 f->tool_minor = le16toh((uint16_t)f->tool_minor);
1006 f->orientation = le16toh((uint16_t)f->orientation);
1007 f->touch_major = le16toh((uint16_t)f->touch_major);
1008 f->touch_minor = le16toh((uint16_t)f->touch_minor);
1009 f->pressure = le16toh((uint16_t)f->pressure);
1010 f->multi = le16toh((uint16_t)f->multi);
1014 "rx=%5d, ry=%5d, tlmaj=%4d, tlmin=%4d, ot=%4x, "
1015 "tchmaj=%4d, tchmin=%4d, presure=%4d, m=%4x\n",
1016 i, ibt, ntouch, f->origin, f->abs_x, f->abs_y,
1017 f->rel_x, f->rel_y, f->tool_major, f->tool_minor, f->orientation,
1018 f->touch_major, f->touch_minor, f->pressure, f->multi);
1019 sc->pos_x[i] = f->abs_x;
1020 sc->pos_y[i] = -f->abs_y;
1021 sc->index[i] = f;
1023 if (evdev_rcpt_mask & EVDEV_RCPT_HW_MOUSE && f->touch_major != 0) {
1026 .x = f->abs_x,
1027 .y = params->y.min + params->y.max - f->abs_y,
1028 .p = f->pressure,
1029 .maj = f->touch_major << 1,
1030 .min = f->touch_minor << 1,
1031 .w_maj = f->tool_major << 1,
1032 .w_min = f->tool_minor << 1,
1033 .ori = params->o.max - f->orientation,
1035 evdev_mt_push_slot(sc->sc_evdev, slot, &slot_data);
1043 evdev_push_key(sc->sc_evdev, BTN_LEFT, ibt);
1044 evdev_sync(sc->sc_evdev);
1047 sc->sc_status.flags &= ~MOUSE_POSCHANGED;
1048 sc->sc_status.flags &= ~MOUSE_STDBUTTONSCHANGED;
1049 sc->sc_status.obutton = sc->sc_status.button;
1050 sc->sc_status.button = 0;
1053 sc->distance = max(sc->distance, max(
1054 abs(sc->pos_x[0] - sc->pos_x[1]),
1055 abs(sc->pos_y[0] - sc->pos_y[1])));
1059 if (params->tp->caps & HAS_INTEGRATED_BUTTON) {
1062 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
1065 if (sc->distance < tun.max_double_tap_distance && abs(sc->dx_sum) < 5 &&
1066 abs(sc->dy_sum) < 5)
1067 sc->sc_status.button |= MOUSE_BUTTON3DOWN;
1069 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
1072 sc->sc_status.button |= MOUSE_BUTTON2DOWN;
1078 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
1081 sc->ibtn = 1;
1083 sc->intr_count++;
1085 if (sc->ntaps < ntouch) {
1088 if (sc->index[0]->touch_major > tun.pressure_tap_threshold &&
1089 sc->index[0]->tool_major <= tun.max_finger_area)
1090 sc->ntaps = 1;
1093 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-30 &&
1094 sc->index[1]->touch_major > tun.pressure_tap_threshold-30)
1095 sc->ntaps = 2;
1098 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-40 &&
1099 sc->index[1]->touch_major > tun.pressure_tap_threshold-40 &&
1100 sc->index[2]->touch_major > tun.pressure_tap_threshold-40)
1101 sc->ntaps = 3;
1108 if (sc->index[0]->touch_major < tun.pressure_untouch_threshold &&
1109 sc->sc_status.button == 0) {
1110 sc->sc_touch = WSP_UNTOUCH;
1111 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1112 sc->intr_count > WSP_TAP_THRESHOLD &&
1113 sc->ntaps && sc->ibtn == 0) {
1115 * Add a pair of events (button-down and
1116 * button-up).
1118 switch (sc->ntaps) {
1120 if (!(params->tp->caps & HAS_INTEGRATED_BUTTON) || tun.enable_single_tap_clicks) {
1127 sc->dx_sum, sc->dy_sum);
1128 if (sc->distance < tun.max_double_tap_distance && abs(sc->dx_sum) < 5 &&
1129 abs(sc->dy_sum) < 5) {
1143 if ((sc->dt_sum / tun.scr_hor_threshold) != 0 &&
1144 sc->ntaps == 2 && sc->scr_mode == WSP_SCR_HOR) {
1146 * translate T-axis into button presses
1149 if (sc->dt_sum > 0)
1151 else if (sc->dt_sum < 0)
1154 sc->dz_count = WSP_DZ_MAX_COUNT;
1155 sc->dz_sum = 0;
1156 sc->intr_count = 0;
1157 sc->ibtn = 0;
1158 sc->ntaps = 0;
1159 sc->finger = 0;
1160 sc->distance = 0;
1161 sc->dt_sum = 0;
1162 sc->dx_sum = 0;
1163 sc->dy_sum = 0;
1164 sc->rdx = 0;
1165 sc->rdy = 0;
1166 sc->rdz = 0;
1167 sc->scr_mode = WSP_SCR_NONE;
1168 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1169 sc->sc_touch == WSP_UNTOUCH) { /* ignore first touch */
1170 sc->sc_touch = WSP_FIRST_TOUCH;
1171 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1172 sc->sc_touch == WSP_FIRST_TOUCH) { /* ignore second touch */
1173 sc->sc_touch = WSP_SECOND_TOUCH;
1175 sc->pre_pos_x[0], sc->pre_pos_y[0]);
1177 if (sc->sc_touch == WSP_SECOND_TOUCH)
1178 sc->sc_touch = WSP_TOUCHING;
1181 sc->index[0]->touch_major >= tun.pressure_touch_threshold) {
1182 dx = sc->pos_x[0] - sc->pre_pos_x[0];
1183 dy = sc->pos_y[0] - sc->pre_pos_y[0];
1186 if (tun.enable_single_tap_movement != 1 && sc->ibtn != 0 && sc->sc_status.button == 0)
1190 if (sc->o_ntouch != ntouch)
1194 if (ntouch == 1 && sc->index[0]->tool_major > tun.max_finger_area)
1197 if (sc->ibtn != 0 && ntouch == 1 &&
1198 sc->intr_count < WSP_TAP_MAX_COUNT &&
1199 abs(sc->dx_sum) < 1 && abs(sc->dy_sum) < 1 )
1202 if (ntouch == 2 && sc->sc_status.button != 0) {
1203 dx = sc->pos_x[sc->finger] - sc->pre_pos_x[sc->finger];
1204 dy = sc->pos_y[sc->finger] - sc->pre_pos_y[sc->finger];
1210 if (sc->index[0]->origin == 0 || sc->index[1]->origin == 0 ||
1211 sc->sc_status.obutton != sc->sc_status.button) {
1213 sc->finger = 0;
1215 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) <
1216 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1217 sc->finger == 0) {
1218 sc->sc_touch = WSP_SECOND_TOUCH;
1220 sc->finger = 1;
1222 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) >=
1223 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1224 sc->finger == 1) {
1225 sc->sc_touch = WSP_SECOND_TOUCH;
1227 sc->finger = 0;
1230 dx, dy, sc->finger);
1232 if (sc->dz_count--) {
1233 rdz = (dy + sc->rdz) % tun.scale_factor;
1234 sc->dz_sum -= (dy + sc->rdz) / tun.scale_factor;
1235 sc->rdz = rdz;
1237 if ((sc->dz_sum / tun.z_factor) != 0)
1238 sc->dz_count = 0;
1240 rdx = (dx + sc->rdx) % tun.scale_factor;
1241 dx = (dx + sc->rdx) / tun.scale_factor;
1242 sc->rdx = rdx;
1244 rdy = (dy + sc->rdy) % tun.scale_factor;
1245 dy = (dy + sc->rdy) / tun.scale_factor;
1246 sc->rdy = rdy;
1248 sc->dx_sum += dx;
1249 sc->dy_sum += dy;
1251 if (ntouch == 2 && sc->sc_status.button == 0) {
1252 if (sc->scr_mode == WSP_SCR_NONE &&
1253 abs(sc->dx_sum) + abs(sc->dy_sum) > tun.scr_hor_threshold)
1254 sc->scr_mode = abs(sc->dx_sum) >
1255 abs(sc->dy_sum) * 2 ? WSP_SCR_HOR : WSP_SCR_VER;
1257 sc->scr_mode, sc->intr_count, sc->dx_sum, sc->dy_sum);
1258 if (sc->scr_mode == WSP_SCR_HOR)
1259 sc->dt_sum += dx;
1261 sc->dt_sum = 0;
1264 if (sc->dz_count == 0)
1265 dz = (sc->dz_sum / tun.z_factor) * (tun.z_invert ? -1 : 1);
1266 if (sc->scr_mode == WSP_SCR_HOR || sc->distance > tun.max_double_tap_distance)
1271 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1275 sc->intr_count = WSP_TAP_MAX_COUNT;
1277 sc->sc_status.flags |= MOUSE_POSCHANGED;
1278 DPRINTFN(WSP_LLEVEL_INFO, "dx=%5d, dy=%5d, dz=%5d, sc_touch=%x, btn=%x\n",
1279 dx, dy, dz, sc->sc_touch, sc->sc_status.button);
1280 sc->sc_status.dx += dx;
1281 sc->sc_status.dy += dy;
1282 sc->sc_status.dz += dz;
1284 wsp_add_to_queue(sc, dx, -dy, dz, sc->sc_status.button);
1285 if (sc->dz_count == 0) {
1286 sc->dz_sum = 0;
1287 sc->rdz = 0;
1290 sc->pre_pos_x[0] = sc->pos_x[0];
1291 sc->pre_pos_y[0] = sc->pos_y[0];
1293 if (ntouch == 2 && sc->sc_status.button != 0) {
1294 sc->pre_pos_x[sc->finger] = sc->pos_x[sc->finger];
1295 sc->pre_pos_y[sc->finger] = sc->pos_y[sc->finger];
1297 sc->o_ntouch = ntouch;
1303 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
1305 sc->tp_datalen);
1328 dx = imax(dx, -256);
1330 dy = imax(dy, -256);
1332 dz = imax(dz, -128);
1343 buf[0] = sc->sc_mode.syncmask[1];
1347 buf[3] = dx - (dx >> 1);
1348 buf[4] = dy - (dy >> 1);
1350 if (sc->sc_mode.level == 1) {
1352 buf[6] = dz - (dz >> 1);/* dz - (dz / 2) */
1355 usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf,
1356 sc->sc_mode.packetsize, 1);
1363 usb_fifo_reset(sc->sc_fifo.fp[USB_FIFO_RX]);
1372 rate = sc->sc_pollrate;
1377 if ((rate > 0) && (sc->sc_xfer[WSP_INTR_DT] != NULL)) {
1379 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1381 usbd_xfer_set_interval(sc->sc_xfer[WSP_INTR_DT], 1000 / rate);
1383 sc->sc_pollrate = 0;
1385 usbd_transfer_start(sc->sc_xfer[WSP_INTR_DT]);
1391 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1402 if (sc->sc_fflags & fflags)
1411 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1419 sc->sc_fflags |= fflags & (FREAD | FWRITE);
1430 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1436 sc->sc_fflags &= ~(fflags & (FREAD | FWRITE));
1453 if ((sc->sc_state & WSP_EVDEV_OPENED) == 0)
1465 mtx_lock(&sc->sc_mutex);
1466 if (sc->sc_fflags == 0)
1470 sc->sc_state |= WSP_EVDEV_OPENED;
1472 mtx_unlock(&sc->sc_mutex);
1482 mtx_lock(&sc->sc_mutex);
1483 sc->sc_state &= ~WSP_EVDEV_OPENED;
1484 if (sc->sc_fflags == 0)
1486 mtx_unlock(&sc->sc_mutex);
1499 mtx_lock(&sc->sc_mutex);
1503 *(mousehw_t *)addr = sc->sc_hw;
1506 *(mousemode_t *)addr = sc->sc_mode;
1511 if (mode.level == -1)
1518 sc->sc_mode.level = mode.level;
1519 sc->sc_pollrate = mode.rate;
1520 sc->sc_hw.buttons = 3;
1522 if (sc->sc_mode.level == 0) {
1523 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1524 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1525 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1526 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1527 } else if (sc->sc_mode.level == 1) {
1528 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1529 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1530 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1531 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1536 *(int *)addr = sc->sc_mode.level;
1543 sc->sc_mode.level = *(int *)addr;
1544 sc->sc_hw.buttons = 3;
1546 if (sc->sc_mode.level == 0) {
1547 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1548 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1549 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1550 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1551 } else if (sc->sc_mode.level == 1) {
1552 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1553 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1554 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1555 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1562 *status = sc->sc_status;
1563 sc->sc_status.obutton = sc->sc_status.button;
1564 sc->sc_status.button = 0;
1565 sc->sc_status.dx = 0;
1566 sc->sc_status.dy = 0;
1567 sc->sc_status.dz = 0;
1569 if (status->dx || status->dy || status->dz)
1570 status->flags |= MOUSE_POSCHANGED;
1571 if (status->button != status->obutton)
1572 status->flags |= MOUSE_BUTTONSCHANGED;
1580 mtx_unlock(&sc->sc_mutex);