29 _LIT(KOtgdiLddFilename, "otgdi"); |
29 _LIT(KOtgdiLddFilename, "otgdi"); |
30 _LIT(KUsbDeviceName, "Usbc"); |
30 _LIT(KUsbDeviceName, "Usbc"); |
31 _LIT(KFileName, "\\T_USBFILE.BIN"); |
31 _LIT(KFileName, "\\T_USBFILE.BIN"); |
32 _LIT(KActivePanic, "T_USB"); |
32 _LIT(KActivePanic, "T_USB"); |
33 |
33 |
34 static const TUint32 KTusbVersion = 20070524; // just an edit date really |
34 static const TUint32 KTusbVersion = 20091224; // just an edit date really |
35 static const TUint8 KUsbrflctVersionMajor = 1; // the version we're compatible with |
35 static const TUint8 KUsbrflctVersionMajor = 1; // the version we're compatible with |
36 static const TUint8 KUsbrflctVersionMinor = 5; |
36 static const TUint8 KUsbrflctVersionMinor = 5; |
37 static const TUint8 KUsbrflctVersionMicro = 0; |
37 static const TUint8 KUsbrflctVersionMicro = 0; |
38 |
38 |
39 static const TInt KMaxFileSize = 100 * 1024 * 1024; // 100MB (requires at least 128MB card) |
39 static const TInt KMaxFileSize = 100 * 1024 * 1024; // 100MB (requires at least 128MB card) |
50 iConsole(aConsole), |
50 iConsole(aConsole), |
51 iRW(NULL), |
51 iRW(NULL), |
52 iBufferSizeChosen(EFalse), |
52 iBufferSizeChosen(EFalse), |
53 iBandwidthPriorityChosen(EFalse), |
53 iBandwidthPriorityChosen(EFalse), |
54 iDMAChosen(EFalse), |
54 iDMAChosen(EFalse), |
|
55 iAllocateDma(EFalse), |
55 iDoubleBufferingChosen(EFalse), |
56 iDoubleBufferingChosen(EFalse), |
|
57 iAllocateDoubleBuffering(EFalse), |
56 iSoftwareConnect(EFalse), |
58 iSoftwareConnect(EFalse), |
57 iHighSpeed(EFalse), |
59 iHighSpeed(EFalse), |
|
60 iResourceAllocationV2(EFalse), |
58 iOtg(EFalse), |
61 iOtg(EFalse), |
59 iVerbose(aVerboseOutput) |
62 iVerbose(aVerboseOutput) |
60 {} |
63 {} |
61 |
64 |
62 |
65 |
110 TUSB_PRINT("Failed to create reader/writer"); |
113 TUSB_PRINT("Failed to create reader/writer"); |
111 User::Leave(-1); |
114 User::Leave(-1); |
112 return; |
115 return; |
113 } |
116 } |
114 TUSB_PRINT("Created reader/writer"); |
117 TUSB_PRINT("Created reader/writer"); |
115 |
118 |
|
119 // check for endpoint resource allocation v2 support |
|
120 TUsbDeviceCaps d_caps; |
|
121 r = iPort.DeviceCaps(d_caps); |
|
122 if (r != KErrNone) |
|
123 { |
|
124 TUSB_PRINT1("Error %d on querying device capabilities", r); |
|
125 User::Leave(-1); |
|
126 return; |
|
127 } |
|
128 iResourceAllocationV2 = ((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0); |
|
129 |
116 // Check for OTG support |
130 // Check for OTG support |
117 TBuf8<KUsbDescSize_Otg> otg_desc; |
131 TBuf8<KUsbDescSize_Otg> otg_desc; |
118 r = iPort.GetOtgDescriptor(otg_desc); |
132 r = iPort.GetOtgDescriptor(otg_desc); |
119 if (!(r == KErrNotSupported || r == KErrNone)) |
133 if (!(r == KErrNotSupported || r == KErrNone)) |
120 { |
134 { |
371 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
385 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
372 goto request_char; |
386 goto request_char; |
373 } |
387 } |
374 TUSB_PRINT1("(Set to 0x%08X)", iBandwidthPriority); |
388 TUSB_PRINT1("(Set to 0x%08X)", iBandwidthPriority); |
375 iBandwidthPriorityChosen = ETrue; |
389 iBandwidthPriorityChosen = ETrue; |
376 |
390 |
|
391 if (!iResourceAllocationV2) |
|
392 { |
|
393 TUSB_PRINT("Configuring interface..."); |
|
394 TInt r = SetupInterface(); |
|
395 if (r != KErrNone) |
|
396 { |
|
397 TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
|
398 CActiveScheduler::Stop(); |
|
399 return; |
|
400 } |
|
401 } |
|
402 } |
|
403 else if (!iDMAChosen) |
|
404 { |
|
405 // Set DMA mode from keypress |
|
406 switch (aChar) |
|
407 { |
|
408 case '1': |
|
409 { |
|
410 TUSB_PRINT("- Trying to deallocate endpoint DMA:\n"); |
|
411 if (!iResourceAllocationV2) |
|
412 { |
|
413 DeAllocateEndpointDMA(EEndpoint1); |
|
414 DeAllocateEndpointDMA(EEndpoint2); |
|
415 } |
|
416 iAllocateDma = EFalse; |
|
417 break; |
|
418 } |
|
419 case '2': |
|
420 { |
|
421 TUSB_PRINT("- Trying to allocate endpoint DMA:\n"); |
|
422 if (!iResourceAllocationV2) |
|
423 { |
|
424 AllocateEndpointDMA(EEndpoint1); |
|
425 AllocateEndpointDMA(EEndpoint2); |
|
426 } |
|
427 iAllocateDma = ETrue; |
|
428 break; |
|
429 } |
|
430 default: |
|
431 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
432 goto request_char; |
|
433 } |
|
434 iDMAChosen = ETrue; |
|
435 } |
|
436 else if (!iDoubleBufferingChosen) |
|
437 { |
|
438 // Set Double Buffering from keypress |
|
439 switch (aChar) |
|
440 { |
|
441 case '1': |
|
442 { |
|
443 TUSB_PRINT("- Trying to deallocate Double Buffering:\n"); |
|
444 if (!iResourceAllocationV2) |
|
445 { |
|
446 DeAllocateDoubleBuffering(EEndpoint1); |
|
447 DeAllocateDoubleBuffering(EEndpoint2); |
|
448 } |
|
449 iAllocateDoubleBuffering = EFalse; |
|
450 break; |
|
451 } |
|
452 case '2': |
|
453 { |
|
454 TUSB_PRINT("- Trying to allocate Double Buffering:\n"); |
|
455 if (!iResourceAllocationV2) |
|
456 { |
|
457 AllocateDoubleBuffering(EEndpoint1); |
|
458 AllocateDoubleBuffering(EEndpoint2); |
|
459 } |
|
460 iAllocateDoubleBuffering = ETrue; |
|
461 break; |
|
462 } |
|
463 default: |
|
464 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
465 goto request_char; |
|
466 } |
|
467 iDoubleBufferingChosen = ETrue; |
|
468 |
|
469 if (iResourceAllocationV2) |
|
470 { |
377 TUSB_PRINT("Configuring interface..."); |
471 TUSB_PRINT("Configuring interface..."); |
378 TInt r = SetupInterface(); |
472 TInt r = SetupInterface(); |
379 if (r != KErrNone) |
473 if (r != KErrNone) |
380 { |
474 { |
381 TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
475 TUSB_PRINT1("Error: %d. Stopping active scheduler...", r); |
382 CActiveScheduler::Stop(); |
476 CActiveScheduler::Stop(); |
383 return; |
477 return; |
384 } |
478 } |
385 } |
479 } |
386 else if (!iDMAChosen) |
|
387 { |
|
388 // Set DMA mode from keypress |
|
389 switch (aChar) |
|
390 { |
|
391 case '1': |
|
392 TUSB_PRINT("- Trying to deallocate endpoint DMA:\n"); |
|
393 DeAllocateEndpointDMA(EEndpoint1); |
|
394 DeAllocateEndpointDMA(EEndpoint2); |
|
395 break; |
|
396 case '2': |
|
397 TUSB_PRINT("- Trying to allocate endpoint DMA:\n"); |
|
398 AllocateEndpointDMA(EEndpoint1); |
|
399 AllocateEndpointDMA(EEndpoint2); |
|
400 break; |
|
401 default: |
|
402 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
403 goto request_char; |
|
404 } |
|
405 iDMAChosen = ETrue; |
|
406 } |
|
407 else if (!iDoubleBufferingChosen) |
|
408 { |
|
409 // Set Double Buffering from keypress |
|
410 switch (aChar) |
|
411 { |
|
412 case '1': |
|
413 TUSB_PRINT("- Trying to deallocate Double Buffering:\n"); |
|
414 DeAllocateDoubleBuffering(EEndpoint1); |
|
415 DeAllocateDoubleBuffering(EEndpoint2); |
|
416 break; |
|
417 case '2': |
|
418 TUSB_PRINT("- Trying to allocate Double Buffering:\n"); |
|
419 AllocateDoubleBuffering(EEndpoint1); |
|
420 AllocateDoubleBuffering(EEndpoint2); |
|
421 break; |
|
422 default: |
|
423 TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint()); |
|
424 goto request_char; |
|
425 } |
|
426 iDoubleBufferingChosen = ETrue; |
|
427 |
480 |
428 // Everything chosen, so let's re-enumerate... |
481 // Everything chosen, so let's re-enumerate... |
429 TUSB_PRINT("Enumeration..."); |
482 TUSB_PRINT("Enumeration..."); |
430 TInt r = ReEnumerate(); |
483 TInt r = ReEnumerate(); |
431 if (r != KErrNone) |
484 if (r != KErrNone) |
680 { |
733 { |
681 TUSB_PRINT1("No suitable endpoints found", r); |
734 TUSB_PRINT1("No suitable endpoints found", r); |
682 return KErrGeneral; |
735 return KErrGeneral; |
683 } |
736 } |
684 |
737 |
|
738 if (iResourceAllocationV2) |
|
739 { |
|
740 if (iAllocateDma) |
|
741 { |
|
742 ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DMA; |
|
743 ifc().iEndpointData[1].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DMA; |
|
744 } |
|
745 if (iAllocateDoubleBuffering) |
|
746 { |
|
747 ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
|
748 ifc().iEndpointData[1].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
|
749 } |
|
750 } |
|
751 |
685 _LIT16(ifcname, "T_USB Test Interface (Default Setting 0)"); |
752 _LIT16(ifcname, "T_USB Test Interface (Default Setting 0)"); |
686 ifc().iString = const_cast<TDesC16*>(&ifcname); |
753 ifc().iString = const_cast<TDesC16*>(&ifcname); |
687 ifc().iTotalEndpointsUsed = 2; |
754 ifc().iTotalEndpointsUsed = 2; |
688 ifc().iClass.iClassNum = 0xff; // vendor-specific |
755 ifc().iClass.iClassNum = 0xff; // vendor-specific |
689 ifc().iClass.iSubClassNum = 0xff; // vendor-specific |
756 ifc().iClass.iSubClassNum = 0xff; // vendor-specific |