USB MSD HID composite device hello world

Dependencies:   USBDevice mbed

Committer:
samux
Date:
Mon Jan 21 12:03:05 2013 +0000
Revision:
0:61e5ecd27a36
USB MSD HID composite device hello world

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:61e5ecd27a36 1 #include "mbed.h"
samux 0:61e5ecd27a36 2 #include "USBMSD_SD.h"
samux 0:61e5ecd27a36 3
samux 0:61e5ecd27a36 4 USBMSD_SD hid_sd(p5, p6, p7, p8, 8, 8);
samux 0:61e5ecd27a36 5 DigitalOut l1(LED1);
samux 0:61e5ecd27a36 6
samux 0:61e5ecd27a36 7 //This report will contain data to be sent
samux 0:61e5ecd27a36 8 HID_REPORT send_report;
samux 0:61e5ecd27a36 9 HID_REPORT recv_report;
samux 0:61e5ecd27a36 10
samux 0:61e5ecd27a36 11 int main() {
samux 0:61e5ecd27a36 12 send_report.length = 8;
samux 0:61e5ecd27a36 13
samux 0:61e5ecd27a36 14 while (1) {
samux 0:61e5ecd27a36 15
samux 0:61e5ecd27a36 16 //Fill the report
samux 0:61e5ecd27a36 17 for (int i = 0; i < send_report.length; i++)
samux 0:61e5ecd27a36 18 send_report.data[i] = rand() & 0xff;
samux 0:61e5ecd27a36 19
samux 0:61e5ecd27a36 20 //Send the report
samux 0:61e5ecd27a36 21 hid_sd.send(&send_report);
samux 0:61e5ecd27a36 22
samux 0:61e5ecd27a36 23 //try to read a msg
samux 0:61e5ecd27a36 24 if(hid_sd.readNB(&recv_report)) {
samux 0:61e5ecd27a36 25 l1 = !l1;
samux 0:61e5ecd27a36 26 for(int i = 1; i < recv_report.length; i++) {
samux 0:61e5ecd27a36 27 printf("%d ", recv_report.data[i]);
samux 0:61e5ecd27a36 28 }
samux 0:61e5ecd27a36 29 printf("\r\n");
samux 0:61e5ecd27a36 30 }
samux 0:61e5ecd27a36 31 }
samux 0:61e5ecd27a36 32 }