Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
USBHost_custom/USBHost/USBDeviceConnected.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- 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?
User | Revision | Line number | New 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 | #ifndef USBDEVICECONNECTED_H |
thedo | 166:3a9487d57a5c | 18 | #define USBDEVICECONNECTED_H |
thedo | 166:3a9487d57a5c | 19 | |
thedo | 166:3a9487d57a5c | 20 | #include "stdint.h" |
thedo | 166:3a9487d57a5c | 21 | #include "USBEndpoint.h" |
thedo | 166:3a9487d57a5c | 22 | #include "USBHostConf.h" |
thedo | 166:3a9487d57a5c | 23 | #include "rtos.h" |
thedo | 166:3a9487d57a5c | 24 | |
thedo | 166:3a9487d57a5c | 25 | class USBHostHub; |
thedo | 166:3a9487d57a5c | 26 | |
thedo | 166:3a9487d57a5c | 27 | typedef struct { |
thedo | 166:3a9487d57a5c | 28 | bool in_use; |
thedo | 166:3a9487d57a5c | 29 | uint8_t nb_endpoint; |
thedo | 166:3a9487d57a5c | 30 | uint8_t intf_class; |
thedo | 166:3a9487d57a5c | 31 | uint8_t intf_subclass; |
thedo | 166:3a9487d57a5c | 32 | uint8_t intf_protocol; |
thedo | 166:3a9487d57a5c | 33 | USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; |
thedo | 166:3a9487d57a5c | 34 | FunctionPointer detach; |
thedo | 166:3a9487d57a5c | 35 | char name[10]; |
thedo | 166:3a9487d57a5c | 36 | } INTERFACE; |
thedo | 166:3a9487d57a5c | 37 | |
thedo | 166:3a9487d57a5c | 38 | /** |
thedo | 166:3a9487d57a5c | 39 | * USBDeviceConnected class |
thedo | 166:3a9487d57a5c | 40 | */ |
thedo | 166:3a9487d57a5c | 41 | class USBDeviceConnected |
thedo | 166:3a9487d57a5c | 42 | { |
thedo | 166:3a9487d57a5c | 43 | public: |
thedo | 166:3a9487d57a5c | 44 | |
thedo | 166:3a9487d57a5c | 45 | /** |
thedo | 166:3a9487d57a5c | 46 | * Constructor |
thedo | 166:3a9487d57a5c | 47 | */ |
thedo | 166:3a9487d57a5c | 48 | USBDeviceConnected(); |
thedo | 166:3a9487d57a5c | 49 | |
thedo | 166:3a9487d57a5c | 50 | /** |
thedo | 166:3a9487d57a5c | 51 | * Attach an USBEndpoint to this device |
thedo | 166:3a9487d57a5c | 52 | * |
thedo | 166:3a9487d57a5c | 53 | * @param intf_nb interface number |
thedo | 166:3a9487d57a5c | 54 | * @param ep pointeur on the USBEndpoint which will be attached |
thedo | 166:3a9487d57a5c | 55 | * @returns true if successful, false otherwise |
thedo | 166:3a9487d57a5c | 56 | */ |
thedo | 166:3a9487d57a5c | 57 | bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); |
thedo | 166:3a9487d57a5c | 58 | |
thedo | 166:3a9487d57a5c | 59 | /** |
thedo | 166:3a9487d57a5c | 60 | * Retrieve an USBEndpoint by its TYPE and DIRECTION |
thedo | 166:3a9487d57a5c | 61 | * |
thedo | 166:3a9487d57a5c | 62 | * @param intf_nb the interface on which to lookup the USBEndpoint |
thedo | 166:3a9487d57a5c | 63 | * @param type type of the USBEndpoint looked for |
thedo | 166:3a9487d57a5c | 64 | * @param dir direction of the USBEndpoint looked for |
thedo | 166:3a9487d57a5c | 65 | * @param index the index of the USBEndpoint whitin the interface |
thedo | 166:3a9487d57a5c | 66 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
thedo | 166:3a9487d57a5c | 67 | */ |
thedo | 166:3a9487d57a5c | 68 | USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); |
thedo | 166:3a9487d57a5c | 69 | |
thedo | 166:3a9487d57a5c | 70 | /** |
thedo | 166:3a9487d57a5c | 71 | * Retrieve an USBEndpoint by its index |
thedo | 166:3a9487d57a5c | 72 | * |
thedo | 166:3a9487d57a5c | 73 | * @param intf_nb interface number |
thedo | 166:3a9487d57a5c | 74 | * @param index index of the USBEndpoint |
thedo | 166:3a9487d57a5c | 75 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
thedo | 166:3a9487d57a5c | 76 | */ |
thedo | 166:3a9487d57a5c | 77 | USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); |
thedo | 166:3a9487d57a5c | 78 | |
thedo | 166:3a9487d57a5c | 79 | /** |
thedo | 166:3a9487d57a5c | 80 | * Add a new interface to this device |
thedo | 166:3a9487d57a5c | 81 | * |
thedo | 166:3a9487d57a5c | 82 | * @param intf_nb interface number |
thedo | 166:3a9487d57a5c | 83 | * @param intf_class interface class |
thedo | 166:3a9487d57a5c | 84 | * @param intf_subclass interface subclass |
thedo | 166:3a9487d57a5c | 85 | * @param intf_protocol interface protocol |
thedo | 166:3a9487d57a5c | 86 | * @returns true if successful, false otherwise |
thedo | 166:3a9487d57a5c | 87 | */ |
thedo | 166:3a9487d57a5c | 88 | bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); |
thedo | 166:3a9487d57a5c | 89 | |
thedo | 166:3a9487d57a5c | 90 | /** |
thedo | 166:3a9487d57a5c | 91 | * Get a specific interface |
thedo | 166:3a9487d57a5c | 92 | * |
thedo | 166:3a9487d57a5c | 93 | * @param index index of the interface to be fetched |
thedo | 166:3a9487d57a5c | 94 | * @returns interface |
thedo | 166:3a9487d57a5c | 95 | */ |
thedo | 166:3a9487d57a5c | 96 | INTERFACE * getInterface(uint8_t index); |
thedo | 166:3a9487d57a5c | 97 | |
thedo | 166:3a9487d57a5c | 98 | /** |
thedo | 166:3a9487d57a5c | 99 | * Attach a member function to call when a the device has been disconnected |
thedo | 166:3a9487d57a5c | 100 | * |
thedo | 166:3a9487d57a5c | 101 | * @param intf_nb interface number |
thedo | 166:3a9487d57a5c | 102 | * @param tptr pointer to the object to call the member function on |
thedo | 166:3a9487d57a5c | 103 | * @param mptr pointer to the member function to be called |
thedo | 166:3a9487d57a5c | 104 | */ |
thedo | 166:3a9487d57a5c | 105 | template<typename T> |
thedo | 166:3a9487d57a5c | 106 | inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { |
thedo | 166:3a9487d57a5c | 107 | if ((mptr != NULL) && (tptr != NULL)) { |
thedo | 166:3a9487d57a5c | 108 | intf[intf_nb].detach.attach(tptr, mptr); |
thedo | 166:3a9487d57a5c | 109 | } |
thedo | 166:3a9487d57a5c | 110 | } |
thedo | 166:3a9487d57a5c | 111 | |
thedo | 166:3a9487d57a5c | 112 | /** |
thedo | 166:3a9487d57a5c | 113 | * Attach a callback called when the device has been disconnected |
thedo | 166:3a9487d57a5c | 114 | * |
thedo | 166:3a9487d57a5c | 115 | * @param intf_nb interface number |
thedo | 166:3a9487d57a5c | 116 | * @param fn function pointer |
thedo | 166:3a9487d57a5c | 117 | */ |
thedo | 166:3a9487d57a5c | 118 | inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { |
thedo | 166:3a9487d57a5c | 119 | if (fn != NULL) { |
thedo | 166:3a9487d57a5c | 120 | intf[intf_nb].detach.attach(fn); |
thedo | 166:3a9487d57a5c | 121 | } |
thedo | 166:3a9487d57a5c | 122 | } |
thedo | 166:3a9487d57a5c | 123 | |
thedo | 166:3a9487d57a5c | 124 | /** |
thedo | 166:3a9487d57a5c | 125 | * Disconnect the device by calling a callback function registered by a driver |
thedo | 166:3a9487d57a5c | 126 | */ |
thedo | 166:3a9487d57a5c | 127 | void disconnect(); |
thedo | 166:3a9487d57a5c | 128 | |
thedo | 166:3a9487d57a5c | 129 | // setters |
thedo | 166:3a9487d57a5c | 130 | void init(uint8_t hub, uint8_t port, bool lowSpeed); |
thedo | 166:3a9487d57a5c | 131 | inline void setAddress(uint8_t addr_) { addr = addr_; }; |
thedo | 166:3a9487d57a5c | 132 | inline void setVid(uint16_t vid_) { vid = vid_; }; |
thedo | 166:3a9487d57a5c | 133 | inline void setPid(uint16_t pid_) { pid = pid_; }; |
thedo | 166:3a9487d57a5c | 134 | inline void setClass(uint8_t device_class_) { device_class = device_class_; }; |
thedo | 166:3a9487d57a5c | 135 | inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; |
thedo | 166:3a9487d57a5c | 136 | inline void setProtocol(uint8_t pr) { proto = pr; }; |
thedo | 166:3a9487d57a5c | 137 | inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; }; |
thedo | 166:3a9487d57a5c | 138 | inline void activeAddress(bool active) { activeAddr = active; }; |
thedo | 166:3a9487d57a5c | 139 | inline void setEnumerated() { enumerated = true; }; |
thedo | 166:3a9487d57a5c | 140 | inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; |
thedo | 166:3a9487d57a5c | 141 | inline void setHubParent(USBHostHub * hub) { hub_parent = hub; }; |
thedo | 166:3a9487d57a5c | 142 | inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); }; |
thedo | 166:3a9487d57a5c | 143 | |
thedo | 166:3a9487d57a5c | 144 | //getters |
thedo | 166:3a9487d57a5c | 145 | inline uint8_t getPort() { return port; }; |
thedo | 166:3a9487d57a5c | 146 | inline uint8_t getHub() { return hub_nb; }; |
thedo | 166:3a9487d57a5c | 147 | inline uint8_t getAddress() { return addr; }; |
thedo | 166:3a9487d57a5c | 148 | inline uint16_t getVid() { return vid; }; |
thedo | 166:3a9487d57a5c | 149 | inline uint16_t getPid() { return pid; }; |
thedo | 166:3a9487d57a5c | 150 | inline uint8_t getClass() { return device_class; }; |
thedo | 166:3a9487d57a5c | 151 | inline uint8_t getSubClass() { return device_subclass; }; |
thedo | 166:3a9487d57a5c | 152 | inline uint8_t getProtocol() { return proto; }; |
thedo | 166:3a9487d57a5c | 153 | inline bool getSpeed() { return speed; }; |
thedo | 166:3a9487d57a5c | 154 | inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; }; |
thedo | 166:3a9487d57a5c | 155 | inline bool isActiveAddress() { return activeAddr; }; |
thedo | 166:3a9487d57a5c | 156 | inline bool isEnumerated() { return enumerated; }; |
thedo | 166:3a9487d57a5c | 157 | inline USBHostHub * getHubParent() { return hub_parent; }; |
thedo | 166:3a9487d57a5c | 158 | inline uint8_t getNbIntf() { return nb_interf; }; |
thedo | 166:3a9487d57a5c | 159 | inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; }; |
thedo | 166:3a9487d57a5c | 160 | |
thedo | 166:3a9487d57a5c | 161 | // in case this device is a hub |
thedo | 166:3a9487d57a5c | 162 | USBHostHub * hub; |
thedo | 166:3a9487d57a5c | 163 | |
thedo | 166:3a9487d57a5c | 164 | private: |
thedo | 166:3a9487d57a5c | 165 | USBHostHub * hub_parent; |
thedo | 166:3a9487d57a5c | 166 | |
thedo | 166:3a9487d57a5c | 167 | INTERFACE intf[MAX_INTF]; |
thedo | 166:3a9487d57a5c | 168 | uint32_t sizeControlEndpoint; |
thedo | 166:3a9487d57a5c | 169 | uint8_t hub_nb; |
thedo | 166:3a9487d57a5c | 170 | uint8_t port; |
thedo | 166:3a9487d57a5c | 171 | uint16_t vid; |
thedo | 166:3a9487d57a5c | 172 | uint16_t pid; |
thedo | 166:3a9487d57a5c | 173 | uint8_t addr; |
thedo | 166:3a9487d57a5c | 174 | uint8_t device_class; |
thedo | 166:3a9487d57a5c | 175 | uint8_t device_subclass; |
thedo | 166:3a9487d57a5c | 176 | uint8_t proto; |
thedo | 166:3a9487d57a5c | 177 | bool speed; |
thedo | 166:3a9487d57a5c | 178 | volatile bool activeAddr; |
thedo | 166:3a9487d57a5c | 179 | volatile bool enumerated; |
thedo | 166:3a9487d57a5c | 180 | uint8_t nb_interf; |
thedo | 166:3a9487d57a5c | 181 | |
thedo | 166:3a9487d57a5c | 182 | void init(); |
thedo | 166:3a9487d57a5c | 183 | }; |
thedo | 166:3a9487d57a5c | 184 | |
thedo | 166:3a9487d57a5c | 185 | #endif |