final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
prijimac-funkcni final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
homzovam 4:77d6450f34d7 1 /* mbed USBHost Library
homzovam 4:77d6450f34d7 2 * Copyright (c) 2006-2013 ARM Limited
homzovam 4:77d6450f34d7 3 *
homzovam 4:77d6450f34d7 4 * Licensed under the Apache License, Version 2.0 (the "License");
homzovam 4:77d6450f34d7 5 * you may not use this file except in compliance with the License.
homzovam 4:77d6450f34d7 6 * You may obtain a copy of the License at
homzovam 4:77d6450f34d7 7 *
homzovam 4:77d6450f34d7 8 * http://www.apache.org/licenses/LICENSE-2.0
homzovam 4:77d6450f34d7 9 *
homzovam 4:77d6450f34d7 10 * Unless required by applicable law or agreed to in writing, software
homzovam 4:77d6450f34d7 11 * distributed under the License is distributed on an "AS IS" BASIS,
homzovam 4:77d6450f34d7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
homzovam 4:77d6450f34d7 13 * See the License for the specific language governing permissions and
homzovam 4:77d6450f34d7 14 * limitations under the License.
homzovam 4:77d6450f34d7 15 */
homzovam 4:77d6450f34d7 16
homzovam 4:77d6450f34d7 17 #include "USBDeviceConnected.h"
homzovam 4:77d6450f34d7 18 #include "dbg.h"
homzovam 4:77d6450f34d7 19
homzovam 4:77d6450f34d7 20 USBDeviceConnected::USBDeviceConnected() {
homzovam 4:77d6450f34d7 21 init();
homzovam 4:77d6450f34d7 22 }
homzovam 4:77d6450f34d7 23
homzovam 4:77d6450f34d7 24 void USBDeviceConnected::init() {
homzovam 4:77d6450f34d7 25 port = 0;
homzovam 4:77d6450f34d7 26 vid = 0;
homzovam 4:77d6450f34d7 27 pid = 0;
homzovam 4:77d6450f34d7 28 nb_interf = 0;
homzovam 4:77d6450f34d7 29 enumerated = false;
homzovam 4:77d6450f34d7 30 device_class = 0;
homzovam 4:77d6450f34d7 31 device_subclass = 0;
homzovam 4:77d6450f34d7 32 proto = 0;
homzovam 4:77d6450f34d7 33 lowSpeed = false;
homzovam 4:77d6450f34d7 34 hub_parent = NULL;
homzovam 4:77d6450f34d7 35 }
homzovam 4:77d6450f34d7 36
homzovam 4:77d6450f34d7 37 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
homzovam 4:77d6450f34d7 38 USB_DBG("intf_nb=%d", intf_nb);
homzovam 4:77d6450f34d7 39 if (intf.count(intf_nb) > 0) {
homzovam 4:77d6450f34d7 40 return false;
homzovam 4:77d6450f34d7 41 }
homzovam 4:77d6450f34d7 42 intf[intf_nb] = new INTERFACE(intf_class, intf_subclass, intf_protocol);
homzovam 4:77d6450f34d7 43 return true;
homzovam 4:77d6450f34d7 44 }
homzovam 4:77d6450f34d7 45
homzovam 4:77d6450f34d7 46 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
homzovam 4:77d6450f34d7 47 if (intf.count(intf_nb) > 0) {
homzovam 4:77d6450f34d7 48 intf[intf_nb]->ep.push_back(ept);
homzovam 4:77d6450f34d7 49 return true;
homzovam 4:77d6450f34d7 50 }
homzovam 4:77d6450f34d7 51 return false;
homzovam 4:77d6450f34d7 52 }
homzovam 4:77d6450f34d7 53
homzovam 4:77d6450f34d7 54 void USBDeviceConnected::init(USBDeviceConnected* parent, uint8_t port_, bool lowSpeed_) {
homzovam 4:77d6450f34d7 55 USB_DBG("init dev: %p", this);
homzovam 4:77d6450f34d7 56 init();
homzovam 4:77d6450f34d7 57 hub_parent = parent;
homzovam 4:77d6450f34d7 58 port = port_;
homzovam 4:77d6450f34d7 59 lowSpeed = lowSpeed_;
homzovam 4:77d6450f34d7 60 }
homzovam 4:77d6450f34d7 61
homzovam 4:77d6450f34d7 62 void USBDeviceConnected::disconnect() {
homzovam 4:77d6450f34d7 63 //for(int i = 0; i < MAX_INTF; i++) {
homzovam 4:77d6450f34d7 64 // intf[i].detach.call();
homzovam 4:77d6450f34d7 65 //}
homzovam 4:77d6450f34d7 66 //init();
homzovam 4:77d6450f34d7 67 }
homzovam 4:77d6450f34d7 68
homzovam 4:77d6450f34d7 69
homzovam 4:77d6450f34d7 70 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
homzovam 4:77d6450f34d7 71 USB_DBG("intf_nb=%d", intf_nb);
homzovam 4:77d6450f34d7 72 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
homzovam 4:77d6450f34d7 73 INTERFACE* inter = intf[intf_nb];
homzovam 4:77d6450f34d7 74 for (int i = 0; i < inter->ep.size(); i++) {
homzovam 4:77d6450f34d7 75 if ((inter->ep[i]->getType() == type) && (inter->ep[i]->getDir() == dir)) {
homzovam 4:77d6450f34d7 76 if(index) {
homzovam 4:77d6450f34d7 77 index--;
homzovam 4:77d6450f34d7 78 } else {
homzovam 4:77d6450f34d7 79 return inter->ep[i];
homzovam 4:77d6450f34d7 80 }
homzovam 4:77d6450f34d7 81 }
homzovam 4:77d6450f34d7 82 }
homzovam 4:77d6450f34d7 83 return NULL;
homzovam 4:77d6450f34d7 84 }
homzovam 4:77d6450f34d7 85
homzovam 4:77d6450f34d7 86 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
homzovam 4:77d6450f34d7 87 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
homzovam 4:77d6450f34d7 88 return intf[intf_nb]->ep[index];
homzovam 4:77d6450f34d7 89 }