only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
USBHost/USBDeviceConnected.h@0:dae1ac0c0a7b, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:33:53 2019 +0000
- Revision:
- 0:dae1ac0c0a7b
only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:dae1ac0c0a7b | 1 | /* mbed USBHost Library |
kenjiArai | 0:dae1ac0c0a7b | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 0:dae1ac0c0a7b | 3 | * |
kenjiArai | 0:dae1ac0c0a7b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:dae1ac0c0a7b | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:dae1ac0c0a7b | 6 | * You may obtain a copy of the License at |
kenjiArai | 0:dae1ac0c0a7b | 7 | * |
kenjiArai | 0:dae1ac0c0a7b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:dae1ac0c0a7b | 9 | * |
kenjiArai | 0:dae1ac0c0a7b | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:dae1ac0c0a7b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:dae1ac0c0a7b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:dae1ac0c0a7b | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 0:dae1ac0c0a7b | 14 | * limitations under the License. |
kenjiArai | 0:dae1ac0c0a7b | 15 | */ |
kenjiArai | 0:dae1ac0c0a7b | 16 | |
kenjiArai | 0:dae1ac0c0a7b | 17 | #ifndef USBDEVICECONNECTED_H |
kenjiArai | 0:dae1ac0c0a7b | 18 | #define USBDEVICECONNECTED_H |
kenjiArai | 0:dae1ac0c0a7b | 19 | |
kenjiArai | 0:dae1ac0c0a7b | 20 | #include "stdint.h" |
kenjiArai | 0:dae1ac0c0a7b | 21 | #include "USBEndpoint.h" |
kenjiArai | 0:dae1ac0c0a7b | 22 | #include "USBHostConf.h" |
kenjiArai | 0:dae1ac0c0a7b | 23 | #include "rtos.h" |
kenjiArai | 0:dae1ac0c0a7b | 24 | #include "Callback.h" |
kenjiArai | 0:dae1ac0c0a7b | 25 | |
kenjiArai | 0:dae1ac0c0a7b | 26 | class USBHostHub; |
kenjiArai | 0:dae1ac0c0a7b | 27 | |
kenjiArai | 0:dae1ac0c0a7b | 28 | typedef struct { |
kenjiArai | 0:dae1ac0c0a7b | 29 | bool in_use; |
kenjiArai | 0:dae1ac0c0a7b | 30 | uint8_t nb_endpoint; |
kenjiArai | 0:dae1ac0c0a7b | 31 | uint8_t intf_class; |
kenjiArai | 0:dae1ac0c0a7b | 32 | uint8_t intf_subclass; |
kenjiArai | 0:dae1ac0c0a7b | 33 | uint8_t intf_protocol; |
kenjiArai | 0:dae1ac0c0a7b | 34 | USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; |
kenjiArai | 0:dae1ac0c0a7b | 35 | Callback<void()> detach; |
kenjiArai | 0:dae1ac0c0a7b | 36 | char name[10]; |
kenjiArai | 0:dae1ac0c0a7b | 37 | } INTERFACE; |
kenjiArai | 0:dae1ac0c0a7b | 38 | |
kenjiArai | 0:dae1ac0c0a7b | 39 | /** |
kenjiArai | 0:dae1ac0c0a7b | 40 | * USBDeviceConnected class |
kenjiArai | 0:dae1ac0c0a7b | 41 | */ |
kenjiArai | 0:dae1ac0c0a7b | 42 | class USBDeviceConnected |
kenjiArai | 0:dae1ac0c0a7b | 43 | { |
kenjiArai | 0:dae1ac0c0a7b | 44 | public: |
kenjiArai | 0:dae1ac0c0a7b | 45 | |
kenjiArai | 0:dae1ac0c0a7b | 46 | /** |
kenjiArai | 0:dae1ac0c0a7b | 47 | * Constructor |
kenjiArai | 0:dae1ac0c0a7b | 48 | */ |
kenjiArai | 0:dae1ac0c0a7b | 49 | USBDeviceConnected(); |
kenjiArai | 0:dae1ac0c0a7b | 50 | |
kenjiArai | 0:dae1ac0c0a7b | 51 | /** |
kenjiArai | 0:dae1ac0c0a7b | 52 | * Attach an USBEndpoint to this device |
kenjiArai | 0:dae1ac0c0a7b | 53 | * |
kenjiArai | 0:dae1ac0c0a7b | 54 | * @param intf_nb interface number |
kenjiArai | 0:dae1ac0c0a7b | 55 | * @param ep pointeur on the USBEndpoint which will be attached |
kenjiArai | 0:dae1ac0c0a7b | 56 | * @returns true if successful, false otherwise |
kenjiArai | 0:dae1ac0c0a7b | 57 | */ |
kenjiArai | 0:dae1ac0c0a7b | 58 | bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); |
kenjiArai | 0:dae1ac0c0a7b | 59 | |
kenjiArai | 0:dae1ac0c0a7b | 60 | /** |
kenjiArai | 0:dae1ac0c0a7b | 61 | * Retrieve an USBEndpoint by its TYPE and DIRECTION |
kenjiArai | 0:dae1ac0c0a7b | 62 | * |
kenjiArai | 0:dae1ac0c0a7b | 63 | * @param intf_nb the interface on which to lookup the USBEndpoint |
kenjiArai | 0:dae1ac0c0a7b | 64 | * @param type type of the USBEndpoint looked for |
kenjiArai | 0:dae1ac0c0a7b | 65 | * @param dir direction of the USBEndpoint looked for |
kenjiArai | 0:dae1ac0c0a7b | 66 | * @param index the index of the USBEndpoint whitin the interface |
kenjiArai | 0:dae1ac0c0a7b | 67 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
kenjiArai | 0:dae1ac0c0a7b | 68 | */ |
kenjiArai | 0:dae1ac0c0a7b | 69 | USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); |
kenjiArai | 0:dae1ac0c0a7b | 70 | |
kenjiArai | 0:dae1ac0c0a7b | 71 | /** |
kenjiArai | 0:dae1ac0c0a7b | 72 | * Retrieve an USBEndpoint by its index |
kenjiArai | 0:dae1ac0c0a7b | 73 | * |
kenjiArai | 0:dae1ac0c0a7b | 74 | * @param intf_nb interface number |
kenjiArai | 0:dae1ac0c0a7b | 75 | * @param index index of the USBEndpoint |
kenjiArai | 0:dae1ac0c0a7b | 76 | * @returns pointer on the USBEndpoint if found, NULL otherwise |
kenjiArai | 0:dae1ac0c0a7b | 77 | */ |
kenjiArai | 0:dae1ac0c0a7b | 78 | USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); |
kenjiArai | 0:dae1ac0c0a7b | 79 | |
kenjiArai | 0:dae1ac0c0a7b | 80 | /** |
kenjiArai | 0:dae1ac0c0a7b | 81 | * Add a new interface to this device |
kenjiArai | 0:dae1ac0c0a7b | 82 | * |
kenjiArai | 0:dae1ac0c0a7b | 83 | * @param intf_nb interface number |
kenjiArai | 0:dae1ac0c0a7b | 84 | * @param intf_class interface class |
kenjiArai | 0:dae1ac0c0a7b | 85 | * @param intf_subclass interface subclass |
kenjiArai | 0:dae1ac0c0a7b | 86 | * @param intf_protocol interface protocol |
kenjiArai | 0:dae1ac0c0a7b | 87 | * @returns true if successful, false otherwise |
kenjiArai | 0:dae1ac0c0a7b | 88 | */ |
kenjiArai | 0:dae1ac0c0a7b | 89 | bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); |
kenjiArai | 0:dae1ac0c0a7b | 90 | |
kenjiArai | 0:dae1ac0c0a7b | 91 | /** |
kenjiArai | 0:dae1ac0c0a7b | 92 | * Get a specific interface |
kenjiArai | 0:dae1ac0c0a7b | 93 | * |
kenjiArai | 0:dae1ac0c0a7b | 94 | * @param index index of the interface to be fetched |
kenjiArai | 0:dae1ac0c0a7b | 95 | * @returns interface |
kenjiArai | 0:dae1ac0c0a7b | 96 | */ |
kenjiArai | 0:dae1ac0c0a7b | 97 | INTERFACE * getInterface(uint8_t index); |
kenjiArai | 0:dae1ac0c0a7b | 98 | |
kenjiArai | 0:dae1ac0c0a7b | 99 | /** |
kenjiArai | 0:dae1ac0c0a7b | 100 | * Attach a member function to call when a the device has been disconnected |
kenjiArai | 0:dae1ac0c0a7b | 101 | * |
kenjiArai | 0:dae1ac0c0a7b | 102 | * @param intf_nb interface number |
kenjiArai | 0:dae1ac0c0a7b | 103 | * @param tptr pointer to the object to call the member function on |
kenjiArai | 0:dae1ac0c0a7b | 104 | * @param mptr pointer to the member function to be called |
kenjiArai | 0:dae1ac0c0a7b | 105 | */ |
kenjiArai | 0:dae1ac0c0a7b | 106 | template<typename T> |
kenjiArai | 0:dae1ac0c0a7b | 107 | inline void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { |
kenjiArai | 0:dae1ac0c0a7b | 108 | if ((mptr != NULL) && (tptr != NULL)) { |
kenjiArai | 0:dae1ac0c0a7b | 109 | intf[intf_nb].detach = callback(tptr, mptr); |
kenjiArai | 0:dae1ac0c0a7b | 110 | } |
kenjiArai | 0:dae1ac0c0a7b | 111 | } |
kenjiArai | 0:dae1ac0c0a7b | 112 | |
kenjiArai | 0:dae1ac0c0a7b | 113 | /** |
kenjiArai | 0:dae1ac0c0a7b | 114 | * Attach a callback called when the device has been disconnected |
kenjiArai | 0:dae1ac0c0a7b | 115 | * |
kenjiArai | 0:dae1ac0c0a7b | 116 | * @param intf_nb interface number |
kenjiArai | 0:dae1ac0c0a7b | 117 | * @param fn function pointer |
kenjiArai | 0:dae1ac0c0a7b | 118 | */ |
kenjiArai | 0:dae1ac0c0a7b | 119 | inline void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { |
kenjiArai | 0:dae1ac0c0a7b | 120 | if (fn != NULL) { |
kenjiArai | 0:dae1ac0c0a7b | 121 | intf[intf_nb].detach = fn; |
kenjiArai | 0:dae1ac0c0a7b | 122 | } |
kenjiArai | 0:dae1ac0c0a7b | 123 | } |
kenjiArai | 0:dae1ac0c0a7b | 124 | |
kenjiArai | 0:dae1ac0c0a7b | 125 | /** |
kenjiArai | 0:dae1ac0c0a7b | 126 | * Disconnect the device by calling a callback function registered by a driver |
kenjiArai | 0:dae1ac0c0a7b | 127 | */ |
kenjiArai | 0:dae1ac0c0a7b | 128 | void disconnect(); |
kenjiArai | 0:dae1ac0c0a7b | 129 | |
kenjiArai | 0:dae1ac0c0a7b | 130 | // setters |
kenjiArai | 0:dae1ac0c0a7b | 131 | void init(uint8_t hub, uint8_t port, bool lowSpeed); |
kenjiArai | 0:dae1ac0c0a7b | 132 | inline void setAddress(uint8_t addr_) { addr = addr_; }; |
kenjiArai | 0:dae1ac0c0a7b | 133 | inline void setVid(uint16_t vid_) { vid = vid_; }; |
kenjiArai | 0:dae1ac0c0a7b | 134 | inline void setPid(uint16_t pid_) { pid = pid_; }; |
kenjiArai | 0:dae1ac0c0a7b | 135 | inline void setClass(uint8_t device_class_) { device_class = device_class_; }; |
kenjiArai | 0:dae1ac0c0a7b | 136 | inline void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; }; |
kenjiArai | 0:dae1ac0c0a7b | 137 | inline void setProtocol(uint8_t pr) { proto = pr; }; |
kenjiArai | 0:dae1ac0c0a7b | 138 | inline void setSizeControlEndpoint(uint32_t size) { sizeControlEndpoint = size; }; |
kenjiArai | 0:dae1ac0c0a7b | 139 | inline void activeAddress(bool active) { activeAddr = active; }; |
kenjiArai | 0:dae1ac0c0a7b | 140 | inline void setEnumerated() { enumerated = true; }; |
kenjiArai | 0:dae1ac0c0a7b | 141 | inline void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; }; |
kenjiArai | 0:dae1ac0c0a7b | 142 | inline void setHubParent(USBHostHub * hub) { hub_parent = hub; }; |
kenjiArai | 0:dae1ac0c0a7b | 143 | inline void setName(const char * name_, uint8_t intf_nb) { strcpy(intf[intf_nb].name, name_); }; |
kenjiArai | 0:dae1ac0c0a7b | 144 | |
kenjiArai | 0:dae1ac0c0a7b | 145 | //getters |
kenjiArai | 0:dae1ac0c0a7b | 146 | inline uint8_t getPort() { return port; }; |
kenjiArai | 0:dae1ac0c0a7b | 147 | inline uint8_t getHub() { return hub_nb; }; |
kenjiArai | 0:dae1ac0c0a7b | 148 | inline uint8_t getAddress() { return addr; }; |
kenjiArai | 0:dae1ac0c0a7b | 149 | inline uint16_t getVid() { return vid; }; |
kenjiArai | 0:dae1ac0c0a7b | 150 | inline uint16_t getPid() { return pid; }; |
kenjiArai | 0:dae1ac0c0a7b | 151 | inline uint8_t getClass() { return device_class; }; |
kenjiArai | 0:dae1ac0c0a7b | 152 | inline uint8_t getSubClass() { return device_subclass; }; |
kenjiArai | 0:dae1ac0c0a7b | 153 | inline uint8_t getProtocol() { return proto; }; |
kenjiArai | 0:dae1ac0c0a7b | 154 | inline bool getSpeed() { return speed; }; |
kenjiArai | 0:dae1ac0c0a7b | 155 | inline uint32_t getSizeControlEndpoint() { return sizeControlEndpoint; }; |
kenjiArai | 0:dae1ac0c0a7b | 156 | inline bool isActiveAddress() { return activeAddr; }; |
kenjiArai | 0:dae1ac0c0a7b | 157 | inline bool isEnumerated() { return enumerated; }; |
kenjiArai | 0:dae1ac0c0a7b | 158 | inline USBHostHub * getHubParent() { return hub_parent; }; |
kenjiArai | 0:dae1ac0c0a7b | 159 | inline uint8_t getNbIntf() { return nb_interf; }; |
kenjiArai | 0:dae1ac0c0a7b | 160 | inline const char * getName(uint8_t intf_nb) { return intf[intf_nb].name; }; |
kenjiArai | 0:dae1ac0c0a7b | 161 | |
kenjiArai | 0:dae1ac0c0a7b | 162 | // in case this device is a hub |
kenjiArai | 0:dae1ac0c0a7b | 163 | USBHostHub * hub; |
kenjiArai | 0:dae1ac0c0a7b | 164 | |
kenjiArai | 0:dae1ac0c0a7b | 165 | private: |
kenjiArai | 0:dae1ac0c0a7b | 166 | USBHostHub * hub_parent; |
kenjiArai | 0:dae1ac0c0a7b | 167 | |
kenjiArai | 0:dae1ac0c0a7b | 168 | INTERFACE intf[MAX_INTF]; |
kenjiArai | 0:dae1ac0c0a7b | 169 | uint32_t sizeControlEndpoint; |
kenjiArai | 0:dae1ac0c0a7b | 170 | uint8_t hub_nb; |
kenjiArai | 0:dae1ac0c0a7b | 171 | uint8_t port; |
kenjiArai | 0:dae1ac0c0a7b | 172 | uint16_t vid; |
kenjiArai | 0:dae1ac0c0a7b | 173 | uint16_t pid; |
kenjiArai | 0:dae1ac0c0a7b | 174 | uint8_t addr; |
kenjiArai | 0:dae1ac0c0a7b | 175 | uint8_t device_class; |
kenjiArai | 0:dae1ac0c0a7b | 176 | uint8_t device_subclass; |
kenjiArai | 0:dae1ac0c0a7b | 177 | uint8_t proto; |
kenjiArai | 0:dae1ac0c0a7b | 178 | bool speed; |
kenjiArai | 0:dae1ac0c0a7b | 179 | volatile bool activeAddr; |
kenjiArai | 0:dae1ac0c0a7b | 180 | volatile bool enumerated; |
kenjiArai | 0:dae1ac0c0a7b | 181 | uint8_t nb_interf; |
kenjiArai | 0:dae1ac0c0a7b | 182 | |
kenjiArai | 0:dae1ac0c0a7b | 183 | void init(); |
kenjiArai | 0:dae1ac0c0a7b | 184 | }; |
kenjiArai | 0:dae1ac0c0a7b | 185 | |
kenjiArai | 0:dae1ac0c0a7b | 186 | #endif |