Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F407VET6_USBHostMSD STM32F407VET6_USBHostMouse STM32F407VET6_USBHostKeyboard STM32F407VET6_USBHostMSD_1
USBHostGamepad.h
00001 /* mbed USBHost Gamepad driver sample 00002 * Copyright (c) 2014 Yuuichi Akagawa 00003 * 00004 * modified from mbed USBHostMouse 00005 * 00006 * Copyright (c) 2014 mbed.org, MIT License 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00009 * and associated documentation files (the "Software"), to deal in the Software without 00010 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00011 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in all copies or 00015 * substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00018 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00020 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 */ 00023 #ifndef USBHOSTGAMEPAD_H 00024 #define USBHOSTGAMEPAD_H 00025 00026 #include "USBHostConf.h" 00027 00028 //#if USBHOST_GAMEPAD 00029 00030 #include "USBHost.h" 00031 //HID Class Request 00032 00033 #define HID_GET_REPORT 0x01 00034 #define HID_GET_IDLE 0x02 00035 #define HID_GET_PROTOCOL 0x03 00036 #define HID_GET_DESCRIPTOR 0x06 00037 #define HID_SET_REPORT 0x09 00038 #define HID_SET_IDLE 0x0a 00039 #define HID_SET_PROTOCOL 0x0b 00040 00041 /** 00042 * A class to communicate a USB MIDI device 00043 */ 00044 00045 class USBHostGamepad : 00046 public IUSBEnumerator 00047 { 00048 public: 00049 /** 00050 * Constructor 00051 */ 00052 USBHostGamepad(); 00053 00054 /** 00055 * Try to connect a gamepad device 00056 * 00057 * @return true if connection was successful 00058 */ 00059 bool connect(); 00060 00061 /** 00062 * Check if a gamepad is connected 00063 * 00064 * @returns true if a gamepad is connected 00065 */ 00066 bool connected(); 00067 00068 /** 00069 * Attach a callback called when a gamepad event is received 00070 * 00071 * @param ptr function pointer 00072 */ 00073 inline void attachEvent(void (*ptr) (uint8_t btnX, uint8_t btnY, uint8_t btnABCD, uint8_t btnSpecial)) 00074 { 00075 if (ptr != NULL) { 00076 onUpdate = ptr; 00077 } 00078 } 00079 00080 /** 00081 * Request the HID report descriptor 00082 * 00083 * @param dev request the device descriptor on this device 00084 * @param buf buffer to store the device descriptor 00085 * @param max_len_buf maximum size of buf 00086 * @param len_dev_descr pointer to store the length of the packet transferred 00087 */ 00088 USB_TYPE getReportDescriptor 00089 ( 00090 USBDeviceConnected* dev, 00091 uint8_t* buf, 00092 uint16_t max_len_buf, 00093 uint16_t* len_rep_descr = NULL 00094 ); 00095 protected: 00096 //From IUSBEnumerator 00097 virtual void setVidPid(uint16_t vid, uint16_t pid); 00098 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 00099 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00100 00101 private: 00102 USBHost* host; 00103 USBDeviceConnected* dev; 00104 USBEndpoint* int_in; 00105 00106 bool dev_connected; 00107 bool gamepad_device_found; 00108 int gamepad_intf; 00109 00110 uint8_t report[8]; 00111 00112 void rxHandler(); 00113 void (*onUpdate) (uint8_t btnX, uint8_t btnY, uint8_t btnABCD, uint8_t btnSpecial); 00114 int report_id; 00115 void init(); 00116 00117 // bool parseHidDescr(); 00118 public: 00119 uint8_t btnX; 00120 uint8_t btnY; 00121 uint8_t btnABCD; 00122 uint8_t btnSpecial; 00123 }; 00124 00125 //#endif 00126 #endif
Generated on Wed Jul 13 2022 07:15:48 by
