USBHID test case

Dependencies:   USBDevice mbed

Committer:
samux
Date:
Fri Nov 18 09:34:41 2011 +0000
Revision:
1:07d521565fd7
Parent:
0:53dfbb3eae55
Child:
2:1db77338562f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:53dfbb3eae55 1 #include "mbed.h"
samux 0:53dfbb3eae55 2 #include "USBHID.h"
samux 0:53dfbb3eae55 3
samux 1:07d521565fd7 4 //We declare a USBHID device. Input out output reports have a length of 8 bytes
samux 1:07d521565fd7 5 USBHID hid(8, 8);
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 1:07d521565fd7 14 send_report.length = 8;
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 1:07d521565fd7 27 pc.printf("recv: ");
samux 0:53dfbb3eae55 28 for(int i = 0; i < recv_report.length; i++) {
samux 0:53dfbb3eae55 29 pc.printf("%d ", recv_report.data[i]);
samux 0:53dfbb3eae55 30 }
samux 0:53dfbb3eae55 31 pc.printf("\r\n");
samux 0:53dfbb3eae55 32 }
samux 0:53dfbb3eae55 33
samux 0:53dfbb3eae55 34 wait(0.1);
samux 0:53dfbb3eae55 35 }
samux 0:53dfbb3eae55 36 }