local fork (temporary)

Dependents:   VodafoneUSBModem_bleedingedge2

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Committer:
donatien
Date:
Tue Jul 31 10:37:16 2012 +0000
Revision:
9:c9e9817c398c
Parent:
6:075e36a3463e
Child:
10:08bce4cd973a
Renamed Endpoint->USBEndpoint because it conflicted with the Socket API! Made some weird symbols mixups happen that made everything explode when the first USB endpoint was allocated.

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 9:c9e9817c398c 23 #include "USBEndpoint.h"
donatien 0:ae46a0638b2c 24
donatien 6:075e36a3463e 25 #define MAX_ENDPOINT_PER_INTERFACE 2
donatien 6:075e36a3463e 26 #define MAX_INTF 2
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 9:c9e9817c398c 34 USBEndpoint * 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 9:c9e9817c398c 48 * Attach an USBEndpoint to this device
donatien 0:ae46a0638b2c 49 *
donatien 9:c9e9817c398c 50 * @param ep pointeur on the USBEndpoint which will be attached
donatien 0:ae46a0638b2c 51 * @returns true if successful, false otherwise
donatien 0:ae46a0638b2c 52 */
donatien 9:c9e9817c398c 53 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
donatien 0:ae46a0638b2c 54
donatien 0:ae46a0638b2c 55 /*
donatien 9:c9e9817c398c 56 * Retrieve an USBEndpoint by its TYPE and DIRECTION
donatien 0:ae46a0638b2c 57 *
donatien 9:c9e9817c398c 58 * @param intf_nb the interface on which to lookup the USBEndpoint
donatien 9:c9e9817c398c 59 * @param type type of the USBEndpoint looked for
donatien 9:c9e9817c398c 60 * @param direction of the USBEndpoint looked for
donatien 9:c9e9817c398c 61 * @param index the index of the USBEndpoint whitin the interface
donatien 9:c9e9817c398c 62 * @returns pointer on the USBEndpoint if found, NULL otherwise
donatien 0:ae46a0638b2c 63 */
donatien 9:c9e9817c398c 64 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
donatien 0:ae46a0638b2c 65
donatien 0:ae46a0638b2c 66 /*
donatien 9:c9e9817c398c 67 * Retrieve an USBEndpoint by its index
donatien 0:ae46a0638b2c 68 *
donatien 9:c9e9817c398c 69 * @param index index of the USBEndpoint
donatien 9:c9e9817c398c 70 * @returns pointer on the USBEndpoint if found, NULL otherwise
donatien 0:ae46a0638b2c 71 */
donatien 9:c9e9817c398c 72 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
donatien 0:ae46a0638b2c 73
donatien 0:ae46a0638b2c 74 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
donatien 0:ae46a0638b2c 75
donatien 0:ae46a0638b2c 76 uint8_t getNbInterface() {return nb_interf;};
donatien 0:ae46a0638b2c 77
donatien 0:ae46a0638b2c 78 INTERFACE * getInterface(uint8_t index);
donatien 0:ae46a0638b2c 79
donatien 0:ae46a0638b2c 80 /**
donatien 0:ae46a0638b2c 81 * Attach a member function to call when a the device has been disconnected
donatien 0:ae46a0638b2c 82 *
donatien 0:ae46a0638b2c 83 * @param tptr pointer to the object to call the member function on
donatien 0:ae46a0638b2c 84 * @param mptr pointer to the member function to be called
donatien 0:ae46a0638b2c 85 */
donatien 0:ae46a0638b2c 86 template<typename T>
donatien 0:ae46a0638b2c 87 void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) {
donatien 0:ae46a0638b2c 88 if ((mptr != NULL) && (tptr != NULL)) {
donatien 0:ae46a0638b2c 89 intf[intf_nb].detach.attach(tptr, mptr);
donatien 0:ae46a0638b2c 90 }
donatien 0:ae46a0638b2c 91 }
donatien 0:ae46a0638b2c 92
donatien 0:ae46a0638b2c 93 /**
donatien 0:ae46a0638b2c 94 * Attach a callback called when the device has been disconnected
donatien 0:ae46a0638b2c 95 *
donatien 0:ae46a0638b2c 96 * @param fptr function pointer
donatien 0:ae46a0638b2c 97 */
donatien 0:ae46a0638b2c 98 void onDisconnect(uint8_t intf_nb, void (*fn)(void)) {
donatien 0:ae46a0638b2c 99 if (fn != NULL) {
donatien 0:ae46a0638b2c 100 intf[intf_nb].detach.attach(fn);
donatien 0:ae46a0638b2c 101 }
donatien 0:ae46a0638b2c 102 }
donatien 0:ae46a0638b2c 103
donatien 0:ae46a0638b2c 104 /*
donatien 0:ae46a0638b2c 105 * Disconnect the device by calling a callback function registered by a driver
donatien 0:ae46a0638b2c 106 */
donatien 0:ae46a0638b2c 107 void disconnect();
donatien 0:ae46a0638b2c 108
donatien 0:ae46a0638b2c 109 /*
donatien 0:ae46a0638b2c 110 * Setters
donatien 0:ae46a0638b2c 111 */
donatien 0:ae46a0638b2c 112 void init(uint8_t hub, uint8_t port, bool lowSpeed);
donatien 0:ae46a0638b2c 113 void setAddress(uint8_t addr) {
donatien 0:ae46a0638b2c 114 this->addr = addr;
donatien 0:ae46a0638b2c 115 };
donatien 0:ae46a0638b2c 116 void setVid(uint16_t vid) {
donatien 0:ae46a0638b2c 117 this->vid = vid;
donatien 0:ae46a0638b2c 118 };
donatien 0:ae46a0638b2c 119 void setPid(uint16_t pid) {
donatien 0:ae46a0638b2c 120 this->pid = pid;
donatien 0:ae46a0638b2c 121 };
donatien 0:ae46a0638b2c 122 void setClass(uint8_t device_class) {
donatien 0:ae46a0638b2c 123 this->device_class = device_class;
donatien 0:ae46a0638b2c 124 };
donatien 0:ae46a0638b2c 125 void setSubClass(uint8_t device_subclass) {
donatien 0:ae46a0638b2c 126 this->device_subclass = device_subclass;
donatien 0:ae46a0638b2c 127 };
donatien 0:ae46a0638b2c 128 void setProtocol(uint8_t pr) {
donatien 0:ae46a0638b2c 129 proto = pr;
donatien 0:ae46a0638b2c 130 };
donatien 0:ae46a0638b2c 131 void setSizeControlEndpoint(uint32_t size) {
donatien 0:ae46a0638b2c 132 sizeControlEndpoint = size;
donatien 0:ae46a0638b2c 133 };
donatien 0:ae46a0638b2c 134 void activeAddress() {
donatien 0:ae46a0638b2c 135 activeAddr = true;
donatien 0:ae46a0638b2c 136 };
donatien 0:ae46a0638b2c 137 void setEnumerated() {
donatien 0:ae46a0638b2c 138 enumerated = true;
donatien 0:ae46a0638b2c 139 };
donatien 0:ae46a0638b2c 140
donatien 0:ae46a0638b2c 141 /*
donatien 0:ae46a0638b2c 142 * Getters
donatien 0:ae46a0638b2c 143 */
donatien 0:ae46a0638b2c 144 uint8_t getPort() {
donatien 0:ae46a0638b2c 145 return port;
donatien 0:ae46a0638b2c 146 };
donatien 0:ae46a0638b2c 147 uint8_t getHub() {
donatien 0:ae46a0638b2c 148 return hub;
donatien 0:ae46a0638b2c 149 };
donatien 0:ae46a0638b2c 150 uint8_t getAddress() {
donatien 0:ae46a0638b2c 151 return addr;
donatien 0:ae46a0638b2c 152 };
donatien 0:ae46a0638b2c 153 uint16_t getVid() {
donatien 0:ae46a0638b2c 154 return vid;
donatien 0:ae46a0638b2c 155 };
donatien 0:ae46a0638b2c 156 uint16_t getPid() {
donatien 0:ae46a0638b2c 157 return pid;
donatien 0:ae46a0638b2c 158 };
donatien 0:ae46a0638b2c 159 uint8_t getClass() {
donatien 0:ae46a0638b2c 160 return device_class;
donatien 0:ae46a0638b2c 161 };
donatien 0:ae46a0638b2c 162 uint8_t getSubClass() {
donatien 0:ae46a0638b2c 163 return device_subclass;
donatien 0:ae46a0638b2c 164 };
donatien 0:ae46a0638b2c 165 uint8_t getProtocol() {
donatien 0:ae46a0638b2c 166 return proto;
donatien 0:ae46a0638b2c 167 };
donatien 0:ae46a0638b2c 168 bool getSpeed() {
donatien 0:ae46a0638b2c 169 return speed;
donatien 0:ae46a0638b2c 170 };
donatien 0:ae46a0638b2c 171 uint32_t getSizeControlEndpoint() {
donatien 0:ae46a0638b2c 172 return sizeControlEndpoint;
donatien 0:ae46a0638b2c 173 };
donatien 0:ae46a0638b2c 174 bool isActiveAddress() {
donatien 0:ae46a0638b2c 175 return activeAddr;
donatien 0:ae46a0638b2c 176 };
donatien 0:ae46a0638b2c 177 bool isEnumerated() {
donatien 0:ae46a0638b2c 178 return enumerated;
donatien 0:ae46a0638b2c 179 };
donatien 0:ae46a0638b2c 180
donatien 0:ae46a0638b2c 181
donatien 0:ae46a0638b2c 182 private:
donatien 0:ae46a0638b2c 183 INTERFACE intf[MAX_INTF];
donatien 9:c9e9817c398c 184 //USBEndpoint * ep[MAX_ENDPOINT_PER_DEVICE];
donatien 0:ae46a0638b2c 185 uint32_t sizeControlEndpoint;
donatien 0:ae46a0638b2c 186 uint8_t hub;
donatien 0:ae46a0638b2c 187 uint8_t port;
donatien 0:ae46a0638b2c 188 uint16_t vid;
donatien 0:ae46a0638b2c 189 uint16_t pid;
donatien 0:ae46a0638b2c 190 uint8_t addr;
donatien 0:ae46a0638b2c 191 uint8_t device_class;
donatien 0:ae46a0638b2c 192 uint8_t device_subclass;
donatien 0:ae46a0638b2c 193 uint8_t proto;
donatien 0:ae46a0638b2c 194 bool speed;
donatien 0:ae46a0638b2c 195 bool activeAddr;
donatien 0:ae46a0638b2c 196 bool enumerated;
donatien 0:ae46a0638b2c 197
donatien 0:ae46a0638b2c 198 uint8_t nb_interf;
donatien 0:ae46a0638b2c 199
donatien 0:ae46a0638b2c 200
donatien 0:ae46a0638b2c 201 void init();
donatien 0:ae46a0638b2c 202
donatien 0:ae46a0638b2c 203 };
donatien 0:ae46a0638b2c 204
donatien 0:ae46a0638b2c 205 #endif