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.
Revision 0:471646bf5f7e, committed 2022-06-16
- Comitter:
- cspista
- Date:
- Thu Jun 16 12:51:10 2022 +0000
- Child:
- 1:86e3171a1f42
- Commit message:
- Final version
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Thu Jun 16 12:51:10 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/USBDevice/#53949e6131f6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jun 16 12:51:10 2022 +0000
@@ -0,0 +1,61 @@
+/* LAB10_USBHID_pnp
+ *
+ * This is a simple Generic HID demo, which is more or less
+ * compatible with the USB HID PnP demo example from the
+ * Microchip Applications Library, so that the PC application
+ * from that package can be used with our firmware as well
+ * (after two small modification).
+ *
+ * The differences:
+ * - We use 12 bit ADC resolution (instead of 10 bit)
+ * - We use Vid=0x0483, Pid=0x5750 which are the official
+ * STM32 Custom Human Interface Device identifiers from
+ * ST Microelectronics.
+ */
+
+#include "mbed.h"
+#include "USBHID.h"
+
+//We declare a USBHID device. Here the input and output reports are 64 bytes long.
+USBHID hid(64,64,0x0483,0x5750); // Vid/Pid: STM32 Custom Human Interface Device
+
+HID_REPORT send_report; //This report will contain data to be sent
+HID_REPORT recv_report; //This report will contain data received
+
+DigitalOut LED_1(LED1); //Buitin KED at PA5
+DigitalIn SW1(BUTTON1,PullUp); //Builtin button at PC13
+AnalogIn adc(A0); //Analog input at A0 (PA0)
+
+int main(void) {
+ uint16_t val = 0;
+ send_report.length = 64;
+ LED_1 = 0;
+ for (int i = 0; i < send_report.length; i++) // Fill the report
+ send_report.data[i] = 0x00;
+ while (1) {
+ if(hid.readNB(&recv_report)) { // try to read a msg
+ switch(recv_report.data[0]) {
+ case 0x80: //Toggle LED state
+ LED_1 = !LED_1;
+ break;
+ case 0x81: //Get push button state
+ send_report.data[0] = recv_report.data[0];
+ send_report.data[1] = SW1;
+ send_report.data[2] = 0;
+ hid.send(&send_report); // Send the report
+ break;
+ case 0x37: //Read POT command.
+ send_report.data[0] = recv_report.data[0];
+ val = adc.read_u16()>>4; // Convert to 12-bits
+ send_report.data[1] = val & 0xFF; // Measured value LSB
+ send_report.data[2] = val >> 8; // Measured value MSB
+ hid.send(&send_report); // Send the report
+ break;
+ default: {
+ send_report.data[0] = 0xFF; // Invalid command
+ hid.send(&send_report); // Send the report
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jun 16 12:51:10 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file