Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* LAB10_USBHID_demo 00002 * 00003 * This is a very simple Generic HID demo, which is based on the 00004 * example program shown in the Cypress AN82072 Application Note. 00005 * Due to the similarities, you can use the graphical PC application 00006 * from the published in the downloadable software package of the above 00007 * mentioned Application Note, if you set the Vid/PId valuaes of aur device 00008 * (VID = 0x1234, PID = 0x0006). 00009 * Note, that besides the Generic Hid Ui.exe executable, you also need 00010 * the dynamic library cyUSB.dll as well (freom the same ZIP package) 00011 */ 00012 00013 #include "mbed.h" 00014 #include "USBHID.h" 00015 00016 //We declare a USBHID device. By default input and output reports are 8 bytes long. 00017 USBHID hid(8, 8); 00018 00019 HID_REPORT send_report; //This report will contain data to be sent 00020 HID_REPORT recv_report; //This report will contain data received 00021 00022 DigitalOut LED_1(LED1); //Buitin KED at PA5 00023 PwmOut LED_2(D3); //External LED at D3 (PB3) 00024 DigitalOut myGND(D4); 00025 DigitalIn SW1(BUTTON1,PullUp); //Builtin button at PC13 00026 AnalogIn adc(A0); //Analog input at A0 (PA0) 00027 00028 int main(void) { 00029 send_report.length = 8; 00030 LED_1 = 0; 00031 LED_2.period_ms(20); 00032 myGND = 0; 00033 while (1) { 00034 uint16_t raw = adc.read_u16(); //Read ADC (A0 chan) 00035 for (int i = 0; i < send_report.length; i++) //Fill the report 00036 send_report.data[i] = 0x00; 00037 send_report.data[0] = !SW1.read(); 00038 send_report.data[3] = (raw>>8); 00039 send_report.data[4] = (raw & 0xff); 00040 hid.send(&send_report); //Send the report 00041 00042 if(hid.readNB(&recv_report)) { //try to read a msg 00043 LED_1 = recv_report.data[0]; 00044 LED_2.write(recv_report.data[1]*0.01f); 00045 } 00046 } 00047 }
Generated on Tue Sep 20 2022 06:57:21 by
1.7.2