only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
USBHost/USBEndpoint.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 USBENDPOINT_H |
kenjiArai | 0:dae1ac0c0a7b | 18 | #define USBENDPOINT_H |
kenjiArai | 0:dae1ac0c0a7b | 19 | |
kenjiArai | 0:dae1ac0c0a7b | 20 | #include "Callback.h" |
kenjiArai | 0:dae1ac0c0a7b | 21 | #include "USBHostTypes.h" |
kenjiArai | 0:dae1ac0c0a7b | 22 | #include "rtos.h" |
kenjiArai | 0:dae1ac0c0a7b | 23 | |
kenjiArai | 0:dae1ac0c0a7b | 24 | class USBDeviceConnected; |
kenjiArai | 0:dae1ac0c0a7b | 25 | |
kenjiArai | 0:dae1ac0c0a7b | 26 | /** |
kenjiArai | 0:dae1ac0c0a7b | 27 | * USBEndpoint class |
kenjiArai | 0:dae1ac0c0a7b | 28 | */ |
kenjiArai | 0:dae1ac0c0a7b | 29 | class USBEndpoint |
kenjiArai | 0:dae1ac0c0a7b | 30 | { |
kenjiArai | 0:dae1ac0c0a7b | 31 | public: |
kenjiArai | 0:dae1ac0c0a7b | 32 | /** |
kenjiArai | 0:dae1ac0c0a7b | 33 | * Constructor |
kenjiArai | 0:dae1ac0c0a7b | 34 | */ |
kenjiArai | 0:dae1ac0c0a7b | 35 | USBEndpoint() { |
kenjiArai | 0:dae1ac0c0a7b | 36 | #ifdef USBHOST_OTHER |
kenjiArai | 0:dae1ac0c0a7b | 37 | speed = false; |
kenjiArai | 0:dae1ac0c0a7b | 38 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 39 | state = USB_TYPE_FREE; |
kenjiArai | 0:dae1ac0c0a7b | 40 | nextEp = NULL; |
kenjiArai | 0:dae1ac0c0a7b | 41 | }; |
kenjiArai | 0:dae1ac0c0a7b | 42 | |
kenjiArai | 0:dae1ac0c0a7b | 43 | /** |
kenjiArai | 0:dae1ac0c0a7b | 44 | * Initialize an endpoint |
kenjiArai | 0:dae1ac0c0a7b | 45 | * |
kenjiArai | 0:dae1ac0c0a7b | 46 | * @param hced hced associated to the endpoint |
kenjiArai | 0:dae1ac0c0a7b | 47 | * @param type endpoint type |
kenjiArai | 0:dae1ac0c0a7b | 48 | * @param dir endpoint direction |
kenjiArai | 0:dae1ac0c0a7b | 49 | * @param size endpoint size |
kenjiArai | 0:dae1ac0c0a7b | 50 | * @param ep_number endpoint number |
kenjiArai | 0:dae1ac0c0a7b | 51 | * @param td_list array of two allocated transfer descriptors |
kenjiArai | 0:dae1ac0c0a7b | 52 | */ |
kenjiArai | 0:dae1ac0c0a7b | 53 | |
kenjiArai | 0:dae1ac0c0a7b | 54 | void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); |
kenjiArai | 0:dae1ac0c0a7b | 55 | |
kenjiArai | 0:dae1ac0c0a7b | 56 | /** |
kenjiArai | 0:dae1ac0c0a7b | 57 | * Set next token. Warning: only useful for the control endpoint |
kenjiArai | 0:dae1ac0c0a7b | 58 | * |
kenjiArai | 0:dae1ac0c0a7b | 59 | * @param token IN, OUT or SETUP token |
kenjiArai | 0:dae1ac0c0a7b | 60 | */ |
kenjiArai | 0:dae1ac0c0a7b | 61 | void setNextToken(uint32_t token); |
kenjiArai | 0:dae1ac0c0a7b | 62 | |
kenjiArai | 0:dae1ac0c0a7b | 63 | /** |
kenjiArai | 0:dae1ac0c0a7b | 64 | * Queue an endpoint |
kenjiArai | 0:dae1ac0c0a7b | 65 | * |
kenjiArai | 0:dae1ac0c0a7b | 66 | * @param endpoint endpoint which will be queued in the linked list |
kenjiArai | 0:dae1ac0c0a7b | 67 | */ |
kenjiArai | 0:dae1ac0c0a7b | 68 | void queueEndpoint(USBEndpoint * endpoint); |
kenjiArai | 0:dae1ac0c0a7b | 69 | |
kenjiArai | 0:dae1ac0c0a7b | 70 | |
kenjiArai | 0:dae1ac0c0a7b | 71 | /** |
kenjiArai | 0:dae1ac0c0a7b | 72 | * Queue a transfer on the endpoint |
kenjiArai | 0:dae1ac0c0a7b | 73 | */ |
kenjiArai | 0:dae1ac0c0a7b | 74 | USB_TYPE queueTransfer(); |
kenjiArai | 0:dae1ac0c0a7b | 75 | |
kenjiArai | 0:dae1ac0c0a7b | 76 | /** |
kenjiArai | 0:dae1ac0c0a7b | 77 | * Unqueue a transfer from the endpoint |
kenjiArai | 0:dae1ac0c0a7b | 78 | * |
kenjiArai | 0:dae1ac0c0a7b | 79 | * @param td hctd which will be unqueued |
kenjiArai | 0:dae1ac0c0a7b | 80 | */ |
kenjiArai | 0:dae1ac0c0a7b | 81 | void unqueueTransfer(volatile HCTD * td); |
kenjiArai | 0:dae1ac0c0a7b | 82 | |
kenjiArai | 0:dae1ac0c0a7b | 83 | /** |
kenjiArai | 0:dae1ac0c0a7b | 84 | * Attach a member function to call when a transfer is finished |
kenjiArai | 0:dae1ac0c0a7b | 85 | * |
kenjiArai | 0:dae1ac0c0a7b | 86 | * @param tptr pointer to the object to call the member function on |
kenjiArai | 0:dae1ac0c0a7b | 87 | * @param mptr pointer to the member function to be called |
kenjiArai | 0:dae1ac0c0a7b | 88 | */ |
kenjiArai | 0:dae1ac0c0a7b | 89 | template<typename T> |
kenjiArai | 0:dae1ac0c0a7b | 90 | inline void attach(T* tptr, void (T::*mptr)(void)) { |
kenjiArai | 0:dae1ac0c0a7b | 91 | if((mptr != NULL) && (tptr != NULL)) { |
kenjiArai | 0:dae1ac0c0a7b | 92 | rx = callback(tptr, mptr); |
kenjiArai | 0:dae1ac0c0a7b | 93 | } |
kenjiArai | 0:dae1ac0c0a7b | 94 | } |
kenjiArai | 0:dae1ac0c0a7b | 95 | |
kenjiArai | 0:dae1ac0c0a7b | 96 | /** |
kenjiArai | 0:dae1ac0c0a7b | 97 | * Attach a callback called when a transfer is finished |
kenjiArai | 0:dae1ac0c0a7b | 98 | * |
kenjiArai | 0:dae1ac0c0a7b | 99 | * @param fptr function pointer |
kenjiArai | 0:dae1ac0c0a7b | 100 | */ |
kenjiArai | 0:dae1ac0c0a7b | 101 | inline void attach(void (*fptr)(void)) { |
kenjiArai | 0:dae1ac0c0a7b | 102 | if(fptr != NULL) { |
kenjiArai | 0:dae1ac0c0a7b | 103 | rx = fptr; |
kenjiArai | 0:dae1ac0c0a7b | 104 | } |
kenjiArai | 0:dae1ac0c0a7b | 105 | } |
kenjiArai | 0:dae1ac0c0a7b | 106 | |
kenjiArai | 0:dae1ac0c0a7b | 107 | /** |
kenjiArai | 0:dae1ac0c0a7b | 108 | * Call the handler associted to the end of a transfer |
kenjiArai | 0:dae1ac0c0a7b | 109 | */ |
kenjiArai | 0:dae1ac0c0a7b | 110 | inline void call() { |
kenjiArai | 0:dae1ac0c0a7b | 111 | if (rx) |
kenjiArai | 0:dae1ac0c0a7b | 112 | rx.call(); |
kenjiArai | 0:dae1ac0c0a7b | 113 | }; |
kenjiArai | 0:dae1ac0c0a7b | 114 | |
kenjiArai | 0:dae1ac0c0a7b | 115 | |
kenjiArai | 0:dae1ac0c0a7b | 116 | // setters |
kenjiArai | 0:dae1ac0c0a7b | 117 | #ifdef USBHOST_OTHER |
kenjiArai | 0:dae1ac0c0a7b | 118 | void setState(USB_TYPE st); |
kenjiArai | 0:dae1ac0c0a7b | 119 | #else |
kenjiArai | 0:dae1ac0c0a7b | 120 | inline void setState(USB_TYPE st) { state = st; } |
kenjiArai | 0:dae1ac0c0a7b | 121 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 122 | void setState(uint8_t st); |
kenjiArai | 0:dae1ac0c0a7b | 123 | void setDeviceAddress(uint8_t addr); |
kenjiArai | 0:dae1ac0c0a7b | 124 | inline void setLengthTransferred(int len) { transferred = len; }; |
kenjiArai | 0:dae1ac0c0a7b | 125 | void setSpeed(uint8_t speed); |
kenjiArai | 0:dae1ac0c0a7b | 126 | void setSize(uint32_t size); |
kenjiArai | 0:dae1ac0c0a7b | 127 | inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } |
kenjiArai | 0:dae1ac0c0a7b | 128 | inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; |
kenjiArai | 0:dae1ac0c0a7b | 129 | |
kenjiArai | 0:dae1ac0c0a7b | 130 | // getters |
kenjiArai | 0:dae1ac0c0a7b | 131 | const char * getStateString(); |
kenjiArai | 0:dae1ac0c0a7b | 132 | inline USB_TYPE getState() { return state; } |
kenjiArai | 0:dae1ac0c0a7b | 133 | inline ENDPOINT_TYPE getType() { return type; }; |
kenjiArai | 0:dae1ac0c0a7b | 134 | #ifdef USBHOST_OTHER |
kenjiArai | 0:dae1ac0c0a7b | 135 | inline uint8_t getDeviceAddress() { return device_address; }; |
kenjiArai | 0:dae1ac0c0a7b | 136 | inline uint32_t getSize() { return size; }; |
kenjiArai | 0:dae1ac0c0a7b | 137 | #else |
kenjiArai | 0:dae1ac0c0a7b | 138 | inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; |
kenjiArai | 0:dae1ac0c0a7b | 139 | inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; |
kenjiArai | 0:dae1ac0c0a7b | 140 | inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; |
kenjiArai | 0:dae1ac0c0a7b | 141 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 142 | inline int getLengthTransferred() { return transferred; } |
kenjiArai | 0:dae1ac0c0a7b | 143 | inline uint8_t * getBufStart() { return buf_start; } |
kenjiArai | 0:dae1ac0c0a7b | 144 | inline uint8_t getAddress(){ return address; }; |
kenjiArai | 0:dae1ac0c0a7b | 145 | inline volatile HCTD** getTDList() { return td_list; }; |
kenjiArai | 0:dae1ac0c0a7b | 146 | inline volatile HCED * getHCED() { return hced; }; |
kenjiArai | 0:dae1ac0c0a7b | 147 | inline ENDPOINT_DIRECTION getDir() { return dir; } |
kenjiArai | 0:dae1ac0c0a7b | 148 | inline volatile HCTD * getProcessedTD() { return td_current; }; |
kenjiArai | 0:dae1ac0c0a7b | 149 | inline volatile HCTD* getNextTD() { return td_current; }; |
kenjiArai | 0:dae1ac0c0a7b | 150 | inline bool isSetup() { return setup; } |
kenjiArai | 0:dae1ac0c0a7b | 151 | inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; |
kenjiArai | 0:dae1ac0c0a7b | 152 | inline uint8_t getIntfNb() { return intf_nb; }; |
kenjiArai | 0:dae1ac0c0a7b | 153 | |
kenjiArai | 0:dae1ac0c0a7b | 154 | USBDeviceConnected * dev; |
kenjiArai | 0:dae1ac0c0a7b | 155 | |
kenjiArai | 0:dae1ac0c0a7b | 156 | Queue<uint8_t, 1> ep_queue; |
kenjiArai | 0:dae1ac0c0a7b | 157 | |
kenjiArai | 0:dae1ac0c0a7b | 158 | private: |
kenjiArai | 0:dae1ac0c0a7b | 159 | ENDPOINT_TYPE type; |
kenjiArai | 0:dae1ac0c0a7b | 160 | volatile USB_TYPE state; |
kenjiArai | 0:dae1ac0c0a7b | 161 | ENDPOINT_DIRECTION dir; |
kenjiArai | 0:dae1ac0c0a7b | 162 | #ifdef USBHOST_OTHER |
kenjiArai | 0:dae1ac0c0a7b | 163 | uint32_t size; |
kenjiArai | 0:dae1ac0c0a7b | 164 | uint32_t ep_number; |
kenjiArai | 0:dae1ac0c0a7b | 165 | uint32_t speed; |
kenjiArai | 0:dae1ac0c0a7b | 166 | uint8_t device_address; |
kenjiArai | 0:dae1ac0c0a7b | 167 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 168 | bool setup; |
kenjiArai | 0:dae1ac0c0a7b | 169 | |
kenjiArai | 0:dae1ac0c0a7b | 170 | uint8_t address; |
kenjiArai | 0:dae1ac0c0a7b | 171 | |
kenjiArai | 0:dae1ac0c0a7b | 172 | int transfer_len; |
kenjiArai | 0:dae1ac0c0a7b | 173 | int transferred; |
kenjiArai | 0:dae1ac0c0a7b | 174 | uint8_t * buf_start; |
kenjiArai | 0:dae1ac0c0a7b | 175 | |
kenjiArai | 0:dae1ac0c0a7b | 176 | Callback<void()> rx; |
kenjiArai | 0:dae1ac0c0a7b | 177 | |
kenjiArai | 0:dae1ac0c0a7b | 178 | USBEndpoint* nextEp; |
kenjiArai | 0:dae1ac0c0a7b | 179 | |
kenjiArai | 0:dae1ac0c0a7b | 180 | // USBEndpoint descriptor |
kenjiArai | 0:dae1ac0c0a7b | 181 | volatile HCED * hced; |
kenjiArai | 0:dae1ac0c0a7b | 182 | |
kenjiArai | 0:dae1ac0c0a7b | 183 | volatile HCTD * td_list[2]; |
kenjiArai | 0:dae1ac0c0a7b | 184 | volatile HCTD * td_current; |
kenjiArai | 0:dae1ac0c0a7b | 185 | volatile HCTD * td_next; |
kenjiArai | 0:dae1ac0c0a7b | 186 | |
kenjiArai | 0:dae1ac0c0a7b | 187 | uint8_t intf_nb; |
kenjiArai | 0:dae1ac0c0a7b | 188 | |
kenjiArai | 0:dae1ac0c0a7b | 189 | }; |
kenjiArai | 0:dae1ac0c0a7b | 190 | |
kenjiArai | 0:dae1ac0c0a7b | 191 | #endif |