Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)
Dependents: DISCO-F746NG_USB_Host
Fork of KL46Z-USBHost by
USBHostHID/USBHostMouseKeyboard.cpp@24:5396b6a93262, 2016-06-13 (annotated)
- Committer:
- DieterGraef
- Date:
- Mon Jun 13 17:21:07 2016 +0000
- Revision:
- 24:5396b6a93262
USB Host for STM32F746 DISCO Board. At the moment you can only use either the High Speed Port or the Fast Speed Port.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 24:5396b6a93262 | 1 | /* mbed USBHost Library |
DieterGraef | 24:5396b6a93262 | 2 | * Copyright (c) 2006-2013 ARM Limited |
DieterGraef | 24:5396b6a93262 | 3 | * |
DieterGraef | 24:5396b6a93262 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
DieterGraef | 24:5396b6a93262 | 5 | * you may not use this file except in compliance with the License. |
DieterGraef | 24:5396b6a93262 | 6 | * You may obtain a copy of the License at |
DieterGraef | 24:5396b6a93262 | 7 | * |
DieterGraef | 24:5396b6a93262 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
DieterGraef | 24:5396b6a93262 | 9 | * |
DieterGraef | 24:5396b6a93262 | 10 | * Unless required by applicable law or agreed to in writing, software |
DieterGraef | 24:5396b6a93262 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
DieterGraef | 24:5396b6a93262 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
DieterGraef | 24:5396b6a93262 | 13 | * See the License for the specific language governing permissions and |
DieterGraef | 24:5396b6a93262 | 14 | * limitations under the License. |
DieterGraef | 24:5396b6a93262 | 15 | */ |
DieterGraef | 24:5396b6a93262 | 16 | |
DieterGraef | 24:5396b6a93262 | 17 | #include "USBHostMouseKeyboard.h" |
DieterGraef | 24:5396b6a93262 | 18 | |
DieterGraef | 24:5396b6a93262 | 19 | #if USBHOST_MOUSE_KEYBOARD |
DieterGraef | 24:5396b6a93262 | 20 | |
DieterGraef | 24:5396b6a93262 | 21 | //#define Keyb_German 1 |
DieterGraef | 24:5396b6a93262 | 22 | |
DieterGraef | 24:5396b6a93262 | 23 | #ifdef Keyb_German |
DieterGraef | 24:5396b6a93262 | 24 | static uint8_t keymap[4][0x39] = { |
DieterGraef | 24:5396b6a93262 | 25 | { 0, 0, 0, 0, 'a', 'b' , |
DieterGraef | 24:5396b6a93262 | 26 | 'c', 'd', 'e', 'f', 'g' , |
DieterGraef | 24:5396b6a93262 | 27 | 'h', 'i', 'j', 'k', 'l', |
DieterGraef | 24:5396b6a93262 | 28 | 'm', 'n', 'o', 'p', 'q', |
DieterGraef | 24:5396b6a93262 | 29 | 'r', 's', 't', 'u', 'v', |
DieterGraef | 24:5396b6a93262 | 30 | 'w', 'x', 'y', 'z', '1', |
DieterGraef | 24:5396b6a93262 | 31 | '2', '3', '4', '5', '6', |
DieterGraef | 24:5396b6a93262 | 32 | '7', '8', '9', '0', 0x0A /*enter*/, |
DieterGraef | 24:5396b6a93262 | 33 | 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, 'ß', |
DieterGraef | 24:5396b6a93262 | 34 | '´', 'ü', '+', '<', '#', |
DieterGraef | 24:5396b6a93262 | 35 | 'ö', 'ä', 0, ',', '.', |
DieterGraef | 24:5396b6a93262 | 36 | '-'}, |
DieterGraef | 24:5396b6a93262 | 37 | |
DieterGraef | 24:5396b6a93262 | 38 | /* CTRL MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 39 | { 0, 0, 0, 0, 0, 0 /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 40 | 0, 0, 0, 0, 0 /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 41 | 0, 0, 0, 0, 0/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 42 | 0, 0, 0, 0, 0/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 43 | 0, 0, 0, 0, 0/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 44 | 0, 0, 0, 0, 0/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 45 | 0, 0, 0, 0, 0/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 46 | 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 47 | 0, 0, 0, 0, 0, /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 48 | 0, 0, 0, 0, 0, /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 49 | 0, 0, 0, 0, 0, /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 50 | 0}, |
DieterGraef | 24:5396b6a93262 | 51 | |
DieterGraef | 24:5396b6a93262 | 52 | /* SHIFT MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 53 | { 0, 0, 0, 0, 'A', 'B' /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 54 | 'C', 'D', 'E', 'F', 'G' /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 55 | 'H', 'I', 'J', 'K', 'L'/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 56 | 'M', 'N', 'O', 'P', 'Q'/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 57 | 'R', 'S', 'T', 'U', 'V'/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 58 | 'W', 'X', 'Y', 'Z', '!'/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 59 | '"', '§', '$', '%', '&'/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 60 | '/', '(', ')', '=', 0, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 61 | 0, 0, 0, 0, '?', /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 62 | '`', 'Ü', '*', '>', '\'', /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 63 | 'Ö', 'Ä', 0, ';', ':', /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 64 | '_'}, |
DieterGraef | 24:5396b6a93262 | 65 | |
DieterGraef | 24:5396b6a93262 | 66 | /* ALT MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 67 | { 0, 0, 0, 0, 0, 0 /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 68 | 0, 0, 0, 0, 0 /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 69 | 0, 0, 0, 0, 0/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 70 | 'µ', 0, 0, 0, '@'/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 71 | 0, 0, 0, 0, 0/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 72 | 0, 0, 0, 0, 0/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 73 | '²','³', 0, 0, 0/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 74 | '{', '[', ']', '}', 0 /*enter*/, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 75 | '\'', 0, 0, 0, '\\', /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 76 | 0, 0, '~', '|', 0, /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 77 | 0, 0, 0, 0, 0, /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 78 | 0} |
DieterGraef | 24:5396b6a93262 | 79 | |
DieterGraef | 24:5396b6a93262 | 80 | }; |
DieterGraef | 24:5396b6a93262 | 81 | #else |
DieterGraef | 24:5396b6a93262 | 82 | static uint8_t keymap[4][0x39] = { |
DieterGraef | 24:5396b6a93262 | 83 | { 0, 0, 0, 0, 'a', 'b' /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 84 | 'c', 'd', 'e', 'f', 'g' /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 85 | 'h', 'i', 'j', 'k', 'l'/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 86 | 'm', 'n', 'o', 'p', 'q'/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 87 | 'r', 's', 't', 'u', 'v'/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 88 | 'w', 'x', 'y', 'z', '1'/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 89 | '2', '3', '4', '5', '6'/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 90 | '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 91 | 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 92 | '=', '[', ']', '\\', '#', /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 93 | ';', '\'', 0, ',', '.', /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 94 | '/'}, |
DieterGraef | 24:5396b6a93262 | 95 | |
DieterGraef | 24:5396b6a93262 | 96 | /* CTRL MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 97 | { 0, 0, 0, 0, 0, 0 /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 98 | 0, 0, 0, 0, 0 /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 99 | 0, 0, 0, 0, 0/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 100 | 0, 0, 0, 0, 0/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 101 | 0, 0, 0, 0, 0/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 102 | 0, 0, 0, 0, 0/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 103 | 0, 0, 0, 0, 0/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 104 | 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 105 | 0, 0, 0, 0, 0, /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 106 | 0, 0, 0, 0, 0, /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 107 | 0, 0, 0, 0, 0, /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 108 | 0}, |
DieterGraef | 24:5396b6a93262 | 109 | |
DieterGraef | 24:5396b6a93262 | 110 | /* SHIFT MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 111 | { 0, 0, 0, 0, 'A', 'B' /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 112 | 'C', 'D', 'E', 'F', 'G' /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 113 | 'H', 'I', 'J', 'K', 'L'/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 114 | 'M', 'N', 'O', 'P', 'Q'/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 115 | 'R', 'S', 'T', 'U', 'V'/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 116 | 'W', 'X', 'Y', 'Z', '!'/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 117 | '@', '#', '$', '%', '^'/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 118 | '&', '*', '(', ')', 0, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 119 | 0, 0, 0, 0, 0, /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 120 | '+', '{', '}', '|', '~', /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 121 | ':', '"', 0, '<', '>', /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 122 | '?'}, |
DieterGraef | 24:5396b6a93262 | 123 | |
DieterGraef | 24:5396b6a93262 | 124 | /* ALT MODIFIER */ |
DieterGraef | 24:5396b6a93262 | 125 | { 0, 0, 0, 0, 0, 0 /*0x05*/, |
DieterGraef | 24:5396b6a93262 | 126 | 0, 0, 0, 0, 0 /*0x0a*/, |
DieterGraef | 24:5396b6a93262 | 127 | 0, 0, 0, 0, 0/*0x0f*/, |
DieterGraef | 24:5396b6a93262 | 128 | 0, 0, 0, 0, 0/*0x14*/, |
DieterGraef | 24:5396b6a93262 | 129 | 0, 0, 0, 0, 0/*0x19*/, |
DieterGraef | 24:5396b6a93262 | 130 | 0, 0, 0, 0, 0/*0x1E*/, |
DieterGraef | 24:5396b6a93262 | 131 | 0, 0, 0, 0, 0/*0x23*/, |
DieterGraef | 24:5396b6a93262 | 132 | 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ |
DieterGraef | 24:5396b6a93262 | 133 | 0, 0, 0, 0, 0, /*0x2d*/ |
DieterGraef | 24:5396b6a93262 | 134 | 0, 0, 0, 0, 0, /*0x32*/ |
DieterGraef | 24:5396b6a93262 | 135 | 0, 0, 0, 0, 0, /*0x37*/ |
DieterGraef | 24:5396b6a93262 | 136 | 0} |
DieterGraef | 24:5396b6a93262 | 137 | |
DieterGraef | 24:5396b6a93262 | 138 | }; |
DieterGraef | 24:5396b6a93262 | 139 | #endif |
DieterGraef | 24:5396b6a93262 | 140 | |
DieterGraef | 24:5396b6a93262 | 141 | USBHostMouseKb::USBHostMouseKb(int Interface) { |
DieterGraef | 24:5396b6a93262 | 142 | host = USBHost::getHostInst(Interface); |
DieterGraef | 24:5396b6a93262 | 143 | init(); |
DieterGraef | 24:5396b6a93262 | 144 | } |
DieterGraef | 24:5396b6a93262 | 145 | |
DieterGraef | 24:5396b6a93262 | 146 | |
DieterGraef | 24:5396b6a93262 | 147 | void USBHostMouseKb::init() { |
DieterGraef | 24:5396b6a93262 | 148 | dev = NULL; |
DieterGraef | 24:5396b6a93262 | 149 | int_in_mouse = NULL; |
DieterGraef | 24:5396b6a93262 | 150 | int_in_kb=NULL; |
DieterGraef | 24:5396b6a93262 | 151 | report_id = 0; |
DieterGraef | 24:5396b6a93262 | 152 | onUpdate = NULL; |
DieterGraef | 24:5396b6a93262 | 153 | onButtonUpdate = NULL; |
DieterGraef | 24:5396b6a93262 | 154 | onXUpdate = NULL; |
DieterGraef | 24:5396b6a93262 | 155 | onYUpdate = NULL; |
DieterGraef | 24:5396b6a93262 | 156 | onZUpdate = NULL; |
DieterGraef | 24:5396b6a93262 | 157 | onKey = NULL; |
DieterGraef | 24:5396b6a93262 | 158 | onKeyCode = NULL; |
DieterGraef | 24:5396b6a93262 | 159 | dev_connected = false; |
DieterGraef | 24:5396b6a93262 | 160 | mouse_intf = -1; |
DieterGraef | 24:5396b6a93262 | 161 | kb_intf=-1; |
DieterGraef | 24:5396b6a93262 | 162 | mouse_device_found = false; |
DieterGraef | 24:5396b6a93262 | 163 | kb_device_found = false; |
DieterGraef | 24:5396b6a93262 | 164 | } |
DieterGraef | 24:5396b6a93262 | 165 | |
DieterGraef | 24:5396b6a93262 | 166 | bool USBHostMouseKb::connected() { |
DieterGraef | 24:5396b6a93262 | 167 | return dev_connected; |
DieterGraef | 24:5396b6a93262 | 168 | } |
DieterGraef | 24:5396b6a93262 | 169 | |
DieterGraef | 24:5396b6a93262 | 170 | void USBHostMouseKb::poll() { |
DieterGraef | 24:5396b6a93262 | 171 | host->poll(); |
DieterGraef | 24:5396b6a93262 | 172 | } |
DieterGraef | 24:5396b6a93262 | 173 | |
DieterGraef | 24:5396b6a93262 | 174 | bool USBHostMouseKb::connect() { |
DieterGraef | 24:5396b6a93262 | 175 | |
DieterGraef | 24:5396b6a93262 | 176 | if (dev_connected) { |
DieterGraef | 24:5396b6a93262 | 177 | return true; |
DieterGraef | 24:5396b6a93262 | 178 | } |
DieterGraef | 24:5396b6a93262 | 179 | |
DieterGraef | 24:5396b6a93262 | 180 | for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) { |
DieterGraef | 24:5396b6a93262 | 181 | if ((dev = host->getDevice(i)) != NULL) { |
DieterGraef | 24:5396b6a93262 | 182 | |
DieterGraef | 24:5396b6a93262 | 183 | if (host->enumerate(dev, this)) |
DieterGraef | 24:5396b6a93262 | 184 | break; |
DieterGraef | 24:5396b6a93262 | 185 | |
DieterGraef | 24:5396b6a93262 | 186 | if ((mouse_device_found)&&(mouse_intf>-1)) { |
DieterGraef | 24:5396b6a93262 | 187 | |
DieterGraef | 24:5396b6a93262 | 188 | int_in_mouse = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN); |
DieterGraef | 24:5396b6a93262 | 189 | if (!int_in_mouse) |
DieterGraef | 24:5396b6a93262 | 190 | return false; |
DieterGraef | 24:5396b6a93262 | 191 | USB_INFO("New Mouse - device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf); |
DieterGraef | 24:5396b6a93262 | 192 | dev->setName("Mouse", mouse_intf); |
DieterGraef | 24:5396b6a93262 | 193 | host->registerDriver(dev, mouse_intf, this, &USBHostMouseKb::init); |
DieterGraef | 24:5396b6a93262 | 194 | int_in_mouse->attach(this, &USBHostMouseKb::rxHandlerMouse); |
DieterGraef | 24:5396b6a93262 | 195 | host->interruptRead(dev, int_in_mouse, report, int_in_mouse->getSize(), false); |
DieterGraef | 24:5396b6a93262 | 196 | dev_connected = true; |
DieterGraef | 24:5396b6a93262 | 197 | } |
DieterGraef | 24:5396b6a93262 | 198 | |
DieterGraef | 24:5396b6a93262 | 199 | if ((kb_device_found)&&(kb_intf>-1)) { |
DieterGraef | 24:5396b6a93262 | 200 | int_in_kb = dev->getEndpoint(kb_intf, INTERRUPT_ENDPOINT, IN); |
DieterGraef | 24:5396b6a93262 | 201 | if (!int_in_kb) |
DieterGraef | 24:5396b6a93262 | 202 | return false; |
DieterGraef | 24:5396b6a93262 | 203 | USB_INFO("New Keyboard - device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, kb_intf); |
DieterGraef | 24:5396b6a93262 | 204 | dev->setName("Keyboard", kb_intf); |
DieterGraef | 24:5396b6a93262 | 205 | host->registerDriver(dev, kb_intf, this, &USBHostMouseKb::init); |
DieterGraef | 24:5396b6a93262 | 206 | int_in_kb->attach(this, &USBHostMouseKb::rxHandlerKb); |
DieterGraef | 24:5396b6a93262 | 207 | host->interruptRead(dev, int_in_kb, report, int_in_kb->getSize(), false); |
DieterGraef | 24:5396b6a93262 | 208 | dev_connected = true; |
DieterGraef | 24:5396b6a93262 | 209 | } |
DieterGraef | 24:5396b6a93262 | 210 | if (dev_connected == true)return true; |
DieterGraef | 24:5396b6a93262 | 211 | } |
DieterGraef | 24:5396b6a93262 | 212 | } |
DieterGraef | 24:5396b6a93262 | 213 | return false; |
DieterGraef | 24:5396b6a93262 | 214 | } |
DieterGraef | 24:5396b6a93262 | 215 | |
DieterGraef | 24:5396b6a93262 | 216 | void USBHostMouseKb::rxHandlerMouse() { |
DieterGraef | 24:5396b6a93262 | 217 | int len = int_in_mouse->getLengthTransferred(); |
DieterGraef | 24:5396b6a93262 | 218 | int len_listen = int_in_mouse->getSize(); |
DieterGraef | 24:5396b6a93262 | 219 | if (!((report[0]==0)&(report[1]==0)&(report[2]==0)&(report[3]==0)&(report[4]==0)&(report[5]==0)&(report[6]==0)&(report[7]==0)&(report[8]==0))) |
DieterGraef | 24:5396b6a93262 | 220 | USB_INFO("RepMouse %d :%d :%d :%d :%d :%d :%d :%d :%d\r\n",report[0],report[1],report[2],report[3],report[4],report[5],report[6],report[7],report[8]); |
DieterGraef | 24:5396b6a93262 | 221 | |
DieterGraef | 24:5396b6a93262 | 222 | if (len<8) |
DieterGraef | 24:5396b6a93262 | 223 | { |
DieterGraef | 24:5396b6a93262 | 224 | if (onUpdate) { |
DieterGraef | 24:5396b6a93262 | 225 | (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]); |
DieterGraef | 24:5396b6a93262 | 226 | } |
DieterGraef | 24:5396b6a93262 | 227 | |
DieterGraef | 24:5396b6a93262 | 228 | if (onButtonUpdate && (buttons != (report[0] & 0x07))) { |
DieterGraef | 24:5396b6a93262 | 229 | (*onButtonUpdate)(report[0] & 0x07); |
DieterGraef | 24:5396b6a93262 | 230 | } |
DieterGraef | 24:5396b6a93262 | 231 | |
DieterGraef | 24:5396b6a93262 | 232 | if (onXUpdate && (x != report[1])) { |
DieterGraef | 24:5396b6a93262 | 233 | (*onXUpdate)(report[1]); |
DieterGraef | 24:5396b6a93262 | 234 | } |
DieterGraef | 24:5396b6a93262 | 235 | |
DieterGraef | 24:5396b6a93262 | 236 | if (onYUpdate && (y != report[2])) { |
DieterGraef | 24:5396b6a93262 | 237 | (*onYUpdate)(report[2]); |
DieterGraef | 24:5396b6a93262 | 238 | } |
DieterGraef | 24:5396b6a93262 | 239 | |
DieterGraef | 24:5396b6a93262 | 240 | if (onZUpdate && (z != report[3])) { |
DieterGraef | 24:5396b6a93262 | 241 | (*onZUpdate)(report[3]); |
DieterGraef | 24:5396b6a93262 | 242 | } |
DieterGraef | 24:5396b6a93262 | 243 | |
DieterGraef | 24:5396b6a93262 | 244 | // update mouse state |
DieterGraef | 24:5396b6a93262 | 245 | buttons = report[0] & 0x07; |
DieterGraef | 24:5396b6a93262 | 246 | x = report[1]; |
DieterGraef | 24:5396b6a93262 | 247 | y = report[2]; |
DieterGraef | 24:5396b6a93262 | 248 | z = report[3]; |
DieterGraef | 24:5396b6a93262 | 249 | |
DieterGraef | 24:5396b6a93262 | 250 | if (dev) |
DieterGraef | 24:5396b6a93262 | 251 | host->interruptRead(dev, int_in_mouse, report, len_listen, false); |
DieterGraef | 24:5396b6a93262 | 252 | return; |
DieterGraef | 24:5396b6a93262 | 253 | } |
DieterGraef | 24:5396b6a93262 | 254 | |
DieterGraef | 24:5396b6a93262 | 255 | if(report[0]==REPORT_ID_IDLE ) |
DieterGraef | 24:5396b6a93262 | 256 | { |
DieterGraef | 24:5396b6a93262 | 257 | if (dev) |
DieterGraef | 24:5396b6a93262 | 258 | host->interruptRead(dev, int_in_mouse, report, len_listen, false); |
DieterGraef | 24:5396b6a93262 | 259 | } |
DieterGraef | 24:5396b6a93262 | 260 | |
DieterGraef | 24:5396b6a93262 | 261 | if(report[0]==REPORT_ID_MOUSE ) |
DieterGraef | 24:5396b6a93262 | 262 | { |
DieterGraef | 24:5396b6a93262 | 263 | if (onUpdate) { |
DieterGraef | 24:5396b6a93262 | 264 | (*onUpdate)(report[1] & 0x07, report[3], report[4], report[5]); |
DieterGraef | 24:5396b6a93262 | 265 | } |
DieterGraef | 24:5396b6a93262 | 266 | |
DieterGraef | 24:5396b6a93262 | 267 | if (onButtonUpdate && (buttons != (report[1] & 0x07))) { |
DieterGraef | 24:5396b6a93262 | 268 | (*onButtonUpdate)(report[1] & 0x07); |
DieterGraef | 24:5396b6a93262 | 269 | } |
DieterGraef | 24:5396b6a93262 | 270 | |
DieterGraef | 24:5396b6a93262 | 271 | if (onXUpdate && (x != report[3])) { |
DieterGraef | 24:5396b6a93262 | 272 | (*onXUpdate)(report[3]); |
DieterGraef | 24:5396b6a93262 | 273 | } |
DieterGraef | 24:5396b6a93262 | 274 | |
DieterGraef | 24:5396b6a93262 | 275 | if (onYUpdate && (y != report[4])) { |
DieterGraef | 24:5396b6a93262 | 276 | (*onYUpdate)(report[4]); |
DieterGraef | 24:5396b6a93262 | 277 | } |
DieterGraef | 24:5396b6a93262 | 278 | |
DieterGraef | 24:5396b6a93262 | 279 | if (onZUpdate && (z != report[5])) { |
DieterGraef | 24:5396b6a93262 | 280 | (*onZUpdate)(report[5]); |
DieterGraef | 24:5396b6a93262 | 281 | } |
DieterGraef | 24:5396b6a93262 | 282 | |
DieterGraef | 24:5396b6a93262 | 283 | // update mouse state |
DieterGraef | 24:5396b6a93262 | 284 | buttons = report[1] & 0x07; |
DieterGraef | 24:5396b6a93262 | 285 | x = report[3]; |
DieterGraef | 24:5396b6a93262 | 286 | y = report[4]; |
DieterGraef | 24:5396b6a93262 | 287 | z = report[5]; |
DieterGraef | 24:5396b6a93262 | 288 | |
DieterGraef | 24:5396b6a93262 | 289 | if (dev) |
DieterGraef | 24:5396b6a93262 | 290 | host->interruptRead(dev, int_in_mouse, report, len_listen, false); |
DieterGraef | 24:5396b6a93262 | 291 | } |
DieterGraef | 24:5396b6a93262 | 292 | } |
DieterGraef | 24:5396b6a93262 | 293 | |
DieterGraef | 24:5396b6a93262 | 294 | void USBHostMouseKb::rxHandlerKb() { |
DieterGraef | 24:5396b6a93262 | 295 | uint8_t key = 0; |
DieterGraef | 24:5396b6a93262 | 296 | int len = int_in_kb->getLengthTransferred(); |
DieterGraef | 24:5396b6a93262 | 297 | int index = (len == 9) ? 1 : 0; |
DieterGraef | 24:5396b6a93262 | 298 | int len_listen = int_in_kb->getSize(); |
DieterGraef | 24:5396b6a93262 | 299 | if (!((report[0]==0)&(report[1]==0)&(report[2]==0)&(report[3]==0)&(report[4]==0)&(report[5]==0)&(report[6]==0)&(report[7]==0)&(report[8]==0))) |
DieterGraef | 24:5396b6a93262 | 300 | USB_INFO("RepKb %d :%d :%d :%d :%d :%d :%d :%d :%d\r\n",report[0],report[1],report[2],report[3],report[4],report[5],report[6],report[7],report[8]); |
DieterGraef | 24:5396b6a93262 | 301 | if(report[0]==REPORT_ID_IDLE ) |
DieterGraef | 24:5396b6a93262 | 302 | { |
DieterGraef | 24:5396b6a93262 | 303 | if (dev) |
DieterGraef | 24:5396b6a93262 | 304 | host->interruptRead(dev, int_in_kb, report, len_listen, false); |
DieterGraef | 24:5396b6a93262 | 305 | } |
DieterGraef | 24:5396b6a93262 | 306 | if ((dev->getVid()==1133)&&(dev->getPid()==50475)) |
DieterGraef | 24:5396b6a93262 | 307 | { |
DieterGraef | 24:5396b6a93262 | 308 | uint8_t modifier=report[0]; |
DieterGraef | 24:5396b6a93262 | 309 | if (report[7]!=0) |
DieterGraef | 24:5396b6a93262 | 310 | { |
DieterGraef | 24:5396b6a93262 | 311 | USB_INFO("RepKb :0x%x\r\n",report[7]); |
DieterGraef | 24:5396b6a93262 | 312 | if ((modifier==64)||(modifier==4))modifier=3; |
DieterGraef | 24:5396b6a93262 | 313 | if(report[7]==0x64)report[7]=0x31; |
DieterGraef | 24:5396b6a93262 | 314 | key = keymap[modifier][report[7]]; |
DieterGraef | 24:5396b6a93262 | 315 | if (key && onKey) { |
DieterGraef | 24:5396b6a93262 | 316 | (*onKey)(key); |
DieterGraef | 24:5396b6a93262 | 317 | } |
DieterGraef | 24:5396b6a93262 | 318 | if ((report[7] || modifier) && onKeyCode) { |
DieterGraef | 24:5396b6a93262 | 319 | (*onKeyCode)(report[7], modifier); |
DieterGraef | 24:5396b6a93262 | 320 | } |
DieterGraef | 24:5396b6a93262 | 321 | } |
DieterGraef | 24:5396b6a93262 | 322 | } |
DieterGraef | 24:5396b6a93262 | 323 | else |
DieterGraef | 24:5396b6a93262 | 324 | { |
DieterGraef | 24:5396b6a93262 | 325 | if (len == 8 || len == 9) { |
DieterGraef | 24:5396b6a93262 | 326 | uint8_t modifier = (report[index] == 4) ? 3 : report[index]; |
DieterGraef | 24:5396b6a93262 | 327 | len_listen = len; |
DieterGraef | 24:5396b6a93262 | 328 | key = keymap[modifier][report[index + 2]]; |
DieterGraef | 24:5396b6a93262 | 329 | if (key && onKey) { |
DieterGraef | 24:5396b6a93262 | 330 | (*onKey)(key); |
DieterGraef | 24:5396b6a93262 | 331 | } |
DieterGraef | 24:5396b6a93262 | 332 | if ((report[index + 2] || modifier) && onKeyCode) { |
DieterGraef | 24:5396b6a93262 | 333 | (*onKeyCode)(report[index + 2], modifier); |
DieterGraef | 24:5396b6a93262 | 334 | } |
DieterGraef | 24:5396b6a93262 | 335 | } |
DieterGraef | 24:5396b6a93262 | 336 | } |
DieterGraef | 24:5396b6a93262 | 337 | if (dev && int_in_kb) |
DieterGraef | 24:5396b6a93262 | 338 | host->interruptRead(dev, int_in_kb, report, len_listen, false); |
DieterGraef | 24:5396b6a93262 | 339 | } |
DieterGraef | 24:5396b6a93262 | 340 | |
DieterGraef | 24:5396b6a93262 | 341 | /*virtual*/ void USBHostMouseKb::setVidPid(uint16_t vid, uint16_t pid) |
DieterGraef | 24:5396b6a93262 | 342 | { |
DieterGraef | 24:5396b6a93262 | 343 | // we don't check VID/PID for keyboard driver |
DieterGraef | 24:5396b6a93262 | 344 | } |
DieterGraef | 24:5396b6a93262 | 345 | |
DieterGraef | 24:5396b6a93262 | 346 | /*virtual*/ bool USBHostMouseKb::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 |
DieterGraef | 24:5396b6a93262 | 347 | { |
DieterGraef | 24:5396b6a93262 | 348 | if ((mouse_intf == -1) && |
DieterGraef | 24:5396b6a93262 | 349 | (intf_class == HID_CLASS) && |
DieterGraef | 24:5396b6a93262 | 350 | (intf_subclass == 0x01) && |
DieterGraef | 24:5396b6a93262 | 351 | (intf_protocol == 0x02)) { |
DieterGraef | 24:5396b6a93262 | 352 | mouse_intf = intf_nb; |
DieterGraef | 24:5396b6a93262 | 353 | return true; |
DieterGraef | 24:5396b6a93262 | 354 | } |
DieterGraef | 24:5396b6a93262 | 355 | if ((kb_intf == -1) && |
DieterGraef | 24:5396b6a93262 | 356 | (intf_class == HID_CLASS) && |
DieterGraef | 24:5396b6a93262 | 357 | (intf_subclass == 0x01) && |
DieterGraef | 24:5396b6a93262 | 358 | (intf_protocol == 0x01)) { |
DieterGraef | 24:5396b6a93262 | 359 | kb_intf = intf_nb; |
DieterGraef | 24:5396b6a93262 | 360 | return true; |
DieterGraef | 24:5396b6a93262 | 361 | } |
DieterGraef | 24:5396b6a93262 | 362 | return false; |
DieterGraef | 24:5396b6a93262 | 363 | } |
DieterGraef | 24:5396b6a93262 | 364 | |
DieterGraef | 24:5396b6a93262 | 365 | /*virtual*/ bool USBHostMouseKb::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
DieterGraef | 24:5396b6a93262 | 366 | { |
DieterGraef | 24:5396b6a93262 | 367 | if (intf_nb == mouse_intf) { |
DieterGraef | 24:5396b6a93262 | 368 | if (type == INTERRUPT_ENDPOINT && dir == IN) { |
DieterGraef | 24:5396b6a93262 | 369 | mouse_device_found = true; |
DieterGraef | 24:5396b6a93262 | 370 | return true; |
DieterGraef | 24:5396b6a93262 | 371 | } |
DieterGraef | 24:5396b6a93262 | 372 | } |
DieterGraef | 24:5396b6a93262 | 373 | if (intf_nb == kb_intf) { |
DieterGraef | 24:5396b6a93262 | 374 | if (type == INTERRUPT_ENDPOINT && dir == IN) { |
DieterGraef | 24:5396b6a93262 | 375 | kb_device_found = true; |
DieterGraef | 24:5396b6a93262 | 376 | return true; |
DieterGraef | 24:5396b6a93262 | 377 | } |
DieterGraef | 24:5396b6a93262 | 378 | } |
DieterGraef | 24:5396b6a93262 | 379 | return false; |
DieterGraef | 24:5396b6a93262 | 380 | } |
DieterGraef | 24:5396b6a93262 | 381 | |
DieterGraef | 24:5396b6a93262 | 382 | #endif |