USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.
Dependencies: FATFileSystem mbed-rtos
Dependents: BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more
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 #include "Callback.h" 00025 00026 class USBHostHub; 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 Callback<void()> detach; 00036 char name[10]; 00037 } INTERFACE; 00038 00039 /** 00040 * USBDeviceConnected class 00041 */ 00042 class USBDeviceConnected 00043 { 00044 public: 00045 00046 /** 00047 * Constructor 00048 */ 00049 USBDeviceConnected(); 00050 00051 /** 00052 * Attach an USBEndpoint to this device 00053 * 00054 * @param intf_nb interface number 00055 * @param ep pointeur on the USBEndpoint which will be attached 00056 * @returns true if successful, false otherwise 00057 */ 00058 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); 00059 00060 /** 00061 * Retrieve an USBEndpoint by its TYPE and DIRECTION 00062 * 00063 * @param intf_nb the interface on which to lookup the USBEndpoint 00064 * @param type type of the USBEndpoint looked for 00065 * @param dir direction of the USBEndpoint looked for 00066 * @param index the index of the USBEndpoint whitin the interface 00067 * @returns pointer on the USBEndpoint if found, NULL otherwise 00068 */ 00069 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); 00070 00071 /** 00072 * Retrieve an USBEndpoint by its index 00073 * 00074 * @param intf_nb interface number 00075 * @param index index of the USBEndpoint 00076 * @returns pointer on the USBEndpoint if found, NULL otherwise 00077 */ 00078 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); 00079 00080 /** 00081 * Add a new interface to this device 00082 * 00083 * @param intf_nb interface number 00084 * @param intf_class interface class 00085 * @param intf_subclass interface subclass 00086 * @param intf_protocol interface protocol 00087 * @returns true if successful, false otherwise 00088 */ 00089 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); 00090 00091 /** 00092 * Get a specific interface 00093 * 00094 * @param index index of the interface to be fetched 00095 * @returns interface 00096 */ 00097 INTERFACE * getInterface(uint8_t index); 00098 00099 /** 00100 * Attach a member function to call when a the device has been disconnected 00101 * 00102 * @param intf_nb interface number 00103 * @param tptr pointer to the object to call the member function on 00104 * @param mptr pointer to the member function to be called 00105 */ 00106 template<typename T> 00107 inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { 00108 if ((mptr != NULL) && (tptr != NULL)) { 00109 intf[intf_nb].detach.attach(tptr, mptr); 00110 } 00111 } 00112 00113 /** 00114 * Attach a callback called when the device has been disconnected 00115 * 00116 * @param intf_nb interface number 00117 * @param fn function pointer 00118 */ 00119 inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { 00120 if (fn != NULL) { 00121 intf[intf_nb].detach.attach(fn); 00122 } 00123 } 00124 00125 /** 00126 * Disconnect the device by calling a callback function registered by a driver 00127 */ 00128 void disconnect(); 00129 00130 // setters 00131 void init(uint8_t hub, uint8_t port, bool lowSpeed); 00132 inline void setAddress(uint8_t addr_) { addr = addr_; }; 00133 inline void setVid(uint16_t vid_) { vid = vid_; }; 00134 inline void setPid(uint16_t pid_) { pid = pid_; }; 00135 inline void setClass(uint8_t device_class_) { device_class = device_class_; }; 00136 inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; 00137 inline void setProtocol(uint8_t pr) { proto = pr; }; 00138 inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; }; 00139 inline void activeAddress(bool active) { activeAddr = active; }; 00140 inline void setEnumerated() { enumerated = true; }; 00141 inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; 00142 inline void setHubParent(USBHostHub * hub) { hub_parent = hub; }; 00143 inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); }; 00144 00145 //getters 00146 inline uint8_t getPort() { return port; }; 00147 inline uint8_t getHub() { return hub_nb; }; 00148 inline uint8_t getAddress() { return addr; }; 00149 inline uint16_t getVid() { return vid; }; 00150 inline uint16_t getPid() { return pid; }; 00151 inline uint8_t getClass() { return device_class; }; 00152 inline uint8_t getSubClass() { return device_subclass; }; 00153 inline uint8_t getProtocol() { return proto; }; 00154 inline bool getSpeed() { return speed; }; 00155 inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; }; 00156 inline bool isActiveAddress() { return activeAddr; }; 00157 inline bool isEnumerated() { return enumerated; }; 00158 inline USBHostHub * getHubParent() { return hub_parent; }; 00159 inline uint8_t getNbIntf() { return nb_interf; }; 00160 inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; }; 00161 00162 // in case this device is a hub 00163 USBHostHub * hub; 00164 00165 private: 00166 USBHostHub * hub_parent; 00167 00168 INTERFACE intf[MAX_INTF]; 00169 uint32_t sizeControlEndpoint; 00170 uint8_t hub_nb; 00171 uint8_t port; 00172 uint16_t vid; 00173 uint16_t pid; 00174 uint8_t addr; 00175 uint8_t device_class; 00176 uint8_t device_subclass; 00177 uint8_t proto; 00178 bool speed; 00179 volatile bool activeAddr; 00180 volatile bool enumerated; 00181 uint8_t nb_interf; 00182 00183 void init(); 00184 }; 00185 00186 #endif
Generated on Tue Jul 12 2022 13:32:26 by 1.7.2