yg lim / Mbed 2 deprecated USBHID_HelloWorld

Dependencies:   USBDevice mbed

Fork of USBHID_HelloWorld by Samuel Mokrani

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBHID.h"
00003 
00004 //We declare a USBHID device. By default input and output reports are 64 bytes long.
00005 USBHID hid(8, 8);
00006 
00007 Serial pc(USBTX, USBRX);
00008 
00009 //This report will contain data to be sent
00010 HID_REPORT send_report;
00011 HID_REPORT recv_report;
00012 
00013 DigitalOut l1(LED1);
00014 
00015 int main(void)
00016 {
00017     send_report.length = 8;
00018 
00019     while (1) {
00020 
00021         //Fill the report
00022         for (int i = 0; i < send_report.length; i++)
00023             send_report.data[i] = rand() & 0xff;
00024 
00025         //Send the report
00026         hid.send(&send_report);
00027 
00028         //try to read a msg
00029         if(hid.readNB(&recv_report)) {
00030             l1 = !l1;
00031             for(int i = 1; i < recv_report.length; i++) {
00032                 pc.printf("%d ", recv_report.data[i]);
00033             }
00034             pc.printf("\r\n");
00035         }
00036     }
00037 }