Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UsbEndpoint.h Source File

UsbEndpoint.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef USB_ENDPOINT_H
00025 #define USB_ENDPOINT_H
00026 
00027 #include "mbed.h"
00028 #include "UsbInc.h"
00029 
00030 class UsbDevice;
00031 
00032 enum UsbEndpointType
00033 {
00034   USB_CONTROL,
00035   USB_BULK
00036 //  USB_INT,
00037 //  USB_ISO
00038 };
00039 
00040 class UsbEndpoint
00041 {
00042 public:
00043   UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr = -1 );
00044   ~UsbEndpoint();
00045 
00046   void setNextToken(uint32_t token); //Only for control Eps
00047   
00048   UsbErr transfer(volatile uint8_t* buf, uint32_t len); 
00049   
00050   int status(); //return UsbErr or transfered len
00051   
00052   void updateAddr(int addr);
00053   void updateSize(uint16_t size);
00054   
00055   //void setOnCompletion( void(*pCb)completed() );
00056   class CDummy;
00057   template <class T>
00058   void setOnCompletion( T* pCbItem, void (T::*pCbMeth)() )
00059   {
00060     m_pCbItem = (CDummy*) pCbItem;
00061     m_pCbMeth = (void (CDummy::*)()) pCbMeth;
00062   }
00063    
00064 //static void completed(){}
00065 
00066 protected:
00067   void onCompletion();
00068 public:
00069   static void sOnCompletion(uint32_t pTd);
00070   
00071 private:
00072   friend class UsbDevice;
00073 
00074   UsbDevice* m_pDevice;
00075   
00076   bool m_dir;
00077   bool m_setup;
00078   UsbEndpointType m_type;
00079   
00080   //bool m_done;
00081   volatile bool m_result;
00082   volatile int m_status;
00083   
00084   volatile uint32_t m_len;
00085   
00086   volatile uint8_t* m_pBufStartPtr;
00087 
00088   volatile HCED* m_pEd; //Ep descriptor
00089   volatile HCTD* m_pTdHead; //Head trf descriptor
00090   volatile HCTD* m_pTdTail; //Tail trf descriptor
00091   
00092   //static volatile HCED* m_pNextEd;
00093   
00094   CDummy* m_pCbItem;
00095   void (CDummy::*m_pCbMeth)();
00096   
00097   
00098   static UsbEndpoint* m_pHeadEp;
00099   UsbEndpoint* m_pNextEp;
00100   
00101 };
00102 
00103 #endif