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
00039 #include <HIDDFunction.h>
00040 #include <HIDDMouseDriver.h>
00041
00042 #include "USBD.h"
00043 #include <USBD_HAL.h>
00044 #include <USBDDriver.h>
00045
00046 #include <USBLib_Trace.h>
00047
00048
00049
00050
00051
00052
00053 #define HIDDMouse_TAG (1 << 3)
00054
00055 #define HIDDMouse_Xsign (1 << 4)
00056
00057 #define HIDDMouse_Ysign (1 << 5)
00058
00059
00060
00061
00062
00063
00064
00065
00066 typedef struct _HIDDMouseReport {
00067
00068 HIDDReportEventCallback fCallback;
00069
00070 void *pArg;
00071
00072
00073 uint16_t wMaxSize;
00074
00075 uint16_t wTransferred;
00076
00077 uint8_t bIdleRate;
00078
00079 uint8_t bDelay;
00080
00081 uint8_t bID;
00082
00083 HIDDMouseInputReport report;
00084 } HIDDMouseReport;
00085
00086
00087
00088
00089 typedef struct _HIDDMouseDriver {
00090
00091
00092 HIDDFunction hidDrv;
00093
00094 HIDDReport *inputReports[1];
00095 } HIDDMouseDriver;
00096
00097
00098
00099
00100
00101
00102 static HIDDMouseDriver hiddMouseDriver;
00103
00104
00105 static HIDDMouseReport hiddInputReport;
00106
00107
00108 static const uint8_t hiddReportDescriptor[] = {
00109
00110
00111 HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID,
00112
00113 HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_MOUSE,
00114 HIDReport_COLLECTION + 1, HIDReport_COLLECTION_APPLICATION,
00115
00116 HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_POINTER,
00117 HIDReport_COLLECTION + 1, HIDReport_COLLECTION_PHYSICAL,
00118
00119
00120 HIDReport_GLOBAL_USAGEPAGE + 1, HIDButton_PAGEID,
00121
00122 HIDReport_GLOBAL_REPORTCOUNT + 1, 3,
00123 HIDReport_GLOBAL_REPORTSIZE + 1, 1,
00124 HIDReport_LOCAL_USAGEMINIMUM + 1, 1,
00125 HIDReport_LOCAL_USAGEMAXIMUM + 1, 3,
00126 HIDReport_GLOBAL_LOGICALMINIMUM + 1, 0,
00127 HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 1,
00128 HIDReport_INPUT + 1, HIDReport_VARIABLE,
00129
00130
00131 HIDReport_GLOBAL_REPORTCOUNT + 1, 1,
00132 HIDReport_GLOBAL_REPORTSIZE + 1, 5,
00133 HIDReport_INPUT + 1, HIDReport_CONSTANT,
00134
00135
00136 HIDReport_GLOBAL_USAGEPAGE + 1, HIDGenericDesktop_PAGEID,
00137 HIDReport_GLOBAL_REPORTSIZE + 1, 8,
00138 HIDReport_GLOBAL_REPORTCOUNT + 1, 2,
00139 HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_X,
00140 HIDReport_LOCAL_USAGE + 1, HIDGenericDesktop_Y,
00141 HIDReport_GLOBAL_LOGICALMINIMUM + 1, (uint8_t) - 127,
00142 HIDReport_GLOBAL_LOGICALMAXIMUM + 1, 127,
00143 HIDReport_INPUT + 1, HIDReport_VARIABLE | HIDReport_RELATIVE,
00144
00145 HIDReport_ENDCOLLECTION,
00146 HIDReport_ENDCOLLECTION
00147 };
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 void HIDDMouseDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
00162 {
00163 HIDDMouseDriver *pMouse = &hiddMouseDriver;
00164 HIDDFunction *pHidd = &pMouse->hidDrv;
00165 USBDDriver *pUsbd = USBD_GetDriver();
00166
00167
00168 pMouse->inputReports[0] = (HIDDReport *)&hiddInputReport;
00169 HIDDFunction_InitializeReport(pMouse->inputReports[0],
00170 HIDDMouseDriver_REPORTDESCRIPTORSIZE,
00171 0,
00172 0, 0);
00173
00174
00175 USBDDriver_Initialize(pUsbd,
00176 pDescriptors,
00177 0);
00178
00179 HIDDFunction_Initialize(pHidd,
00180 pUsbd, 0,
00181 hiddReportDescriptor,
00182 (HIDDReport **)(&pMouse->inputReports), 1,
00183 0, 0);
00184 USBD_Init();
00185 }
00186
00187
00188
00189
00190
00191 void HIDDMouseDriver_ConfigurationChangedHandler(uint8_t cfgnum)
00192 {
00193 HIDDMouseDriver *pMouse = &hiddMouseDriver;
00194 HIDDFunction *pHidd = &pMouse->hidDrv;
00195 USBDDriver *pUsbd = pHidd->pUsbd;
00196 USBConfigurationDescriptor *pDesc;
00197
00198 if (cfgnum > 0) {
00199
00200
00201 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
00202 HIDDFunction_ParseInterface(pHidd,
00203 (USBGenericDescriptor *)pDesc,
00204 pDesc->wTotalLength);
00205 }
00206 }
00207
00208
00209
00210
00211
00212 void HIDDMouseDriver_RequestHandler(const USBGenericRequest *request)
00213 {
00214 HIDDMouseDriver *pMouse = &hiddMouseDriver;
00215 HIDDFunction *pHidd = &pMouse->hidDrv;
00216 USBDDriver *pUsbd = pHidd->pUsbd;
00217
00218 TRACE_INFO("NewReq ");
00219
00220
00221 if (USBRC_SUCCESS == HIDDFunction_RequestHandler(pHidd,
00222 request))
00223 return;
00224
00225 else
00226
00227 USBDDriver_RequestHandler(pUsbd, request);
00228
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238 uint8_t HIDDMouseDriver_ChangePoints(uint8_t bmButtons,
00239 int8_t deltaX,
00240 int8_t deltaY)
00241 {
00242 HIDDMouseDriver *pMouse = &hiddMouseDriver;
00243 HIDDFunction *pHidd = &pMouse->hidDrv;
00244 HIDDMouseInputReport *pReport = &hiddInputReport.report;
00245
00246 pReport->bmButtons = (bmButtons & 0x07) | HIDDMouse_TAG;
00247 pReport->bX = deltaX;
00248 pReport->bY = deltaY;
00249
00250
00251 return USBD_Write(pHidd->bPipeIN,
00252 (void *)pReport,
00253 sizeof(HIDDMouseInputReport),
00254 0,
00255 0);
00256 }
00257
00258
00259
00260
00261
00262 void HIDDMouseDriver_RemoteWakeUp(void)
00263 {
00264 HIDDMouseDriver *pMouse = &hiddMouseDriver;
00265 HIDDFunction *pHidd = &pMouse->hidDrv;
00266 USBDDriver *pUsbd = pHidd->pUsbd;
00267
00268
00269 if (USBDDriver_IsRemoteWakeUpEnabled(pUsbd))
00270
00271 USBD_RemoteWakeUp();
00272 }
00273
00274
00275