Add USB HID Gamepad hosting support to mbed board (depends on USBHost library)
Dependents: mbed_gamepad_example
USBHostGamepad.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef USBHOSTGAMEPAD_H 00018 #define USBHOSTGAMEPAD_H 00019 00020 #include "USBHostConf.h" 00021 00022 #define USBHOST_GAMEPAD 1 00023 00024 #if USBHOST_GAMEPAD 00025 00026 #include "USBHost.h" 00027 00028 /** 00029 * A class to communicate a USB Gamepad 00030 */ 00031 class USBHostGamepad : public IUSBEnumerator 00032 { 00033 public: 00034 00035 /** 00036 * Constructor 00037 */ 00038 USBHostGamepad(); 00039 00040 /** 00041 * Try to connect a Gamepad device 00042 * 00043 * @return true if connection was successful 00044 */ 00045 bool connect(); 00046 00047 /** 00048 * Check if a Gamepad is connected 00049 * 00050 * @returns true if a Gamepad is connected 00051 */ 00052 bool connected(); 00053 00054 /** 00055 * Attach a callback called when a Gamepad event is received 00056 * 00057 * @param ptr function pointer 00058 */ 00059 inline void attachEvent(void (*ptr)(uint8_t x, uint8_t y, uint8_t z, uint8_t rz, uint16_t buttons)) 00060 { 00061 if (ptr != NULL) { 00062 onUpdate = ptr; 00063 } 00064 } 00065 00066 protected: 00067 //From IUSBEnumerator 00068 virtual void setVidPid(uint16_t vid, uint16_t pid); 00069 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 00070 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00071 00072 private: 00073 USBHost * host; 00074 USBDeviceConnected * dev; 00075 USBEndpoint * int_in; 00076 uint8_t report[8]; 00077 bool dev_connected; 00078 bool gamepad_device_found; 00079 int gamepad_intf; 00080 00081 void rxHandler(); 00082 void (*onUpdate)(uint8_t x, uint8_t y, uint8_t z, uint8_t rz, uint16_t buttons); 00083 int report_id; 00084 void init(); 00085 }; 00086 00087 #endif 00088 00089 #endif
Generated on Tue Jul 12 2022 20:44:17 by 1.7.2