Lines Matching refs:sc

606 static int wsp_enable(struct wsp_softc *sc);
607 static void wsp_disable(struct wsp_softc *sc);
610 static void wsp_reset_buf(struct wsp_softc *sc);
634 wsp_set_device_mode(struct wsp_softc *sc, uint8_t on)
636 const struct wsp_dev_params *params = sc->sc_params;
644 err = usbd_req_get_report(sc->sc_usb_device, NULL,
664 return (usbd_req_set_report(sc->sc_usb_device, NULL,
670 wsp_enable(struct wsp_softc *sc)
673 memset(&sc->sc_status, 0, sizeof(sc->sc_status));
674 sc->sc_state |= WSP_ENABLED;
681 wsp_disable(struct wsp_softc *sc)
683 sc->sc_state &= ~WSP_ENABLED;
720 struct wsp_softc *sc = device_get_softc(dev);
726 DPRINTFN(WSP_LLEVEL_INFO, "sc=%p\n", sc);
734 sc->tp_datalen = hid_report_size(d_ptr, d_len, hid_input, NULL);
737 if (sc->tp_datalen <= 0 || sc->tp_datalen > WSP_BUFFER_MAX) {
739 "datalength: %d\n", sc->tp_datalen);
746 sc->sc_usb_device = uaa->device;
749 sc->sc_params = wsp_dev_params + USB_GET_DRIVER_INFO(uaa);
766 err = wsp_set_device_mode(sc, 0);
772 err = wsp_set_device_mode(sc, 1);
778 mtx_init(&sc->sc_mutex, "wspmtx", NULL, MTX_DEF | MTX_RECURSE);
781 &uaa->info.bIfaceIndex, sc->sc_xfer, wsp_config,
782 WSP_N_TRANSFER, sc, &sc->sc_mutex);
787 if (usb_fifo_attach(sc->sc_usb_device, sc, &sc->sc_mutex,
788 &wsp_fifo_methods, &sc->sc_fifo,
795 sc->sc_hw.buttons = 3;
796 sc->sc_hw.iftype = MOUSE_IF_USB;
797 sc->sc_hw.type = MOUSE_PAD;
798 sc->sc_hw.model = MOUSE_MODEL_GENERIC;
799 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
800 sc->sc_mode.rate = -1;
801 sc->sc_mode.resolution = MOUSE_RES_UNKNOWN;
802 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
803 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
804 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
806 sc->sc_touch = WSP_UNTOUCH;
807 sc->scr_mode = WSP_SCR_NONE;
819 struct wsp_softc *sc = device_get_softc(dev);
821 (void) wsp_set_device_mode(sc, 0);
823 mtx_lock(&sc->sc_mutex);
824 if (sc->sc_state & WSP_ENABLED)
825 wsp_disable(sc);
826 mtx_unlock(&sc->sc_mutex);
828 usb_fifo_detach(&sc->sc_fifo);
830 usbd_transfer_unsetup(sc->sc_xfer, WSP_N_TRANSFER);
832 mtx_destroy(&sc->sc_mutex);
840 struct wsp_softc *sc = usbd_xfer_softc(xfer);
841 const struct wsp_dev_params *params = sc->sc_params;
859 if (sc->dz_count == 0)
860 sc->dz_count = WSP_DZ_MAX_COUNT;
869 usbd_copy_out(pc, 0, sc->tp_data, len);
874 len, sc->tp_data[0], sc->tp_data[1]);
878 if (len < sc->tp_datalen) {
880 memset(sc->tp_data + len, 0, sc->tp_datalen - len);
883 h = (struct tp_header *)(sc->tp_data);
886 ibt = sc->tp_data[params->tp_button];
887 ntouch = sc->tp_data[params->tp_button - 1];
896 f = (struct tp_finger *)(sc->tp_data + params->tp_offset + params->tp_delta + i * params->tp_fsize);
919 sc->pos_x[i] = f->abs_x;
920 sc->pos_y[i] = -f->abs_y;
921 sc->index[i] = f;
924 sc->sc_status.flags &= ~MOUSE_POSCHANGED;
925 sc->sc_status.flags &= ~MOUSE_STDBUTTONSCHANGED;
926 sc->sc_status.obutton = sc->sc_status.button;
927 sc->sc_status.button = 0;
931 sc->sc_status.button |= MOUSE_BUTTON3DOWN;
933 sc->sc_status.button |= MOUSE_BUTTON2DOWN;
935 sc->sc_status.button |= MOUSE_BUTTON1DOWN;
936 sc->ibtn = 1;
938 sc->intr_count++;
940 if (sc->ntaps < ntouch) {
943 if (sc->index[0]->touch_major > tun.pressure_tap_threshold &&
944 sc->index[0]->tool_major <= 1200)
945 sc->ntaps = 1;
948 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-30 &&
949 sc->index[1]->touch_major > tun.pressure_tap_threshold-30)
950 sc->ntaps = 2;
953 if (sc->index[0]->touch_major > tun.pressure_tap_threshold-40 &&
954 sc->index[1]->touch_major > tun.pressure_tap_threshold-40 &&
955 sc->index[2]->touch_major > tun.pressure_tap_threshold-40)
956 sc->ntaps = 3;
963 sc->distance = max(sc->distance, max(
964 abs(sc->pos_x[0] - sc->pos_x[1]),
965 abs(sc->pos_y[0] - sc->pos_y[1])));
967 if (sc->index[0]->touch_major < tun.pressure_untouch_threshold &&
968 sc->sc_status.button == 0) {
969 sc->sc_touch = WSP_UNTOUCH;
970 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
971 sc->intr_count > WSP_TAP_THRESHOLD &&
972 sc->ntaps && sc->ibtn == 0) {
977 switch (sc->ntaps) {
980 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON1DOWN);
986 sc->dx_sum, sc->dy_sum);
987 if (sc->distance < MAX_DISTANCE && abs(sc->dx_sum) < 5 &&
988 abs(sc->dy_sum) < 5) {
989 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON3DOWN);
994 wsp_add_to_queue(sc, 0, 0, 0, MOUSE_BUTTON2DOWN);
1000 wsp_add_to_queue(sc, 0, 0, 0, 0); /* button release */
1002 if ((sc->dt_sum / tun.scr_hor_threshold) != 0 &&
1003 sc->ntaps == 2 && sc->scr_mode == WSP_SCR_HOR) {
1009 if (sc->dt_sum > 0)
1010 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 3);
1011 else if (sc->dt_sum < 0)
1012 wsp_add_to_queue(sc, 0, 0, 0, 1UL << 4);
1014 sc->dz_count = WSP_DZ_MAX_COUNT;
1015 sc->dz_sum = 0;
1016 sc->intr_count = 0;
1017 sc->ibtn = 0;
1018 sc->ntaps = 0;
1019 sc->finger = 0;
1020 sc->distance = 0;
1021 sc->dt_sum = 0;
1022 sc->dx_sum = 0;
1023 sc->dy_sum = 0;
1024 sc->rdx = 0;
1025 sc->rdy = 0;
1026 sc->rdz = 0;
1027 sc->scr_mode = WSP_SCR_NONE;
1028 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1029 sc->sc_touch == WSP_UNTOUCH) { /* ignore first touch */
1030 sc->sc_touch = WSP_FIRST_TOUCH;
1031 } else if (sc->index[0]->touch_major >= tun.pressure_touch_threshold &&
1032 sc->sc_touch == WSP_FIRST_TOUCH) { /* ignore second touch */
1033 sc->sc_touch = WSP_SECOND_TOUCH;
1035 sc->pre_pos_x, sc->pre_pos_y);
1037 if (sc->sc_touch == WSP_SECOND_TOUCH)
1038 sc->sc_touch = WSP_TOUCHING;
1041 sc->index[0]->touch_major >= tun.pressure_touch_threshold) {
1042 dx = sc->pos_x[0] - sc->pre_pos_x;
1043 dy = sc->pos_y[0] - sc->pre_pos_y;
1046 if (sc->ibtn != 0 && sc->sc_status.button == 0)
1050 if (sc->o_ntouch != ntouch)
1054 if (ntouch == 1 && sc->index[0]->tool_major > 1200)
1057 if (sc->ibtn != 0 && ntouch == 1 &&
1058 sc->intr_count < WSP_TAP_MAX_COUNT &&
1059 abs(sc->dx_sum) < 1 && abs(sc->dy_sum) < 1 )
1062 if (ntouch == 2 && sc->sc_status.button != 0) {
1063 dx = sc->pos_x[sc->finger] - sc->pre_pos_x;
1064 dy = sc->pos_y[sc->finger] - sc->pre_pos_y;
1070 if (sc->index[0]->origin == 0 || sc->index[1]->origin == 0 ||
1071 sc->sc_status.obutton != sc->sc_status.button) {
1073 sc->finger = 0;
1075 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) <
1076 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1077 sc->finger == 0) {
1078 sc->sc_touch = WSP_SECOND_TOUCH;
1080 sc->finger = 1;
1082 if ((abs(sc->index[0]->rel_x) + abs(sc->index[0]->rel_y)) >=
1083 (abs(sc->index[1]->rel_x) + abs(sc->index[1]->rel_y)) &&
1084 sc->finger == 1) {
1085 sc->sc_touch = WSP_SECOND_TOUCH;
1087 sc->finger = 0;
1090 dx, dy, sc->finger);
1092 if (sc->dz_count--) {
1093 rdz = (dy + sc->rdz) % tun.scale_factor;
1094 sc->dz_sum -= (dy + sc->rdz) / tun.scale_factor;
1095 sc->rdz = rdz;
1097 if ((sc->dz_sum / tun.z_factor) != 0)
1098 sc->dz_count = 0;
1100 rdx = (dx + sc->rdx) % tun.scale_factor;
1101 dx = (dx + sc->rdx) / tun.scale_factor;
1102 sc->rdx = rdx;
1104 rdy = (dy + sc->rdy) % tun.scale_factor;
1105 dy = (dy + sc->rdy) / tun.scale_factor;
1106 sc->rdy = rdy;
1108 sc->dx_sum += dx;
1109 sc->dy_sum += dy;
1111 if (ntouch == 2 && sc->sc_status.button == 0) {
1112 if (sc->scr_mode == WSP_SCR_NONE &&
1113 abs(sc->dx_sum) + abs(sc->dy_sum) > tun.scr_hor_threshold)
1114 sc->scr_mode = abs(sc->dx_sum) >
1115 abs(sc->dy_sum) * 2 ? WSP_SCR_HOR : WSP_SCR_VER;
1117 sc->scr_mode, sc->intr_count, sc->dx_sum, sc->dy_sum);
1118 if (sc->scr_mode == WSP_SCR_HOR)
1119 sc->dt_sum += dx;
1121 sc->dt_sum = 0;
1124 if (sc->dz_count == 0)
1125 dz = sc->dz_sum / tun.z_factor;
1126 if (sc->scr_mode == WSP_SCR_HOR ||
1127 abs(sc->pos_x[0] - sc->pos_x[1]) > MAX_DISTANCE ||
1128 abs(sc->pos_y[0] - sc->pos_y[1]) > MAX_DISTANCE)
1133 if (sc->intr_count < WSP_TAP_MAX_COUNT &&
1137 sc->intr_count = WSP_TAP_MAX_COUNT;
1139 sc->sc_status.flags |= MOUSE_POSCHANGED;
1141 dx, dy, dz, sc->sc_touch, sc->sc_status.button);
1142 sc->sc_status.dx += dx;
1143 sc->sc_status.dy += dy;
1144 sc->sc_status.dz += dz;
1146 wsp_add_to_queue(sc, dx, -dy, dz, sc->sc_status.button);
1147 if (sc->dz_count == 0) {
1148 sc->dz_sum = 0;
1149 sc->rdz = 0;
1153 sc->pre_pos_x = sc->pos_x[0];
1154 sc->pre_pos_y = sc->pos_y[0];
1156 if (ntouch == 2 && sc->sc_status.button != 0) {
1157 sc->pre_pos_x = sc->pos_x[sc->finger];
1158 sc->pre_pos_y = sc->pos_y[sc->finger];
1160 sc->o_ntouch = ntouch;
1166 sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
1168 sc->tp_datalen);
1184 wsp_add_to_queue(struct wsp_softc *sc, int dx, int dy, int dz,
1206 buf[0] = sc->sc_mode.syncmask[1];
1213 if (sc->sc_mode.level == 1) {
1218 usb_fifo_put_data_linear(sc->sc_fifo.fp[USB_FIFO_RX], buf,
1219 sc->sc_mode.packetsize, 1);
1223 wsp_reset_buf(struct wsp_softc *sc)
1226 usb_fifo_reset(sc->sc_fifo.fp[USB_FIFO_RX]);
1232 struct wsp_softc *sc = usb_fifo_softc(fifo);
1236 rate = sc->sc_pollrate;
1241 if ((rate > 0) && (sc->sc_xfer[WSP_INTR_DT] != NULL)) {
1243 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1245 usbd_xfer_set_interval(sc->sc_xfer[WSP_INTR_DT], 1000 / rate);
1247 sc->sc_pollrate = 0;
1249 usbd_transfer_start(sc->sc_xfer[WSP_INTR_DT]);
1255 struct wsp_softc *sc = usb_fifo_softc(fifo);
1257 usbd_transfer_stop(sc->sc_xfer[WSP_INTR_DT]);
1267 struct wsp_softc *sc = usb_fifo_softc(fifo);
1270 if (sc->sc_state & WSP_ENABLED)
1277 rc = wsp_enable(sc);
1290 struct wsp_softc *sc = usb_fifo_softc(fifo);
1292 wsp_disable(sc);
1300 struct wsp_softc *sc = usb_fifo_softc(fifo);
1304 mtx_lock(&sc->sc_mutex);
1308 *(mousehw_t *)addr = sc->sc_hw;
1311 *(mousemode_t *)addr = sc->sc_mode;
1323 sc->sc_mode.level = mode.level;
1324 sc->sc_pollrate = mode.rate;
1325 sc->sc_hw.buttons = 3;
1327 if (sc->sc_mode.level == 0) {
1328 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1329 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1330 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1331 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1332 } else if (sc->sc_mode.level == 1) {
1333 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1334 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1335 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1336 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1338 wsp_reset_buf(sc);
1341 *(int *)addr = sc->sc_mode.level;
1348 sc->sc_mode.level = *(int *)addr;
1349 sc->sc_hw.buttons = 3;
1351 if (sc->sc_mode.level == 0) {
1352 sc->sc_mode.protocol = MOUSE_PROTO_MSC;
1353 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE;
1354 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
1355 sc->sc_mode.syncmask[1] = MOUSE_MSC_SYNC;
1356 } else if (sc->sc_mode.level == 1) {
1357 sc->sc_mode.protocol = MOUSE_PROTO_SYSMOUSE;
1358 sc->sc_mode.packetsize = MOUSE_SYS_PACKETSIZE;
1359 sc->sc_mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
1360 sc->sc_mode.syncmask[1] = MOUSE_SYS_SYNC;
1362 wsp_reset_buf(sc);
1367 *status = sc->sc_status;
1368 sc->sc_status.obutton = sc->sc_status.button;
1369 sc->sc_status.button = 0;
1370 sc->sc_status.dx = 0;
1371 sc->sc_status.dy = 0;
1372 sc->sc_status.dz = 0;
1385 mtx_unlock(&sc->sc_mutex);