Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768
Dependents: F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld
Fork of KL46Z-USBHost by
USBHostCam.h
00001 // USBHostCam.h 00002 #include "USBHostConf.h" 00003 #include "USBHost.h" 00004 #include "BaseUvc.h" 00005 #include "decodeMJPEG.h" 00006 #pragma once 00007 00008 #define _160x120 2 00009 #define _176x144 3 00010 #define _320x176 4 00011 #define _320x240 5 00012 #define _352x288 6 00013 #define _432x240 7 00014 #define _640x480 1 00015 #define _544x288 8 00016 #define _640x360 9 00017 #define _752x416 10 00018 #define _800x448 11 00019 #define _800x600 12 00020 00021 #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; 00022 00023 struct CamInfo { 00024 uint16_t vid; 00025 uint16_t pid; 00026 uint8_t size; 00027 uint8_t option; 00028 // 00029 const char* name; 00030 uint8_t formatIndex; 00031 uint8_t frameIndex; 00032 uint32_t interval; 00033 uint8_t en; 00034 uint8_t mps; 00035 uint8_t if_alt; 00036 uint8_t frameCount; // ITD frame count 1-8 00037 uint8_t queueLimit; // ITD queue limit 1-3 00038 }; 00039 00040 /** 00041 * A class to communicate a Cam 00042 */ 00043 class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { 00044 public: 00045 /** 00046 * Constructor 00047 * 00048 */ 00049 USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); 00050 00051 /** 00052 * Check if a Cam device is connected 00053 * 00054 * @return true if a Cam device is connected 00055 */ 00056 bool connected(); 00057 00058 /** 00059 * Try to connect to a Cam device 00060 * 00061 * @return true if connection was successful 00062 */ 00063 bool connect(); 00064 00065 /** 00066 * read jpeg image 00067 * 00068 * @param buf read buffer 00069 * @param size buffer size 00070 * @param timeout_ms timeout default 15sec 00071 * @return jpeg size if read success else -1 00072 */ 00073 int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); 00074 00075 protected: 00076 //From IUSBEnumerator 00077 virtual void setVidPid(uint16_t vid, uint16_t pid); 00078 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 00079 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00080 00081 private: 00082 bool dev_connected; 00083 00084 int cam_intf; 00085 bool device_found; 00086 bool caminfo_found; 00087 00088 uint8_t _seq; 00089 uint8_t* _buf; 00090 int _pos; 00091 int _size; 00092 CamInfo* CamInfoList; 00093 CamInfo* caminfo; 00094 uint8_t _caminfo_size; 00095 uint8_t _caminfo_option; 00096 00097 virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG 00098 void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); 00099 void init(); 00100 };
Generated on Wed Jul 13 2022 05:41:27 by 1.7.2