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