The beta version of the Vodafone K3770 dongle driver
This library is deprecated. Please use the newest production branch of the library from https://mbed.org/users/mbed_official/code/VodafoneUSBModem/
USBHostWANDongleLib/USBHost/USBDeviceConnected.h@1:4b33ffe61bfa, 2012-11-01 (annotated)
- Committer:
- donatien
- Date:
- Thu Nov 01 10:03:50 2012 +0000
- Revision:
- 1:4b33ffe61bfa
- Parent:
- 0:0ac66acdfdc0
Deprecating library, pointing out at new one
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0ac66acdfdc0 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
donatien | 0:0ac66acdfdc0 | 2 | * |
donatien | 0:0ac66acdfdc0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:0ac66acdfdc0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
donatien | 0:0ac66acdfdc0 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
donatien | 0:0ac66acdfdc0 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
donatien | 0:0ac66acdfdc0 | 7 | * Software is furnished to do so, subject to the following conditions: |
donatien | 0:0ac66acdfdc0 | 8 | * |
donatien | 0:0ac66acdfdc0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:0ac66acdfdc0 | 10 | * substantial portions of the Software. |
donatien | 0:0ac66acdfdc0 | 11 | * |
donatien | 0:0ac66acdfdc0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:0ac66acdfdc0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:0ac66acdfdc0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:0ac66acdfdc0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:0ac66acdfdc0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:0ac66acdfdc0 | 17 | */ |
donatien | 0:0ac66acdfdc0 | 18 | |
donatien | 0:0ac66acdfdc0 | 19 | #ifndef USBDEVICECONNECTED_H |
donatien | 0:0ac66acdfdc0 | 20 | #define USBDEVICECONNECTED_H |
donatien | 0:0ac66acdfdc0 | 21 | |
donatien | 0:0ac66acdfdc0 | 22 | #include "stdint.h" |
donatien | 0:0ac66acdfdc0 | 23 | #include "Endpoint.h" |
donatien | 0:0ac66acdfdc0 | 24 | |
donatien | 0:0ac66acdfdc0 | 25 | #define MAX_ENDPOINT_PER_INTERFACE 4 |
donatien | 0:0ac66acdfdc0 | 26 | #define MAX_INTF 4 |
donatien | 0:0ac66acdfdc0 | 27 | |
donatien | 0:0ac66acdfdc0 | 28 | typedef struct { |
donatien | 0:0ac66acdfdc0 | 29 | bool in_use; |
donatien | 0:0ac66acdfdc0 | 30 | uint8_t nb_endpoint; |
donatien | 0:0ac66acdfdc0 | 31 | uint8_t intf_class; |
donatien | 0:0ac66acdfdc0 | 32 | uint8_t intf_subclass; |
donatien | 0:0ac66acdfdc0 | 33 | uint8_t intf_protocol; |
donatien | 0:0ac66acdfdc0 | 34 | Endpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; |
donatien | 0:0ac66acdfdc0 | 35 | FunctionPointer detach; |
donatien | 0:0ac66acdfdc0 | 36 | }INTERFACE; |
donatien | 0:0ac66acdfdc0 | 37 | |
donatien | 0:0ac66acdfdc0 | 38 | |
donatien | 0:0ac66acdfdc0 | 39 | class USBDeviceConnected { |
donatien | 0:0ac66acdfdc0 | 40 | public: |
donatien | 0:0ac66acdfdc0 | 41 | |
donatien | 0:0ac66acdfdc0 | 42 | /* |
donatien | 0:0ac66acdfdc0 | 43 | * Constructor |
donatien | 0:0ac66acdfdc0 | 44 | */ |
donatien | 0:0ac66acdfdc0 | 45 | USBDeviceConnected(); |
donatien | 0:0ac66acdfdc0 | 46 | |
donatien | 0:0ac66acdfdc0 | 47 | /* |
donatien | 0:0ac66acdfdc0 | 48 | * Attach an endpoint to this device |
donatien | 0:0ac66acdfdc0 | 49 | * |
donatien | 0:0ac66acdfdc0 | 50 | * @param ep pointeur on the endpoint which will be attached |
donatien | 0:0ac66acdfdc0 | 51 | * @returns true if successful, false otherwise |
donatien | 0:0ac66acdfdc0 | 52 | */ |
donatien | 0:0ac66acdfdc0 | 53 | bool addEndpoint(uint8_t intf_nb, Endpoint * ep); |
donatien | 0:0ac66acdfdc0 | 54 | |
donatien | 0:0ac66acdfdc0 | 55 | /* |
donatien | 0:0ac66acdfdc0 | 56 | * Retrieve an endpoint by its TYPE and DIRECTION |
donatien | 0:0ac66acdfdc0 | 57 | * |
donatien | 0:0ac66acdfdc0 | 58 | * @param type type of the endpoint looked for |
donatien | 0:0ac66acdfdc0 | 59 | * @param direction of the endpoint looked for |
donatien | 0:0ac66acdfdc0 | 60 | * @returns pointer on the endpoint if found, NULL otherwise |
donatien | 0:0ac66acdfdc0 | 61 | */ |
donatien | 0:0ac66acdfdc0 | 62 | Endpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); |
donatien | 0:0ac66acdfdc0 | 63 | |
donatien | 0:0ac66acdfdc0 | 64 | /* |
donatien | 0:0ac66acdfdc0 | 65 | * Retrieve an endpoint by its index |
donatien | 0:0ac66acdfdc0 | 66 | * |
donatien | 0:0ac66acdfdc0 | 67 | * @param index index of the endpoint |
donatien | 0:0ac66acdfdc0 | 68 | * @returns pointer on the endpoint if found, NULL otherwise |
donatien | 0:0ac66acdfdc0 | 69 | */ |
donatien | 0:0ac66acdfdc0 | 70 | Endpoint * getEndpoint(uint8_t intf_nb, uint8_t index); |
donatien | 0:0ac66acdfdc0 | 71 | |
donatien | 0:0ac66acdfdc0 | 72 | bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); |
donatien | 0:0ac66acdfdc0 | 73 | |
donatien | 0:0ac66acdfdc0 | 74 | uint8_t getNbInterface() {return nb_interf;}; |
donatien | 0:0ac66acdfdc0 | 75 | |
donatien | 0:0ac66acdfdc0 | 76 | INTERFACE * getInterface(uint8_t index); |
donatien | 0:0ac66acdfdc0 | 77 | |
donatien | 0:0ac66acdfdc0 | 78 | /** |
donatien | 0:0ac66acdfdc0 | 79 | * Attach a member function to call when a the device has been disconnected |
donatien | 0:0ac66acdfdc0 | 80 | * |
donatien | 0:0ac66acdfdc0 | 81 | * @param tptr pointer to the object to call the member function on |
donatien | 0:0ac66acdfdc0 | 82 | * @param mptr pointer to the member function to be called |
donatien | 0:0ac66acdfdc0 | 83 | */ |
donatien | 0:0ac66acdfdc0 | 84 | template<typename T> |
donatien | 0:0ac66acdfdc0 | 85 | void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { |
donatien | 0:0ac66acdfdc0 | 86 | if ((mptr != NULL) && (tptr != NULL)) { |
donatien | 0:0ac66acdfdc0 | 87 | intf[intf_nb].detach.attach(tptr, mptr); |
donatien | 0:0ac66acdfdc0 | 88 | } |
donatien | 0:0ac66acdfdc0 | 89 | } |
donatien | 0:0ac66acdfdc0 | 90 | |
donatien | 0:0ac66acdfdc0 | 91 | /** |
donatien | 0:0ac66acdfdc0 | 92 | * Attach a callback called when the device has been disconnected |
donatien | 0:0ac66acdfdc0 | 93 | * |
donatien | 0:0ac66acdfdc0 | 94 | * @param fptr function pointer |
donatien | 0:0ac66acdfdc0 | 95 | */ |
donatien | 0:0ac66acdfdc0 | 96 | void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { |
donatien | 0:0ac66acdfdc0 | 97 | if (fn != NULL) { |
donatien | 0:0ac66acdfdc0 | 98 | intf[intf_nb].detach.attach(fn); |
donatien | 0:0ac66acdfdc0 | 99 | } |
donatien | 0:0ac66acdfdc0 | 100 | } |
donatien | 0:0ac66acdfdc0 | 101 | |
donatien | 0:0ac66acdfdc0 | 102 | /* |
donatien | 0:0ac66acdfdc0 | 103 | * Disconnect the device by calling a callback function registered by a driver |
donatien | 0:0ac66acdfdc0 | 104 | */ |
donatien | 0:0ac66acdfdc0 | 105 | void disconnect(); |
donatien | 0:0ac66acdfdc0 | 106 | |
donatien | 0:0ac66acdfdc0 | 107 | /* |
donatien | 0:0ac66acdfdc0 | 108 | * Setters |
donatien | 0:0ac66acdfdc0 | 109 | */ |
donatien | 0:0ac66acdfdc0 | 110 | void init(uint8_t hub, uint8_t port, bool lowSpeed); |
donatien | 0:0ac66acdfdc0 | 111 | void setAddress(uint8_t addr) { |
donatien | 0:0ac66acdfdc0 | 112 | this->addr = addr; |
donatien | 0:0ac66acdfdc0 | 113 | }; |
donatien | 0:0ac66acdfdc0 | 114 | void setVid(uint16_t vid) { |
donatien | 0:0ac66acdfdc0 | 115 | this->vid = vid; |
donatien | 0:0ac66acdfdc0 | 116 | }; |
donatien | 0:0ac66acdfdc0 | 117 | void setPid(uint16_t pid) { |
donatien | 0:0ac66acdfdc0 | 118 | this->pid = pid; |
donatien | 0:0ac66acdfdc0 | 119 | }; |
donatien | 0:0ac66acdfdc0 | 120 | void setClass(uint8_t device_class) { |
donatien | 0:0ac66acdfdc0 | 121 | this->device_class = device_class; |
donatien | 0:0ac66acdfdc0 | 122 | }; |
donatien | 0:0ac66acdfdc0 | 123 | void setSubClass(uint8_t device_subclass) { |
donatien | 0:0ac66acdfdc0 | 124 | this->device_subclass = device_subclass; |
donatien | 0:0ac66acdfdc0 | 125 | }; |
donatien | 0:0ac66acdfdc0 | 126 | void setProtocol(uint8_t pr) { |
donatien | 0:0ac66acdfdc0 | 127 | proto = pr; |
donatien | 0:0ac66acdfdc0 | 128 | }; |
donatien | 0:0ac66acdfdc0 | 129 | void setSizeControlEndpoint(uint32_t size) { |
donatien | 0:0ac66acdfdc0 | 130 | sizeControlEndpoint = size; |
donatien | 0:0ac66acdfdc0 | 131 | }; |
donatien | 0:0ac66acdfdc0 | 132 | void activeAddress() { |
donatien | 0:0ac66acdfdc0 | 133 | activeAddr = true; |
donatien | 0:0ac66acdfdc0 | 134 | }; |
donatien | 0:0ac66acdfdc0 | 135 | void setEnumerated() { |
donatien | 0:0ac66acdfdc0 | 136 | enumerated = true; |
donatien | 0:0ac66acdfdc0 | 137 | }; |
donatien | 0:0ac66acdfdc0 | 138 | |
donatien | 0:0ac66acdfdc0 | 139 | /* |
donatien | 0:0ac66acdfdc0 | 140 | * Getters |
donatien | 0:0ac66acdfdc0 | 141 | */ |
donatien | 0:0ac66acdfdc0 | 142 | uint8_t getPort() { |
donatien | 0:0ac66acdfdc0 | 143 | return port; |
donatien | 0:0ac66acdfdc0 | 144 | }; |
donatien | 0:0ac66acdfdc0 | 145 | uint8_t getHub() { |
donatien | 0:0ac66acdfdc0 | 146 | return hub; |
donatien | 0:0ac66acdfdc0 | 147 | }; |
donatien | 0:0ac66acdfdc0 | 148 | uint8_t getAddress() { |
donatien | 0:0ac66acdfdc0 | 149 | return addr; |
donatien | 0:0ac66acdfdc0 | 150 | }; |
donatien | 0:0ac66acdfdc0 | 151 | uint16_t getVid() { |
donatien | 0:0ac66acdfdc0 | 152 | return vid; |
donatien | 0:0ac66acdfdc0 | 153 | }; |
donatien | 0:0ac66acdfdc0 | 154 | uint16_t getPid() { |
donatien | 0:0ac66acdfdc0 | 155 | return pid; |
donatien | 0:0ac66acdfdc0 | 156 | }; |
donatien | 0:0ac66acdfdc0 | 157 | uint8_t getClass() { |
donatien | 0:0ac66acdfdc0 | 158 | return device_class; |
donatien | 0:0ac66acdfdc0 | 159 | }; |
donatien | 0:0ac66acdfdc0 | 160 | uint8_t getSubClass() { |
donatien | 0:0ac66acdfdc0 | 161 | return device_subclass; |
donatien | 0:0ac66acdfdc0 | 162 | }; |
donatien | 0:0ac66acdfdc0 | 163 | uint8_t getProtocol() { |
donatien | 0:0ac66acdfdc0 | 164 | return proto; |
donatien | 0:0ac66acdfdc0 | 165 | }; |
donatien | 0:0ac66acdfdc0 | 166 | bool getSpeed() { |
donatien | 0:0ac66acdfdc0 | 167 | return speed; |
donatien | 0:0ac66acdfdc0 | 168 | }; |
donatien | 0:0ac66acdfdc0 | 169 | uint32_t getSizeControlEndpoint() { |
donatien | 0:0ac66acdfdc0 | 170 | return sizeControlEndpoint; |
donatien | 0:0ac66acdfdc0 | 171 | }; |
donatien | 0:0ac66acdfdc0 | 172 | bool isActiveAddress() { |
donatien | 0:0ac66acdfdc0 | 173 | return activeAddr; |
donatien | 0:0ac66acdfdc0 | 174 | }; |
donatien | 0:0ac66acdfdc0 | 175 | bool isEnumerated() { |
donatien | 0:0ac66acdfdc0 | 176 | return enumerated; |
donatien | 0:0ac66acdfdc0 | 177 | }; |
donatien | 0:0ac66acdfdc0 | 178 | |
donatien | 0:0ac66acdfdc0 | 179 | |
donatien | 0:0ac66acdfdc0 | 180 | private: |
donatien | 0:0ac66acdfdc0 | 181 | INTERFACE intf[MAX_INTF]; |
donatien | 0:0ac66acdfdc0 | 182 | //Endpoint * ep[MAX_ENDPOINT_PER_DEVICE]; |
donatien | 0:0ac66acdfdc0 | 183 | uint32_t sizeControlEndpoint; |
donatien | 0:0ac66acdfdc0 | 184 | uint8_t hub; |
donatien | 0:0ac66acdfdc0 | 185 | uint8_t port; |
donatien | 0:0ac66acdfdc0 | 186 | uint16_t vid; |
donatien | 0:0ac66acdfdc0 | 187 | uint16_t pid; |
donatien | 0:0ac66acdfdc0 | 188 | uint8_t addr; |
donatien | 0:0ac66acdfdc0 | 189 | uint8_t device_class; |
donatien | 0:0ac66acdfdc0 | 190 | uint8_t device_subclass; |
donatien | 0:0ac66acdfdc0 | 191 | uint8_t proto; |
donatien | 0:0ac66acdfdc0 | 192 | bool speed; |
donatien | 0:0ac66acdfdc0 | 193 | bool activeAddr; |
donatien | 0:0ac66acdfdc0 | 194 | bool enumerated; |
donatien | 0:0ac66acdfdc0 | 195 | |
donatien | 0:0ac66acdfdc0 | 196 | uint8_t nb_interf; |
donatien | 0:0ac66acdfdc0 | 197 | |
donatien | 0:0ac66acdfdc0 | 198 | |
donatien | 0:0ac66acdfdc0 | 199 | void init(); |
donatien | 0:0ac66acdfdc0 | 200 | |
donatien | 0:0ac66acdfdc0 | 201 | }; |
donatien | 0:0ac66acdfdc0 | 202 | |
donatien | 0:0ac66acdfdc0 | 203 | #endif |