Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBHostWANDongle by
USBDeviceConnected.h
00001 /* Copyright (c) 2010-2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBDEVICECONNECTED_H 00020 #define USBDEVICECONNECTED_H 00021 00022 #include "stdint.h" 00023 #include "USBEndpoint.h" 00024 00025 #define MAX_ENDPOINT_PER_INTERFACE 2 00026 #define MAX_INTF 3 00027 00028 typedef struct { 00029 bool in_use; 00030 uint8_t nb_endpoint; 00031 uint8_t intf_class; 00032 uint8_t intf_subclass; 00033 uint8_t intf_protocol; 00034 USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; 00035 FunctionPointer detach; 00036 }INTERFACE; 00037 00038 00039 class USBDeviceConnected { 00040 public: 00041 00042 /* 00043 * Constructor 00044 */ 00045 USBDeviceConnected(); 00046 00047 /* 00048 * Attach an USBEndpoint to this device 00049 * 00050 * @param ep pointeur on the USBEndpoint which will be attached 00051 * @returns true if successful, false otherwise 00052 */ 00053 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); 00054 00055 /* 00056 * Retrieve an USBEndpoint by its TYPE and DIRECTION 00057 * 00058 * @param intf_nb the interface on which to lookup the USBEndpoint 00059 * @param type type of the USBEndpoint looked for 00060 * @param direction of the USBEndpoint looked for 00061 * @param index the index of the USBEndpoint whitin the interface 00062 * @returns pointer on the USBEndpoint if found, NULL otherwise 00063 */ 00064 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); 00065 00066 /* 00067 * Retrieve an USBEndpoint by its index 00068 * 00069 * @param index index of the USBEndpoint 00070 * @returns pointer on the USBEndpoint if found, NULL otherwise 00071 */ 00072 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); 00073 00074 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); 00075 00076 uint8_t getNbInterface() {return nb_interf;}; 00077 00078 INTERFACE * getInterface(uint8_t index); 00079 00080 /** 00081 * Attach a member function to call when a the device has been disconnected 00082 * 00083 * @param tptr pointer to the object to call the member function on 00084 * @param mptr pointer to the member function to be called 00085 */ 00086 template<typename T> 00087 void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { 00088 if ((mptr != NULL) && (tptr != NULL)) { 00089 intf[intf_nb].detach.attach(tptr, mptr); 00090 } 00091 } 00092 00093 /** 00094 * Attach a callback called when the device has been disconnected 00095 * 00096 * @param fptr function pointer 00097 */ 00098 void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { 00099 if (fn != NULL) { 00100 intf[intf_nb].detach.attach(fn); 00101 } 00102 } 00103 00104 /* 00105 * Disconnect the device by calling a callback function registered by a driver 00106 */ 00107 void disconnect(); 00108 00109 /* 00110 * Setters 00111 */ 00112 void init(uint8_t hub, uint8_t port, bool lowSpeed); 00113 void setAddress(uint8_t addr) { 00114 this->addr = addr; 00115 }; 00116 void setVid(uint16_t vid) { 00117 this->vid = vid; 00118 }; 00119 void setPid(uint16_t pid) { 00120 this->pid = pid; 00121 }; 00122 void setClass(uint8_t device_class) { 00123 this->device_class = device_class; 00124 }; 00125 void setSubClass(uint8_t device_subclass) { 00126 this->device_subclass = device_subclass; 00127 }; 00128 void setProtocol(uint8_t pr) { 00129 proto = pr; 00130 }; 00131 void setSizeControlEndpoint(uint32_t size) { 00132 sizeControlEndpoint = size; 00133 }; 00134 void activeAddress() { 00135 activeAddr = true; 00136 }; 00137 void setEnumerated() { 00138 enumerated = true; 00139 }; 00140 00141 /* 00142 * Getters 00143 */ 00144 uint8_t getPort() { 00145 return port; 00146 }; 00147 uint8_t getHub() { 00148 return hub; 00149 }; 00150 uint8_t getAddress() { 00151 return addr; 00152 }; 00153 uint16_t getVid() { 00154 return vid; 00155 }; 00156 uint16_t getPid() { 00157 return pid; 00158 }; 00159 uint8_t getClass() { 00160 return device_class; 00161 }; 00162 uint8_t getSubClass() { 00163 return device_subclass; 00164 }; 00165 uint8_t getProtocol() { 00166 return proto; 00167 }; 00168 bool getSpeed() { 00169 return speed; 00170 }; 00171 uint32_t getSizeControlEndpoint() { 00172 return sizeControlEndpoint; 00173 }; 00174 bool isActiveAddress() { 00175 return activeAddr; 00176 }; 00177 bool isEnumerated() { 00178 return enumerated; 00179 }; 00180 00181 00182 private: 00183 INTERFACE intf[MAX_INTF]; 00184 //USBEndpoint * ep[MAX_ENDPOINT_PER_DEVICE]; 00185 uint32_t sizeControlEndpoint; 00186 uint8_t hub; 00187 uint8_t port; 00188 uint16_t vid; 00189 uint16_t pid; 00190 uint8_t addr; 00191 uint8_t device_class; 00192 uint8_t device_subclass; 00193 uint8_t proto; 00194 bool speed; 00195 bool activeAddr; 00196 bool enumerated; 00197 00198 uint8_t nb_interf; 00199 00200 00201 void init(); 00202 00203 }; 00204 00205 #endif
Generated on Thu Jul 14 2022 09:11:27 by
1.7.2
