yg lim
/
USBHID_HelloWorld
....
Fork of USBHID_HelloWorld by
main.cpp@8:51572f1cec33, 2015-02-16 (annotated)
- Committer:
- yglim
- Date:
- Mon Feb 16 04:54:21 2015 +0000
- Revision:
- 8:51572f1cec33
- Parent:
- 6:3f614fb580cd
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 3:8f52e961548d | 1 | #include "mbed.h" |
samux | 3:8f52e961548d | 2 | #include "USBHID.h" |
yglim | 8:51572f1cec33 | 3 | |
samux | 5:b1d34990a376 | 4 | //We declare a USBHID device. By default input and output reports are 64 bytes long. |
samux | 5:b1d34990a376 | 5 | USBHID hid(8, 8); |
yglim | 8:51572f1cec33 | 6 | |
samux | 5:b1d34990a376 | 7 | Serial pc(USBTX, USBRX); |
yglim | 8:51572f1cec33 | 8 | |
samux | 3:8f52e961548d | 9 | //This report will contain data to be sent |
samux | 3:8f52e961548d | 10 | HID_REPORT send_report; |
samux | 5:b1d34990a376 | 11 | HID_REPORT recv_report; |
yglim | 8:51572f1cec33 | 12 | |
samux | 5:b1d34990a376 | 13 | DigitalOut l1(LED1); |
yglim | 8:51572f1cec33 | 14 | |
yglim | 8:51572f1cec33 | 15 | int main(void) |
yglim | 8:51572f1cec33 | 16 | { |
samux | 5:b1d34990a376 | 17 | send_report.length = 8; |
yglim | 8:51572f1cec33 | 18 | |
samux | 3:8f52e961548d | 19 | while (1) { |
yglim | 8:51572f1cec33 | 20 | |
samux | 5:b1d34990a376 | 21 | //Fill the report |
samux | 5:b1d34990a376 | 22 | for (int i = 0; i < send_report.length; i++) |
samux | 5:b1d34990a376 | 23 | send_report.data[i] = rand() & 0xff; |
yglim | 8:51572f1cec33 | 24 | |
samux | 3:8f52e961548d | 25 | //Send the report |
samux | 3:8f52e961548d | 26 | hid.send(&send_report); |
yglim | 8:51572f1cec33 | 27 | |
samux | 5:b1d34990a376 | 28 | //try to read a msg |
samux | 5:b1d34990a376 | 29 | if(hid.readNB(&recv_report)) { |
samux | 5:b1d34990a376 | 30 | l1 = !l1; |
samux | 5:b1d34990a376 | 31 | for(int i = 1; i < recv_report.length; i++) { |
samux | 5:b1d34990a376 | 32 | pc.printf("%d ", recv_report.data[i]); |
samux | 5:b1d34990a376 | 33 | } |
samux | 5:b1d34990a376 | 34 | pc.printf("\r\n"); |
samux | 5:b1d34990a376 | 35 | } |
samux | 3:8f52e961548d | 36 | } |
samux | 3:8f52e961548d | 37 | } |