ums.c (09c817ba36db7c3a4ff5e25ac55816ca181a403d) | ums.c (81f8288460fdd631d953f272ffaa1153fce07e9c) |
---|---|
1/*- 2 * Copyright (c) 1998 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Lennart Augustsson (lennart@augustsson.net) at 7 * Carlstedt Research & Technology. 8 * --- 126 unchanged lines hidden (view full) --- 135 struct ums_info sc_info[UMS_INFO_MAX]; 136 137 mousehw_t sc_hw; 138 mousemode_t sc_mode; 139 mousestatus_t sc_status; 140 141 struct usb_xfer *sc_xfer[UMS_N_TRANSFER]; 142 | 1/*- 2 * Copyright (c) 1998 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Lennart Augustsson (lennart@augustsson.net) at 7 * Carlstedt Research & Technology. 8 * --- 126 unchanged lines hidden (view full) --- 135 struct ums_info sc_info[UMS_INFO_MAX]; 136 137 mousehw_t sc_hw; 138 mousemode_t sc_mode; 139 mousestatus_t sc_status; 140 141 struct usb_xfer *sc_xfer[UMS_N_TRANSFER]; 142 |
143 int sc_pollrate; 144 |
|
143 uint8_t sc_buttons; 144 uint8_t sc_iid; 145 uint8_t sc_temp[64]; 146}; 147 148static void ums_put_queue_timeout(void *__sc); 149 150static usb_callback_t ums_intr_callback; --- 32 unchanged lines hidden (view full) --- 183static void 184ums_intr_callback(struct usb_xfer *xfer, usb_error_t error) 185{ 186 struct ums_softc *sc = usbd_xfer_softc(xfer); 187 struct ums_info *info = &sc->sc_info[0]; 188 struct usb_page_cache *pc; 189 uint8_t *buf = sc->sc_temp; 190 int32_t buttons = 0; | 145 uint8_t sc_buttons; 146 uint8_t sc_iid; 147 uint8_t sc_temp[64]; 148}; 149 150static void ums_put_queue_timeout(void *__sc); 151 152static usb_callback_t ums_intr_callback; --- 32 unchanged lines hidden (view full) --- 185static void 186ums_intr_callback(struct usb_xfer *xfer, usb_error_t error) 187{ 188 struct ums_softc *sc = usbd_xfer_softc(xfer); 189 struct ums_info *info = &sc->sc_info[0]; 190 struct usb_page_cache *pc; 191 uint8_t *buf = sc->sc_temp; 192 int32_t buttons = 0; |
193 int32_t buttons_found = 0; |
|
191 int32_t dw = 0; 192 int32_t dx = 0; 193 int32_t dy = 0; 194 int32_t dz = 0; 195 int32_t dt = 0; 196 uint8_t i; 197 uint8_t id; 198 int len; --- 59 unchanged lines hidden (view full) --- 258 dz -= temp; 259 } 260 261 if ((info->sc_flags & UMS_FLAG_T_AXIS) && 262 (id == info->sc_iid_t)) 263 dt -= hid_get_data(buf, len, &info->sc_loc_t); 264 265 for (i = 0; i < info->sc_buttons; i++) { | 194 int32_t dw = 0; 195 int32_t dx = 0; 196 int32_t dy = 0; 197 int32_t dz = 0; 198 int32_t dt = 0; 199 uint8_t i; 200 uint8_t id; 201 int len; --- 59 unchanged lines hidden (view full) --- 261 dz -= temp; 262 } 263 264 if ((info->sc_flags & UMS_FLAG_T_AXIS) && 265 (id == info->sc_iid_t)) 266 dt -= hid_get_data(buf, len, &info->sc_loc_t); 267 268 for (i = 0; i < info->sc_buttons; i++) { |
269 uint32_t mask; 270 mask = 1UL << UMS_BUT(i); 271 /* check for correct button ID */ |
|
266 if (id != info->sc_iid_btn[i]) 267 continue; | 272 if (id != info->sc_iid_btn[i]) 273 continue; |
268 if (hid_get_data(buf, len, &info->sc_loc_btn[i])) { 269 buttons |= (1 << UMS_BUT(i)); 270 } | 274 /* check for button pressed */ 275 if (hid_get_data(buf, len, &info->sc_loc_btn[i])) 276 buttons |= mask; 277 /* register button mask */ 278 buttons_found |= mask; |
271 } 272 273 if (++info != &sc->sc_info[UMS_INFO_MAX]) 274 goto repeat; 275 | 279 } 280 281 if (++info != &sc->sc_info[UMS_INFO_MAX]) 282 goto repeat; 283 |
284 /* keep old button value(s) for non-detected buttons */ 285 buttons |= sc->sc_status.button & ~buttons_found; 286 |
|
276 if (dx || dy || dz || dt || dw || 277 (buttons != sc->sc_status.button)) { 278 279 DPRINTFN(6, "x:%d y:%d z:%d t:%d w:%d buttons:0x%08x\n", 280 dx, dy, dz, dt, dw, buttons); 281 282 sc->sc_status.button = buttons; 283 sc->sc_status.dx += dx; --- 225 unchanged lines hidden (view full) --- 509 err = usbd_transfer_setup(uaa->device, 510 &uaa->info.bIfaceIndex, sc->sc_xfer, ums_config, 511 UMS_N_TRANSFER, sc, &sc->sc_mtx); 512 513 if (err) { 514 DPRINTF("error=%s\n", usbd_errstr(err)); 515 goto detach; 516 } | 287 if (dx || dy || dz || dt || dw || 288 (buttons != sc->sc_status.button)) { 289 290 DPRINTFN(6, "x:%d y:%d z:%d t:%d w:%d buttons:0x%08x\n", 291 dx, dy, dz, dt, dw, buttons); 292 293 sc->sc_status.button = buttons; 294 sc->sc_status.dx += dx; --- 225 unchanged lines hidden (view full) --- 520 err = usbd_transfer_setup(uaa->device, 521 &uaa->info.bIfaceIndex, sc->sc_xfer, ums_config, 522 UMS_N_TRANSFER, sc, &sc->sc_mtx); 523 524 if (err) { 525 DPRINTF("error=%s\n", usbd_errstr(err)); 526 goto detach; 527 } |
528 529 /* Get HID descriptor */ |
|
517 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr, 518 &d_len, M_TEMP, uaa->info.bIfaceIndex); 519 520 if (err) { 521 device_printf(dev, "error reading report description\n"); 522 goto detach; 523 } 524 525 isize = hid_report_size(d_ptr, d_len, hid_input, &sc->sc_iid); 526 527 /* 528 * The Microsoft Wireless Notebook Optical Mouse seems to be in worse 529 * shape than the Wireless Intellimouse 2.0, as its X, Y, wheel, and 530 * all of its other button positions are all off. It also reports that 531 * it has two addional buttons and a tilt wheel. 532 */ 533 if (usb_test_quirk(uaa, UQ_MS_BAD_CLASS)) { | 530 err = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr, 531 &d_len, M_TEMP, uaa->info.bIfaceIndex); 532 533 if (err) { 534 device_printf(dev, "error reading report description\n"); 535 goto detach; 536 } 537 538 isize = hid_report_size(d_ptr, d_len, hid_input, &sc->sc_iid); 539 540 /* 541 * The Microsoft Wireless Notebook Optical Mouse seems to be in worse 542 * shape than the Wireless Intellimouse 2.0, as its X, Y, wheel, and 543 * all of its other button positions are all off. It also reports that 544 * it has two addional buttons and a tilt wheel. 545 */ 546 if (usb_test_quirk(uaa, UQ_MS_BAD_CLASS)) { |
547 548 sc->sc_iid = 0; 549 |
|
534 info = &sc->sc_info[0]; 535 info->sc_flags = (UMS_FLAG_X_AXIS | 536 UMS_FLAG_Y_AXIS | 537 UMS_FLAG_Z_AXIS | 538 UMS_FLAG_SBU); 539 info->sc_buttons = 3; 540 isize = 5; 541 /* 1st byte of descriptor report contains garbage */ 542 info->sc_loc_x.pos = 16; | 550 info = &sc->sc_info[0]; 551 info->sc_flags = (UMS_FLAG_X_AXIS | 552 UMS_FLAG_Y_AXIS | 553 UMS_FLAG_Z_AXIS | 554 UMS_FLAG_SBU); 555 info->sc_buttons = 3; 556 isize = 5; 557 /* 1st byte of descriptor report contains garbage */ 558 info->sc_loc_x.pos = 16; |
559 info->sc_loc_x.size = 8; |
|
543 info->sc_loc_y.pos = 24; | 560 info->sc_loc_y.pos = 24; |
561 info->sc_loc_y.size = 8; |
|
544 info->sc_loc_z.pos = 32; | 562 info->sc_loc_z.pos = 32; |
563 info->sc_loc_z.size = 8; |
|
545 info->sc_loc_btn[0].pos = 8; | 564 info->sc_loc_btn[0].pos = 8; |
565 info->sc_loc_btn[0].size = 1; |
|
546 info->sc_loc_btn[1].pos = 9; | 566 info->sc_loc_btn[1].pos = 9; |
567 info->sc_loc_btn[1].size = 1; |
|
547 info->sc_loc_btn[2].pos = 10; | 568 info->sc_loc_btn[2].pos = 10; |
569 info->sc_loc_btn[2].size = 1; |
|
548 549 /* Announce device */ 550 device_printf(dev, "3 buttons and [XYZ] " 551 "coordinates ID=0\n"); 552 553 } else { 554 /* Search the HID descriptor and announce device */ 555 for (i = 0; i < UMS_INFO_MAX; i++) { --- 92 unchanged lines hidden (view full) --- 648 649 return (0); 650} 651 652static void 653ums_start_read(struct usb_fifo *fifo) 654{ 655 struct ums_softc *sc = usb_fifo_softc(fifo); | 570 571 /* Announce device */ 572 device_printf(dev, "3 buttons and [XYZ] " 573 "coordinates ID=0\n"); 574 575 } else { 576 /* Search the HID descriptor and announce device */ 577 for (i = 0; i < UMS_INFO_MAX; i++) { --- 92 unchanged lines hidden (view full) --- 670 671 return (0); 672} 673 674static void 675ums_start_read(struct usb_fifo *fifo) 676{ 677 struct ums_softc *sc = usb_fifo_softc(fifo); |
678 int rate; |
|
656 | 679 |
680 /* Check if we should override the default polling interval */ 681 rate = sc->sc_pollrate; 682 /* Range check rate */ 683 if (rate > 1000) 684 rate = 1000; 685 /* Check for set rate */ 686 if ((rate > 0) && (sc->sc_xfer[UMS_INTR_DT] != NULL)) { 687 DPRINTF("Setting pollrate = %d\n", rate); 688 /* Stop current transfer, if any */ 689 usbd_transfer_stop(sc->sc_xfer[UMS_INTR_DT]); 690 /* Set new interval */ 691 usbd_xfer_set_interval(sc->sc_xfer[UMS_INTR_DT], 1000 / rate); 692 /* Only set pollrate once */ 693 sc->sc_pollrate = 0; 694 } 695 |
|
657 usbd_transfer_start(sc->sc_xfer[UMS_INTR_DT]); 658} 659 660static void 661ums_stop_read(struct usb_fifo *fifo) 662{ 663 struct ums_softc *sc = usb_fifo_softc(fifo); 664 --- 121 unchanged lines hidden (view full) --- 786 /* don't change the current setting */ 787 } else if ((mode.level < 0) || (mode.level > 1)) { 788 error = EINVAL; 789 goto done; 790 } else { 791 sc->sc_mode.level = mode.level; 792 } 793 | 696 usbd_transfer_start(sc->sc_xfer[UMS_INTR_DT]); 697} 698 699static void 700ums_stop_read(struct usb_fifo *fifo) 701{ 702 struct ums_softc *sc = usb_fifo_softc(fifo); 703 --- 121 unchanged lines hidden (view full) --- 825 /* don't change the current setting */ 826 } else if ((mode.level < 0) || (mode.level > 1)) { 827 error = EINVAL; 828 goto done; 829 } else { 830 sc->sc_mode.level = mode.level; 831 } 832 |
833 /* store polling rate */ 834 sc->sc_pollrate = mode.rate; 835 |
|
794 if (sc->sc_mode.level == 0) { 795 if (sc->sc_buttons > MOUSE_MSC_MAXBUTTON) 796 sc->sc_hw.buttons = MOUSE_MSC_MAXBUTTON; 797 else 798 sc->sc_hw.buttons = sc->sc_buttons; 799 sc->sc_mode.protocol = MOUSE_PROTO_MSC; 800 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE; 801 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK; --- 92 unchanged lines hidden --- | 836 if (sc->sc_mode.level == 0) { 837 if (sc->sc_buttons > MOUSE_MSC_MAXBUTTON) 838 sc->sc_hw.buttons = MOUSE_MSC_MAXBUTTON; 839 else 840 sc->sc_hw.buttons = sc->sc_buttons; 841 sc->sc_mode.protocol = MOUSE_PROTO_MSC; 842 sc->sc_mode.packetsize = MOUSE_MSC_PACKETSIZE; 843 sc->sc_mode.syncmask[0] = MOUSE_MSC_SYNCMASK; --- 92 unchanged lines hidden --- |