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