Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbd_core_hid.c Source File

usbd_core_hid.c

Go to the documentation of this file.
00001 /**
00002  * @file    usbd_core_hid.c
00003  * @brief   Human Interface Device driver
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include <string.h>
00023 
00024 #include "rl_usb.h"
00025 #include "usb_for_lib.h"
00026 
00027 
00028 /*
00029  *  Get Descriptor USB Device Request - HID specific handling
00030  *    Parameters:      None
00031  *    Return Value:    TRUE - Success, FALSE - Error
00032  */
00033 
00034 __weak BOOL USBD_ReqGetDescriptor_HID(U8 **pD, U32 *len)
00035 {
00036     switch (USBD_SetupPacket.wValueH) {
00037         case HID_HID_DESCRIPTOR_TYPE:
00038             if (USBD_SetupPacket.wIndexL != usbd_hid_if_num &&
00039                 USBD_SetupPacket.wIndexL != usbd_webusb_if_num) {
00040                 return (__FALSE);
00041             }
00042 
00043             if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
00044                 return (__FALSE);  /* High speed request but high-speed not enabled */
00045             }
00046 
00047             if (USBD_HighSpeed == __FALSE) {
00048                 *pD = (U8 *)USBD_ConfigDescriptor;
00049             } else {
00050                 *pD = (U8 *)USBD_ConfigDescriptor_HS;
00051             }
00052 
00053             USBD_EP0Data.pData = *pD + USBD_HID_DescriptorOffset;
00054             *len = USB_HID_DESC_SIZE;
00055             break;
00056 
00057         case HID_REPORT_DESCRIPTOR_TYPE:
00058             if (USBD_SetupPacket.wIndexL != usbd_hid_if_num &&
00059                 USBD_SetupPacket.wIndexL != usbd_webusb_if_num) {
00060                 return (__FALSE);
00061             }
00062 
00063             USBD_EP0Data.pData = (U8 *)USBD_HID_ReportDescriptor;
00064             *len = USBD_HID_ReportDescriptorSize;
00065             break;
00066 
00067         case HID_PHYSICAL_DESCRIPTOR_TYPE:
00068             return (__FALSE);    /* HID Physical Descriptor is not supported */
00069 
00070         default:
00071             return (__FALSE);
00072     }
00073 
00074     return (__TRUE);
00075 }
00076 
00077 
00078 /*
00079  *  USB Device Endpoint 0 Event Callback - HID specific handling (Setup Request To Interface)
00080  *    Parameters:      none
00081  *    Return Value:    TRUE - Setup class request ok, FALSE - Setup class request not supported
00082  */
00083 
00084 __weak BOOL USBD_EndPoint0_Setup_HID_ReqToIF(void)
00085 {
00086     if (USBD_SetupPacket.wIndexL == usbd_hid_if_num ||
00087         USBD_SetupPacket.wIndexL == usbd_webusb_if_num) {
00088         switch (USBD_SetupPacket.bRequest) {
00089             case HID_REQUEST_GET_REPORT:
00090                 if (USBD_HID_GetReport()) {
00091                     if (USBD_SetupPacket.wValueH == HID_REPORT_INPUT) {
00092                         USBD_EP0Data.pData = &USBD_HID_InReport[1];      /* point to data to be sent (skip ReportID) */
00093                     } else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
00094                         USBD_EP0Data.pData = &USBD_HID_FeatReport[1];    /* point to data to be sent (skip ReportID) */
00095                     }
00096 
00097                     USBD_DataInStage();                                /* send requested data */
00098                     return (__TRUE);
00099                 }
00100 
00101                 break;
00102 
00103             case HID_REQUEST_SET_REPORT:
00104                 if (USBD_SetupPacket.wValueH == HID_REPORT_OUTPUT) {
00105                     USBD_EP0Data.pData = &USBD_HID_OutReport[1];       /* out data to be received (skip ReportID) */
00106                 } else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
00107                     USBD_EP0Data.pData = &USBD_HID_FeatReport[1];      /* out data to be received (skip ReportID) */
00108                 }
00109 
00110                 return (__TRUE);
00111 
00112             case HID_REQUEST_GET_IDLE:
00113                 if (USBD_HID_GetIdle()) {
00114                     USBD_EP0Data.pData = USBD_EP0Buf;                  /* point to data to be sent */
00115                     USBD_DataInStage();                                /* send requested data */
00116                     return (__TRUE);
00117                 }
00118 
00119                 break;
00120 
00121             case HID_REQUEST_SET_IDLE:
00122                 if (USBD_HID_SetIdle()) {
00123                     USBD_StatusInStage();                              /* send Acknowledge */
00124                     return (__TRUE);
00125                 }
00126 
00127                 break;
00128 
00129             case HID_REQUEST_GET_PROTOCOL:
00130                 if (USBD_HID_GetProtocol()) {
00131                     USBD_EP0Data.pData = USBD_EP0Buf;                  /* point to data to be sent */
00132                     USBD_DataInStage();                                /* send requested data */
00133                     return (__TRUE);
00134                 }
00135 
00136                 break;
00137 
00138             case HID_REQUEST_SET_PROTOCOL:
00139                 if (USBD_HID_SetProtocol()) {
00140                     USBD_StatusInStage();                              /* send Acknowledge */
00141                     return (__TRUE);
00142                 }
00143 
00144                 break;
00145         }
00146     }
00147 
00148     return (__FALSE);
00149 }
00150 
00151 
00152 /*
00153  *  USB Device Endpoint 0 Event Callback - HID specific handling (Out Request To Interface)
00154  *    Parameters:      none
00155  *    Return Value:    TRUE - Out class request ok, FALSE - Out class request not supported
00156  */
00157 
00158 __weak BOOL USBD_EndPoint0_Out_HID_ReqToIF(void)
00159 {
00160     if (USBD_SetupPacket.wIndexL == usbd_hid_if_num ||
00161         USBD_SetupPacket.wIndexL == usbd_webusb_if_num) {
00162         switch (USBD_SetupPacket.bRequest) {
00163             case HID_REQUEST_SET_REPORT:
00164                 if (USBD_HID_SetReport()) {
00165                     USBD_StatusInStage();                        /* send Acknowledge */
00166                     return (__TRUE);
00167                 }
00168 
00169                 break;
00170         }
00171     }
00172 
00173     return (__FALSE);
00174 }