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 USBHost by
USBDeviceConnected.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef USBDEVICECONNECTED_H 00018 #define USBDEVICECONNECTED_H 00019 00020 #include "stdint.h" 00021 #include "USBEndpoint.h" 00022 #include "USBHostConf.h" 00023 #include "rtos.h" 00024 00025 class USBHostHub; 00026 00027 typedef struct { 00028 bool in_use; 00029 uint8_t nb_endpoint; 00030 uint8_t intf_class; 00031 uint8_t intf_subclass; 00032 uint8_t intf_protocol; 00033 USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; 00034 FunctionPointer detach; 00035 char name[10]; 00036 } INTERFACE; 00037 00038 /** 00039 * USBDeviceConnected class 00040 */ 00041 class USBDeviceConnected 00042 { 00043 public: 00044 00045 /** 00046 * Constructor 00047 */ 00048 USBDeviceConnected(); 00049 00050 /** 00051 * Attach an USBEndpoint to this device 00052 * 00053 * @param intf_nb interface number 00054 * @param ep pointeur on the USBEndpoint which will be attached 00055 * @returns true if successful, false otherwise 00056 */ 00057 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); 00058 00059 /** 00060 * Retrieve an USBEndpoint by its TYPE and DIRECTION 00061 * 00062 * @param intf_nb the interface on which to lookup the USBEndpoint 00063 * @param type type of the USBEndpoint looked for 00064 * @param dir direction of the USBEndpoint looked for 00065 * @param index the index of the USBEndpoint whitin the interface 00066 * @returns pointer on the USBEndpoint if found, NULL otherwise 00067 */ 00068 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); 00069 00070 /** 00071 * Retrieve an USBEndpoint by its index 00072 * 00073 * @param intf_nb interface number 00074 * @param index index of the USBEndpoint 00075 * @returns pointer on the USBEndpoint if found, NULL otherwise 00076 */ 00077 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); 00078 00079 /** 00080 * Add a new interface to this device 00081 * 00082 * @param intf_nb interface number 00083 * @param intf_class interface class 00084 * @param intf_subclass interface subclass 00085 * @param intf_protocol interface protocol 00086 * @returns true if successful, false otherwise 00087 */ 00088 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); 00089 00090 /** 00091 * Get a specific interface 00092 * 00093 * @param index index of the interface to be fetched 00094 * @returns interface 00095 */ 00096 INTERFACE * getInterface(uint8_t index); 00097 00098 /** 00099 * Attach a member function to call when a the device has been disconnected 00100 * 00101 * @param intf_nb interface number 00102 * @param tptr pointer to the object to call the member function on 00103 * @param mptr pointer to the member function to be called 00104 */ 00105 template<typename T> 00106 inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { 00107 if ((mptr != NULL) && (tptr != NULL)) { 00108 intf[intf_nb].detach.attach(tptr, mptr); 00109 } 00110 } 00111 00112 /** 00113 * Attach a callback called when the device has been disconnected 00114 * 00115 * @param intf_nb interface number 00116 * @param fn function pointer 00117 */ 00118 inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { 00119 if (fn != NULL) { 00120 intf[intf_nb].detach.attach(fn); 00121 } 00122 } 00123 00124 /** 00125 * Disconnect the device by calling a callback function registered by a driver 00126 */ 00127 void disconnect(); 00128 00129 // setters 00130 void init(uint8_t hub, uint8_t port, bool lowSpeed); 00131 inline void setAddress(uint8_t addr_) { addr = addr_; }; 00132 inline void setVid(uint16_t vid_) { vid = vid_; }; 00133 inline void setPid(uint16_t pid_) { pid = pid_; }; 00134 inline void setClass(uint8_t device_class_) { device_class = device_class_; }; 00135 inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; 00136 inline void setProtocol(uint8_t pr) { proto = pr; }; 00137 inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; }; 00138 inline void activeAddress(bool active) { activeAddr = active; }; 00139 inline void setEnumerated() { enumerated = true; }; 00140 inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; 00141 inline void setHubParent(USBHostHub * hub) { hub_parent = hub; }; 00142 inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); }; 00143 00144 //getters 00145 inline uint8_t getPort() { return port; }; 00146 inline uint8_t getHub() { return hub_nb; }; 00147 inline uint8_t getAddress() { return addr; }; 00148 inline uint16_t getVid() { return vid; }; 00149 inline uint16_t getPid() { return pid; }; 00150 inline uint8_t getClass() { return device_class; }; 00151 inline uint8_t getSubClass() { return device_subclass; }; 00152 inline uint8_t getProtocol() { return proto; }; 00153 inline bool getSpeed() { return speed; }; 00154 inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; }; 00155 inline bool isActiveAddress() { return activeAddr; }; 00156 inline bool isEnumerated() { return enumerated; }; 00157 inline USBHostHub * getHubParent() { return hub_parent; }; 00158 inline uint8_t getNbIntf() { return nb_interf; }; 00159 inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; }; 00160 00161 // in case this device is a hub 00162 USBHostHub * hub; 00163 00164 private: 00165 USBHostHub * hub_parent; 00166 00167 INTERFACE intf[MAX_INTF]; 00168 uint32_t sizeControlEndpoint; 00169 uint8_t hub_nb; 00170 uint8_t port; 00171 uint16_t vid; 00172 uint16_t pid; 00173 uint8_t addr; 00174 uint8_t device_class; 00175 uint8_t device_subclass; 00176 uint8_t proto; 00177 bool speed; 00178 volatile bool activeAddr; 00179 volatile bool enumerated; 00180 uint8_t nb_interf; 00181 00182 void init(); 00183 }; 00184 00185 #endif
Generated on Sat Jul 16 2022 04:39:31 by
