diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-09-20 02:10:12 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-10-16 21:14:42 +0100 |
commit | 1b2cc053d38a96027d649cb1028717b881dc82c3 (patch) | |
tree | a1f99d0f8827a354ae64bf5d9f7cb66c332daf26 | |
parent | 3318ba4795b9e9033db2ba1281144e8ba55bb4cb (diff) | |
download | rockbox-1b2cc053d38a96027d649cb1028717b881dc82c3.tar.gz rockbox-1b2cc053d38a96027d649cb1028717b881dc82c3.zip |
usb: port usb_hid control request handling to new API
Change-Id: I9028cf06e91c9fcbe271f6ad81d6b252cb4e7cec
-rw-r--r-- | firmware/usbstack/usb_hid.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c index c7dc81e4c1..121736d2dd 100644 --- a/firmware/usbstack/usb_hid.c +++ b/firmware/usbstack/usb_hid.c | |||
@@ -664,7 +664,7 @@ void usb_hid_transfer_complete(int ep, int dir, int status, int length) | |||
664 | * In order to allow sending info to the DAP, the Set Report mechanism can be | 664 | * In order to allow sending info to the DAP, the Set Report mechanism can be |
665 | * used by defining vendor specific output reports and send them from the host | 665 | * used by defining vendor specific output reports and send them from the host |
666 | * to the DAP using the host's custom driver */ | 666 | * to the DAP using the host's custom driver */ |
667 | static int usb_hid_set_report(struct usb_ctrlrequest *req) | 667 | static int usb_hid_set_report(struct usb_ctrlrequest *req, void *reqdata) |
668 | { | 668 | { |
669 | static unsigned char buf[SET_REPORT_BUF_LEN] USB_DEVBSS_ATTR | 669 | static unsigned char buf[SET_REPORT_BUF_LEN] USB_DEVBSS_ATTR |
670 | __attribute__((aligned(32))); | 670 | __attribute__((aligned(32))); |
@@ -692,8 +692,11 @@ static int usb_hid_set_report(struct usb_ctrlrequest *req) | |||
692 | return 4; | 692 | return 4; |
693 | } | 693 | } |
694 | 694 | ||
695 | memset(buf, 0, length); | 695 | if(!reqdata) { |
696 | usb_drv_recv_nonblocking(EP_CONTROL, buf, length); | 696 | memset(buf, 0, length); |
697 | usb_drv_control_response(USB_CONTROL_RECEIVE, buf, length); | ||
698 | return 0; | ||
699 | } | ||
697 | 700 | ||
698 | #ifdef LOGF_ENABLE | 701 | #ifdef LOGF_ENABLE |
699 | if (buf[1] & 0x01) | 702 | if (buf[1] & 0x01) |
@@ -710,10 +713,11 @@ static int usb_hid_set_report(struct usb_ctrlrequest *req) | |||
710 | 713 | ||
711 | /* Defining other LEDs and setting them from the USB host (OS) can be used | 714 | /* Defining other LEDs and setting them from the USB host (OS) can be used |
712 | * to send messages to the DAP */ | 715 | * to send messages to the DAP */ |
716 | usb_drv_control_response(USB_CONTROL_ACK, NULL, 0); | ||
713 | return 0; | 717 | return 0; |
714 | } | 718 | } |
715 | 719 | ||
716 | static int usb_hid_get_report(struct usb_ctrlrequest *req, unsigned char** dest) | 720 | static int usb_hid_get_report(struct usb_ctrlrequest *req, unsigned char* dest) |
717 | { | 721 | { |
718 | if ((req->wValue >> 8) != REPORT_TYPE_FEATURE) | 722 | if ((req->wValue >> 8) != REPORT_TYPE_FEATURE) |
719 | { | 723 | { |
@@ -739,10 +743,9 @@ static int usb_hid_get_report(struct usb_ctrlrequest *req, unsigned char** dest) | |||
739 | return 4; | 743 | return 4; |
740 | } | 744 | } |
741 | 745 | ||
742 | (*dest)[0] = 0; | 746 | dest[0] = 0; |
743 | (*dest)[1] = battery_level(); | 747 | dest[1] = battery_level(); |
744 | *dest += GET_REPORT_BUF_LEN; | 748 | usb_drv_control_response(USB_CONTROL_ACK, dest, 2); |
745 | |||
746 | return 0; | 749 | return 0; |
747 | } | 750 | } |
748 | 751 | ||
@@ -774,8 +777,7 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, void *reqdata, unsigne | |||
774 | 777 | ||
775 | if (dest != orig_dest) | 778 | if (dest != orig_dest) |
776 | { | 779 | { |
777 | usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */ | 780 | usb_drv_control_response(USB_CONTROL_ACK, orig_dest, dest - orig_dest); |
778 | usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); | ||
779 | return true; | 781 | return true; |
780 | } | 782 | } |
781 | break; | 783 | break; |
@@ -792,34 +794,21 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, void *reqdata, unsigne | |||
792 | switch (req->bRequest) | 794 | switch (req->bRequest) |
793 | { | 795 | { |
794 | case USB_HID_SET_REPORT: | 796 | case USB_HID_SET_REPORT: |
795 | rc = usb_hid_set_report(req); | 797 | rc = usb_hid_set_report(req, reqdata); |
796 | break; | 798 | break; |
797 | case USB_HID_GET_REPORT: | 799 | case USB_HID_GET_REPORT: |
798 | rc = usb_hid_get_report(req, &dest); | 800 | rc = usb_hid_get_report(req, dest); |
799 | break; | 801 | break; |
800 | case USB_HID_SET_IDLE: | 802 | case USB_HID_SET_IDLE: |
801 | rc = 0; | 803 | usb_drv_control_response(USB_CONTROL_ACK, NULL, 0); |
802 | break; | 804 | return true; |
803 | default: | 805 | default: |
804 | /* all other requests are errors */ | 806 | /* all other requests are errors */ |
805 | rc = -1; | 807 | return false; |
806 | break; | ||
807 | } | ||
808 | |||
809 | if(rc != 0) | ||
810 | break; | ||
811 | |||
812 | if (dest != orig_dest) | ||
813 | { | ||
814 | usb_drv_recv_nonblocking(EP_CONTROL, NULL, 0); /* ack */ | ||
815 | usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); | ||
816 | } | ||
817 | else | ||
818 | { | ||
819 | usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ | ||
820 | } | 808 | } |
821 | 809 | ||
822 | return true; | 810 | if(rc == 0) |
811 | return true; | ||
823 | } | 812 | } |
824 | 813 | ||
825 | case USB_TYPE_VENDOR: | 814 | case USB_TYPE_VENDOR: |