Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

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 "USBHostMouse.h"
thedo 166:3a9487d57a5c 18
thedo 166:3a9487d57a5c 19 #if USBHOST_MOUSE
thedo 166:3a9487d57a5c 20
thedo 166:3a9487d57a5c 21 USBHostMouse::USBHostMouse() {
thedo 166:3a9487d57a5c 22 host = USBHost::getHostInst();
thedo 166:3a9487d57a5c 23 init();
thedo 166:3a9487d57a5c 24 }
thedo 166:3a9487d57a5c 25
thedo 166:3a9487d57a5c 26 void USBHostMouse::init() {
thedo 166:3a9487d57a5c 27 dev = NULL;
thedo 166:3a9487d57a5c 28 int_in = NULL;
thedo 166:3a9487d57a5c 29 onUpdate = NULL;
thedo 166:3a9487d57a5c 30 onButtonUpdate = NULL;
thedo 166:3a9487d57a5c 31 onXUpdate = NULL;
thedo 166:3a9487d57a5c 32 onYUpdate = NULL;
thedo 166:3a9487d57a5c 33 onZUpdate = NULL;
thedo 166:3a9487d57a5c 34 report_id = 0;
thedo 166:3a9487d57a5c 35 dev_connected = false;
thedo 166:3a9487d57a5c 36 mouse_device_found = false;
thedo 166:3a9487d57a5c 37 mouse_intf = -1;
thedo 166:3a9487d57a5c 38
thedo 166:3a9487d57a5c 39 buttons = 0;
thedo 166:3a9487d57a5c 40 x = 0;
thedo 166:3a9487d57a5c 41 y = 0;
thedo 166:3a9487d57a5c 42 z = 0;
thedo 166:3a9487d57a5c 43 }
thedo 166:3a9487d57a5c 44
thedo 166:3a9487d57a5c 45 bool USBHostMouse::connected() {
thedo 166:3a9487d57a5c 46 return dev_connected;
thedo 166:3a9487d57a5c 47 }
thedo 166:3a9487d57a5c 48
thedo 166:3a9487d57a5c 49 bool USBHostMouse::connect() {
thedo 166:3a9487d57a5c 50 int len_listen;
thedo 166:3a9487d57a5c 51
thedo 166:3a9487d57a5c 52 if (dev_connected) {
thedo 166:3a9487d57a5c 53 return true;
thedo 166:3a9487d57a5c 54 }
thedo 166:3a9487d57a5c 55
thedo 166:3a9487d57a5c 56 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
thedo 166:3a9487d57a5c 57 if ((dev = host->getDevice(i)) != NULL) {
thedo 166:3a9487d57a5c 58
thedo 166:3a9487d57a5c 59 if(host->enumerate(dev, this))
thedo 166:3a9487d57a5c 60 break;
thedo 166:3a9487d57a5c 61
thedo 166:3a9487d57a5c 62 if (mouse_device_found) {
thedo 166:3a9487d57a5c 63
thedo 166:3a9487d57a5c 64 int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
thedo 166:3a9487d57a5c 65 if (!int_in)
thedo 166:3a9487d57a5c 66 break;
thedo 166:3a9487d57a5c 67
thedo 166:3a9487d57a5c 68 USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
thedo 166:3a9487d57a5c 69 dev->setName("Mouse", mouse_intf);
thedo 166:3a9487d57a5c 70 host->registerDriver(dev, mouse_intf, this, &USBHostMouse::init);
thedo 166:3a9487d57a5c 71
thedo 166:3a9487d57a5c 72 int_in->attach(this, &USBHostMouse::rxHandler);
thedo 166:3a9487d57a5c 73 len_listen = int_in->getSize();
thedo 166:3a9487d57a5c 74 if (len_listen > sizeof(report)) {
thedo 166:3a9487d57a5c 75 len_listen = sizeof(report);
thedo 166:3a9487d57a5c 76 }
thedo 166:3a9487d57a5c 77 host->interruptRead(dev, int_in, report, len_listen, false);
thedo 166:3a9487d57a5c 78
thedo 166:3a9487d57a5c 79 dev_connected = true;
thedo 166:3a9487d57a5c 80 return true;
thedo 166:3a9487d57a5c 81 }
thedo 166:3a9487d57a5c 82 }
thedo 166:3a9487d57a5c 83 }
thedo 166:3a9487d57a5c 84 init();
thedo 166:3a9487d57a5c 85 return false;
thedo 166:3a9487d57a5c 86 }
thedo 166:3a9487d57a5c 87
thedo 166:3a9487d57a5c 88 void USBHostMouse::rxHandler() {
thedo 166:3a9487d57a5c 89 int len_listen = int_in->getSize();
thedo 166:3a9487d57a5c 90
thedo 166:3a9487d57a5c 91 if (onUpdate) {
thedo 166:3a9487d57a5c 92 (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
thedo 166:3a9487d57a5c 93 }
thedo 166:3a9487d57a5c 94
thedo 166:3a9487d57a5c 95 if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
thedo 166:3a9487d57a5c 96 (*onButtonUpdate)(report[0] & 0x07);
thedo 166:3a9487d57a5c 97 }
thedo 166:3a9487d57a5c 98
thedo 166:3a9487d57a5c 99 if (onXUpdate && (x != report[1])) {
thedo 166:3a9487d57a5c 100 (*onXUpdate)(report[1]);
thedo 166:3a9487d57a5c 101 }
thedo 166:3a9487d57a5c 102
thedo 166:3a9487d57a5c 103 if (onYUpdate && (y != report[2])) {
thedo 166:3a9487d57a5c 104 (*onYUpdate)(report[2]);
thedo 166:3a9487d57a5c 105 }
thedo 166:3a9487d57a5c 106
thedo 166:3a9487d57a5c 107 if (onZUpdate && (z != report[3])) {
thedo 166:3a9487d57a5c 108 (*onZUpdate)(report[3]);
thedo 166:3a9487d57a5c 109 }
thedo 166:3a9487d57a5c 110
thedo 166:3a9487d57a5c 111 // update mouse state
thedo 166:3a9487d57a5c 112 buttons = report[0] & 0x07;
thedo 166:3a9487d57a5c 113 x = report[1];
thedo 166:3a9487d57a5c 114 y = report[2];
thedo 166:3a9487d57a5c 115 z = report[3];
thedo 166:3a9487d57a5c 116
thedo 166:3a9487d57a5c 117 if (len_listen > sizeof(report)) {
thedo 166:3a9487d57a5c 118 len_listen = sizeof(report);
thedo 166:3a9487d57a5c 119 }
thedo 166:3a9487d57a5c 120
thedo 166:3a9487d57a5c 121 if (dev)
thedo 166:3a9487d57a5c 122 host->interruptRead(dev, int_in, report, len_listen, false);
thedo 166:3a9487d57a5c 123 }
thedo 166:3a9487d57a5c 124
thedo 166:3a9487d57a5c 125 /*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
thedo 166:3a9487d57a5c 126 {
thedo 166:3a9487d57a5c 127 // we don't check VID/PID for mouse driver
thedo 166:3a9487d57a5c 128 }
thedo 166:3a9487d57a5c 129
thedo 166:3a9487d57a5c 130 /*virtual*/ bool USBHostMouse::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 131 {
thedo 166:3a9487d57a5c 132 if ((mouse_intf == -1) &&
thedo 166:3a9487d57a5c 133 (intf_class == HID_CLASS) &&
thedo 166:3a9487d57a5c 134 (intf_subclass == 0x01) &&
thedo 166:3a9487d57a5c 135 (intf_protocol == 0x02)) {
thedo 166:3a9487d57a5c 136 mouse_intf = intf_nb;
thedo 166:3a9487d57a5c 137 return true;
thedo 166:3a9487d57a5c 138 }
thedo 166:3a9487d57a5c 139 return false;
thedo 166:3a9487d57a5c 140 }
thedo 166:3a9487d57a5c 141
thedo 166:3a9487d57a5c 142 /*virtual*/ bool USBHostMouse::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
thedo 166:3a9487d57a5c 143 {
thedo 166:3a9487d57a5c 144 if (intf_nb == mouse_intf) {
thedo 166:3a9487d57a5c 145 if (type == INTERRUPT_ENDPOINT && dir == IN) {
thedo 166:3a9487d57a5c 146 mouse_device_found = true;
thedo 166:3a9487d57a5c 147 return true;
thedo 166:3a9487d57a5c 148 }
thedo 166:3a9487d57a5c 149 }
thedo 166:3a9487d57a5c 150 return false;
thedo 166:3a9487d57a5c 151 }
thedo 166:3a9487d57a5c 152
thedo 166:3a9487d57a5c 153 #endif