test public
Dependencies: HttpServer_snapshot_mbed-os
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 /** Attach a function to call whenever a serial interrupt is generated 00081 * 00082 * @param func A pointer to a void function, or 0 to set as none 00083 */ 00084 inline void attach(Callback<void()> func) { 00085 rx = func; 00086 } 00087 00088 /** Attach a function to call when touch panel int 00089 * 00090 * @param obj pointer to the object to call the member function on 00091 * @param method pointer to the member function to be called 00092 */ 00093 template<typename T> 00094 inline void attach(T* obj, void (T::*method)()) { 00095 // Underlying call thread safe 00096 attach(callback(obj, method)); 00097 } 00098 00099 /** 00100 * Call the handler associted to the end of a transfer 00101 */ 00102 inline void call() { 00103 if (rx) 00104 rx.call(); 00105 }; 00106 00107 00108 // setters 00109 inline void setState(USB_TYPE st) { state = st; } 00110 void setState(uint8_t st); 00111 void setDeviceAddress(uint8_t addr); 00112 inline void setLengthTransferred(int len) { transferred = len; }; 00113 void setSpeed(uint8_t speed); 00114 void setSize(uint32_t size); 00115 inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } 00116 inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; 00117 00118 // getters 00119 const char * getStateString(); 00120 inline USB_TYPE getState() { return state; } 00121 inline ENDPOINT_TYPE getType() { return type; }; 00122 #ifdef USBHOST_OTHER 00123 inline uint8_t getDeviceAddress() { return device_address; }; 00124 inline uint32_t getSize() { return size; }; 00125 #else 00126 inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; 00127 inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; 00128 inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; 00129 #endif 00130 inline int getLengthTransferred() { return transferred; } 00131 inline uint8_t * getBufStart() { return buf_start; } 00132 inline uint8_t getAddress(){ return address; }; 00133 inline volatile HCTD** getTDList() { return td_list; }; 00134 inline volatile HCED * getHCED() { return hced; }; 00135 inline ENDPOINT_DIRECTION getDir() { return dir; } 00136 inline volatile HCTD * getProcessedTD() { return td_current; }; 00137 inline volatile HCTD* getNextTD() { return td_current; }; 00138 inline bool isSetup() { return setup; } 00139 inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; 00140 inline uint8_t getIntfNb() { return intf_nb; }; 00141 00142 USBDeviceConnected * dev; 00143 00144 Queue<uint8_t, 1> ep_queue; 00145 00146 private: 00147 ENDPOINT_TYPE type; 00148 volatile USB_TYPE state; 00149 ENDPOINT_DIRECTION dir; 00150 #ifdef USBHOST_OTHER 00151 uint32_t size; 00152 uint32_t ep_number; 00153 uint32_t speed; 00154 uint8_t device_address; 00155 #endif 00156 bool setup; 00157 00158 uint8_t address; 00159 00160 int transfer_len; 00161 int transferred; 00162 uint8_t * buf_start; 00163 00164 Callback<void()> rx; 00165 00166 USBEndpoint* nextEp; 00167 00168 // USBEndpoint descriptor 00169 volatile HCED * hced; 00170 00171 volatile HCTD * td_list[2]; 00172 volatile HCTD * td_current; 00173 volatile HCTD * td_next; 00174 00175 uint8_t intf_nb; 00176 00177 }; 00178 00179 #endif
Generated on Wed Jul 13 2022 05:33:37 by 1.7.2