KRAI 2017 / Mbed 2 deprecated USBPAD

Dependencies:   mbed

Fork of Nucleo_Ex04_USBPAD by woodstock .

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostGamepad.h Source File

USBHostGamepad.h

00001 /* 
00002  * modified from
00003  * mbed USBHost Gamepad driver sample
00004  * Copyright (c) 2014 Yuuichi Akagawa
00005  *
00006  * modified from mbed USBHostMouse
00007  *
00008  * Copyright (c) 2014 mbed.org, MIT License
00009  *
00010  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00011  * and associated documentation files (the "Software"), to deal in the Software without
00012  * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00013  * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00014  * Software is furnished to do so, subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included in all copies or
00017  * substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00020  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00024  */
00025 
00026 #ifndef USBHOSTGAMEPAD_H
00027 #define USBHOSTGAMEPAD_H
00028 
00029 #include "USBHostConf.h"
00030 
00031 //#if USBHOST_GAMEPAD
00032 
00033 #include "USBHost.h"
00034 //HID Class Request
00035 #define HID_GET_REPORT                                 0x01
00036 #define HID_GET_IDLE                                   0x02
00037 #define HID_GET_PROTOCOL                               0x03
00038 #define HID_GET_DESCRIPTOR                             0x06
00039 #define HID_SET_REPORT                                 0x09
00040 #define HID_SET_IDLE                                   0x0a
00041 #define HID_SET_PROTOCOL                               0x0b
00042 
00043 /** 
00044  * A class to communicate a USB MIDI device
00045  */
00046 class USBHostGamepad : public IUSBEnumerator {
00047 public:
00048     /**
00049      * Constructor
00050      */
00051     USBHostGamepad();
00052 
00053     /**
00054      * Try to connect a gamepad device
00055      *
00056      * @return true if connection was successful
00057      */
00058     bool connect();
00059 
00060     /**
00061     * Check if a gamepad is connected
00062     *
00063     * @returns true if a gamepad is connected
00064     */
00065     bool connected();
00066 
00067     uint8_t report[8]; /* modified 2016 Racoon */
00068     int rxSize;
00069         
00070 protected:
00071     //From IUSBEnumerator
00072     virtual void setVidPid(uint16_t vid, uint16_t pid);
00073     virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
00074     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00075 
00076 private:
00077     USBHost * host;
00078     USBDeviceConnected * dev;
00079     USBEndpoint * int_in;
00080 
00081     bool dev_connected;
00082     bool gamepad_device_found;
00083     int gamepad_intf;
00084 
00085     void rxHandler();
00086     void init();
00087 };
00088 
00089 #endif
00090