Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:00:41 2017 +0000
Revision:
166:3a9487d57a5c
This is Opencv 3.1 project on GR-PEACH board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /* mbed USBHost Library
thedo 166:3a9487d57a5c 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:3a9487d57a5c 3 *
thedo 166:3a9487d57a5c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:3a9487d57a5c 5 * you may not use this file except in compliance with the License.
thedo 166:3a9487d57a5c 6 * You may obtain a copy of the License at
thedo 166:3a9487d57a5c 7 *
thedo 166:3a9487d57a5c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:3a9487d57a5c 9 *
thedo 166:3a9487d57a5c 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:3a9487d57a5c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:3a9487d57a5c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:3a9487d57a5c 13 * See the License for the specific language governing permissions and
thedo 166:3a9487d57a5c 14 * limitations under the License.
thedo 166:3a9487d57a5c 15 */
thedo 166:3a9487d57a5c 16
thedo 166:3a9487d57a5c 17 #include "USBHostKeyboard.h"
thedo 166:3a9487d57a5c 18
thedo 166:3a9487d57a5c 19 #if USBHOST_KEYBOARD
thedo 166:3a9487d57a5c 20
thedo 166:3a9487d57a5c 21 static uint8_t keymap[4][0x39] = {
thedo 166:3a9487d57a5c 22 { 0, 0, 0, 0, 'a', 'b' /*0x05*/,
thedo 166:3a9487d57a5c 23 'c', 'd', 'e', 'f', 'g' /*0x0a*/,
thedo 166:3a9487d57a5c 24 'h', 'i', 'j', 'k', 'l'/*0x0f*/,
thedo 166:3a9487d57a5c 25 'm', 'n', 'o', 'p', 'q'/*0x14*/,
thedo 166:3a9487d57a5c 26 'r', 's', 't', 'u', 'v'/*0x19*/,
thedo 166:3a9487d57a5c 27 'w', 'x', 'y', 'z', '1'/*0x1E*/,
thedo 166:3a9487d57a5c 28 '2', '3', '4', '5', '6'/*0x23*/,
thedo 166:3a9487d57a5c 29 '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/
thedo 166:3a9487d57a5c 30 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/
thedo 166:3a9487d57a5c 31 '=', '[', ']', '\\', '#', /*0x32*/
thedo 166:3a9487d57a5c 32 ';', '\'', 0, ',', '.', /*0x37*/
thedo 166:3a9487d57a5c 33 '/'},
thedo 166:3a9487d57a5c 34
thedo 166:3a9487d57a5c 35 /* CTRL MODIFIER */
thedo 166:3a9487d57a5c 36 { 0, 0, 0, 0, 0, 0 /*0x05*/,
thedo 166:3a9487d57a5c 37 0, 0, 0, 0, 0 /*0x0a*/,
thedo 166:3a9487d57a5c 38 0, 0, 0, 0, 0/*0x0f*/,
thedo 166:3a9487d57a5c 39 0, 0, 0, 0, 0/*0x14*/,
thedo 166:3a9487d57a5c 40 0, 0, 0, 0, 0/*0x19*/,
thedo 166:3a9487d57a5c 41 0, 0, 0, 0, 0/*0x1E*/,
thedo 166:3a9487d57a5c 42 0, 0, 0, 0, 0/*0x23*/,
thedo 166:3a9487d57a5c 43 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
thedo 166:3a9487d57a5c 44 0, 0, 0, 0, 0, /*0x2d*/
thedo 166:3a9487d57a5c 45 0, 0, 0, 0, 0, /*0x32*/
thedo 166:3a9487d57a5c 46 0, 0, 0, 0, 0, /*0x37*/
thedo 166:3a9487d57a5c 47 0},
thedo 166:3a9487d57a5c 48
thedo 166:3a9487d57a5c 49 /* SHIFT MODIFIER */
thedo 166:3a9487d57a5c 50 { 0, 0, 0, 0, 'A', 'B' /*0x05*/,
thedo 166:3a9487d57a5c 51 'C', 'D', 'E', 'F', 'G' /*0x0a*/,
thedo 166:3a9487d57a5c 52 'H', 'I', 'J', 'K', 'L'/*0x0f*/,
thedo 166:3a9487d57a5c 53 'M', 'N', 'O', 'P', 'Q'/*0x14*/,
thedo 166:3a9487d57a5c 54 'R', 'S', 'T', 'U', 'V'/*0x19*/,
thedo 166:3a9487d57a5c 55 'W', 'X', 'Y', 'Z', '!'/*0x1E*/,
thedo 166:3a9487d57a5c 56 '@', '#', '$', '%', '^'/*0x23*/,
thedo 166:3a9487d57a5c 57 '&', '*', '(', ')', 0, /*0x28*/
thedo 166:3a9487d57a5c 58 0, 0, 0, 0, 0, /*0x2d*/
thedo 166:3a9487d57a5c 59 '+', '{', '}', '|', '~', /*0x32*/
thedo 166:3a9487d57a5c 60 ':', '"', 0, '<', '>', /*0x37*/
thedo 166:3a9487d57a5c 61 '?'},
thedo 166:3a9487d57a5c 62
thedo 166:3a9487d57a5c 63 /* ALT MODIFIER */
thedo 166:3a9487d57a5c 64 { 0, 0, 0, 0, 0, 0 /*0x05*/,
thedo 166:3a9487d57a5c 65 0, 0, 0, 0, 0 /*0x0a*/,
thedo 166:3a9487d57a5c 66 0, 0, 0, 0, 0/*0x0f*/,
thedo 166:3a9487d57a5c 67 0, 0, 0, 0, 0/*0x14*/,
thedo 166:3a9487d57a5c 68 0, 0, 0, 0, 0/*0x19*/,
thedo 166:3a9487d57a5c 69 0, 0, 0, 0, 0/*0x1E*/,
thedo 166:3a9487d57a5c 70 0, 0, 0, 0, 0/*0x23*/,
thedo 166:3a9487d57a5c 71 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
thedo 166:3a9487d57a5c 72 0, 0, 0, 0, 0, /*0x2d*/
thedo 166:3a9487d57a5c 73 0, 0, 0, 0, 0, /*0x32*/
thedo 166:3a9487d57a5c 74 0, 0, 0, 0, 0, /*0x37*/
thedo 166:3a9487d57a5c 75 0}
thedo 166:3a9487d57a5c 76
thedo 166:3a9487d57a5c 77 };
thedo 166:3a9487d57a5c 78
thedo 166:3a9487d57a5c 79
thedo 166:3a9487d57a5c 80 USBHostKeyboard::USBHostKeyboard() {
thedo 166:3a9487d57a5c 81 host = USBHost::getHostInst();
thedo 166:3a9487d57a5c 82 init();
thedo 166:3a9487d57a5c 83 }
thedo 166:3a9487d57a5c 84
thedo 166:3a9487d57a5c 85
thedo 166:3a9487d57a5c 86 void USBHostKeyboard::init() {
thedo 166:3a9487d57a5c 87 dev = NULL;
thedo 166:3a9487d57a5c 88 int_in = NULL;
thedo 166:3a9487d57a5c 89 report_id = 0;
thedo 166:3a9487d57a5c 90 onKey = NULL;
thedo 166:3a9487d57a5c 91 onKeyCode = NULL;
thedo 166:3a9487d57a5c 92 dev_connected = false;
thedo 166:3a9487d57a5c 93 keyboard_intf = -1;
thedo 166:3a9487d57a5c 94 keyboard_device_found = false;
thedo 166:3a9487d57a5c 95 }
thedo 166:3a9487d57a5c 96
thedo 166:3a9487d57a5c 97 bool USBHostKeyboard::connected() {
thedo 166:3a9487d57a5c 98 return dev_connected;
thedo 166:3a9487d57a5c 99 }
thedo 166:3a9487d57a5c 100
thedo 166:3a9487d57a5c 101
thedo 166:3a9487d57a5c 102 bool USBHostKeyboard::connect() {
thedo 166:3a9487d57a5c 103
thedo 166:3a9487d57a5c 104 if (dev_connected) {
thedo 166:3a9487d57a5c 105 return true;
thedo 166:3a9487d57a5c 106 }
thedo 166:3a9487d57a5c 107
thedo 166:3a9487d57a5c 108 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
thedo 166:3a9487d57a5c 109 if ((dev = host->getDevice(i)) != NULL) {
thedo 166:3a9487d57a5c 110
thedo 166:3a9487d57a5c 111 if (host->enumerate(dev, this))
thedo 166:3a9487d57a5c 112 break;
thedo 166:3a9487d57a5c 113
thedo 166:3a9487d57a5c 114 if (keyboard_device_found) {
thedo 166:3a9487d57a5c 115 int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN);
thedo 166:3a9487d57a5c 116
thedo 166:3a9487d57a5c 117 if (!int_in)
thedo 166:3a9487d57a5c 118 break;
thedo 166:3a9487d57a5c 119
thedo 166:3a9487d57a5c 120 USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf);
thedo 166:3a9487d57a5c 121 dev->setName("Keyboard", keyboard_intf);
thedo 166:3a9487d57a5c 122 host->registerDriver(dev, keyboard_intf, this, &USBHostKeyboard::init);
thedo 166:3a9487d57a5c 123
thedo 166:3a9487d57a5c 124 int_in->attach(this, &USBHostKeyboard::rxHandler);
thedo 166:3a9487d57a5c 125 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
thedo 166:3a9487d57a5c 126
thedo 166:3a9487d57a5c 127 dev_connected = true;
thedo 166:3a9487d57a5c 128 return true;
thedo 166:3a9487d57a5c 129 }
thedo 166:3a9487d57a5c 130 }
thedo 166:3a9487d57a5c 131 }
thedo 166:3a9487d57a5c 132 init();
thedo 166:3a9487d57a5c 133 return false;
thedo 166:3a9487d57a5c 134 }
thedo 166:3a9487d57a5c 135
thedo 166:3a9487d57a5c 136 void USBHostKeyboard::rxHandler() {
thedo 166:3a9487d57a5c 137 int len = int_in->getLengthTransferred();
thedo 166:3a9487d57a5c 138 int index = (len == 9) ? 1 : 0;
thedo 166:3a9487d57a5c 139 int len_listen = int_in->getSize();
thedo 166:3a9487d57a5c 140 uint8_t key = 0;
thedo 166:3a9487d57a5c 141 if (len == 8 || len == 9) {
thedo 166:3a9487d57a5c 142 uint8_t modifier = (report[index] == 4) ? 3 : report[index];
thedo 166:3a9487d57a5c 143 len_listen = len;
thedo 166:3a9487d57a5c 144 key = keymap[modifier][report[index + 2]];
thedo 166:3a9487d57a5c 145 if (key && onKey) {
thedo 166:3a9487d57a5c 146 (*onKey)(key);
thedo 166:3a9487d57a5c 147 }
thedo 166:3a9487d57a5c 148 if ((report[index + 2] || modifier) && onKeyCode) {
thedo 166:3a9487d57a5c 149 (*onKeyCode)(report[index + 2], modifier);
thedo 166:3a9487d57a5c 150 }
thedo 166:3a9487d57a5c 151 }
thedo 166:3a9487d57a5c 152 if (dev && int_in)
thedo 166:3a9487d57a5c 153 host->interruptRead(dev, int_in, report, len_listen, false);
thedo 166:3a9487d57a5c 154 }
thedo 166:3a9487d57a5c 155
thedo 166:3a9487d57a5c 156 /*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)
thedo 166:3a9487d57a5c 157 {
thedo 166:3a9487d57a5c 158 // we don't check VID/PID for keyboard driver
thedo 166:3a9487d57a5c 159 }
thedo 166:3a9487d57a5c 160
thedo 166:3a9487d57a5c 161 /*virtual*/ bool USBHostKeyboard::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
thedo 166:3a9487d57a5c 162 {
thedo 166:3a9487d57a5c 163 if ((keyboard_intf == -1) &&
thedo 166:3a9487d57a5c 164 (intf_class == HID_CLASS) &&
thedo 166:3a9487d57a5c 165 (intf_subclass == 0x01) &&
thedo 166:3a9487d57a5c 166 (intf_protocol == 0x01)) {
thedo 166:3a9487d57a5c 167 keyboard_intf = intf_nb;
thedo 166:3a9487d57a5c 168 return true;
thedo 166:3a9487d57a5c 169 }
thedo 166:3a9487d57a5c 170 return false;
thedo 166:3a9487d57a5c 171 }
thedo 166:3a9487d57a5c 172
thedo 166:3a9487d57a5c 173 /*virtual*/ bool USBHostKeyboard::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
thedo 166:3a9487d57a5c 174 {
thedo 166:3a9487d57a5c 175 if (intf_nb == keyboard_intf) {
thedo 166:3a9487d57a5c 176 if (type == INTERRUPT_ENDPOINT && dir == IN) {
thedo 166:3a9487d57a5c 177 keyboard_device_found = true;
thedo 166:3a9487d57a5c 178 return true;
thedo 166:3a9487d57a5c 179 }
thedo 166:3a9487d57a5c 180 }
thedo 166:3a9487d57a5c 181 return false;
thedo 166:3a9487d57a5c 182 }
thedo 166:3a9487d57a5c 183
thedo 166:3a9487d57a5c 184 #endif