USBHID test case

Dependencies:   USBDevice mbed

Committer:
samux
Date:
Fri Mar 01 13:23:28 2013 +0000
Revision:
3:19e7fc58da6b
Parent:
2:1db77338562f
use latest USBDevice lib (FRDM-KL25Z support)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 2:1db77338562f 1 #include "mbed.h"
samux 2:1db77338562f 2 #include "USBHID.h"
samux 2:1db77338562f 3
samux 2:1db77338562f 4 //We declare a USBHID device. Input out output reports have a length of 8 bytes
samux 2:1db77338562f 5 USBHID hid(8, 8);
samux 2:1db77338562f 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;
samux 2:1db77338562f 10
samux 2:1db77338562f 11 Serial pc(USBTX, USBRX);
samux 2:1db77338562f 12
samux 2:1db77338562f 13 int main(void) {
samux 2:1db77338562f 14 send_report.length = 8;
samux 2:1db77338562f 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 }
samux 2:1db77338562f 21
samux 2:1db77338562f 22 //Send the report
samux 2:1db77338562f 23 hid.send(&send_report);
samux 2:1db77338562f 24
samux 2:1db77338562f 25 //try to read a msg
samux 2:1db77338562f 26 if(hid.readNB(&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 }
samux 2:1db77338562f 33
samux 2:1db77338562f 34 wait(0.1);
samux 2:1db77338562f 35 }
samux 0:53dfbb3eae55 36 }