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 "USBDeviceConnected.h"
thedo 166:3a9487d57a5c 18 #include "dbg.h"
thedo 166:3a9487d57a5c 19
thedo 166:3a9487d57a5c 20 USBDeviceConnected::USBDeviceConnected() {
thedo 166:3a9487d57a5c 21 init();
thedo 166:3a9487d57a5c 22 }
thedo 166:3a9487d57a5c 23
thedo 166:3a9487d57a5c 24 void USBDeviceConnected::init() {
thedo 166:3a9487d57a5c 25 hub_nb = 0;
thedo 166:3a9487d57a5c 26 port = 0;
thedo 166:3a9487d57a5c 27 vid = 0;
thedo 166:3a9487d57a5c 28 pid = 0;
thedo 166:3a9487d57a5c 29 nb_interf = 0;
thedo 166:3a9487d57a5c 30 enumerated = false;
thedo 166:3a9487d57a5c 31 activeAddr = false;
thedo 166:3a9487d57a5c 32 sizeControlEndpoint = 8;
thedo 166:3a9487d57a5c 33 device_class = 0;
thedo 166:3a9487d57a5c 34 device_subclass = 0;
thedo 166:3a9487d57a5c 35 proto = 0;
thedo 166:3a9487d57a5c 36 speed = false;
thedo 166:3a9487d57a5c 37 for (int i = 0; i < MAX_INTF; i++) {
thedo 166:3a9487d57a5c 38 memset((void *)&intf[i], 0, sizeof(INTERFACE));
thedo 166:3a9487d57a5c 39 intf[i].in_use = false;
thedo 166:3a9487d57a5c 40 for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) {
thedo 166:3a9487d57a5c 41 intf[i].ep[j] = NULL;
thedo 166:3a9487d57a5c 42 strcpy(intf[i].name, "Unknown");
thedo 166:3a9487d57a5c 43 }
thedo 166:3a9487d57a5c 44 }
thedo 166:3a9487d57a5c 45 hub_parent = NULL;
thedo 166:3a9487d57a5c 46 hub = NULL;
thedo 166:3a9487d57a5c 47 nb_interf = 0;
thedo 166:3a9487d57a5c 48 }
thedo 166:3a9487d57a5c 49
thedo 166:3a9487d57a5c 50 INTERFACE * USBDeviceConnected::getInterface(uint8_t index) {
thedo 166:3a9487d57a5c 51 if (index >= MAX_INTF)
thedo 166:3a9487d57a5c 52 return NULL;
thedo 166:3a9487d57a5c 53
thedo 166:3a9487d57a5c 54 if (intf[index].in_use)
thedo 166:3a9487d57a5c 55 return &intf[index];
thedo 166:3a9487d57a5c 56
thedo 166:3a9487d57a5c 57 return NULL;
thedo 166:3a9487d57a5c 58 }
thedo 166:3a9487d57a5c 59
thedo 166:3a9487d57a5c 60 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
thedo 166:3a9487d57a5c 61 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) {
thedo 166:3a9487d57a5c 62 return false;
thedo 166:3a9487d57a5c 63 }
thedo 166:3a9487d57a5c 64 intf[intf_nb].in_use = true;
thedo 166:3a9487d57a5c 65 intf[intf_nb].intf_class = intf_class;
thedo 166:3a9487d57a5c 66 intf[intf_nb].intf_subclass = intf_subclass;
thedo 166:3a9487d57a5c 67 intf[intf_nb].intf_protocol = intf_protocol;
thedo 166:3a9487d57a5c 68 intf[intf_nb].nb_endpoint = 0;
thedo 166:3a9487d57a5c 69 return true;
thedo 166:3a9487d57a5c 70 }
thedo 166:3a9487d57a5c 71
thedo 166:3a9487d57a5c 72 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
thedo 166:3a9487d57a5c 73 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) {
thedo 166:3a9487d57a5c 74 return false;
thedo 166:3a9487d57a5c 75 }
thedo 166:3a9487d57a5c 76 intf[intf_nb].nb_endpoint++;
thedo 166:3a9487d57a5c 77
thedo 166:3a9487d57a5c 78 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
thedo 166:3a9487d57a5c 79 if (intf[intf_nb].ep[i] == NULL) {
thedo 166:3a9487d57a5c 80 intf[intf_nb].ep[i] = ept;
thedo 166:3a9487d57a5c 81 return true;
thedo 166:3a9487d57a5c 82 }
thedo 166:3a9487d57a5c 83 }
thedo 166:3a9487d57a5c 84 return false;
thedo 166:3a9487d57a5c 85 }
thedo 166:3a9487d57a5c 86
thedo 166:3a9487d57a5c 87 void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) {
thedo 166:3a9487d57a5c 88 USB_DBG("init dev: %p", this);
thedo 166:3a9487d57a5c 89 init();
thedo 166:3a9487d57a5c 90 hub_nb = hub_;
thedo 166:3a9487d57a5c 91 port = port_;
thedo 166:3a9487d57a5c 92 speed = lowSpeed_;
thedo 166:3a9487d57a5c 93 }
thedo 166:3a9487d57a5c 94
thedo 166:3a9487d57a5c 95 void USBDeviceConnected::disconnect() {
thedo 166:3a9487d57a5c 96 for(int i = 0; i < MAX_INTF; i++) {
thedo 166:3a9487d57a5c 97 intf[i].detach.call();
thedo 166:3a9487d57a5c 98 }
thedo 166:3a9487d57a5c 99 init();
thedo 166:3a9487d57a5c 100 }
thedo 166:3a9487d57a5c 101
thedo 166:3a9487d57a5c 102
thedo 166:3a9487d57a5c 103 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
thedo 166:3a9487d57a5c 104 if (intf_nb >= MAX_INTF) {
thedo 166:3a9487d57a5c 105 return NULL;
thedo 166:3a9487d57a5c 106 }
thedo 166:3a9487d57a5c 107 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
thedo 166:3a9487d57a5c 108 if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
thedo 166:3a9487d57a5c 109 if(index) {
thedo 166:3a9487d57a5c 110 index--;
thedo 166:3a9487d57a5c 111 } else {
thedo 166:3a9487d57a5c 112 return intf[intf_nb].ep[i];
thedo 166:3a9487d57a5c 113 }
thedo 166:3a9487d57a5c 114 }
thedo 166:3a9487d57a5c 115 }
thedo 166:3a9487d57a5c 116 return NULL;
thedo 166:3a9487d57a5c 117 }
thedo 166:3a9487d57a5c 118
thedo 166:3a9487d57a5c 119 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
thedo 166:3a9487d57a5c 120 if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) {
thedo 166:3a9487d57a5c 121 return NULL;
thedo 166:3a9487d57a5c 122 }
thedo 166:3a9487d57a5c 123 return intf[intf_nb].ep[index];
thedo 166:3a9487d57a5c 124 }