USBHost Gamepad driver sample for GR-PEACH

Dependencies:   USBHostGamepad mbed-src

/media/uploads/YuuichiAkagawa/peach-gamepad.jpg

ReportDescriptor

09 04     Usage(Gamepad)
A1 01     Collection(Application)
 A1 02     Collection(Logical)
  75 08      ReportSize=8
  95 02      ReportCount=2
  15 00      LogicalMinimum(0)
  26 FF 00   LogicalMaximum(255)
  35 00      PhysicalMinimum(0)
  46 FF 00   PhysicalMaximum(255)
  09 30      Usage(X)
  09 31      Usage(Y)
  81 02      Input(Data, Variable, Absolute)
  95 03      ReportCount=3
  81 01      Input(Const, Array, Absolute)
  75 01      ReportSize=1
  95 04      ReportCount=4
  25 01      LogicalMaximum(1)
  45 01      PhysicalMaximum(1)
  81 01      Input(Const, Array, Absolute)
  75 01      ReportSize=1
  95 06      ReportCount=6
  25 01      LogicalMaximum(1)
  45 01      PhysicalMaximum(1)
  05 09      UsagePage(Button) 
  19 01      UageMinimum(1)
  29 06      UsageMaximum(6)
  81 02      Input(Data, Variable, Absolute)
  06 00 FF   UsagePage(VendorDefined)
  75 01      ReportSize=1
  95 0E      ReportCount=14
  25 01      LogicalMaximum(1)
  45 01      PhysicalMaximum(1)
  09 01      Usage(Pointer)
  81 02      Input(Data, Variable, Absolute)
 C0          EndCollection
 A1 02       Collection(Logical)
  75 08      ReportSize=8
  95 07      ReportCount=7
  46 FF 00   PhysicalMaximum(255)
  26 FF 00   LogicalMaximum(255)
  09 02      Usage(Mouse)
  91 02      OUTPUT(Data, Variable, Absolute)
 C0          EndCollection
C0           EndCollection

main.cpp

Committer:
YuuichiAkagawa
Date:
2015-01-14
Revision:
1:5c0f9b413b1e
Parent:
0:e6aa53f51545

File content as of revision 1:5c0f9b413b1e:

#include "mbed.h"
#include "USBHostGamepad.h"

Serial pc(USBTX, USBRX);
DigitalOut led(LED1);

void onEvent(uint8_t btnX, uint8_t btnY, uint8_t btnABCD, uint8_t btnSpecial) {
    
    pc.printf(" D-Pad : X:%02X Y:%02X\r\n", btnX, btnY);
    pc.printf(" Button: %c%c%c%c %s %s %s\r\n", ((btnABCD & 0x10)? 'A':'-'),
                                       ((btnABCD & 0x20)? 'B':'-'),
                                       ((btnABCD & 0x40)? 'C':'-'),
                                       ((btnABCD & 0x80)? 'D':'-'),
                                       ((btnSpecial & 0x8)? "-----":"TURBO"),
                                       ((btnSpecial & 0x2)? "Select":"------"),
                                       ((btnSpecial & 0x1)? "Start" :"-----"));
}
 
void gamepad_task(void const *) {
 
    USBHostGamepad gamepad;
 
    while(1) {
        // try to connect a USB gamepad
        while(!gamepad.connect())
            Thread::wait(500);
 
        // when connected, attach handler called on gamepad event
        gamepad.attachEvent(onEvent);
 
        // wait until the gamepad is disconnected
        while(gamepad.connected())
            Thread::wait(500);
    }
}
 
int main() {
    Thread gamepadTask(gamepad_task, NULL, osPriorityNormal, 256 * 4);
    while(1) {
        led=!led;
        Thread::wait(500);
    }
}