....

Dependencies:   USBDevice mbed

Fork of USBHID_HelloWorld by Samuel Mokrani

Committer:
samux
Date:
Thu Nov 03 12:26:16 2011 +0000
Revision:
1:0216a6726c1c
Parent:
0:30b74cf0e645
Child:
2:d07a799c6926

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:30b74cf0e645 1 #include "mbed.h"
samux 0:30b74cf0e645 2 #include "USBHID.h"
samux 0:30b74cf0e645 3
samux 1:0216a6726c1c 4 //We declare a USBHID device: it can send 1 byte and receive 1 byte
samux 1:0216a6726c1c 5 USBHID hid(1, 1);
samux 1:0216a6726c1c 6
samux 1:0216a6726c1c 7 //Two reports where will be stored values to send and received
samux 1:0216a6726c1c 8 HID_REPORT recv_report;
samux 1:0216a6726c1c 9 HID_REPORT send_report;
samux 1:0216a6726c1c 10
samux 1:0216a6726c1c 11 //Bus of leds
samux 0:30b74cf0e645 12 BusOut leds(LED1,LED2,LED3,LED4);
samux 0:30b74cf0e645 13
samux 1:0216a6726c1c 14 //Bus of buttons
samux 1:0216a6726c1c 15 BusInOut buttons(p21, p22, p23, p24);
samux 1:0216a6726c1c 16
samux 0:30b74cf0e645 17 int main(void) {
samux 1:0216a6726c1c 18 uint8_t p_bus = 0;
samux 1:0216a6726c1c 19 send_report.length = 1;
samux 1:0216a6726c1c 20
samux 0:30b74cf0e645 21 while (1) {
samux 1:0216a6726c1c 22 //If a data is received, update led bus
samux 1:0216a6726c1c 23 if (hid.readNB(&recv_report)) {
samux 1:0216a6726c1c 24 leds = recv_report.data[0];
samux 1:0216a6726c1c 25 }
samux 1:0216a6726c1c 26
samux 1:0216a6726c1c 27 //if the bus of buttons has changed, send a report
samux 1:0216a6726c1c 28 if (buttons.read() != p_bus) {
samux 1:0216a6726c1c 29 p_bus = buttons.read();
samux 1:0216a6726c1c 30 send_report.data[0] = p_bus;
samux 1:0216a6726c1c 31 hid.send(&send_report);
samux 1:0216a6726c1c 32 }
samux 1:0216a6726c1c 33 wait(0.01);
samux 0:30b74cf0e645 34 }
samux 0:30b74cf0e645 35 }