Usb read

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Wed Feb 05 13:34:37 2014 +0000
Revision:
10:40c7f6788902
Parent:
9:7f9f64cf5ded
fix endpoint callback.

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 9:7f9f64cf5ded 18 #include "dbg.h"
va009039 8:6463cd1964c0 19
va009039 8:6463cd1964c0 20 USBDeviceConnected::USBDeviceConnected() {
va009039 8:6463cd1964c0 21 init();
va009039 8:6463cd1964c0 22 }
va009039 8:6463cd1964c0 23
va009039 8:6463cd1964c0 24 void USBDeviceConnected::init() {
va009039 8:6463cd1964c0 25 port = 0;
va009039 8:6463cd1964c0 26 vid = 0;
va009039 8:6463cd1964c0 27 pid = 0;
va009039 8:6463cd1964c0 28 nb_interf = 0;
va009039 8:6463cd1964c0 29 enumerated = false;
va009039 8:6463cd1964c0 30 device_class = 0;
va009039 8:6463cd1964c0 31 device_subclass = 0;
va009039 8:6463cd1964c0 32 proto = 0;
va009039 8:6463cd1964c0 33 lowSpeed = false;
va009039 10:40c7f6788902 34 hub_parent = NULL;
va009039 8:6463cd1964c0 35 }
va009039 8:6463cd1964c0 36
va009039 8:6463cd1964c0 37 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
va009039 9:7f9f64cf5ded 38 USB_DBG("intf_nb=%d", intf_nb);
va009039 10:40c7f6788902 39 if (intf.count(intf_nb) > 0) {
va009039 10:40c7f6788902 40 return false;
va009039 9:7f9f64cf5ded 41 }
va009039 10:40c7f6788902 42 intf[intf_nb] = new INTERFACE(intf_class, intf_subclass, intf_protocol);
va009039 8:6463cd1964c0 43 return true;
va009039 8:6463cd1964c0 44 }
va009039 8:6463cd1964c0 45
va009039 8:6463cd1964c0 46 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
va009039 10:40c7f6788902 47 if (intf.count(intf_nb) > 0) {
va009039 10:40c7f6788902 48 intf[intf_nb]->ep.push_back(ept);
va009039 10:40c7f6788902 49 return true;
va009039 10:40c7f6788902 50 }
va009039 10:40c7f6788902 51 return false;
va009039 8:6463cd1964c0 52 }
va009039 8:6463cd1964c0 53
va009039 10:40c7f6788902 54 void USBDeviceConnected::init(USBDeviceConnected* parent, uint8_t port_, bool lowSpeed_) {
va009039 8:6463cd1964c0 55 USB_DBG("init dev: %p", this);
va009039 8:6463cd1964c0 56 init();
va009039 10:40c7f6788902 57 hub_parent = parent;
va009039 8:6463cd1964c0 58 port = port_;
va009039 8:6463cd1964c0 59 lowSpeed = lowSpeed_;
va009039 8:6463cd1964c0 60 }
va009039 8:6463cd1964c0 61
va009039 8:6463cd1964c0 62 void USBDeviceConnected::disconnect() {
va009039 8:6463cd1964c0 63 //for(int i = 0; i < MAX_INTF; i++) {
va009039 8:6463cd1964c0 64 // intf[i].detach.call();
va009039 8:6463cd1964c0 65 //}
va009039 8:6463cd1964c0 66 //init();
va009039 8:6463cd1964c0 67 }
va009039 8:6463cd1964c0 68
va009039 8:6463cd1964c0 69
va009039 8:6463cd1964c0 70 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
va009039 9:7f9f64cf5ded 71 USB_DBG("intf_nb=%d", intf_nb);
va009039 10:40c7f6788902 72 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
va009039 10:40c7f6788902 73 INTERFACE* inter = intf[intf_nb];
va009039 9:7f9f64cf5ded 74 for (int i = 0; i < inter->ep.size(); i++) {
va009039 10:40c7f6788902 75 if ((inter->ep[i]->getType() == type) && (inter->ep[i]->getDir() == dir)) {
va009039 8:6463cd1964c0 76 if(index) {
va009039 8:6463cd1964c0 77 index--;
va009039 8:6463cd1964c0 78 } else {
va009039 10:40c7f6788902 79 return inter->ep[i];
va009039 8:6463cd1964c0 80 }
va009039 8:6463cd1964c0 81 }
va009039 8:6463cd1964c0 82 }
va009039 8:6463cd1964c0 83 return NULL;
va009039 8:6463cd1964c0 84 }
va009039 8:6463cd1964c0 85
va009039 8:6463cd1964c0 86 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
va009039 10:40c7f6788902 87 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
va009039 10:40c7f6788902 88 return intf[intf_nb]->ep[index];
va009039 8:6463cd1964c0 89 }