Mercurial > louis > kiibohd-controller
comparison Output/pjrcUSB/arm/usb_dev.c @ 383:801e7628d977
Fixing long-standing SET_REPORT bug
- Implementation was completely wrong (has never worked properly)
- Now working in both NKRO and 6KRO modes
- Added more debugging code if things go wrong again
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 09 Oct 2015 18:18:07 -0700 |
parents | fbe55b27dc02 |
children | d8f61e15aca1 |
comparison
equal
deleted
inserted
replaced
382:2268093deff4 | 383:801e7628d977 |
---|---|
422 // XXX Needed? | 422 // XXX Needed? |
423 //serial_print("set coding, waiting...\n"); | 423 //serial_print("set coding, waiting...\n"); |
424 return; | 424 return; |
425 | 425 |
426 case 0x0921: // HID SET_REPORT | 426 case 0x0921: // HID SET_REPORT |
427 #ifdef UART_DEBUG | 427 // Interface |
428 warn_msg("SET_REPORT - "); | 428 switch ( setup.wIndex & 0xFF ) |
429 printHex( setup.wValue ); | 429 { |
430 print(" - "); | 430 // Keyboard Interface |
431 printHex( setup.wValue & 0xFF ); | 431 case KEYBOARD_INTERFACE: |
432 print( NL ); | 432 break; |
433 #endif | 433 // NKRO Keyboard Interface |
434 USBKeys_LEDs = setup.wValue & 0xFF; | 434 case NKRO_KEYBOARD_INTERFACE: |
435 | 435 break; |
436 // Must be stall for some reason... -HaaTa | 436 default: |
437 endpoint0_stall(); | 437 warn_msg("Unknown interface - "); |
438 printHex( setup.wIndex ); | |
439 print( NL ); | |
440 endpoint0_stall(); | |
441 break; | |
442 } | |
443 | |
438 return; | 444 return; |
439 | 445 |
440 case 0x01A1: // HID GET_REPORT | 446 case 0x01A1: // HID GET_REPORT |
441 #ifdef UART_DEBUG | 447 #ifdef UART_DEBUG |
442 print("GET_REPORT - "); | 448 print("GET_REPORT - "); |
610 printHex(setup.wValue); | 616 printHex(setup.wValue); |
611 print(", wIndex:"); | 617 print(", wIndex:"); |
612 printHex(setup.wIndex); | 618 printHex(setup.wIndex); |
613 print(", len:"); | 619 print(", len:"); |
614 printHex(setup.wLength); | 620 printHex(setup.wLength); |
621 print(" -- "); | |
622 printHex32(setup.word1); | |
623 print(" "); | |
624 printHex32(setup.word2); | |
615 print(NL); | 625 print(NL); |
616 #endif | 626 #endif |
617 // actually "do" the setup request | 627 // actually "do" the setup request |
618 usb_setup(); | 628 usb_setup(); |
619 // unfreeze the USB, now that we're ready | 629 // unfreeze the USB, now that we're ready |
620 USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit | 630 USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit |
621 break; | 631 break; |
622 | 632 |
623 case 0x01: // OUT transaction received from host | 633 case 0x01: // OUT transaction received from host |
624 case 0x02: | 634 case 0x02: |
625 #ifdef UART_DEBUG | 635 #ifdef UART_DEBUG_UNKNOWN |
626 print("PID=OUT"NL); | 636 print("PID=OUT wRequestAndType:"); |
637 printHex(setup.wRequestAndType); | |
638 print(", wValue:"); | |
639 printHex(setup.wValue); | |
640 print(", wIndex:"); | |
641 printHex(setup.wIndex); | |
642 print(", len:"); | |
643 printHex(setup.wLength); | |
644 print(" -- "); | |
645 printHex32(setup.word1); | |
646 print(" "); | |
647 printHex32(setup.word2); | |
648 print(NL); | |
627 #endif | 649 #endif |
650 | |
628 // CDC Interface | 651 // CDC Interface |
629 if ( setup.wRequestAndType == 0x2021 /*CDC_SET_LINE_CODING*/ ) | 652 if ( setup.wRequestAndType == 0x2021 /*CDC_SET_LINE_CODING*/ ) |
630 { | 653 { |
631 int i; | 654 int i; |
632 uint8_t *dst = (uint8_t *)usb_cdc_line_coding; | 655 uint8_t *dst = (uint8_t *)usb_cdc_line_coding; |
641 if ( usb_cdc_line_coding[0] == 134 ) | 664 if ( usb_cdc_line_coding[0] == 134 ) |
642 usb_reboot_timer = 15; | 665 usb_reboot_timer = 15; |
643 endpoint0_transmit( NULL, 0 ); | 666 endpoint0_transmit( NULL, 0 ); |
644 } | 667 } |
645 | 668 |
646 // Keyboard Interface | 669 // Keyboard SET_REPORT |
647 if ( setup.word1 == 0x02000921 && setup.word2 == ( (1<<16) | KEYBOARD_INTERFACE ) ) | 670 if ( setup.wRequestAndType == 0x921 && setup.wValue & 0x200 ) |
648 { | 671 { |
649 USBKeys_LEDs = buf[0]; | 672 // Interface |
650 endpoint0_transmit( NULL, 0 ); | 673 switch ( setup.wIndex & 0xFF ) |
651 } | 674 { |
652 // NKRO Keyboard Interface | 675 // Keyboard Interface |
653 if ( setup.word1 == 0x02000921 && setup.word2 == ( (1<<16) | NKRO_KEYBOARD_INTERFACE ) ) | 676 case KEYBOARD_INTERFACE: |
654 { | 677 USBKeys_LEDs = buf[0]; |
655 USBKeys_LEDs = buf[0]; | 678 endpoint0_transmit( NULL, 0 ); |
656 endpoint0_transmit( NULL, 0 ); | 679 break; |
680 // NKRO Keyboard Interface | |
681 case NKRO_KEYBOARD_INTERFACE: | |
682 // Only use 2nd byte, first byte is the report id | |
683 USBKeys_LEDs = buf[1]; | |
684 endpoint0_transmit( NULL, 0 ); | |
685 break; | |
686 default: | |
687 warn_msg("Unknown interface - "); | |
688 printHex( setup.wIndex ); | |
689 print( NL ); | |
690 break; | |
691 } | |
692 | |
693 #ifdef UART_DEBUG | |
694 for ( size_t len = 0; len < setup.wLength; len++ ) | |
695 { | |
696 printHex( buf[ len ] ); | |
697 print(" "); | |
698 } | |
699 print( NL ); | |
700 #endif | |
657 } | 701 } |
658 | 702 |
659 // give the buffer back | 703 // give the buffer back |
660 b->desc = BDT_DESC( EP0_SIZE, DATA1 ); | 704 b->desc = BDT_DESC( EP0_SIZE, DATA1 ); |
661 break; | 705 break; |