Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program
Dependencies: LPC4088-USBHost mbed
EA LPC4088 QSB/LPC1768をUSBホストにしてWebカメラからJPEG画像を読み取るテストプログラムです。
The usage is the same as KL46Z-USBHostC270_example.
使い方はKL46Z-USBHostC270_exampleと同じです。
動作確認: Logitech C270,Logitech Q200R(Qcam Orbit AF)
LPC4088-USBHostC270/USBHostCam.h@1:1bb68ef9aa77, 2014-04-25 (annotated)
- Committer:
- va009039
- Date:
- Fri Apr 25 05:55:06 2014 +0000
- Revision:
- 1:1bb68ef9aa77
- Parent:
- 0:c972ee42b455
update LPC4088-USBHost library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:c972ee42b455 | 1 | // USBHostCam.h |
va009039 | 0:c972ee42b455 | 2 | #include "USBHostConf.h" |
va009039 | 0:c972ee42b455 | 3 | #include "USBHost.h" |
va009039 | 0:c972ee42b455 | 4 | #include "USBIsochronous.h" |
va009039 | 0:c972ee42b455 | 5 | #include "BaseUvc.h" |
va009039 | 0:c972ee42b455 | 6 | #include "decodeMJPEG.h" |
va009039 | 0:c972ee42b455 | 7 | #pragma once |
va009039 | 0:c972ee42b455 | 8 | |
va009039 | 0:c972ee42b455 | 9 | #define _160x120 2 |
va009039 | 0:c972ee42b455 | 10 | #define _176x144 3 |
va009039 | 0:c972ee42b455 | 11 | #define _320x176 4 |
va009039 | 0:c972ee42b455 | 12 | #define _320x240 5 |
va009039 | 0:c972ee42b455 | 13 | #define _352x288 6 |
va009039 | 0:c972ee42b455 | 14 | #define _432x240 7 |
va009039 | 0:c972ee42b455 | 15 | #define _640x480 1 |
va009039 | 0:c972ee42b455 | 16 | #define _544x288 8 |
va009039 | 0:c972ee42b455 | 17 | #define _640x360 9 |
va009039 | 0:c972ee42b455 | 18 | #define _752x416 10 |
va009039 | 0:c972ee42b455 | 19 | #define _800x448 11 |
va009039 | 0:c972ee42b455 | 20 | #define _800x600 12 |
va009039 | 0:c972ee42b455 | 21 | |
va009039 | 0:c972ee42b455 | 22 | #if 0 |
va009039 | 0:c972ee42b455 | 23 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
va009039 | 0:c972ee42b455 | 24 | #else |
va009039 | 0:c972ee42b455 | 25 | #define TEST_ASSERT(A) while(0) |
va009039 | 0:c972ee42b455 | 26 | #endif |
va009039 | 0:c972ee42b455 | 27 | |
va009039 | 0:c972ee42b455 | 28 | |
va009039 | 0:c972ee42b455 | 29 | struct CamInfo { |
va009039 | 0:c972ee42b455 | 30 | uint16_t vid; |
va009039 | 0:c972ee42b455 | 31 | uint16_t pid; |
va009039 | 0:c972ee42b455 | 32 | uint8_t size; |
va009039 | 0:c972ee42b455 | 33 | uint8_t option; |
va009039 | 0:c972ee42b455 | 34 | // |
va009039 | 0:c972ee42b455 | 35 | const char* name; |
va009039 | 0:c972ee42b455 | 36 | uint8_t formatIndex; |
va009039 | 0:c972ee42b455 | 37 | uint8_t frameIndex; |
va009039 | 0:c972ee42b455 | 38 | uint32_t interval; |
va009039 | 0:c972ee42b455 | 39 | uint8_t en; |
va009039 | 0:c972ee42b455 | 40 | uint8_t mps; |
va009039 | 0:c972ee42b455 | 41 | uint8_t if_alt; |
va009039 | 0:c972ee42b455 | 42 | uint8_t frameCount; // ITD frame count 1-8 |
va009039 | 0:c972ee42b455 | 43 | uint8_t queueLimit; // ITD queue limit 1-3 |
va009039 | 0:c972ee42b455 | 44 | }; |
va009039 | 0:c972ee42b455 | 45 | |
va009039 | 0:c972ee42b455 | 46 | /** |
va009039 | 0:c972ee42b455 | 47 | * A class to communicate a Cam |
va009039 | 0:c972ee42b455 | 48 | */ |
va009039 | 0:c972ee42b455 | 49 | class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { |
va009039 | 0:c972ee42b455 | 50 | public: |
va009039 | 0:c972ee42b455 | 51 | /** |
va009039 | 0:c972ee42b455 | 52 | * Constructor |
va009039 | 0:c972ee42b455 | 53 | * |
va009039 | 0:c972ee42b455 | 54 | */ |
va009039 | 0:c972ee42b455 | 55 | USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); |
va009039 | 0:c972ee42b455 | 56 | |
va009039 | 0:c972ee42b455 | 57 | /** |
va009039 | 0:c972ee42b455 | 58 | * Check if a Cam device is connected |
va009039 | 0:c972ee42b455 | 59 | * |
va009039 | 0:c972ee42b455 | 60 | * @return true if a Cam device is connected |
va009039 | 0:c972ee42b455 | 61 | */ |
va009039 | 0:c972ee42b455 | 62 | bool connected(); |
va009039 | 0:c972ee42b455 | 63 | |
va009039 | 0:c972ee42b455 | 64 | /** |
va009039 | 0:c972ee42b455 | 65 | * Try to connect to a Cam device |
va009039 | 0:c972ee42b455 | 66 | * |
va009039 | 0:c972ee42b455 | 67 | * @return true if connection was successful |
va009039 | 0:c972ee42b455 | 68 | */ |
va009039 | 0:c972ee42b455 | 69 | bool connect(); |
va009039 | 0:c972ee42b455 | 70 | |
va009039 | 0:c972ee42b455 | 71 | /** |
va009039 | 0:c972ee42b455 | 72 | * read jpeg image |
va009039 | 0:c972ee42b455 | 73 | * |
va009039 | 0:c972ee42b455 | 74 | * @param buf read buffer |
va009039 | 0:c972ee42b455 | 75 | * @param size buffer size |
va009039 | 0:c972ee42b455 | 76 | * @param timeout_ms timeout default 15sec |
va009039 | 0:c972ee42b455 | 77 | * @return jpeg size if read success else -1 |
va009039 | 0:c972ee42b455 | 78 | */ |
va009039 | 0:c972ee42b455 | 79 | int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); |
va009039 | 0:c972ee42b455 | 80 | |
va009039 | 0:c972ee42b455 | 81 | protected: |
va009039 | 0:c972ee42b455 | 82 | //From IUSBEnumerator |
va009039 | 0:c972ee42b455 | 83 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 | 0:c972ee42b455 | 84 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
va009039 | 0:c972ee42b455 | 85 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 | 0:c972ee42b455 | 86 | |
va009039 | 0:c972ee42b455 | 87 | private: |
va009039 | 0:c972ee42b455 | 88 | bool dev_connected; |
va009039 | 0:c972ee42b455 | 89 | |
va009039 | 0:c972ee42b455 | 90 | int cam_intf; |
va009039 | 0:c972ee42b455 | 91 | bool device_found; |
va009039 | 0:c972ee42b455 | 92 | bool caminfo_found; |
va009039 | 0:c972ee42b455 | 93 | uint8_t _seq; |
va009039 | 0:c972ee42b455 | 94 | uint8_t* _buf; |
va009039 | 0:c972ee42b455 | 95 | int _pos; |
va009039 | 0:c972ee42b455 | 96 | int _size; |
va009039 | 0:c972ee42b455 | 97 | CamInfo* CamInfoList; |
va009039 | 0:c972ee42b455 | 98 | CamInfo* caminfo; |
va009039 | 0:c972ee42b455 | 99 | uint8_t _caminfo_size; |
va009039 | 0:c972ee42b455 | 100 | uint8_t _caminfo_option; |
va009039 | 0:c972ee42b455 | 101 | |
va009039 | 0:c972ee42b455 | 102 | virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG |
va009039 | 0:c972ee42b455 | 103 | void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); |
va009039 | 0:c972ee42b455 | 104 | void init(); |
va009039 | 0:c972ee42b455 | 105 | void onDisconnect(); |
va009039 | 0:c972ee42b455 | 106 | }; |