Reading data from a USB Gamepad with USB-Host mode.
Fork of Nucleo_Ex04_USBPAD by
main.cpp@1:94e011434208, 2016-04-28 (annotated)
- Committer:
- jose_23991
- Date:
- Thu Apr 28 21:09:39 2016 +0000
- Revision:
- 1:94e011434208
- Parent:
- 0:b5f79b4f741d
- Child:
- 2:7c1379b29ce6
Nucleo_GamepadUSB tested, working with low speeds devices, but not with full speed!! why??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jose_23991 | 1:94e011434208 | 1 | // Pins connections: 5V-Vbus | GND-GND | Data+-PA_12 | Data--PA_11 |
jose_23991 | 1:94e011434208 | 2 | |
beaglescout007 | 0:b5f79b4f741d | 3 | #include "mbed.h" |
beaglescout007 | 0:b5f79b4f741d | 4 | #include "USBHostGamepad.h" |
beaglescout007 | 0:b5f79b4f741d | 5 | |
beaglescout007 | 0:b5f79b4f741d | 6 | USBHostGamepad *pad; |
beaglescout007 | 0:b5f79b4f741d | 7 | |
jose_23991 | 1:94e011434208 | 8 | Serial serial(SERIAL_TX, SERIAL_RX); |
jose_23991 | 1:94e011434208 | 9 | |
beaglescout007 | 0:b5f79b4f741d | 10 | // LED |
jose_23991 | 1:94e011434208 | 11 | DigitalOut led(LED1, 0); // Create the LED object and setup OFF |
beaglescout007 | 0:b5f79b4f741d | 12 | |
beaglescout007 | 0:b5f79b4f741d | 13 | int main() |
beaglescout007 | 0:b5f79b4f741d | 14 | { |
jose_23991 | 1:94e011434208 | 15 | // USB Gamepad Initialize |
beaglescout007 | 0:b5f79b4f741d | 16 | pad = new USBHostGamepad(); |
beaglescout007 | 0:b5f79b4f741d | 17 | if (!pad->connect()) { |
jose_23991 | 1:94e011434208 | 18 | serial.printf("USB Connection failed\r\n"); |
beaglescout007 | 0:b5f79b4f741d | 19 | while(1); |
beaglescout007 | 0:b5f79b4f741d | 20 | } |
jose_23991 | 1:94e011434208 | 21 | else |
jose_23991 | 1:94e011434208 | 22 | { |
jose_23991 | 1:94e011434208 | 23 | led = 1; |
jose_23991 | 1:94e011434208 | 24 | serial.printf("USB Connection stablished\r\n"); |
jose_23991 | 1:94e011434208 | 25 | } |
beaglescout007 | 0:b5f79b4f741d | 26 | |
beaglescout007 | 0:b5f79b4f741d | 27 | while(1) |
beaglescout007 | 0:b5f79b4f741d | 28 | { |
beaglescout007 | 0:b5f79b4f741d | 29 | USBHost::poll(); |
beaglescout007 | 0:b5f79b4f741d | 30 | |
jose_23991 | 1:94e011434208 | 31 | serial.printf("%02x %02x %02x %02x %02x %02x %02x %02x\r\n", pad->report[0],pad->report[1],pad->report[2],pad->report[3],pad->report[4],pad->report[5],pad->report[6],pad->report[7]); |
beaglescout007 | 0:b5f79b4f741d | 32 | wait_ms(16); |
beaglescout007 | 0:b5f79b4f741d | 33 | } |
beaglescout007 | 0:b5f79b4f741d | 34 | } |