Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)

Dependents:   DISCO-F746NG_USB_Host

Fork of KL46Z-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Fri Jan 31 13:45:07 2014 +0000
Revision:
8:6463cd1964c0
Child:
9:7f9f64cf5ded
USB hub support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 8:6463cd1964c0 1 /* mbed USBHost Library
va009039 8:6463cd1964c0 2 * Copyright (c) 2006-2013 ARM Limited
va009039 8:6463cd1964c0 3 *
va009039 8:6463cd1964c0 4 * Licensed under the Apache License, Version 2.0 (the "License");
va009039 8:6463cd1964c0 5 * you may not use this file except in compliance with the License.
va009039 8:6463cd1964c0 6 * You may obtain a copy of the License at
va009039 8:6463cd1964c0 7 *
va009039 8:6463cd1964c0 8 * http://www.apache.org/licenses/LICENSE-2.0
va009039 8:6463cd1964c0 9 *
va009039 8:6463cd1964c0 10 * Unless required by applicable law or agreed to in writing, software
va009039 8:6463cd1964c0 11 * distributed under the License is distributed on an "AS IS" BASIS,
va009039 8:6463cd1964c0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
va009039 8:6463cd1964c0 13 * See the License for the specific language governing permissions and
va009039 8:6463cd1964c0 14 * limitations under the License.
va009039 8:6463cd1964c0 15 */
va009039 8:6463cd1964c0 16
va009039 8:6463cd1964c0 17 #include "USBDeviceConnected.h"
va009039 8:6463cd1964c0 18 //#include "dbg.h"
va009039 8:6463cd1964c0 19 #define USB_DBG(...) while(0)
va009039 8:6463cd1964c0 20
va009039 8:6463cd1964c0 21 USBDeviceConnected::USBDeviceConnected() {
va009039 8:6463cd1964c0 22 init();
va009039 8:6463cd1964c0 23 }
va009039 8:6463cd1964c0 24
va009039 8:6463cd1964c0 25 void USBDeviceConnected::init() {
va009039 8:6463cd1964c0 26 hub_nb = 0;
va009039 8:6463cd1964c0 27 port = 0;
va009039 8:6463cd1964c0 28 vid = 0;
va009039 8:6463cd1964c0 29 pid = 0;
va009039 8:6463cd1964c0 30 nb_interf = 0;
va009039 8:6463cd1964c0 31 enumerated = false;
va009039 8:6463cd1964c0 32 //activeAddr = false;
va009039 8:6463cd1964c0 33 //sizeControlEndpoint = 8;
va009039 8:6463cd1964c0 34 device_class = 0;
va009039 8:6463cd1964c0 35 device_subclass = 0;
va009039 8:6463cd1964c0 36 proto = 0;
va009039 8:6463cd1964c0 37 lowSpeed = false;
va009039 8:6463cd1964c0 38 for (int i = 0; i < MAX_INTF; i++) {
va009039 8:6463cd1964c0 39 memset((void *)&intf[i], 0, sizeof(INTERFACE));
va009039 8:6463cd1964c0 40 intf[i].in_use = false;
va009039 8:6463cd1964c0 41 for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) {
va009039 8:6463cd1964c0 42 intf[i].ep[j] = NULL;
va009039 8:6463cd1964c0 43 //strcpy(intf[i].name, "Unknown");
va009039 8:6463cd1964c0 44 }
va009039 8:6463cd1964c0 45 }
va009039 8:6463cd1964c0 46 //hub_parent = NULL;
va009039 8:6463cd1964c0 47 //hub = NULL;
va009039 8:6463cd1964c0 48 nb_interf = 0;
va009039 8:6463cd1964c0 49 }
va009039 8:6463cd1964c0 50
va009039 8:6463cd1964c0 51 INTERFACE * USBDeviceConnected::getInterface(uint8_t index) {
va009039 8:6463cd1964c0 52 if (index >= MAX_INTF)
va009039 8:6463cd1964c0 53 return NULL;
va009039 8:6463cd1964c0 54
va009039 8:6463cd1964c0 55 if (intf[index].in_use)
va009039 8:6463cd1964c0 56 return &intf[index];
va009039 8:6463cd1964c0 57
va009039 8:6463cd1964c0 58 return NULL;
va009039 8:6463cd1964c0 59 }
va009039 8:6463cd1964c0 60
va009039 8:6463cd1964c0 61 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
va009039 8:6463cd1964c0 62 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) {
va009039 8:6463cd1964c0 63 return false;
va009039 8:6463cd1964c0 64 }
va009039 8:6463cd1964c0 65 intf[intf_nb].in_use = true;
va009039 8:6463cd1964c0 66 intf[intf_nb].intf_class = intf_class;
va009039 8:6463cd1964c0 67 intf[intf_nb].intf_subclass = intf_subclass;
va009039 8:6463cd1964c0 68 intf[intf_nb].intf_protocol = intf_protocol;
va009039 8:6463cd1964c0 69 intf[intf_nb].nb_endpoint = 0;
va009039 8:6463cd1964c0 70 return true;
va009039 8:6463cd1964c0 71 }
va009039 8:6463cd1964c0 72
va009039 8:6463cd1964c0 73 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
va009039 8:6463cd1964c0 74 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) {
va009039 8:6463cd1964c0 75 return false;
va009039 8:6463cd1964c0 76 }
va009039 8:6463cd1964c0 77 intf[intf_nb].nb_endpoint++;
va009039 8:6463cd1964c0 78
va009039 8:6463cd1964c0 79 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
va009039 8:6463cd1964c0 80 if (intf[intf_nb].ep[i] == NULL) {
va009039 8:6463cd1964c0 81 intf[intf_nb].ep[i] = ept;
va009039 8:6463cd1964c0 82 return true;
va009039 8:6463cd1964c0 83 }
va009039 8:6463cd1964c0 84 }
va009039 8:6463cd1964c0 85 return false;
va009039 8:6463cd1964c0 86 }
va009039 8:6463cd1964c0 87
va009039 8:6463cd1964c0 88 void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) {
va009039 8:6463cd1964c0 89 USB_DBG("init dev: %p", this);
va009039 8:6463cd1964c0 90 init();
va009039 8:6463cd1964c0 91 hub_nb = hub_;
va009039 8:6463cd1964c0 92 port = port_;
va009039 8:6463cd1964c0 93 lowSpeed = lowSpeed_;
va009039 8:6463cd1964c0 94 }
va009039 8:6463cd1964c0 95
va009039 8:6463cd1964c0 96 void USBDeviceConnected::disconnect() {
va009039 8:6463cd1964c0 97 //for(int i = 0; i < MAX_INTF; i++) {
va009039 8:6463cd1964c0 98 // intf[i].detach.call();
va009039 8:6463cd1964c0 99 //}
va009039 8:6463cd1964c0 100 //init();
va009039 8:6463cd1964c0 101 }
va009039 8:6463cd1964c0 102
va009039 8:6463cd1964c0 103
va009039 8:6463cd1964c0 104 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
va009039 8:6463cd1964c0 105 if (intf_nb >= MAX_INTF) {
va009039 8:6463cd1964c0 106 return NULL;
va009039 8:6463cd1964c0 107 }
va009039 8:6463cd1964c0 108 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
va009039 8:6463cd1964c0 109 if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
va009039 8:6463cd1964c0 110 if(index) {
va009039 8:6463cd1964c0 111 index--;
va009039 8:6463cd1964c0 112 } else {
va009039 8:6463cd1964c0 113 return intf[intf_nb].ep[i];
va009039 8:6463cd1964c0 114 }
va009039 8:6463cd1964c0 115 }
va009039 8:6463cd1964c0 116 }
va009039 8:6463cd1964c0 117 return NULL;
va009039 8:6463cd1964c0 118 }
va009039 8:6463cd1964c0 119
va009039 8:6463cd1964c0 120 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
va009039 8:6463cd1964c0 121 if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) {
va009039 8:6463cd1964c0 122 return NULL;
va009039 8:6463cd1964c0 123 }
va009039 8:6463cd1964c0 124 return intf[intf_nb].ep[index];
va009039 8:6463cd1964c0 125 }