dari pinpin usb langsung
Dependencies: mbed
Fork of Nucleo_Ex04_USBPAD by
USBHost/USBHostGamepad.h@0:b5f79b4f741d, 2016-03-15 (annotated)
- Committer:
- beaglescout007
- Date:
- Tue Mar 15 11:39:04 2016 +0000
- Revision:
- 0:b5f79b4f741d
Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beaglescout007 | 0:b5f79b4f741d | 1 | /* |
beaglescout007 | 0:b5f79b4f741d | 2 | * modified from |
beaglescout007 | 0:b5f79b4f741d | 3 | * mbed USBHost Gamepad driver sample |
beaglescout007 | 0:b5f79b4f741d | 4 | * Copyright (c) 2014 Yuuichi Akagawa |
beaglescout007 | 0:b5f79b4f741d | 5 | * |
beaglescout007 | 0:b5f79b4f741d | 6 | * modified from mbed USBHostMouse |
beaglescout007 | 0:b5f79b4f741d | 7 | * |
beaglescout007 | 0:b5f79b4f741d | 8 | * Copyright (c) 2014 mbed.org, MIT License |
beaglescout007 | 0:b5f79b4f741d | 9 | * |
beaglescout007 | 0:b5f79b4f741d | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
beaglescout007 | 0:b5f79b4f741d | 11 | * and associated documentation files (the "Software"), to deal in the Software without |
beaglescout007 | 0:b5f79b4f741d | 12 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
beaglescout007 | 0:b5f79b4f741d | 13 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
beaglescout007 | 0:b5f79b4f741d | 14 | * Software is furnished to do so, subject to the following conditions: |
beaglescout007 | 0:b5f79b4f741d | 15 | * |
beaglescout007 | 0:b5f79b4f741d | 16 | * The above copyright notice and this permission notice shall be included in all copies or |
beaglescout007 | 0:b5f79b4f741d | 17 | * substantial portions of the Software. |
beaglescout007 | 0:b5f79b4f741d | 18 | * |
beaglescout007 | 0:b5f79b4f741d | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
beaglescout007 | 0:b5f79b4f741d | 20 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
beaglescout007 | 0:b5f79b4f741d | 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
beaglescout007 | 0:b5f79b4f741d | 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
beaglescout007 | 0:b5f79b4f741d | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
beaglescout007 | 0:b5f79b4f741d | 24 | */ |
beaglescout007 | 0:b5f79b4f741d | 25 | |
beaglescout007 | 0:b5f79b4f741d | 26 | #ifndef USBHOSTGAMEPAD_H |
beaglescout007 | 0:b5f79b4f741d | 27 | #define USBHOSTGAMEPAD_H |
beaglescout007 | 0:b5f79b4f741d | 28 | |
beaglescout007 | 0:b5f79b4f741d | 29 | #include "USBHostConf.h" |
beaglescout007 | 0:b5f79b4f741d | 30 | |
beaglescout007 | 0:b5f79b4f741d | 31 | //#if USBHOST_GAMEPAD |
beaglescout007 | 0:b5f79b4f741d | 32 | |
beaglescout007 | 0:b5f79b4f741d | 33 | #include "USBHost.h" |
beaglescout007 | 0:b5f79b4f741d | 34 | //HID Class Request |
beaglescout007 | 0:b5f79b4f741d | 35 | #define HID_GET_REPORT 0x01 |
beaglescout007 | 0:b5f79b4f741d | 36 | #define HID_GET_IDLE 0x02 |
beaglescout007 | 0:b5f79b4f741d | 37 | #define HID_GET_PROTOCOL 0x03 |
beaglescout007 | 0:b5f79b4f741d | 38 | #define HID_GET_DESCRIPTOR 0x06 |
beaglescout007 | 0:b5f79b4f741d | 39 | #define HID_SET_REPORT 0x09 |
beaglescout007 | 0:b5f79b4f741d | 40 | #define HID_SET_IDLE 0x0a |
beaglescout007 | 0:b5f79b4f741d | 41 | #define HID_SET_PROTOCOL 0x0b |
beaglescout007 | 0:b5f79b4f741d | 42 | |
beaglescout007 | 0:b5f79b4f741d | 43 | /** |
beaglescout007 | 0:b5f79b4f741d | 44 | * A class to communicate a USB MIDI device |
beaglescout007 | 0:b5f79b4f741d | 45 | */ |
beaglescout007 | 0:b5f79b4f741d | 46 | class USBHostGamepad : public IUSBEnumerator { |
beaglescout007 | 0:b5f79b4f741d | 47 | public: |
beaglescout007 | 0:b5f79b4f741d | 48 | /** |
beaglescout007 | 0:b5f79b4f741d | 49 | * Constructor |
beaglescout007 | 0:b5f79b4f741d | 50 | */ |
beaglescout007 | 0:b5f79b4f741d | 51 | USBHostGamepad(); |
beaglescout007 | 0:b5f79b4f741d | 52 | |
beaglescout007 | 0:b5f79b4f741d | 53 | /** |
beaglescout007 | 0:b5f79b4f741d | 54 | * Try to connect a gamepad device |
beaglescout007 | 0:b5f79b4f741d | 55 | * |
beaglescout007 | 0:b5f79b4f741d | 56 | * @return true if connection was successful |
beaglescout007 | 0:b5f79b4f741d | 57 | */ |
beaglescout007 | 0:b5f79b4f741d | 58 | bool connect(); |
beaglescout007 | 0:b5f79b4f741d | 59 | |
beaglescout007 | 0:b5f79b4f741d | 60 | /** |
beaglescout007 | 0:b5f79b4f741d | 61 | * Check if a gamepad is connected |
beaglescout007 | 0:b5f79b4f741d | 62 | * |
beaglescout007 | 0:b5f79b4f741d | 63 | * @returns true if a gamepad is connected |
beaglescout007 | 0:b5f79b4f741d | 64 | */ |
beaglescout007 | 0:b5f79b4f741d | 65 | bool connected(); |
beaglescout007 | 0:b5f79b4f741d | 66 | |
beaglescout007 | 0:b5f79b4f741d | 67 | uint8_t report[8]; /* modified 2016 Racoon */ |
beaglescout007 | 0:b5f79b4f741d | 68 | int rxSize; |
beaglescout007 | 0:b5f79b4f741d | 69 | |
beaglescout007 | 0:b5f79b4f741d | 70 | protected: |
beaglescout007 | 0:b5f79b4f741d | 71 | //From IUSBEnumerator |
beaglescout007 | 0:b5f79b4f741d | 72 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
beaglescout007 | 0:b5f79b4f741d | 73 | 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 |
beaglescout007 | 0:b5f79b4f741d | 74 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
beaglescout007 | 0:b5f79b4f741d | 75 | |
beaglescout007 | 0:b5f79b4f741d | 76 | private: |
beaglescout007 | 0:b5f79b4f741d | 77 | USBHost * host; |
beaglescout007 | 0:b5f79b4f741d | 78 | USBDeviceConnected * dev; |
beaglescout007 | 0:b5f79b4f741d | 79 | USBEndpoint * int_in; |
beaglescout007 | 0:b5f79b4f741d | 80 | |
beaglescout007 | 0:b5f79b4f741d | 81 | bool dev_connected; |
beaglescout007 | 0:b5f79b4f741d | 82 | bool gamepad_device_found; |
beaglescout007 | 0:b5f79b4f741d | 83 | int gamepad_intf; |
beaglescout007 | 0:b5f79b4f741d | 84 | |
beaglescout007 | 0:b5f79b4f741d | 85 | void rxHandler(); |
beaglescout007 | 0:b5f79b4f741d | 86 | void init(); |
beaglescout007 | 0:b5f79b4f741d | 87 | }; |
beaglescout007 | 0:b5f79b4f741d | 88 | |
beaglescout007 | 0:b5f79b4f741d | 89 | #endif |
beaglescout007 | 0:b5f79b4f741d | 90 |