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

« Back to documentation index

Show/hide line numbers usbd_core_cdc.c Source File

usbd_core_cdc.c

Go to the documentation of this file.
00001 /**
00002  * @file    usbd_core_cdc.c
00003  * @brief   Communication Device Class 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  *  USB Device Endpoint 0 Event Callback - CDC specific handling (Setup Request To Interface)
00030  *    Parameters:      none
00031  *    Return Value:    TRUE - Setup class request ok, FALSE - Setup class request not supported
00032  */
00033 
00034 __weak BOOL USBD_EndPoint0_Setup_CDC_ReqToIF(void)
00035 {
00036     if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num)  || /* IF number correct? */
00037             (USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) {
00038         switch (USBD_SetupPacket.bRequest) {
00039             case CDC_SEND_ENCAPSULATED_COMMAND:
00040                 USBD_EP0Data.pData = USBD_EP0Buf;                    /* data to be received, see USBD_EVT_OUT */
00041                 return (__TRUE);
00042 
00043             case CDC_GET_ENCAPSULATED_RESPONSE:
00044                 if (USBD_CDC_ACM_GetEncapsulatedResponse()) {
00045                     USBD_EP0Data.pData = USBD_EP0Buf;                  /* point to data to be sent */
00046                     USBD_DataInStage();                                /* send requested data */
00047                     return (__TRUE);
00048                 }
00049 
00050                 break;
00051 
00052             case CDC_SET_COMM_FEATURE:
00053                 USBD_EP0Data.pData = USBD_EP0Buf;                    /* data to be received, see USBD_EVT_OUT */
00054                 return (__TRUE);
00055 
00056             case CDC_GET_COMM_FEATURE:
00057                 if (USBD_CDC_ACM_GetCommFeature(USBD_SetupPacket.wValue)) {
00058                     USBD_EP0Data.pData = USBD_EP0Buf;                  /* point to data to be sent */
00059                     USBD_DataInStage();                                /* send requested data */
00060                     return (__TRUE);
00061                 }
00062 
00063                 break;
00064 
00065             case CDC_CLEAR_COMM_FEATURE:
00066                 if (USBD_CDC_ACM_ClearCommFeature(USBD_SetupPacket.wValue)) {
00067                     USBD_StatusInStage();                              /* send Acknowledge */
00068                     return (__TRUE);
00069                 }
00070 
00071                 break;
00072 
00073             case CDC_SET_LINE_CODING:
00074                 USBD_EP0Data.pData = USBD_EP0Buf;                    /* data to be received, see USBD_EVT_OUT */
00075                 return (__TRUE);
00076 
00077             case CDC_GET_LINE_CODING:
00078                 if (USBD_CDC_ACM_GetLineCoding()) {
00079                     USBD_EP0Data.pData = USBD_EP0Buf;                  /* point to data to be sent */
00080                     USBD_DataInStage();                                /* send requested data */
00081                     return (__TRUE);
00082                 }
00083 
00084                 break;
00085 
00086             case CDC_SET_CONTROL_LINE_STATE:
00087                 if (USBD_CDC_ACM_SetControlLineState(USBD_SetupPacket.wValue)) {
00088                     USBD_StatusInStage();                              /* send Acknowledge */
00089                     return (__TRUE);
00090                 }
00091 
00092                 break;
00093 
00094             case CDC_SEND_BREAK:
00095                 if (USBD_CDC_ACM_SendBreak(USBD_SetupPacket.wValue)) {
00096                     USBD_StatusInStage();                              /* send Acknowledge */
00097                     return (__TRUE);
00098                 }
00099 
00100                 break;
00101         }
00102     }
00103 
00104     return (__FALSE);
00105 }
00106 
00107 
00108 /*
00109  *  USB Device Endpoint 0 Event Callback - CDC specific handling (Out Request To Interface)
00110  *    Parameters:      none
00111  *    Return Value:    TRUE - Out class request ok, FALSE - Out class request not supported
00112  */
00113 
00114 __weak BOOL USBD_EndPoint0_Out_CDC_ReqToIF(void)
00115 {
00116     if ((USBD_SetupPacket.wIndexL == usbd_cdc_acm_cif_num) || /* IF number correct? */
00117             (USBD_SetupPacket.wIndexL == usbd_cdc_acm_dif_num)) {
00118         switch (USBD_SetupPacket.bRequest) {
00119             case CDC_SEND_ENCAPSULATED_COMMAND:
00120                 if (USBD_CDC_ACM_SendEncapsulatedCommand()) {
00121                     USBD_StatusInStage();                        /* send Acknowledge */
00122                     return (__TRUE);
00123                 }
00124 
00125                 break;
00126 
00127             case CDC_SET_COMM_FEATURE:
00128                 if (USBD_CDC_ACM_SetCommFeature(USBD_SetupPacket.wValue)) {
00129                     USBD_StatusInStage();                        /* send Acknowledge */
00130                     return (__TRUE);
00131                 }
00132 
00133                 break;
00134 
00135             case CDC_SET_LINE_CODING:
00136                 if (USBD_CDC_ACM_SetLineCoding()) {
00137                     USBD_StatusInStage();                        /* send Acknowledge */
00138                     return (__TRUE);
00139                 }
00140 
00141                 break;
00142         }
00143     }
00144 
00145     return (__FALSE);
00146 }