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.h@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 |
---|---|---|---|
va009039 | 12:b91fdea8c0a7 | 1 | /* mbed USBHost Library |
va009039 | 12:b91fdea8c0a7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 12:b91fdea8c0a7 | 3 | * |
va009039 | 12:b91fdea8c0a7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 12:b91fdea8c0a7 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 12:b91fdea8c0a7 | 6 | * You may obtain a copy of the License at |
va009039 | 12:b91fdea8c0a7 | 7 | * |
va009039 | 12:b91fdea8c0a7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 12:b91fdea8c0a7 | 9 | * |
va009039 | 12:b91fdea8c0a7 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 12:b91fdea8c0a7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 12:b91fdea8c0a7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 12:b91fdea8c0a7 | 13 | * See the License for the specific language governing permissions and |
va009039 | 12:b91fdea8c0a7 | 14 | * limitations under the License. |
va009039 | 12:b91fdea8c0a7 | 15 | */ |
va009039 | 12:b91fdea8c0a7 | 16 | #pragma once |
va009039 | 12:b91fdea8c0a7 | 17 | |
va009039 | 12:b91fdea8c0a7 | 18 | #include "USBEndpoint.h" |
va009039 | 12:b91fdea8c0a7 | 19 | #include "USBHostConf.h" |
va009039 | 12:b91fdea8c0a7 | 20 | #include "myvector.h" |
va009039 | 12:b91fdea8c0a7 | 21 | #include "mymap.h" |
va009039 | 12:b91fdea8c0a7 | 22 | |
va009039 | 12:b91fdea8c0a7 | 23 | class USBEndpoint; |
va009039 | 12:b91fdea8c0a7 | 24 | |
va009039 | 12:b91fdea8c0a7 | 25 | struct INTERFACE { |
va009039 | 12:b91fdea8c0a7 | 26 | INTERFACE(uint8_t _class, uint8_t _subclass, uint8_t _protocol) { |
va009039 | 12:b91fdea8c0a7 | 27 | intf_class = _class; |
va009039 | 12:b91fdea8c0a7 | 28 | intf_subclass = _subclass; |
va009039 | 12:b91fdea8c0a7 | 29 | intf_protocol = _protocol; |
va009039 | 12:b91fdea8c0a7 | 30 | } |
va009039 | 12:b91fdea8c0a7 | 31 | uint8_t intf_class; |
va009039 | 12:b91fdea8c0a7 | 32 | uint8_t intf_subclass; |
va009039 | 12:b91fdea8c0a7 | 33 | uint8_t intf_protocol; |
DieterGraef | 24:5396b6a93262 | 34 | myvector<USBEndpoint*>ep; |
DieterGraef | 24:5396b6a93262 | 35 | }; |
va009039 | 12:b91fdea8c0a7 | 36 | |
va009039 | 12:b91fdea8c0a7 | 37 | /** |
va009039 | 12:b91fdea8c0a7 | 38 | * USBDeviceConnected class |
va009039 | 12:b91fdea8c0a7 | 39 | */ |
va009039 | 12:b91fdea8c0a7 | 40 | class USBDeviceConnected { |
va009039 | 12:b91fdea8c0a7 | 41 | public: |
va009039 | 12:b91fdea8c0a7 | 42 | |
va009039 | 12:b91fdea8c0a7 | 43 | /** |
va009039 | 12:b91fdea8c0a7 | 44 | * Constructor |
va009039 | 12:b91fdea8c0a7 | 45 | */ |
va009039 | 12:b91fdea8c0a7 | 46 | USBDeviceConnected(); |
va009039 | 12:b91fdea8c0a7 | 47 | |
va009039 | 12:b91fdea8c0a7 | 48 | /** |
va009039 | 12:b91fdea8c0a7 | 49 | * Attach an USBEndpoint to this device |
va009039 | 12:b91fdea8c0a7 | 50 | * |
va009039 | 12:b91fdea8c0a7 | 51 | * @param intf_nb interface number |
va009039 | 12:b91fdea8c0a7 | 52 | * @param ep pointeur on the USBEndpoint which will be attached |
va009039 | 12:b91fdea8c0a7 | 53 | * @returns true if successful, false otherwise |
va009039 | 12:b91fdea8c0a7 | 54 | */ |
va009039 | 12:b91fdea8c0a7 | 55 | bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); |
va009039 | 12:b91fdea8c0a7 | 56 | |
va009039 | 12:b91fdea8c0a7 | 57 | /** |
va009039 | 12:b91fdea8c0a7 | 58 | * Retrieve an USBEndpoint by its TYPE and DIRECTION |
va009039 | 12:b91fdea8c0a7 | 59 | * |
va009039 | 12:b91fdea8c0a7 | 60 | * @param intf_nb the interface on which to lookup the USBEndpoint |
va009039 | 12:b91fdea8c0a7 | 61 | * @param type type of the USBEndpoint looked for |
va009039 | 12:b91fdea8c0a7 | 62 | * @param dir direction of the USBEndpoint looked for |
va009039 | 12:b91fdea8c0a7 | 63 | * @param index the index of the USBEndpoint whitin the interface |
va009039 | 12:b91fdea8c0a7 | 64 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
va009039 | 12:b91fdea8c0a7 | 65 | */ |
va009039 | 12:b91fdea8c0a7 | 66 | USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); |
va009039 | 12:b91fdea8c0a7 | 67 | |
va009039 | 12:b91fdea8c0a7 | 68 | /** |
va009039 | 12:b91fdea8c0a7 | 69 | * Retrieve an USBEndpoint by its index |
va009039 | 12:b91fdea8c0a7 | 70 | * |
va009039 | 12:b91fdea8c0a7 | 71 | * @param intf_nb interface number |
va009039 | 12:b91fdea8c0a7 | 72 | * @param index index of the USBEndpoint |
va009039 | 12:b91fdea8c0a7 | 73 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
va009039 | 12:b91fdea8c0a7 | 74 | */ |
va009039 | 12:b91fdea8c0a7 | 75 | USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); |
va009039 | 12:b91fdea8c0a7 | 76 | |
va009039 | 12:b91fdea8c0a7 | 77 | /** |
va009039 | 12:b91fdea8c0a7 | 78 | * Add a new interface to this device |
va009039 | 12:b91fdea8c0a7 | 79 | * |
va009039 | 12:b91fdea8c0a7 | 80 | * @param intf_nb interface number |
va009039 | 12:b91fdea8c0a7 | 81 | * @param intf_class interface class |
va009039 | 12:b91fdea8c0a7 | 82 | * @param intf_subclass interface subclass |
va009039 | 12:b91fdea8c0a7 | 83 | * @param intf_protocol interface protocol |
va009039 | 12:b91fdea8c0a7 | 84 | * @returns true if successful, false otherwise |
va009039 | 12:b91fdea8c0a7 | 85 | */ |
va009039 | 12:b91fdea8c0a7 | 86 | bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); |
va009039 | 12:b91fdea8c0a7 | 87 | |
va009039 | 12:b91fdea8c0a7 | 88 | /** |
va009039 | 12:b91fdea8c0a7 | 89 | * Disconnect the device by calling a callback function registered by a driver |
va009039 | 12:b91fdea8c0a7 | 90 | */ |
va009039 | 12:b91fdea8c0a7 | 91 | void disconnect(); |
va009039 | 12:b91fdea8c0a7 | 92 | |
va009039 | 12:b91fdea8c0a7 | 93 | void init(USBDeviceConnected* parent, uint8_t _port, bool _lowSpeed); |
va009039 | 12:b91fdea8c0a7 | 94 | void setAddress(uint8_t addr_) { addr = addr_; }; |
va009039 | 12:b91fdea8c0a7 | 95 | void setVid(uint16_t vid_) { vid = vid_; }; |
va009039 | 12:b91fdea8c0a7 | 96 | void setPid(uint16_t pid_) { pid = pid_; }; |
va009039 | 12:b91fdea8c0a7 | 97 | void setClass(uint8_t device_class_) { device_class = device_class_; } |
va009039 | 12:b91fdea8c0a7 | 98 | void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; |
va009039 | 12:b91fdea8c0a7 | 99 | void setProtocol(uint8_t pr) { proto = pr; }; |
va009039 | 12:b91fdea8c0a7 | 100 | void setEnumerated() { enumerated = true; }; |
va009039 | 12:b91fdea8c0a7 | 101 | void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; |
va009039 | 12:b91fdea8c0a7 | 102 | void setSpeed(bool _lowSpeed) { lowSpeed = _lowSpeed; } |
va009039 | 12:b91fdea8c0a7 | 103 | void setName(const char * name_, uint8_t intf_nb) { return; }; |
va009039 | 12:b91fdea8c0a7 | 104 | void setEpCtl(USBEndpoint* ep) { ep_ctl = ep; } |
va009039 | 12:b91fdea8c0a7 | 105 | |
va009039 | 12:b91fdea8c0a7 | 106 | static int getNewAddress() { |
va009039 | 12:b91fdea8c0a7 | 107 | static int addr = 1; |
va009039 | 12:b91fdea8c0a7 | 108 | return addr++; |
va009039 | 12:b91fdea8c0a7 | 109 | } |
va009039 | 12:b91fdea8c0a7 | 110 | uint8_t getAddress() { return addr; }; |
va009039 | 12:b91fdea8c0a7 | 111 | uint16_t getVid() { return vid; }; |
va009039 | 12:b91fdea8c0a7 | 112 | uint16_t getPid() { return pid; }; |
va009039 | 12:b91fdea8c0a7 | 113 | uint8_t getClass() { return device_class; }; |
va009039 | 12:b91fdea8c0a7 | 114 | bool getSpeed() { return lowSpeed; } |
va009039 | 12:b91fdea8c0a7 | 115 | bool isEnumerated() { return enumerated; }; |
va009039 | 12:b91fdea8c0a7 | 116 | USBEndpoint* getEpCtl() { return ep_ctl; } |
va009039 | 12:b91fdea8c0a7 | 117 | |
va009039 | 12:b91fdea8c0a7 | 118 | private: |
va009039 | 12:b91fdea8c0a7 | 119 | USBDeviceConnected* hub_parent; |
va009039 | 12:b91fdea8c0a7 | 120 | mymap<int,INTERFACE*>intf; |
va009039 | 12:b91fdea8c0a7 | 121 | uint8_t port; |
va009039 | 12:b91fdea8c0a7 | 122 | uint16_t vid; |
va009039 | 12:b91fdea8c0a7 | 123 | uint16_t pid; |
va009039 | 12:b91fdea8c0a7 | 124 | uint8_t addr; |
va009039 | 12:b91fdea8c0a7 | 125 | uint8_t device_class; |
va009039 | 12:b91fdea8c0a7 | 126 | uint8_t device_subclass; |
va009039 | 12:b91fdea8c0a7 | 127 | uint8_t proto; |
va009039 | 12:b91fdea8c0a7 | 128 | bool lowSpeed; |
va009039 | 12:b91fdea8c0a7 | 129 | bool enumerated; |
va009039 | 12:b91fdea8c0a7 | 130 | uint8_t nb_interf; |
va009039 | 12:b91fdea8c0a7 | 131 | USBEndpoint* ep_ctl; |
va009039 | 12:b91fdea8c0a7 | 132 | void init(); |
va009039 | 12:b91fdea8c0a7 | 133 | }; |