Samuel Mokrani
/
USBHID_HelloWorld
USBHID Hello World
main.cpp@5:b1d34990a376, 2011-11-30 (annotated)
- Committer:
- samux
- Date:
- Wed Nov 30 11:10:44 2011 +0000
- Revision:
- 5:b1d34990a376
- Parent:
- 3:8f52e961548d
- Child:
- 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" |
samux | 3:8f52e961548d | 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); |
samux | 5:b1d34990a376 | 6 | |
samux | 5:b1d34990a376 | 7 | Serial pc(USBTX, USBRX); |
samux | 3:8f52e961548d | 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; |
samux | 5:b1d34990a376 | 12 | |
samux | 5:b1d34990a376 | 13 | DigitalOut l1(LED1); |
samux | 3:8f52e961548d | 14 | |
samux | 3:8f52e961548d | 15 | int main(void) { |
samux | 5:b1d34990a376 | 16 | send_report.length = 8; |
samux | 5:b1d34990a376 | 17 | |
samux | 3:8f52e961548d | 18 | while (1) { |
samux | 5:b1d34990a376 | 19 | |
samux | 5:b1d34990a376 | 20 | //Fill the report |
samux | 5:b1d34990a376 | 21 | for (int i = 0; i < send_report.length; i++) |
samux | 5:b1d34990a376 | 22 | send_report.data[i] = rand() & 0xff; |
samux | 5:b1d34990a376 | 23 | |
samux | 3:8f52e961548d | 24 | //Send the report |
samux | 3:8f52e961548d | 25 | hid.send(&send_report); |
samux | 5:b1d34990a376 | 26 | |
samux | 5:b1d34990a376 | 27 | //try to read a msg |
samux | 5:b1d34990a376 | 28 | if(hid.readNB(&recv_report)) { |
samux | 5:b1d34990a376 | 29 | l1 = !l1; |
samux | 5:b1d34990a376 | 30 | for(int i = 1; i < recv_report.length; i++) { |
samux | 5:b1d34990a376 | 31 | pc.printf("%d ", recv_report.data[i]); |
samux | 5:b1d34990a376 | 32 | } |
samux | 5:b1d34990a376 | 33 | pc.printf("\r\n"); |
samux | 5:b1d34990a376 | 34 | } |
samux | 3:8f52e961548d | 35 | } |
samux | 3:8f52e961548d | 36 | } |