This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.
Dependencies: mbed DebugLibrary
NetServices/drv/usb/UsbEndpoint.h@1:995212d326ca, 2011-02-11 (annotated)
- Committer:
- Yann
- Date:
- Fri Feb 11 10:17:20 2011 +0000
- Revision:
- 1:995212d326ca
- Parent:
- 0:f30e2135b0db
V0.0.0.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 0:f30e2135b0db | 1 | |
Yann | 0:f30e2135b0db | 2 | /* |
Yann | 0:f30e2135b0db | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
Yann | 0:f30e2135b0db | 4 | |
Yann | 0:f30e2135b0db | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Yann | 0:f30e2135b0db | 6 | of this software and associated documentation files (the "Software"), to deal |
Yann | 0:f30e2135b0db | 7 | in the Software without restriction, including without limitation the rights |
Yann | 0:f30e2135b0db | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Yann | 0:f30e2135b0db | 9 | copies of the Software, and to permit persons to whom the Software is |
Yann | 0:f30e2135b0db | 10 | furnished to do so, subject to the following conditions: |
Yann | 0:f30e2135b0db | 11 | |
Yann | 0:f30e2135b0db | 12 | The above copyright notice and this permission notice shall be included in |
Yann | 0:f30e2135b0db | 13 | all copies or substantial portions of the Software. |
Yann | 0:f30e2135b0db | 14 | |
Yann | 0:f30e2135b0db | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Yann | 0:f30e2135b0db | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Yann | 0:f30e2135b0db | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Yann | 0:f30e2135b0db | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Yann | 0:f30e2135b0db | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Yann | 0:f30e2135b0db | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Yann | 0:f30e2135b0db | 21 | THE SOFTWARE. |
Yann | 0:f30e2135b0db | 22 | */ |
Yann | 0:f30e2135b0db | 23 | |
Yann | 0:f30e2135b0db | 24 | #ifndef USB_ENDPOINT_H |
Yann | 0:f30e2135b0db | 25 | #define USB_ENDPOINT_H |
Yann | 0:f30e2135b0db | 26 | |
Yann | 0:f30e2135b0db | 27 | #include "mbed.h" |
Yann | 0:f30e2135b0db | 28 | #include "UsbInc.h" |
Yann | 0:f30e2135b0db | 29 | |
Yann | 0:f30e2135b0db | 30 | class UsbDevice; |
Yann | 0:f30e2135b0db | 31 | |
Yann | 0:f30e2135b0db | 32 | enum UsbEndpointType |
Yann | 0:f30e2135b0db | 33 | { |
Yann | 0:f30e2135b0db | 34 | USB_CONTROL, |
Yann | 0:f30e2135b0db | 35 | USB_BULK |
Yann | 0:f30e2135b0db | 36 | // USB_INT, |
Yann | 0:f30e2135b0db | 37 | // USB_ISO |
Yann | 0:f30e2135b0db | 38 | }; |
Yann | 0:f30e2135b0db | 39 | |
Yann | 0:f30e2135b0db | 40 | class UsbEndpoint |
Yann | 0:f30e2135b0db | 41 | { |
Yann | 0:f30e2135b0db | 42 | public: |
Yann | 0:f30e2135b0db | 43 | UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr = -1 ); |
Yann | 0:f30e2135b0db | 44 | ~UsbEndpoint(); |
Yann | 0:f30e2135b0db | 45 | |
Yann | 0:f30e2135b0db | 46 | void setNextToken(uint32_t token); //Only for control Eps |
Yann | 0:f30e2135b0db | 47 | |
Yann | 0:f30e2135b0db | 48 | UsbErr transfer(volatile uint8_t* buf, uint32_t len); |
Yann | 0:f30e2135b0db | 49 | |
Yann | 0:f30e2135b0db | 50 | int status(); //return UsbErr or transfered len |
Yann | 0:f30e2135b0db | 51 | |
Yann | 0:f30e2135b0db | 52 | void updateAddr(int addr); |
Yann | 0:f30e2135b0db | 53 | void updateSize(uint16_t size); |
Yann | 0:f30e2135b0db | 54 | |
Yann | 0:f30e2135b0db | 55 | //void setOnCompletion( void(*pCb)completed() ); |
Yann | 0:f30e2135b0db | 56 | class CDummy; |
Yann | 0:f30e2135b0db | 57 | template <class T> |
Yann | 0:f30e2135b0db | 58 | void setOnCompletion( T* pCbItem, void (T::*pCbMeth)() ) |
Yann | 0:f30e2135b0db | 59 | { |
Yann | 0:f30e2135b0db | 60 | m_pCbItem = (CDummy*) pCbItem; |
Yann | 0:f30e2135b0db | 61 | m_pCbMeth = (void (CDummy::*)()) pCbMeth; |
Yann | 0:f30e2135b0db | 62 | } |
Yann | 0:f30e2135b0db | 63 | |
Yann | 0:f30e2135b0db | 64 | //static void completed(){} |
Yann | 0:f30e2135b0db | 65 | |
Yann | 0:f30e2135b0db | 66 | protected: |
Yann | 0:f30e2135b0db | 67 | void onCompletion(); |
Yann | 0:f30e2135b0db | 68 | public: |
Yann | 0:f30e2135b0db | 69 | static void sOnCompletion(uint32_t pTd); |
Yann | 0:f30e2135b0db | 70 | |
Yann | 0:f30e2135b0db | 71 | private: |
Yann | 0:f30e2135b0db | 72 | friend class UsbDevice; |
Yann | 0:f30e2135b0db | 73 | |
Yann | 0:f30e2135b0db | 74 | UsbDevice* m_pDevice; |
Yann | 0:f30e2135b0db | 75 | |
Yann | 0:f30e2135b0db | 76 | bool m_dir; |
Yann | 0:f30e2135b0db | 77 | bool m_setup; |
Yann | 0:f30e2135b0db | 78 | UsbEndpointType m_type; |
Yann | 0:f30e2135b0db | 79 | |
Yann | 0:f30e2135b0db | 80 | //bool m_done; |
Yann | 0:f30e2135b0db | 81 | volatile bool m_result; |
Yann | 0:f30e2135b0db | 82 | volatile int m_status; |
Yann | 0:f30e2135b0db | 83 | |
Yann | 0:f30e2135b0db | 84 | volatile uint32_t m_len; |
Yann | 0:f30e2135b0db | 85 | |
Yann | 0:f30e2135b0db | 86 | volatile uint8_t* m_pBufStartPtr; |
Yann | 0:f30e2135b0db | 87 | |
Yann | 0:f30e2135b0db | 88 | volatile HCED* m_pEd; //Ep descriptor |
Yann | 0:f30e2135b0db | 89 | volatile HCTD* m_pTdHead; //Head trf descriptor |
Yann | 0:f30e2135b0db | 90 | volatile HCTD* m_pTdTail; //Tail trf descriptor |
Yann | 0:f30e2135b0db | 91 | |
Yann | 0:f30e2135b0db | 92 | //static volatile HCED* m_pNextEd; |
Yann | 0:f30e2135b0db | 93 | |
Yann | 0:f30e2135b0db | 94 | CDummy* m_pCbItem; |
Yann | 0:f30e2135b0db | 95 | void (CDummy::*m_pCbMeth)(); |
Yann | 0:f30e2135b0db | 96 | |
Yann | 0:f30e2135b0db | 97 | |
Yann | 0:f30e2135b0db | 98 | static UsbEndpoint* m_pHeadEp; |
Yann | 0:f30e2135b0db | 99 | UsbEndpoint* m_pNextEp; |
Yann | 0:f30e2135b0db | 100 | |
Yann | 0:f30e2135b0db | 101 | }; |
Yann | 0:f30e2135b0db | 102 | |
Yann | 0:f30e2135b0db | 103 | #endif |