USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHostC270/USBHostCam.h@26:53970cabf56d, 2015-06-26 (annotated)
- Committer:
- fritz291
- Date:
- Fri Jun 26 19:30:55 2015 +0000
- Revision:
- 26:53970cabf56d
- Parent:
- 18:61554f238584
Fixed small error in testAT function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 |
13:8774c07f12a5 | 1 | // USBHostCam.h |
va009039 |
13:8774c07f12a5 | 2 | #include "USBHostConf.h" |
va009039 |
13:8774c07f12a5 | 3 | #include "USBHost.h" |
va009039 |
13:8774c07f12a5 | 4 | #include "BaseUvc.h" |
va009039 |
13:8774c07f12a5 | 5 | #include "decodeMJPEG.h" |
va009039 |
13:8774c07f12a5 | 6 | #pragma once |
va009039 |
13:8774c07f12a5 | 7 | |
va009039 |
13:8774c07f12a5 | 8 | #define _160x120 2 |
va009039 |
13:8774c07f12a5 | 9 | #define _176x144 3 |
va009039 |
13:8774c07f12a5 | 10 | #define _320x176 4 |
va009039 |
13:8774c07f12a5 | 11 | #define _320x240 5 |
va009039 |
13:8774c07f12a5 | 12 | #define _352x288 6 |
va009039 |
13:8774c07f12a5 | 13 | #define _432x240 7 |
va009039 |
13:8774c07f12a5 | 14 | #define _640x480 1 |
va009039 |
13:8774c07f12a5 | 15 | #define _544x288 8 |
va009039 |
13:8774c07f12a5 | 16 | #define _640x360 9 |
va009039 |
13:8774c07f12a5 | 17 | #define _752x416 10 |
va009039 |
13:8774c07f12a5 | 18 | #define _800x448 11 |
va009039 |
13:8774c07f12a5 | 19 | #define _800x600 12 |
va009039 |
13:8774c07f12a5 | 20 | |
va009039 |
13:8774c07f12a5 | 21 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
va009039 |
13:8774c07f12a5 | 22 | |
va009039 |
13:8774c07f12a5 | 23 | struct CamInfo { |
va009039 |
13:8774c07f12a5 | 24 | uint16_t vid; |
va009039 |
13:8774c07f12a5 | 25 | uint16_t pid; |
va009039 |
13:8774c07f12a5 | 26 | uint8_t size; |
va009039 |
13:8774c07f12a5 | 27 | uint8_t option; |
va009039 |
13:8774c07f12a5 | 28 | // |
va009039 |
13:8774c07f12a5 | 29 | const char* name; |
va009039 |
13:8774c07f12a5 | 30 | uint8_t formatIndex; |
va009039 |
13:8774c07f12a5 | 31 | uint8_t frameIndex; |
va009039 |
13:8774c07f12a5 | 32 | uint32_t interval; |
va009039 |
13:8774c07f12a5 | 33 | uint8_t en; |
va009039 |
13:8774c07f12a5 | 34 | uint8_t mps; |
va009039 |
13:8774c07f12a5 | 35 | uint8_t if_alt; |
va009039 |
18:61554f238584 | 36 | uint8_t frameCount; // ITD frame count 1-8 |
va009039 |
18:61554f238584 | 37 | uint8_t queueLimit; // ITD queue limit 1-3 |
va009039 |
13:8774c07f12a5 | 38 | }; |
va009039 |
13:8774c07f12a5 | 39 | |
va009039 |
13:8774c07f12a5 | 40 | /** |
va009039 |
13:8774c07f12a5 | 41 | * A class to communicate a Cam |
va009039 |
13:8774c07f12a5 | 42 | */ |
va009039 |
13:8774c07f12a5 | 43 | class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { |
va009039 |
13:8774c07f12a5 | 44 | public: |
va009039 |
13:8774c07f12a5 | 45 | /** |
va009039 |
13:8774c07f12a5 | 46 | * Constructor |
va009039 |
13:8774c07f12a5 | 47 | * |
va009039 |
13:8774c07f12a5 | 48 | */ |
va009039 |
13:8774c07f12a5 | 49 | USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); |
va009039 |
13:8774c07f12a5 | 50 | |
va009039 |
13:8774c07f12a5 | 51 | /** |
va009039 |
13:8774c07f12a5 | 52 | * Check if a Cam device is connected |
va009039 |
13:8774c07f12a5 | 53 | * |
va009039 |
13:8774c07f12a5 | 54 | * @return true if a Cam device is connected |
va009039 |
13:8774c07f12a5 | 55 | */ |
va009039 |
13:8774c07f12a5 | 56 | bool connected(); |
va009039 |
13:8774c07f12a5 | 57 | |
va009039 |
13:8774c07f12a5 | 58 | /** |
va009039 |
13:8774c07f12a5 | 59 | * Try to connect to a Cam device |
va009039 |
13:8774c07f12a5 | 60 | * |
va009039 |
13:8774c07f12a5 | 61 | * @return true if connection was successful |
va009039 |
13:8774c07f12a5 | 62 | */ |
va009039 |
13:8774c07f12a5 | 63 | bool connect(); |
va009039 |
13:8774c07f12a5 | 64 | |
va009039 |
13:8774c07f12a5 | 65 | /** |
va009039 |
13:8774c07f12a5 | 66 | * read jpeg image |
va009039 |
13:8774c07f12a5 | 67 | * |
va009039 |
13:8774c07f12a5 | 68 | * @param buf read buffer |
va009039 |
13:8774c07f12a5 | 69 | * @param size buffer size |
va009039 |
13:8774c07f12a5 | 70 | * @param timeout_ms timeout default 15sec |
va009039 |
13:8774c07f12a5 | 71 | * @return jpeg size if read success else -1 |
va009039 |
13:8774c07f12a5 | 72 | */ |
va009039 |
13:8774c07f12a5 | 73 | int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); |
va009039 |
13:8774c07f12a5 | 74 | |
va009039 |
13:8774c07f12a5 | 75 | protected: |
va009039 |
13:8774c07f12a5 | 76 | //From IUSBEnumerator |
va009039 |
13:8774c07f12a5 | 77 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 |
13:8774c07f12a5 | 78 | 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 |
13:8774c07f12a5 | 79 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 |
13:8774c07f12a5 | 80 | |
va009039 |
13:8774c07f12a5 | 81 | private: |
va009039 |
13:8774c07f12a5 | 82 | bool dev_connected; |
va009039 |
13:8774c07f12a5 | 83 | |
va009039 |
13:8774c07f12a5 | 84 | int cam_intf; |
va009039 |
13:8774c07f12a5 | 85 | bool device_found; |
va009039 |
13:8774c07f12a5 | 86 | bool caminfo_found; |
va009039 |
13:8774c07f12a5 | 87 | |
va009039 |
13:8774c07f12a5 | 88 | uint8_t _seq; |
va009039 |
13:8774c07f12a5 | 89 | uint8_t* _buf; |
va009039 |
13:8774c07f12a5 | 90 | int _pos; |
va009039 |
13:8774c07f12a5 | 91 | int _size; |
va009039 |
13:8774c07f12a5 | 92 | CamInfo* CamInfoList; |
va009039 |
13:8774c07f12a5 | 93 | CamInfo* caminfo; |
va009039 |
13:8774c07f12a5 | 94 | uint8_t _caminfo_size; |
va009039 |
13:8774c07f12a5 | 95 | uint8_t _caminfo_option; |
va009039 |
13:8774c07f12a5 | 96 | |
va009039 |
13:8774c07f12a5 | 97 | virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG |
va009039 |
13:8774c07f12a5 | 98 | void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); |
va009039 |
13:8774c07f12a5 | 99 | void init(); |
va009039 |
13:8774c07f12a5 | 100 | }; |