Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
USBEndpoint.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef USBENDPOINT_H 00018 #define USBENDPOINT_H 00019 00020 #include "Callback.h" 00021 #include "USBHostTypes.h" 00022 #include "rtos.h" 00023 00024 class USBDeviceConnected; 00025 00026 /** 00027 * USBEndpoint class 00028 */ 00029 class USBEndpoint 00030 { 00031 public: 00032 /** 00033 * Constructor 00034 */ 00035 USBEndpoint() { 00036 state = USB_TYPE_FREE; 00037 nextEp = NULL; 00038 }; 00039 00040 /** 00041 * Initialize an endpoint 00042 * 00043 * @param hced hced associated to the endpoint 00044 * @param type endpoint type 00045 * @param dir endpoint direction 00046 * @param size endpoint size 00047 * @param ep_number endpoint number 00048 * @param td_list array of two allocated transfer descriptors 00049 */ 00050 00051 void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); 00052 00053 /** 00054 * Set next token. Warning: only useful for the control endpoint 00055 * 00056 * @param token IN, OUT or SETUP token 00057 */ 00058 void setNextToken(uint32_t token); 00059 00060 /** 00061 * Queue an endpoint 00062 * 00063 * @param endpoint endpoint which will be queued in the linked list 00064 */ 00065 void queueEndpoint(USBEndpoint * endpoint); 00066 00067 00068 /** 00069 * Queue a transfer on the endpoint 00070 */ 00071 USB_TYPE queueTransfer(); 00072 00073 /** 00074 * Unqueue a transfer from the endpoint 00075 * 00076 * @param td hctd which will be unqueued 00077 */ 00078 void unqueueTransfer(volatile HCTD * td); 00079 00080 /** 00081 * Attach a member function to call when a transfer is finished 00082 * 00083 * @param tptr pointer to the object to call the member function on 00084 * @param mptr pointer to the member function to be called 00085 */ 00086 template<typename T> 00087 inline void attach(T* tptr, void (T::*mptr)(void)) { 00088 if((mptr != NULL) && (tptr != NULL)) { 00089 rx.attach(tptr, mptr); 00090 } 00091 } 00092 00093 /** 00094 * Attach a callback called when a transfer is finished 00095 * 00096 * @param fptr function pointer 00097 */ 00098 inline void attach(void (*fptr)(void)) { 00099 if(fptr != NULL) { 00100 rx.attach(fptr); 00101 } 00102 } 00103 00104 /** 00105 * Call the handler associted to the end of a transfer 00106 */ 00107 inline void call() { 00108 if (rx) 00109 rx.call(); 00110 }; 00111 00112 00113 // setters 00114 inline void setState(USB_TYPE st) { state = st; } 00115 void setState(uint8_t st); 00116 void setDeviceAddress(uint8_t addr); 00117 inline void setLengthTransferred(int len) { transferred = len; }; 00118 void setSpeed(uint8_t speed); 00119 void setSize(uint32_t size); 00120 inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } 00121 inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; 00122 00123 // getters 00124 const char * getStateString(); 00125 inline USB_TYPE getState() { return state; } 00126 inline ENDPOINT_TYPE getType() { return type; }; 00127 #ifdef USBHOST_OTHER 00128 inline uint8_t getDeviceAddress() { return device_address; }; 00129 inline uint32_t getSize() { return size; }; 00130 #else 00131 inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; 00132 inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; 00133 inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; 00134 #endif 00135 inline int getLengthTransferred() { return transferred; } 00136 inline uint8_t * getBufStart() { return buf_start; } 00137 inline uint8_t getAddress(){ return address; }; 00138 inline volatile HCTD** getTDList() { return td_list; }; 00139 inline volatile HCED * getHCED() { return hced; }; 00140 inline ENDPOINT_DIRECTION getDir() { return dir; } 00141 inline volatile HCTD * getProcessedTD() { return td_current; }; 00142 inline volatile HCTD* getNextTD() { return td_current; }; 00143 inline bool isSetup() { return setup; } 00144 inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; 00145 inline uint8_t getIntfNb() { return intf_nb; }; 00146 00147 USBDeviceConnected * dev; 00148 00149 Queue<uint8_t, 1> ep_queue; 00150 00151 private: 00152 ENDPOINT_TYPE type; 00153 volatile USB_TYPE state; 00154 ENDPOINT_DIRECTION dir; 00155 #ifdef USBHOST_OTHER 00156 uint32_t size; 00157 uint32_t ep_number; 00158 uint32_t speed; 00159 uint8_t device_address; 00160 #endif 00161 bool setup; 00162 00163 uint8_t address; 00164 00165 int transfer_len; 00166 int transferred; 00167 uint8_t * buf_start; 00168 00169 Callback<void()> rx; 00170 00171 USBEndpoint* nextEp; 00172 00173 // USBEndpoint descriptor 00174 volatile HCED * hced; 00175 00176 volatile HCTD * td_list[2]; 00177 volatile HCTD * td_current; 00178 volatile HCTD * td_next; 00179 00180 uint8_t intf_nb; 00181 00182 }; 00183 00184 #endif
Generated on Tue Jul 12 2022 11:02:58 by
