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:
2:a8b2d0cd9bbd
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 #include "USBDeviceConnected.h"
donatien 0:ae46a0638b2c 20
donatien 0:ae46a0638b2c 21 USBDeviceConnected::USBDeviceConnected() {
donatien 0:ae46a0638b2c 22 init();
donatien 0:ae46a0638b2c 23 }
donatien 0:ae46a0638b2c 24
donatien 0:ae46a0638b2c 25 void USBDeviceConnected::init() {
donatien 0:ae46a0638b2c 26 hub = 0;
donatien 0:ae46a0638b2c 27 port = 0;
donatien 0:ae46a0638b2c 28 vid = 0;
donatien 0:ae46a0638b2c 29 pid = 0;
donatien 0:ae46a0638b2c 30 nb_interf = 0;
donatien 0:ae46a0638b2c 31 enumerated = false;
donatien 0:ae46a0638b2c 32 activeAddr = false;
donatien 0:ae46a0638b2c 33 sizeControlEndpoint = 8;
donatien 0:ae46a0638b2c 34 device_class = 0;
donatien 0:ae46a0638b2c 35 device_subclass = 0;
donatien 0:ae46a0638b2c 36 proto = 0;
donatien 0:ae46a0638b2c 37 speed = false;
donatien 0:ae46a0638b2c 38 for (int i = 0; i < MAX_INTF; i++) {
donatien 0:ae46a0638b2c 39 memset((void *)&intf[i], 0, sizeof(INTERFACE));
donatien 0:ae46a0638b2c 40 intf[i].in_use = false;
donatien 0:ae46a0638b2c 41 for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) {
donatien 0:ae46a0638b2c 42 intf[i].ep[j] = NULL;
donatien 0:ae46a0638b2c 43 }
donatien 0:ae46a0638b2c 44 }
donatien 0:ae46a0638b2c 45 }
donatien 0:ae46a0638b2c 46
donatien 0:ae46a0638b2c 47 INTERFACE * USBDeviceConnected::getInterface(uint8_t index) {
donatien 0:ae46a0638b2c 48 if (index >= MAX_INTF) {
donatien 0:ae46a0638b2c 49 return NULL;
donatien 0:ae46a0638b2c 50 }
donatien 0:ae46a0638b2c 51 return &intf[index];
donatien 0:ae46a0638b2c 52 }
donatien 0:ae46a0638b2c 53
donatien 0:ae46a0638b2c 54 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
donatien 0:ae46a0638b2c 55 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) {
donatien 0:ae46a0638b2c 56 return false;
donatien 0:ae46a0638b2c 57 }
donatien 0:ae46a0638b2c 58 intf[intf_nb].in_use = true;
donatien 0:ae46a0638b2c 59 intf[intf_nb].intf_class = intf_class;
donatien 0:ae46a0638b2c 60 intf[intf_nb].intf_subclass = intf_subclass;
donatien 0:ae46a0638b2c 61 intf[intf_nb].intf_protocol = intf_protocol;
donatien 0:ae46a0638b2c 62 intf[intf_nb].nb_endpoint = 0;
donatien 0:ae46a0638b2c 63 nb_interf++;
donatien 0:ae46a0638b2c 64 return true;
donatien 0:ae46a0638b2c 65 }
donatien 0:ae46a0638b2c 66
donatien 9:c9e9817c398c 67 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
donatien 0:ae46a0638b2c 68 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) {
donatien 0:ae46a0638b2c 69 return false;
donatien 0:ae46a0638b2c 70 }
donatien 0:ae46a0638b2c 71 intf[intf_nb].nb_endpoint++;
donatien 0:ae46a0638b2c 72
donatien 0:ae46a0638b2c 73 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
donatien 0:ae46a0638b2c 74 if (intf[intf_nb].ep[i] == NULL) {
donatien 0:ae46a0638b2c 75 intf[intf_nb].ep[i] = ept;
donatien 0:ae46a0638b2c 76 return true;
donatien 0:ae46a0638b2c 77 }
donatien 0:ae46a0638b2c 78 }
donatien 0:ae46a0638b2c 79 return false;
donatien 0:ae46a0638b2c 80 }
donatien 0:ae46a0638b2c 81
donatien 0:ae46a0638b2c 82 void USBDeviceConnected::init(uint8_t hub, uint8_t port, bool lowSpeed) {
donatien 0:ae46a0638b2c 83 init();
donatien 0:ae46a0638b2c 84 this->hub = hub;
donatien 0:ae46a0638b2c 85 this->port = port;
donatien 0:ae46a0638b2c 86 this->speed = lowSpeed;
donatien 0:ae46a0638b2c 87 }
donatien 0:ae46a0638b2c 88
donatien 0:ae46a0638b2c 89 void USBDeviceConnected::disconnect() {
donatien 0:ae46a0638b2c 90 for(int i = 0; i < nb_interf; i++) {
donatien 0:ae46a0638b2c 91 intf[i].detach.call();
donatien 0:ae46a0638b2c 92 }
donatien 0:ae46a0638b2c 93 init();
donatien 0:ae46a0638b2c 94 }
donatien 0:ae46a0638b2c 95
donatien 0:ae46a0638b2c 96
donatien 0:ae46a0638b2c 97
donatien 9:c9e9817c398c 98 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
donatien 0:ae46a0638b2c 99 if (intf_nb >= MAX_INTF) {
donatien 0:ae46a0638b2c 100 return NULL;
donatien 0:ae46a0638b2c 101 }
donatien 0:ae46a0638b2c 102 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
donatien 0:ae46a0638b2c 103 if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
donatien 2:a8b2d0cd9bbd 104 if(index)
donatien 2:a8b2d0cd9bbd 105 {
donatien 2:a8b2d0cd9bbd 106 index--;
donatien 2:a8b2d0cd9bbd 107 }
donatien 2:a8b2d0cd9bbd 108 else
donatien 2:a8b2d0cd9bbd 109 {
donatien 2:a8b2d0cd9bbd 110 return intf[intf_nb].ep[i];
donatien 2:a8b2d0cd9bbd 111 }
donatien 0:ae46a0638b2c 112 }
donatien 0:ae46a0638b2c 113 }
donatien 0:ae46a0638b2c 114 return NULL;
donatien 0:ae46a0638b2c 115 }
donatien 0:ae46a0638b2c 116
donatien 9:c9e9817c398c 117 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
donatien 0:ae46a0638b2c 118 if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) {
donatien 0:ae46a0638b2c 119 return NULL;
donatien 0:ae46a0638b2c 120 }
donatien 0:ae46a0638b2c 121 return intf[intf_nb].ep[index];
donatien 0:ae46a0638b2c 122 }