USB host library, support isochronous,bulk,interrupt and control.
Dependents: BaseUsbHost_example BaseJpegDecode_example SimpleJpegDecode_example
Import programBaseUsbHost_example
BaseUsbHost example program
Diff: BaseUsbHost.h
- Revision:
- 1:3b7bc4f87a61
- Parent:
- 0:b7d6879637a8
- Child:
- 2:fe1e62051d88
--- a/BaseUsbHost.h Tue Dec 04 13:29:41 2012 +0000 +++ b/BaseUsbHost.h Wed Dec 05 13:23:06 2012 +0000 @@ -1,4 +1,4 @@ -// BaseUsbHost.h 2012/12/4 +// BaseUsbHost.h 2012/12/5 #ifndef BASE_USB_HOST_H #define BASE_USB_HOST_H @@ -164,10 +164,6 @@ int controlSend(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex=0, const uint8_t* data=NULL, int length=0); int controlReceive(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t* data, int length); // - uint8_t DeviceClass; - uint8_t DeviceSubClass; - uint8_t DeviceProtocol; - // int open(int addr); void setup(HCTD* td, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex=0, uint16_t wLength=0); }; @@ -176,15 +172,15 @@ public: BulkEp(int addr, uint8_t ep, uint16_t size); virtual void irqWdhHandler(HCTD* td) {m_queue.put(td);} - int read(uint8_t* buf, int len, int millisec=osWaitForever); - int write(const uint8_t* buf, int len, int millisec=osWaitForever); + int bulkSend(const uint8_t* buf, int len, int millisec=osWaitForever); + int bulkReceive(uint8_t* buf, int len, int millisec=osWaitForever); }; class InterruptEp : public BaseEp { public: InterruptEp(int addr, uint8_t ep, uint16_t size, int lowSpeed=0); + int interruptReceive(uint8_t* buf, int len, int millisec=osWaitForever); virtual void irqWdhHandler(HCTD* td) {m_queue.put(td);} - int read(uint8_t* buf, int len, int millisec=osWaitForever); }; class IsochronousEp : public BaseEp { @@ -192,7 +188,8 @@ IsochronousEp(int addr, uint8_t ep, uint16_t size); virtual void irqWdhHandler(HCTD* td); void reset(); - HCITD* read(); + HCITD* isochronousReveive(); + int isochronousSend(uint8_t* buf, int len); HCITD* new_HCITD(); HCITD* get_queue_HCITD(uint32_t millisec); int m_itd_queue_count; @@ -201,6 +198,7 @@ int m_FrameCount; // 1-8 }; +// --- HUB -------------------------------------------------- #define MAX_HUB_PORT 4 class UsbHub { @@ -218,5 +216,50 @@ ControlEp* PortEp[MAX_HUB_PORT]; // port endpoint(control) }; +// --- UVC -------------------------------------------------- +#define _30FPS 333333 +#define _25FPS 400000 +#define _20FPS 500000 +#define _15FPS 666666 +#define _10FPS 1000000 +#define _5FPS 2000000 +#define _1FPS 10000000 + +#define SET_CUR 0x01 +#define GET_CUR 0x81 +#define GET_MIN 0x82 +#define GET_MAX 0x83 +#define GET_RES 0x84 +#define GET_LEN 0x85 +#define GET_INFO 0x86 +#define GET_DEF 0x87 + +#define VS_PROBE_CONTROL 0x01 +#define VS_COMMIT_CONTROL 0x02 + +class BaseUvc { +public: + void poll(); + int Control(int req, int cs, int index, uint8_t* buf, int size); + ControlEp* m_ctlEp; + IsochronousEp* m_isoEp; + uint32_t report_cc_count[16]; // ConditionCode + uint32_t report_ps_cc_count[16]; // Packt Status ConditionCode + // callback + void onResult(uint16_t frame, uint8_t* buf, int len); + void setOnResult( void (*pMethod)(uint16_t, uint8_t*, int) ); + class CDummy; + template<class T> + void setOnResult( T* pItem, void (T::*pMethod)(uint16_t, uint8_t*, int) ) + { + m_pCb = NULL; + m_pCbItem = (CDummy*) pItem; + m_pCbMeth = (void (CDummy::*)(uint16_t, uint8_t*, int)) pMethod; + } + void clearOnResult(); + CDummy* m_pCbItem; + void (CDummy::*m_pCbMeth)(uint16_t, uint8_t*, int); + void (*m_pCb)(uint16_t, uint8_t*, int); +}; #endif //BASE_USB_HOST_H