Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768
Dependents: F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld
Fork of KL46Z-USBHost by
USBDeviceConnected.cpp
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "USBDeviceConnected.h" 00018 #include "dbg.h" 00019 00020 USBDeviceConnected::USBDeviceConnected() { 00021 init(); 00022 } 00023 00024 void USBDeviceConnected::init() { 00025 port = 0; 00026 vid = 0; 00027 pid = 0; 00028 nb_interf = 0; 00029 enumerated = false; 00030 device_class = 0; 00031 device_subclass = 0; 00032 proto = 0; 00033 lowSpeed = false; 00034 hub_parent = NULL; 00035 } 00036 00037 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) { 00038 USB_DBG("intf_nb=%d", intf_nb); 00039 if (intf.count(intf_nb) > 0) { 00040 return false; 00041 } 00042 intf[intf_nb] = new INTERFACE(intf_class, intf_subclass, intf_protocol); 00043 return true; 00044 } 00045 00046 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) { 00047 if (intf.count(intf_nb) > 0) { 00048 intf[intf_nb]->ep.push_back(ept); 00049 return true; 00050 } 00051 return false; 00052 } 00053 00054 void USBDeviceConnected::init(USBDeviceConnected* parent, uint8_t port_, bool lowSpeed_) { 00055 USB_DBG("init dev: %p", this); 00056 init(); 00057 hub_parent = parent; 00058 port = port_; 00059 lowSpeed = lowSpeed_; 00060 } 00061 00062 void USBDeviceConnected::disconnect() { 00063 //for(int i = 0; i < MAX_INTF; i++) { 00064 // intf[i].detach.call(); 00065 //} 00066 //init(); 00067 } 00068 00069 00070 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) { 00071 USB_DBG("intf_nb=%d", intf_nb); 00072 USB_TEST_ASSERT(intf.count(intf_nb) > 0); 00073 INTERFACE* inter = intf[intf_nb]; 00074 for (int i = 0; i < inter->ep.size(); i++) { 00075 if ((inter->ep[i]->getType() == type) && (inter->ep[i]->getDir() == dir)) { 00076 if(index) { 00077 index--; 00078 } else { 00079 return inter->ep[i]; 00080 } 00081 } 00082 } 00083 return NULL; 00084 } 00085 00086 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) { 00087 USB_TEST_ASSERT(intf.count(intf_nb) > 0); 00088 return intf[intf_nb]->ep[index]; 00089 }
Generated on Wed Jul 13 2022 05:41:27 by 1.7.2