Oscar de Jesus Vasquez
/
USBHID_TestCase_LV
-----
Fork of USBHID_TestCase by
main.cpp@0:53dfbb3eae55, 2011-11-17 (annotated)
- Committer:
- samux
- Date:
- Thu Nov 17 11:29:46 2011 +0000
- Revision:
- 0:53dfbb3eae55
- Child:
- 1:07d521565fd7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:53dfbb3eae55 | 1 | #include "mbed.h" |
samux | 0:53dfbb3eae55 | 2 | #include "USBHID.h" |
samux | 0:53dfbb3eae55 | 3 | |
samux | 0:53dfbb3eae55 | 4 | //We declare a USBHID device. By default input and output reports are 64 bytes long. |
samux | 0:53dfbb3eae55 | 5 | USBHID hid; |
samux | 0:53dfbb3eae55 | 6 | |
samux | 0:53dfbb3eae55 | 7 | //This report will contain data to be sent |
samux | 0:53dfbb3eae55 | 8 | HID_REPORT send_report; |
samux | 0:53dfbb3eae55 | 9 | HID_REPORT recv_report; |
samux | 0:53dfbb3eae55 | 10 | |
samux | 0:53dfbb3eae55 | 11 | Serial pc(USBTX, USBRX); |
samux | 0:53dfbb3eae55 | 12 | |
samux | 0:53dfbb3eae55 | 13 | int main(void) { |
samux | 0:53dfbb3eae55 | 14 | send_report.length = 64; |
samux | 0:53dfbb3eae55 | 15 | |
samux | 0:53dfbb3eae55 | 16 | while (1) { |
samux | 0:53dfbb3eae55 | 17 | //Fill the report |
samux | 0:53dfbb3eae55 | 18 | for (int i = 0; i < send_report.length; i++) { |
samux | 0:53dfbb3eae55 | 19 | send_report.data[i] = rand() & 0xff; |
samux | 0:53dfbb3eae55 | 20 | } |
samux | 0:53dfbb3eae55 | 21 | |
samux | 0:53dfbb3eae55 | 22 | //Send the report |
samux | 0:53dfbb3eae55 | 23 | hid.send(&send_report); |
samux | 0:53dfbb3eae55 | 24 | |
samux | 0:53dfbb3eae55 | 25 | //try to read a msg |
samux | 0:53dfbb3eae55 | 26 | if(hid.readNB(&recv_report)) { |
samux | 0:53dfbb3eae55 | 27 | for(int i = 0; i < recv_report.length; i++) { |
samux | 0:53dfbb3eae55 | 28 | pc.printf("%d ", recv_report.data[i]); |
samux | 0:53dfbb3eae55 | 29 | } |
samux | 0:53dfbb3eae55 | 30 | pc.printf("\r\n"); |
samux | 0:53dfbb3eae55 | 31 | } |
samux | 0:53dfbb3eae55 | 32 | |
samux | 0:53dfbb3eae55 | 33 | wait(0.1); |
samux | 0:53dfbb3eae55 | 34 | } |
samux | 0:53dfbb3eae55 | 35 | } |