local fork (temporary)

Dependents:   VodafoneUSBModem_bleedingedge2

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Committer:
donatien
Date:
Thu May 24 16:39:35 2012 +0000
Revision:
0:ae46a0638b2c
Child:
2:a8b2d0cd9bbd
Initial Commit

Who changed what in which revision?

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