Samuel Mokrani
/
USBHID_HelloWorld
USBHID Hello World
Embed:
(wiki syntax)
Show/hide line numbers
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 send_report.length = 8; 00017 00018 while (1) { 00019 00020 //Fill the report 00021 for (int i = 0; i < send_report.length; i++) 00022 send_report.data[i] = rand() & 0xff; 00023 00024 //Send the report 00025 hid.send(&send_report); 00026 00027 //try to read a msg 00028 if(hid.readNB(&recv_report)) { 00029 l1 = !l1; 00030 for(int i = 1; i < recv_report.length; i++) { 00031 pc.printf("%d ", recv_report.data[i]); 00032 } 00033 pc.printf("\r\n"); 00034 } 00035 } 00036 }
Generated on Tue Jul 12 2022 14:04:59 by 1.7.2