Usb read
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
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 #pragma once 00018 #include "FunctionPointer.h" 00019 #include "USBHostTypes.h" 00020 #include "USBDeviceConnected.h" 00021 00022 class USBDeviceConnected; 00023 00024 /** 00025 * USBEndpoint class 00026 */ 00027 class USBEndpoint { 00028 public: 00029 /** 00030 * Constructor 00031 */ 00032 USBEndpoint(USBDeviceConnected* _dev) { 00033 init(CONTROL_ENDPOINT, IN, 8, 0); 00034 dev = _dev; 00035 } 00036 00037 /** 00038 * Initialize an endpoint 00039 * 00040 * @param type endpoint type 00041 * @param dir endpoint direction 00042 * @param size endpoint size 00043 * @param ep_number endpoint number 00044 */ 00045 void init(ENDPOINT_TYPE _type, ENDPOINT_DIRECTION _dir, uint32_t size, uint8_t ep_number) { 00046 type = _type; 00047 dir = _dir; 00048 MaxPacketSize = size; 00049 address = ep_number; 00050 data01_toggle = DATA0; 00051 } 00052 00053 /** 00054 * Attach a member function to call when a transfer is finished 00055 * 00056 * @param tptr pointer to the object to call the member function on 00057 * @param mptr pointer to the member function to be called 00058 */ 00059 template<typename T> 00060 inline void attach(T* tptr, void (T::*mptr)(void)) { 00061 if((mptr != NULL) && (tptr != NULL)) { 00062 rx.attach(tptr, mptr); 00063 } 00064 } 00065 00066 /** 00067 * Attach a callback called when a transfer is finished 00068 * 00069 * @param fptr function pointer 00070 */ 00071 inline void attach(void (*fptr)(void)) { 00072 if(fptr != NULL) { 00073 rx.attach(fptr); 00074 } 00075 } 00076 00077 /** 00078 * Call the handler associted to the end of a transfer 00079 */ 00080 inline void call() { 00081 rx.call(); 00082 }; 00083 00084 void setDevice(USBDeviceConnected* _dev) { dev = _dev; } 00085 void setState(uint8_t st){}; // dummy 00086 void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; } 00087 void setLengthTransferred(int len) { transferred = len; }; 00088 void setAddress(int addr) { address = addr; } 00089 void setSize(int size) { MaxPacketSize = size; } 00090 void setData01(uint8_t data01) { data01_toggle = data01; } 00091 void setNextEndpoint(USBEndpoint* ep) { nextEp = ep; }; 00092 00093 USBDeviceConnected* getDevice() { return dev; } 00094 ENDPOINT_TYPE getType() { return type; }; 00095 int getLengthTransferred() { return transferred; } 00096 uint8_t *getBufStart() { return buf_start; } 00097 int getBufSize() { return buf_size; } 00098 uint8_t getAddress(){ return address; }; 00099 int getSize() { return MaxPacketSize; } 00100 ENDPOINT_DIRECTION getDir() { return dir; } 00101 uint8_t getData01() { return data01_toggle; } 00102 void toggleData01() { 00103 data01_toggle = (data01_toggle == DATA0) ? DATA1 : DATA0; 00104 } 00105 USBEndpoint* nextEndpoint() { return nextEp; }; 00106 00107 private: 00108 ENDPOINT_TYPE type; 00109 ENDPOINT_DIRECTION dir; 00110 USBDeviceConnected* dev; 00111 uint8_t data01_toggle; // DATA0,DATA1 00112 uint8_t address; 00113 int transferred; 00114 uint8_t * buf_start; 00115 int buf_size; 00116 FunctionPointer rx; 00117 int MaxPacketSize; 00118 USBEndpoint* nextEp; 00119 }; 00120 00121 class EndpointQueue { 00122 public: 00123 EndpointQueue():head(NULL),tail(NULL) {} 00124 void push(USBEndpoint* ep) { 00125 if (head) { 00126 tail->setNextEndpoint(ep); 00127 } else { 00128 head = ep; 00129 } 00130 tail = ep; 00131 ep->setNextEndpoint(NULL); 00132 } 00133 USBEndpoint* pop() { 00134 USBEndpoint* ep = head; 00135 if (ep) { 00136 head = ep->nextEndpoint(); 00137 } 00138 return ep; 00139 } 00140 bool empty() { return head == NULL; } 00141 00142 private: 00143 USBEndpoint* head; 00144 USBEndpoint* tail; 00145 };
Generated on Tue Jul 12 2022 19:09:12 by
![doxygen](doxygen.png)