BLE demo for mbed Ported RunningElectronics's SBDBT firmware for BLE. It can communicate with iOS

Dependencies:   FatFileSystem mbed

Fork of BTstack by Norimasa Okamoto

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 #include "Usb_td.h"
00030 
00031 class UsbDevice;
00032 
00033 enum UsbEndpointType
00034 {
00035   USB_CONTROL,
00036   USB_BULK,
00037   USB_INT,
00038   USB_ISO
00039 };
00040 
00041 class UsbEndpoint
00042 {
00043 public:
00044   UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr = -1 );
00045   ~UsbEndpoint();
00046   void UsbEndpoint_iso(UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr);
00047 
00048   void setNextToken(uint32_t token); //Only for control Eps
00049   
00050   UsbErr transfer(volatile uint8_t* buf, uint32_t len); 
00051   UsbErr transfer(uint16_t frame, int count, volatile uint8_t* buf, int len); // for isochronous
00052   int m_itdActive; 
00053   tdqueue <HCITD*> queue_done_itd;
00054   int status(); //return UsbErr or transfered len
00055   
00056   void updateAddr(int addr);
00057   void updateSize(uint16_t size);
00058   
00059   //void setOnCompletion( void(*pCb)completed() );
00060   class CDummy;
00061   template <class T>
00062   void setOnCompletion( T* pCbItem, void (T::*pCbMeth)() )
00063   {
00064     m_pCbItem = (CDummy*) pCbItem;
00065     m_pCbMeth = (void (CDummy::*)()) pCbMeth;
00066   }
00067    
00068 //static void completed(){}
00069 
00070 protected:
00071   void onCompletion();
00072 public:
00073   static void sOnCompletion(uint32_t pTd);
00074   
00075 private:
00076   friend class UsbDevice;
00077 
00078   UsbDevice* m_pDevice;
00079   
00080   bool m_dir;
00081   bool m_setup;
00082   UsbEndpointType m_type;
00083   
00084   //bool m_done;
00085   volatile bool m_result;
00086   volatile int m_status;
00087   
00088   volatile uint32_t m_len;
00089   
00090   volatile uint8_t* m_pBufStartPtr;
00091 
00092   volatile HCED* m_pEd; //Ep descriptor
00093 
00094   volatile HCTD* m_pTdHead; //Head trf descriptor
00095   volatile HCTD* m_pTdTail; //Tail trf descriptor
00096 
00097   CDummy* m_pCbItem;
00098   void (CDummy::*m_pCbMeth)();
00099 };
00100 #endif