Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

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

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
Parent:
166:240bc5a0f42a
gr-peach-opencv-project-sd-card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:240bc5a0f42a 1 /* mbed USBHost Library
thedo 166:240bc5a0f42a 2 * Copyright (c) 2006-2013 ARM Limited
thedo 166:240bc5a0f42a 3 *
thedo 166:240bc5a0f42a 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 166:240bc5a0f42a 5 * you may not use this file except in compliance with the License.
thedo 166:240bc5a0f42a 6 * You may obtain a copy of the License at
thedo 166:240bc5a0f42a 7 *
thedo 166:240bc5a0f42a 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 166:240bc5a0f42a 9 *
thedo 166:240bc5a0f42a 10 * Unless required by applicable law or agreed to in writing, software
thedo 166:240bc5a0f42a 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 166:240bc5a0f42a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 166:240bc5a0f42a 13 * See the License for the specific language governing permissions and
thedo 166:240bc5a0f42a 14 * limitations under the License.
thedo 166:240bc5a0f42a 15 */
thedo 166:240bc5a0f42a 16
thedo 166:240bc5a0f42a 17 #ifndef USBDEVICECONNECTED_H
thedo 166:240bc5a0f42a 18 #define USBDEVICECONNECTED_H
thedo 166:240bc5a0f42a 19
thedo 166:240bc5a0f42a 20 #include "stdint.h"
thedo 166:240bc5a0f42a 21 #include "USBEndpoint.h"
thedo 166:240bc5a0f42a 22 #include "USBHostConf.h"
thedo 166:240bc5a0f42a 23 #include "rtos.h"
thedo 166:240bc5a0f42a 24
thedo 166:240bc5a0f42a 25 class USBHostHub;
thedo 166:240bc5a0f42a 26
thedo 166:240bc5a0f42a 27 typedef struct {
thedo 166:240bc5a0f42a 28 bool in_use;
thedo 166:240bc5a0f42a 29 uint8_t nb_endpoint;
thedo 166:240bc5a0f42a 30 uint8_t intf_class;
thedo 166:240bc5a0f42a 31 uint8_t intf_subclass;
thedo 166:240bc5a0f42a 32 uint8_t intf_protocol;
thedo 166:240bc5a0f42a 33 USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE];
thedo 166:240bc5a0f42a 34 FunctionPointer detach;
thedo 166:240bc5a0f42a 35 char name[10];
thedo 166:240bc5a0f42a 36 } INTERFACE;
thedo 166:240bc5a0f42a 37
thedo 166:240bc5a0f42a 38 /**
thedo 166:240bc5a0f42a 39 * USBDeviceConnected class
thedo 166:240bc5a0f42a 40 */
thedo 166:240bc5a0f42a 41 class USBDeviceConnected
thedo 166:240bc5a0f42a 42 {
thedo 166:240bc5a0f42a 43 public:
thedo 166:240bc5a0f42a 44
thedo 166:240bc5a0f42a 45 /**
thedo 166:240bc5a0f42a 46 * Constructor
thedo 166:240bc5a0f42a 47 */
thedo 166:240bc5a0f42a 48 USBDeviceConnected();
thedo 166:240bc5a0f42a 49
thedo 166:240bc5a0f42a 50 /**
thedo 166:240bc5a0f42a 51 * Attach an USBEndpoint to this device
thedo 166:240bc5a0f42a 52 *
thedo 166:240bc5a0f42a 53 * @param intf_nb interface number
thedo 166:240bc5a0f42a 54 * @param ep pointeur on the USBEndpoint which will be attached
thedo 166:240bc5a0f42a 55 * @returns true if successful, false otherwise
thedo 166:240bc5a0f42a 56 */
thedo 166:240bc5a0f42a 57 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
thedo 166:240bc5a0f42a 58
thedo 166:240bc5a0f42a 59 /**
thedo 166:240bc5a0f42a 60 * Retrieve an USBEndpoint by its TYPE and DIRECTION
thedo 166:240bc5a0f42a 61 *
thedo 166:240bc5a0f42a 62 * @param intf_nb the interface on which to lookup the USBEndpoint
thedo 166:240bc5a0f42a 63 * @param type type of the USBEndpoint looked for
thedo 166:240bc5a0f42a 64 * @param dir direction of the USBEndpoint looked for
thedo 166:240bc5a0f42a 65 * @param index the index of the USBEndpoint whitin the interface
thedo 166:240bc5a0f42a 66 * @returns pointer on the USBEndpoint if found, NULL otherwise
thedo 166:240bc5a0f42a 67 */
thedo 166:240bc5a0f42a 68 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
thedo 166:240bc5a0f42a 69
thedo 166:240bc5a0f42a 70 /**
thedo 166:240bc5a0f42a 71 * Retrieve an USBEndpoint by its index
thedo 166:240bc5a0f42a 72 *
thedo 166:240bc5a0f42a 73 * @param intf_nb interface number
thedo 166:240bc5a0f42a 74 * @param index index of the USBEndpoint
thedo 166:240bc5a0f42a 75 * @returns pointer on the USBEndpoint if found, NULL otherwise
thedo 166:240bc5a0f42a 76 */
thedo 166:240bc5a0f42a 77 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
thedo 166:240bc5a0f42a 78
thedo 166:240bc5a0f42a 79 /**
thedo 166:240bc5a0f42a 80 * Add a new interface to this device
thedo 166:240bc5a0f42a 81 *
thedo 166:240bc5a0f42a 82 * @param intf_nb interface number
thedo 166:240bc5a0f42a 83 * @param intf_class interface class
thedo 166:240bc5a0f42a 84 * @param intf_subclass interface subclass
thedo 166:240bc5a0f42a 85 * @param intf_protocol interface protocol
thedo 166:240bc5a0f42a 86 * @returns true if successful, false otherwise
thedo 166:240bc5a0f42a 87 */
thedo 166:240bc5a0f42a 88 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
thedo 166:240bc5a0f42a 89
thedo 166:240bc5a0f42a 90 /**
thedo 166:240bc5a0f42a 91 * Get a specific interface
thedo 166:240bc5a0f42a 92 *
thedo 166:240bc5a0f42a 93 * @param index index of the interface to be fetched
thedo 166:240bc5a0f42a 94 * @returns interface
thedo 166:240bc5a0f42a 95 */
thedo 166:240bc5a0f42a 96 INTERFACE * getInterface(uint8_t index);
thedo 166:240bc5a0f42a 97
thedo 166:240bc5a0f42a 98 /**
thedo 166:240bc5a0f42a 99 * Attach a member function to call when a the device has been disconnected
thedo 166:240bc5a0f42a 100 *
thedo 166:240bc5a0f42a 101 * @param intf_nb interface number
thedo 166:240bc5a0f42a 102 * @param tptr pointer to the object to call the member function on
thedo 166:240bc5a0f42a 103 * @param mptr pointer to the member function to be called
thedo 166:240bc5a0f42a 104 */
thedo 166:240bc5a0f42a 105 template<typename T>
thedo 166:240bc5a0f42a 106 inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) {
thedo 166:240bc5a0f42a 107 if ((mptr != NULL) && (tptr != NULL)) {
thedo 166:240bc5a0f42a 108 intf[intf_nb].detach.attach(tptr, mptr);
thedo 166:240bc5a0f42a 109 }
thedo 166:240bc5a0f42a 110 }
thedo 166:240bc5a0f42a 111
thedo 166:240bc5a0f42a 112 /**
thedo 166:240bc5a0f42a 113 * Attach a callback called when the device has been disconnected
thedo 166:240bc5a0f42a 114 *
thedo 166:240bc5a0f42a 115 * @param intf_nb interface number
thedo 166:240bc5a0f42a 116 * @param fn function pointer
thedo 166:240bc5a0f42a 117 */
thedo 166:240bc5a0f42a 118 inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) {
thedo 166:240bc5a0f42a 119 if (fn != NULL) {
thedo 166:240bc5a0f42a 120 intf[intf_nb].detach.attach(fn);
thedo 166:240bc5a0f42a 121 }
thedo 166:240bc5a0f42a 122 }
thedo 166:240bc5a0f42a 123
thedo 166:240bc5a0f42a 124 /**
thedo 166:240bc5a0f42a 125 * Disconnect the device by calling a callback function registered by a driver
thedo 166:240bc5a0f42a 126 */
thedo 166:240bc5a0f42a 127 void disconnect();
thedo 166:240bc5a0f42a 128
thedo 166:240bc5a0f42a 129 // setters
thedo 166:240bc5a0f42a 130 void init(uint8_t hub, uint8_t port, bool lowSpeed);
thedo 166:240bc5a0f42a 131 inline void setAddress(uint8_t addr_) { addr = addr_; };
thedo 166:240bc5a0f42a 132 inline void setVid(uint16_t vid_) { vid = vid_; };
thedo 166:240bc5a0f42a 133 inline void setPid(uint16_t pid_) { pid = pid_; };
thedo 166:240bc5a0f42a 134 inline void setClass(uint8_t device_class_) { device_class = device_class_; };
thedo 166:240bc5a0f42a 135 inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; };
thedo 166:240bc5a0f42a 136 inline void setProtocol(uint8_t pr) { proto = pr; };
thedo 166:240bc5a0f42a 137 inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; };
thedo 166:240bc5a0f42a 138 inline void activeAddress(bool active) { activeAddr = active; };
thedo 166:240bc5a0f42a 139 inline void setEnumerated() { enumerated = true; };
thedo 166:240bc5a0f42a 140 inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; };
thedo 166:240bc5a0f42a 141 inline void setHubParent(USBHostHub * hub) { hub_parent = hub; };
thedo 166:240bc5a0f42a 142 inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); };
thedo 166:240bc5a0f42a 143
thedo 166:240bc5a0f42a 144 //getters
thedo 166:240bc5a0f42a 145 inline uint8_t getPort() { return port; };
thedo 166:240bc5a0f42a 146 inline uint8_t getHub() { return hub_nb; };
thedo 166:240bc5a0f42a 147 inline uint8_t getAddress() { return addr; };
thedo 166:240bc5a0f42a 148 inline uint16_t getVid() { return vid; };
thedo 166:240bc5a0f42a 149 inline uint16_t getPid() { return pid; };
thedo 166:240bc5a0f42a 150 inline uint8_t getClass() { return device_class; };
thedo 166:240bc5a0f42a 151 inline uint8_t getSubClass() { return device_subclass; };
thedo 166:240bc5a0f42a 152 inline uint8_t getProtocol() { return proto; };
thedo 166:240bc5a0f42a 153 inline bool getSpeed() { return speed; };
thedo 166:240bc5a0f42a 154 inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; };
thedo 166:240bc5a0f42a 155 inline bool isActiveAddress() { return activeAddr; };
thedo 166:240bc5a0f42a 156 inline bool isEnumerated() { return enumerated; };
thedo 166:240bc5a0f42a 157 inline USBHostHub * getHubParent() { return hub_parent; };
thedo 166:240bc5a0f42a 158 inline uint8_t getNbIntf() { return nb_interf; };
thedo 166:240bc5a0f42a 159 inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; };
thedo 166:240bc5a0f42a 160
thedo 166:240bc5a0f42a 161 // in case this device is a hub
thedo 166:240bc5a0f42a 162 USBHostHub * hub;
thedo 166:240bc5a0f42a 163
thedo 166:240bc5a0f42a 164 private:
thedo 166:240bc5a0f42a 165 USBHostHub * hub_parent;
thedo 166:240bc5a0f42a 166
thedo 166:240bc5a0f42a 167 INTERFACE intf[MAX_INTF];
thedo 166:240bc5a0f42a 168 uint32_t sizeControlEndpoint;
thedo 166:240bc5a0f42a 169 uint8_t hub_nb;
thedo 166:240bc5a0f42a 170 uint8_t port;
thedo 166:240bc5a0f42a 171 uint16_t vid;
thedo 166:240bc5a0f42a 172 uint16_t pid;
thedo 166:240bc5a0f42a 173 uint8_t addr;
thedo 166:240bc5a0f42a 174 uint8_t device_class;
thedo 166:240bc5a0f42a 175 uint8_t device_subclass;
thedo 166:240bc5a0f42a 176 uint8_t proto;
thedo 166:240bc5a0f42a 177 bool speed;
thedo 166:240bc5a0f42a 178 volatile bool activeAddr;
thedo 166:240bc5a0f42a 179 volatile bool enumerated;
thedo 166:240bc5a0f42a 180 uint8_t nb_interf;
thedo 166:240bc5a0f42a 181
thedo 166:240bc5a0f42a 182 void init();
thedo 166:240bc5a0f42a 183 };
thedo 166:240bc5a0f42a 184
thedo 166:240bc5a0f42a 185 #endif