modified to compile for me
Fork of F401RE-USBHost by
USBHostHID/USBHostMouse.h@8:6463cd1964c0, 2014-01-31 (annotated)
- Committer:
- va009039
- Date:
- Fri Jan 31 13:45:07 2014 +0000
- Revision:
- 8:6463cd1964c0
- Parent:
- 3:a3872f7593e2
- Child:
- 9:7f9f64cf5ded
USB hub support.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 8:6463cd1964c0 | 1 | /* mbed USBHost Library |
va009039 | 8:6463cd1964c0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 8:6463cd1964c0 | 3 | * |
va009039 | 8:6463cd1964c0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 8:6463cd1964c0 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 8:6463cd1964c0 | 6 | * You may obtain a copy of the License at |
va009039 | 8:6463cd1964c0 | 7 | * |
va009039 | 8:6463cd1964c0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 8:6463cd1964c0 | 9 | * |
va009039 | 8:6463cd1964c0 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 8:6463cd1964c0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 8:6463cd1964c0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 8:6463cd1964c0 | 13 | * See the License for the specific language governing permissions and |
va009039 | 8:6463cd1964c0 | 14 | * limitations under the License. |
va009039 | 8:6463cd1964c0 | 15 | */ |
va009039 | 8:6463cd1964c0 | 16 | |
va009039 | 0:5160ee0c522d | 17 | #include "USBHost.h" |
va009039 | 0:5160ee0c522d | 18 | |
va009039 | 8:6463cd1964c0 | 19 | class USBHostMouse : public IUSBEnumerator { |
va009039 | 0:5160ee0c522d | 20 | public: |
va009039 | 8:6463cd1964c0 | 21 | |
va009039 | 8:6463cd1964c0 | 22 | /** |
va009039 | 8:6463cd1964c0 | 23 | * Constructor |
va009039 | 8:6463cd1964c0 | 24 | */ |
va009039 | 8:6463cd1964c0 | 25 | USBHostMouse(); |
va009039 | 8:6463cd1964c0 | 26 | |
va009039 | 8:6463cd1964c0 | 27 | /** |
va009039 | 8:6463cd1964c0 | 28 | * Try to connect a mouse device |
va009039 | 8:6463cd1964c0 | 29 | * |
va009039 | 8:6463cd1964c0 | 30 | * @return true if connection was successful |
va009039 | 8:6463cd1964c0 | 31 | */ |
va009039 | 8:6463cd1964c0 | 32 | bool connect(); |
va009039 | 8:6463cd1964c0 | 33 | |
va009039 | 8:6463cd1964c0 | 34 | /** |
va009039 | 8:6463cd1964c0 | 35 | * Check if a mouse is connected |
va009039 | 8:6463cd1964c0 | 36 | * |
va009039 | 8:6463cd1964c0 | 37 | * @returns true if a mouse is connected |
va009039 | 8:6463cd1964c0 | 38 | */ |
va009039 | 8:6463cd1964c0 | 39 | bool connected(); |
va009039 | 8:6463cd1964c0 | 40 | |
va009039 | 8:6463cd1964c0 | 41 | int readReport(uint8_t* data) { |
va009039 | 8:6463cd1964c0 | 42 | int rc = host->interruptRead(dev, int_in, data, 4); |
va009039 | 8:6463cd1964c0 | 43 | return rc == USB_TYPE_OK ? 4 : 0; |
va009039 | 0:5160ee0c522d | 44 | } |
va009039 | 8:6463cd1964c0 | 45 | void attachEvent(void (*ptr)(uint8_t* data, int size)) { |
va009039 | 8:6463cd1964c0 | 46 | if (ptr != NULL) { |
va009039 | 8:6463cd1964c0 | 47 | onUpdate = ptr; |
va009039 | 8:6463cd1964c0 | 48 | } |
va009039 | 0:5160ee0c522d | 49 | } |
va009039 | 8:6463cd1964c0 | 50 | void poll() { |
va009039 | 8:6463cd1964c0 | 51 | USB_TYPE rc = host->interruptRead(dev, int_in, report, sizeof(report)); |
va009039 | 8:6463cd1964c0 | 52 | if (rc == USB_TYPE_OK) { |
va009039 | 8:6463cd1964c0 | 53 | if (onUpdate) { |
va009039 | 8:6463cd1964c0 | 54 | (*onUpdate)(report, int_in->getLengthTransferred()); |
va009039 | 8:6463cd1964c0 | 55 | } |
va009039 | 8:6463cd1964c0 | 56 | } |
va009039 | 8:6463cd1964c0 | 57 | } |
va009039 | 8:6463cd1964c0 | 58 | |
va009039 | 8:6463cd1964c0 | 59 | protected: |
va009039 | 8:6463cd1964c0 | 60 | //From IUSBEnumerator |
va009039 | 8:6463cd1964c0 | 61 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 | 8:6463cd1964c0 | 62 | 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 |
va009039 | 8:6463cd1964c0 | 63 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 | 0:5160ee0c522d | 64 | |
va009039 | 0:5160ee0c522d | 65 | private: |
va009039 | 0:5160ee0c522d | 66 | USBHost * host; |
va009039 | 8:6463cd1964c0 | 67 | USBDeviceConnected * dev; |
va009039 | 8:6463cd1964c0 | 68 | USBEndpoint * int_in; |
va009039 | 8:6463cd1964c0 | 69 | uint8_t report[4]; |
va009039 | 8:6463cd1964c0 | 70 | |
va009039 | 8:6463cd1964c0 | 71 | bool dev_connected; |
va009039 | 8:6463cd1964c0 | 72 | bool mouse_device_found; |
va009039 | 8:6463cd1964c0 | 73 | int mouse_intf; |
va009039 | 8:6463cd1964c0 | 74 | |
va009039 | 8:6463cd1964c0 | 75 | uint8_t buttons; |
va009039 | 8:6463cd1964c0 | 76 | int8_t x; |
va009039 | 8:6463cd1964c0 | 77 | int8_t y; |
va009039 | 8:6463cd1964c0 | 78 | int8_t z; |
va009039 | 8:6463cd1964c0 | 79 | |
va009039 | 8:6463cd1964c0 | 80 | void (*onUpdate)(uint8_t* data, int size); |
va009039 | 8:6463cd1964c0 | 81 | void (*onButtonUpdate)(uint8_t buttons); |
va009039 | 8:6463cd1964c0 | 82 | void (*onXUpdate)(int8_t x); |
va009039 | 8:6463cd1964c0 | 83 | void (*onYUpdate)(int8_t y); |
va009039 | 8:6463cd1964c0 | 84 | void (*onZUpdate)(int8_t z); |
va009039 | 8:6463cd1964c0 | 85 | int report_id; |
va009039 | 8:6463cd1964c0 | 86 | void init(); |
va009039 | 0:5160ee0c522d | 87 | }; |
va009039 | 0:5160ee0c522d | 88 |