Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
USBHostGCUtilities.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 1:a5258871b33d
Method ramp scrolling improved, and more bitmaps moved to QSPI memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | |
jmitc91516 | 1:a5258871b33d | 2 | #include "USBHostGCUtilities.h" |
jmitc91516 | 1:a5258871b33d | 3 | |
jmitc91516 | 1:a5258871b33d | 4 | /* |
jmitc91516 | 1:a5258871b33d | 5 | As described in the header file, this is a class containing utility functions for communicating with the GC, |
jmitc91516 | 1:a5258871b33d | 6 | to try and reduce the amount of similar code duplicated between classes. |
jmitc91516 | 1:a5258871b33d | 7 | |
jmitc91516 | 1:a5258871b33d | 8 | All functions are static. |
jmitc91516 | 1:a5258871b33d | 9 | */ |
jmitc91516 | 1:a5258871b33d | 10 | |
jmitc91516 | 1:a5258871b33d | 11 | /* |
jmitc91516 | 1:a5258871b33d | 12 | As the name implies, sends a command to the GC and returns the response. |
jmitc91516 | 1:a5258871b33d | 13 | |
jmitc91516 | 1:a5258871b33d | 14 | Args: pointer to a USBDeviceConnected instance |
jmitc91516 | 1:a5258871b33d | 15 | pointer to a USBHostGC instance |
jmitc91516 | 1:a5258871b33d | 16 | pointer to a buffer containing the command, as a null-terminated string |
jmitc91516 | 1:a5258871b33d | 17 | pointer to a buffer to contain the response, as a null-terminated string |
jmitc91516 | 1:a5258871b33d | 18 | |
jmitc91516 | 1:a5258871b33d | 19 | No return code (it is up to the caller to examine the response to see whether |
jmitc91516 | 1:a5258871b33d | 20 | the command succeeded or failed) |
jmitc91516 | 1:a5258871b33d | 21 | */ |
jmitc91516 | 1:a5258871b33d | 22 | void USBHostGCUtilities::SendCommandToGCAndGetResponse(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, char* command, char* response) |
jmitc91516 | 1:a5258871b33d | 23 | { |
jmitc91516 | 1:a5258871b33d | 24 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 1:a5258871b33d | 25 | |
jmitc91516 | 1:a5258871b33d | 26 | usbHostGC->SetDeviceReport(usbDevice, command, response); |
jmitc91516 | 1:a5258871b33d | 27 | //#define DEBUG_PRINT_HERE |
jmitc91516 | 1:a5258871b33d | 28 | #ifdef DEBUG_PRINT_HERE |
jmitc91516 | 1:a5258871b33d | 29 | char dbg[100]; |
jmitc91516 | 1:a5258871b33d | 30 | sprintf(dbg, "USB::SendCmd cmd \"%s\", response \"%s\"", command, response); |
jmitc91516 | 1:a5258871b33d | 31 | SpecialDebugPrint(dbg, 10, 275); |
jmitc91516 | 1:a5258871b33d | 32 | #endif // DEBUG_PRINT_HERE |
jmitc91516 | 1:a5258871b33d | 33 | } |
jmitc91516 | 1:a5258871b33d | 34 | |
jmitc91516 | 1:a5258871b33d | 35 | |
jmitc91516 | 1:a5258871b33d | 36 | /* |
jmitc91516 | 1:a5258871b33d | 37 | Sends a command to the GC for which we expect a response of "DACK" if successful, |
jmitc91516 | 1:a5258871b33d | 38 | "DNAK" or "EPKT" if failure. |
jmitc91516 | 1:a5258871b33d | 39 | |
jmitc91516 | 1:a5258871b33d | 40 | Args: pointer to a USBDeviceConnected instance |
jmitc91516 | 1:a5258871b33d | 41 | pointer to a USBHostGC instance |
jmitc91516 | 1:a5258871b33d | 42 | a pointer to the command in question, as a null terminated string |
jmitc91516 | 1:a5258871b33d | 43 | |
jmitc91516 | 1:a5258871b33d | 44 | Returns true if the GC responded with "DACK", false for anything else |
jmitc91516 | 1:a5258871b33d | 45 | */ |
jmitc91516 | 1:a5258871b33d | 46 | bool USBHostGCUtilities::SendCommandToGCWithDACKResponse(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, char *cmd) |
jmitc91516 | 1:a5258871b33d | 47 | { |
jmitc91516 | 1:a5258871b33d | 48 | char response[50]; |
jmitc91516 | 1:a5258871b33d | 49 | SendCommandToGCAndGetResponse(usbDevice, usbHostGC, cmd, response); |
jmitc91516 | 1:a5258871b33d | 50 | // We expect a response like this: "DACK" for success, "DNAK" for failure, "EPKT" for error |
jmitc91516 | 1:a5258871b33d | 51 | |
jmitc91516 | 1:a5258871b33d | 52 | return (response[1] == 'A'); |
jmitc91516 | 1:a5258871b33d | 53 | } |