Daiki Kato
/
USBHID_TestCase_mbed-os
USBHID test case for mbed-os.
Please refer to the following.
https://os.mbed.com/cookbook/USBHID-bindings-
main.cpp@4:fbf649bca9d0, 2018-12-10 (annotated)
- Committer:
- dkato
- Date:
- Mon Dec 10 01:53:38 2018 +0000
- Revision:
- 4:fbf649bca9d0
- Parent:
- 2:1db77338562f
Changed to mbed-os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 2:1db77338562f | 1 | #include "mbed.h" |
samux | 2:1db77338562f | 2 | #include "USBHID.h" |
dkato | 4:fbf649bca9d0 | 3 | |
samux | 2:1db77338562f | 4 | //We declare a USBHID device. Input out output reports have a length of 8 bytes |
dkato | 4:fbf649bca9d0 | 5 | USBHID hid(true, 8, 8); |
dkato | 4:fbf649bca9d0 | 6 | |
samux | 2:1db77338562f | 7 | //This report will contain data to be sent |
samux | 2:1db77338562f | 8 | HID_REPORT send_report; |
samux | 2:1db77338562f | 9 | HID_REPORT recv_report; |
dkato | 4:fbf649bca9d0 | 10 | |
samux | 2:1db77338562f | 11 | Serial pc(USBTX, USBRX); |
dkato | 4:fbf649bca9d0 | 12 | |
samux | 2:1db77338562f | 13 | int main(void) { |
samux | 2:1db77338562f | 14 | send_report.length = 8; |
dkato | 4:fbf649bca9d0 | 15 | |
samux | 2:1db77338562f | 16 | while (1) { |
samux | 2:1db77338562f | 17 | //Fill the report |
samux | 2:1db77338562f | 18 | for (int i = 0; i < send_report.length; i++) { |
samux | 2:1db77338562f | 19 | send_report.data[i] = rand() & 0xff; |
samux | 2:1db77338562f | 20 | } |
dkato | 4:fbf649bca9d0 | 21 | |
samux | 2:1db77338562f | 22 | //Send the report |
samux | 2:1db77338562f | 23 | hid.send(&send_report); |
dkato | 4:fbf649bca9d0 | 24 | |
samux | 2:1db77338562f | 25 | //try to read a msg |
dkato | 4:fbf649bca9d0 | 26 | if(hid.read_nb(&recv_report)) { |
samux | 2:1db77338562f | 27 | pc.printf("recv: "); |
samux | 2:1db77338562f | 28 | for(int i = 0; i < recv_report.length; i++) { |
samux | 2:1db77338562f | 29 | pc.printf("%d ", recv_report.data[i]); |
samux | 2:1db77338562f | 30 | } |
samux | 2:1db77338562f | 31 | pc.printf("\r\n"); |
samux | 2:1db77338562f | 32 | } |
dkato | 4:fbf649bca9d0 | 33 | |
samux | 2:1db77338562f | 34 | wait(0.1); |
samux | 2:1db77338562f | 35 | } |
dkato | 4:fbf649bca9d0 | 36 | } |