BA
/
BaBoRo1
mbed-os/features/unsupported/USBHost/USBHostHID/USBHostMouse.h@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:380207fcb5c1 | 1 | /* mbed USBHost Library |
borlanic | 0:380207fcb5c1 | 2 | * Copyright (c) 2006-2013 ARM Limited |
borlanic | 0:380207fcb5c1 | 3 | * |
borlanic | 0:380207fcb5c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:380207fcb5c1 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:380207fcb5c1 | 6 | * You may obtain a copy of the License at |
borlanic | 0:380207fcb5c1 | 7 | * |
borlanic | 0:380207fcb5c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:380207fcb5c1 | 9 | * |
borlanic | 0:380207fcb5c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:380207fcb5c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:380207fcb5c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:380207fcb5c1 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:380207fcb5c1 | 14 | * limitations under the License. |
borlanic | 0:380207fcb5c1 | 15 | */ |
borlanic | 0:380207fcb5c1 | 16 | |
borlanic | 0:380207fcb5c1 | 17 | #ifndef USBHOSTMOUSE_H |
borlanic | 0:380207fcb5c1 | 18 | #define USBHOSTMOUSE_H |
borlanic | 0:380207fcb5c1 | 19 | |
borlanic | 0:380207fcb5c1 | 20 | #include "USBHostConf.h" |
borlanic | 0:380207fcb5c1 | 21 | |
borlanic | 0:380207fcb5c1 | 22 | #if USBHOST_MOUSE |
borlanic | 0:380207fcb5c1 | 23 | |
borlanic | 0:380207fcb5c1 | 24 | #include "USBHost.h" |
borlanic | 0:380207fcb5c1 | 25 | |
borlanic | 0:380207fcb5c1 | 26 | /** |
borlanic | 0:380207fcb5c1 | 27 | * A class to communicate a USB mouse |
borlanic | 0:380207fcb5c1 | 28 | */ |
borlanic | 0:380207fcb5c1 | 29 | class USBHostMouse : public IUSBEnumerator |
borlanic | 0:380207fcb5c1 | 30 | { |
borlanic | 0:380207fcb5c1 | 31 | public: |
borlanic | 0:380207fcb5c1 | 32 | |
borlanic | 0:380207fcb5c1 | 33 | /** |
borlanic | 0:380207fcb5c1 | 34 | * Constructor |
borlanic | 0:380207fcb5c1 | 35 | */ |
borlanic | 0:380207fcb5c1 | 36 | USBHostMouse(); |
borlanic | 0:380207fcb5c1 | 37 | |
borlanic | 0:380207fcb5c1 | 38 | /** |
borlanic | 0:380207fcb5c1 | 39 | * Try to connect a mouse device |
borlanic | 0:380207fcb5c1 | 40 | * |
borlanic | 0:380207fcb5c1 | 41 | * @return true if connection was successful |
borlanic | 0:380207fcb5c1 | 42 | */ |
borlanic | 0:380207fcb5c1 | 43 | bool connect(); |
borlanic | 0:380207fcb5c1 | 44 | |
borlanic | 0:380207fcb5c1 | 45 | /** |
borlanic | 0:380207fcb5c1 | 46 | * Check if a mouse is connected |
borlanic | 0:380207fcb5c1 | 47 | * |
borlanic | 0:380207fcb5c1 | 48 | * @returns true if a mouse is connected |
borlanic | 0:380207fcb5c1 | 49 | */ |
borlanic | 0:380207fcb5c1 | 50 | bool connected(); |
borlanic | 0:380207fcb5c1 | 51 | |
borlanic | 0:380207fcb5c1 | 52 | /** |
borlanic | 0:380207fcb5c1 | 53 | * Attach a callback called when a mouse event is received |
borlanic | 0:380207fcb5c1 | 54 | * |
borlanic | 0:380207fcb5c1 | 55 | * @param ptr function pointer |
borlanic | 0:380207fcb5c1 | 56 | */ |
borlanic | 0:380207fcb5c1 | 57 | inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) |
borlanic | 0:380207fcb5c1 | 58 | { |
borlanic | 0:380207fcb5c1 | 59 | if (ptr != NULL) { |
borlanic | 0:380207fcb5c1 | 60 | onUpdate = ptr; |
borlanic | 0:380207fcb5c1 | 61 | } |
borlanic | 0:380207fcb5c1 | 62 | } |
borlanic | 0:380207fcb5c1 | 63 | |
borlanic | 0:380207fcb5c1 | 64 | /** |
borlanic | 0:380207fcb5c1 | 65 | * Attach a callback called when the button state changes |
borlanic | 0:380207fcb5c1 | 66 | * |
borlanic | 0:380207fcb5c1 | 67 | * @param ptr function pointer |
borlanic | 0:380207fcb5c1 | 68 | */ |
borlanic | 0:380207fcb5c1 | 69 | inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) |
borlanic | 0:380207fcb5c1 | 70 | { |
borlanic | 0:380207fcb5c1 | 71 | if (ptr != NULL) { |
borlanic | 0:380207fcb5c1 | 72 | onButtonUpdate = ptr; |
borlanic | 0:380207fcb5c1 | 73 | } |
borlanic | 0:380207fcb5c1 | 74 | } |
borlanic | 0:380207fcb5c1 | 75 | |
borlanic | 0:380207fcb5c1 | 76 | /** |
borlanic | 0:380207fcb5c1 | 77 | * Attach a callback called when the X axis value changes |
borlanic | 0:380207fcb5c1 | 78 | * |
borlanic | 0:380207fcb5c1 | 79 | * @param ptr function pointer |
borlanic | 0:380207fcb5c1 | 80 | */ |
borlanic | 0:380207fcb5c1 | 81 | inline void attachXEvent(void (*ptr)(int8_t x)) |
borlanic | 0:380207fcb5c1 | 82 | { |
borlanic | 0:380207fcb5c1 | 83 | if (ptr != NULL) { |
borlanic | 0:380207fcb5c1 | 84 | onXUpdate = ptr; |
borlanic | 0:380207fcb5c1 | 85 | } |
borlanic | 0:380207fcb5c1 | 86 | } |
borlanic | 0:380207fcb5c1 | 87 | |
borlanic | 0:380207fcb5c1 | 88 | /** |
borlanic | 0:380207fcb5c1 | 89 | * Attach a callback called when the Y axis value changes |
borlanic | 0:380207fcb5c1 | 90 | * |
borlanic | 0:380207fcb5c1 | 91 | * @param ptr function pointer |
borlanic | 0:380207fcb5c1 | 92 | */ |
borlanic | 0:380207fcb5c1 | 93 | inline void attachYEvent(void (*ptr)(int8_t y)) |
borlanic | 0:380207fcb5c1 | 94 | { |
borlanic | 0:380207fcb5c1 | 95 | if (ptr != NULL) { |
borlanic | 0:380207fcb5c1 | 96 | onYUpdate = ptr; |
borlanic | 0:380207fcb5c1 | 97 | } |
borlanic | 0:380207fcb5c1 | 98 | } |
borlanic | 0:380207fcb5c1 | 99 | |
borlanic | 0:380207fcb5c1 | 100 | /** |
borlanic | 0:380207fcb5c1 | 101 | * Attach a callback called when the Z axis value changes (scrolling) |
borlanic | 0:380207fcb5c1 | 102 | * |
borlanic | 0:380207fcb5c1 | 103 | * @param ptr function pointer |
borlanic | 0:380207fcb5c1 | 104 | */ |
borlanic | 0:380207fcb5c1 | 105 | inline void attachZEvent(void (*ptr)(int8_t z)) |
borlanic | 0:380207fcb5c1 | 106 | { |
borlanic | 0:380207fcb5c1 | 107 | if (ptr != NULL) { |
borlanic | 0:380207fcb5c1 | 108 | onZUpdate = ptr; |
borlanic | 0:380207fcb5c1 | 109 | } |
borlanic | 0:380207fcb5c1 | 110 | } |
borlanic | 0:380207fcb5c1 | 111 | |
borlanic | 0:380207fcb5c1 | 112 | protected: |
borlanic | 0:380207fcb5c1 | 113 | //From IUSBEnumerator |
borlanic | 0:380207fcb5c1 | 114 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
borlanic | 0:380207fcb5c1 | 115 | 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 |
borlanic | 0:380207fcb5c1 | 116 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
borlanic | 0:380207fcb5c1 | 117 | |
borlanic | 0:380207fcb5c1 | 118 | private: |
borlanic | 0:380207fcb5c1 | 119 | USBHost * host; |
borlanic | 0:380207fcb5c1 | 120 | USBDeviceConnected * dev; |
borlanic | 0:380207fcb5c1 | 121 | USBEndpoint * int_in; |
borlanic | 0:380207fcb5c1 | 122 | uint8_t report[64]; |
borlanic | 0:380207fcb5c1 | 123 | bool dev_connected; |
borlanic | 0:380207fcb5c1 | 124 | bool mouse_device_found; |
borlanic | 0:380207fcb5c1 | 125 | int mouse_intf; |
borlanic | 0:380207fcb5c1 | 126 | |
borlanic | 0:380207fcb5c1 | 127 | uint8_t buttons; |
borlanic | 0:380207fcb5c1 | 128 | int8_t x; |
borlanic | 0:380207fcb5c1 | 129 | int8_t y; |
borlanic | 0:380207fcb5c1 | 130 | int8_t z; |
borlanic | 0:380207fcb5c1 | 131 | |
borlanic | 0:380207fcb5c1 | 132 | void rxHandler(); |
borlanic | 0:380207fcb5c1 | 133 | void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z); |
borlanic | 0:380207fcb5c1 | 134 | void (*onButtonUpdate)(uint8_t buttons); |
borlanic | 0:380207fcb5c1 | 135 | void (*onXUpdate)(int8_t x); |
borlanic | 0:380207fcb5c1 | 136 | void (*onYUpdate)(int8_t y); |
borlanic | 0:380207fcb5c1 | 137 | void (*onZUpdate)(int8_t z); |
borlanic | 0:380207fcb5c1 | 138 | int report_id; |
borlanic | 0:380207fcb5c1 | 139 | void init(); |
borlanic | 0:380207fcb5c1 | 140 | }; |
borlanic | 0:380207fcb5c1 | 141 | |
borlanic | 0:380207fcb5c1 | 142 | #endif |
borlanic | 0:380207fcb5c1 | 143 | |
borlanic | 0:380207fcb5c1 | 144 | #endif |