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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 #include "board.h"
00110
00111 #include <HIDDTransferDriver.h>
00112
00113 #include <stdio.h>
00114 #include <string.h>
00115
00116
00117
00118
00119
00120
00121 #define DEBOUNCE_TIME 10
00122 #define NO_PUSHBUTTON
00123
00124
00125
00126
00127
00128 extern USBDDriverDescriptors hiddTransferDriverDescriptors;
00129
00130
00131
00132
00133
00134
00135 #ifndef NO_PUSHBUTTON
00136 static Pin pinsButtons[] = { PINS_PUSHBUTTONS } ;
00137 #endif
00138
00139 #ifndef NO_PUSHBUTTON
00140
00141
00142
00143
00144
00145 static const Pin pinWakeUp = PIN_PUSHBUTTON_1 ;
00146
00147
00148
00149
00150
00151 static void WakeUpHandler( const Pin *pin )
00152 {
00153 TRACE_DEBUG( "Wake-up handler\n\r" ) ;
00154
00155
00156 if ( !PIO_Get( &pinWakeUp ) ) {
00157 HIDDTransferDriver_RemoteWakeUp() ;
00158 }
00159 }
00160
00161
00162
00163
00164 static void _ConfigureWakeUp( void )
00165 {
00166 TRACE_INFO( "Wake-up configuration\n\r" ) ;
00167
00168
00169 PIO_Configure( &pinWakeUp, 1 ) ;
00170 PIO_SetDebounceFilter( &pinWakeUp, DEBOUNCE_TIME );
00171 PIO_ConfigureIt( &pinWakeUp, WakeUpHandler ) ;
00172 PIO_EnableIt( &pinWakeUp ) ;
00173 }
00174 #endif
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 static void _ShowBuffer( uint8_t* pucBuffer, uint32_t dwLen )
00187 {
00188 uint32_t dw ;
00189
00190 for ( dw = 0 ; dw < dwLen ; dw++ ) {
00191 if ( (dw & 0x7) == 0 ) {
00192 printf( "\n\r" ) ;
00193 }
00194 printf( " %02x", pucBuffer[dw] ) ;
00195 }
00196 printf( "\n\r" ) ;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 void USBDCallbacks_RequestReceived(const USBGenericRequest *request)
00208 {
00209 HIDDTransferDriver_RequestHandler(request);
00210 }
00211
00212
00213
00214
00215
00216
00217 void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
00218 {
00219 HIDDTransferDriver_ConfigurationChangedHandler(cfgnum);
00220 }
00221
00222
00223
00224
00225 static void _ConfigureUotghs(void)
00226 {
00227
00228
00229
00230 PMC->PMC_SCDR = PMC_SCDR_USBCLK;
00231
00232 PMC->PMC_USB = PMC_USB_USBS;
00233
00234 PMC_EnablePeripheral(ID_USBHS);
00235 USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD_DEVICE;
00236
00237 PMC->CKGR_UCKR = CKGR_UCKR_UPLLEN | CKGR_UCKR_UPLLCOUNT(0xF);
00238
00239 while( !(PMC->PMC_SR & PMC_SR_LOCKU) );
00240
00241
00242 NVIC_EnableIRQ(USBHS_IRQn) ;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 int main( void )
00255 {
00256 uint32_t dwCnt=0 ;
00257 uint32_t dwLen ;
00258 uint8_t iBuffer[64] ;
00259 uint8_t oBuffer[64] = {0x80} ;
00260 uint8_t bmLEDs=0 ;
00261 uint8_t update ;
00262
00263
00264 WDT_Disable( WDT ) ;
00265
00266 SCB_EnableICache();
00267 SCB_EnableDCache();
00268
00269 printf( "-- USB Device HID Transfer Project %s --\n\r", SOFTPACK_VERSION ) ;
00270 printf( "-- %s\n\r", BOARD_NAME ) ;
00271 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00272
00273
00274 PIO_InitializeInterrupts( 0 ) ;
00275
00276
00277 _ConfigureUotghs();
00278
00279 #ifndef NO_PUSHBUTTON
00280
00281 _ConfigureWakeUp() ;
00282 #endif
00283
00284
00285 LED_Configure( LED_YELLOW1 ) ;
00286 LED_Configure( LED_YELLOW0 ) ;
00287 LED_Set( LED_YELLOW0 ) ;
00288 LED_Clear( LED_YELLOW1 ) ;
00289 #ifdef NO_PUSHBUTTON
00290 printf( "-- : DBG key 1 2 used as buttons\n\r" );
00291 printf( "-- : 1st press to push, 2nd press to release\n\r" );
00292 #else
00293 PIO_Configure( pinsButtons, PIO_LISTSIZE( pinsButtons ) ) ;
00294 #endif
00295
00296
00297 HIDDTransferDriver_Initialize( &hiddTransferDriverDescriptors ) ;
00298
00299
00300 USBD_Connect();
00301
00302
00303 while ( 1 ) {
00304 if ( USBD_GetState() < USBD_STATE_CONFIGURED ) {
00305 continue ;
00306 }
00307 update = 0 ;
00308 dwLen = HIDDTransferDriver_Read( iBuffer, 64 ) ;
00309 if ( dwLen ) {
00310 printf( "Data In(%u):",(unsigned int) dwLen ) ;
00311 _ShowBuffer( iBuffer, dwLen ) ;
00312
00313 bmLEDs = iBuffer[0] ;
00314 update = 1 ;
00315 }
00316 dwLen = HIDDTransferDriver_ReadReport( iBuffer, 64 ) ;
00317 if ( dwLen ) {
00318 printf( "Report In(%u):", (unsigned int)dwLen ) ;
00319 _ShowBuffer( iBuffer, dwLen ) ;
00320
00321 bmLEDs = iBuffer[0] ;
00322 update = 1 ;
00323 }
00324
00325 if ( update && (0x80 & bmLEDs) ) {
00326
00327 if ( bmLEDs & 0x01 ) {
00328 LED_Set( LED_YELLOW0 ) ;
00329 } else {
00330 LED_Clear( LED_YELLOW0 ) ;
00331 }
00332
00333
00334 if ( bmLEDs & 0x02 ) {
00335 LED_Set( LED_YELLOW1 ) ;
00336 } else {
00337 LED_Clear( LED_YELLOW1 ) ;
00338 }
00339 }
00340
00341 #ifdef NO_PUSHBUTTON
00342 if ( DBG_IsRxReady( ) ) {
00343 uint8_t key = DBG_GetChar( ) ;
00344 switch( key ) {
00345 case '1' :
00346 if (oBuffer[0] & 0x01) oBuffer[0] &= ~0x01u ;
00347 else oBuffer[0] |= 0x01u ;
00348 break ;
00349 case '2' :
00350 if (oBuffer[0] & 0x02) oBuffer[0] &= ~0x02u ;
00351 else oBuffer[0] |= 0x02u ;
00352 break ;
00353 }
00354 }
00355 #else
00356 oBuffer[0] = 0x80 ;
00357 if ( PIO_Get( &pinsButtons[PUSHBUTTON_BP1]) == 0 ) {
00358 oBuffer[0] |= 0x01 ;
00359 }
00360 if ( PIO_Get( &pinsButtons[PUSHBUTTON_BP2] ) == 0 ) {
00361 oBuffer[0] |= 0x02 ;
00362 }
00363 #endif
00364
00365 sprintf( (char*)&oBuffer[5], ":%04x:%05u!",
00366 (unsigned int)dwCnt, (unsigned int)dwCnt ) ;
00367 oBuffer[1] = (uint8_t)(dwCnt) ;
00368 oBuffer[2] = (uint8_t)(dwCnt >> 8) ;
00369 oBuffer[3] = (uint8_t)(dwCnt >> 16) ;
00370 oBuffer[4] = (uint8_t)(dwCnt >> 24) ;
00371 if ( USBD_STATUS_SUCCESS == HIDDTransferDriver_Write( oBuffer, 64, 0, 0 ) ) {
00372 dwCnt ++ ;
00373 }
00374 }
00375 }
00376