Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <USBLib_Trace.h>
00039
00040
00041 #include "USBD.h"
00042 #include <USBD_HAL.h>
00043 #include <USBDDriver.h>
00044
00045
00046 #include <DUALCDCDDriver.h>
00047
00048
00049
00050
00051
00052
00053 #define NUM_PORTS 2
00054
00055
00056 #define NUM_INTERFACES ((DUALCDCDDriverDescriptors_NUMINTERFACE+3)&0xFC)
00057
00058
00059
00060
00061
00062
00063 typedef struct _DualCdcdSerialDriver {
00064
00065 CDCDSerialPort cdcdSerialPort[NUM_PORTS];
00066 } DualCdcdSerialDriver;
00067
00068
00069
00070
00071
00072
00073 DualCdcdSerialDriver dualcdcdDriver;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void DUALCDCDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
00088 {
00089 USBDDriver *pUsbd = USBD_GetDriver();
00090 CDCDSerialPort *pCdcd = &dualcdcdDriver.cdcdSerialPort[0];
00091
00092 TRACE_INFO("DUALCDCDDriver_Initialize\n\r");
00093
00094 pCdcd = &dualcdcdDriver.cdcdSerialPort[0];
00095 CDCDSerialPort_Initialize(pCdcd, pUsbd,
00096 0,
00097 0,
00098 DUALCDCDDriverDescriptors_INTERFACENUM0, 2);
00099
00100 pCdcd = &dualcdcdDriver.cdcdSerialPort[1];
00101 CDCDSerialPort_Initialize(pCdcd, pUsbd,
00102 0,
00103 0,
00104 DUALCDCDDriverDescriptors_INTERFACENUM1, 2);
00105
00106
00107 USBDDriver_Initialize(pUsbd,
00108 pDescriptors,
00109 0);
00110
00111 USBD_Init();
00112 }
00113
00114
00115
00116
00117
00118
00119 void DUALCDCDDriver_ConfigurationChangeHandler(uint8_t cfgnum)
00120 {
00121 CDCDSerialPort *pCdcd = &dualcdcdDriver.cdcdSerialPort[0];
00122 USBDDriver *pUsbd = pCdcd->pUsbd;
00123 USBConfigurationDescriptor *pDesc;
00124 USBGenericDescriptor *pD;
00125 uint32_t i, len;
00126
00127 if (cfgnum > 0) {
00128
00129
00130 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
00131
00132 pD = (USBGenericDescriptor *)pDesc;
00133 len = pDesc->wTotalLength;
00134
00135 for (i = 0; i < NUM_PORTS; i ++) {
00136 pCdcd = &dualcdcdDriver.cdcdSerialPort[i];
00137 pD = CDCDSerialPort_ParseInterfaces(pCdcd, pD, len);
00138 len = pDesc->wTotalLength - ((uint32_t)pD - (uint32_t)pDesc);
00139 }
00140 }
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 void DUALCDCDDriver_RequestHandler(const USBGenericRequest *request)
00150 {
00151 CDCDSerialPort *pCdcd = 0;
00152 USBDDriver *pUsbd = 0;
00153 uint32_t rc, i;
00154
00155 TRACE_INFO_WP("NewReq ");
00156
00157 for (i = 0; i < NUM_PORTS; i ++) {
00158 pCdcd = &dualcdcdDriver.cdcdSerialPort[i];
00159 rc = CDCDSerialPort_RequestHandler(pCdcd, request);
00160 if (rc == USBRC_SUCCESS)
00161 break;
00162 }
00163
00164
00165 if (rc != USBRC_SUCCESS) {
00166 if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) {
00167 pUsbd = pCdcd->pUsbd;
00168 USBDDriver_RequestHandler(pUsbd, request);
00169 }
00170 else {
00171 TRACE_WARNING(
00172 "DUALCDCDDriver_RequestHandler: Unsupported request (%d,%d)\n\r",
00173 USBGenericRequest_GetType(request),
00174 USBGenericRequest_GetRequest(request));
00175 USBD_Stall(0);
00176 }
00177 }
00178
00179 }
00180
00181
00182
00183
00184
00185 CDCDSerialPort *DUALCDCDDriver_GetSerialPort(uint32_t port)
00186 {
00187 if (port < NUM_PORTS)
00188 return &dualcdcdDriver.cdcdSerialPort[port];
00189
00190 return 0;
00191 }
00192
00193
00194