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 Norimasa Okamoto

Committer:
va009039
Date:
Tue Jun 10 13:38:41 2014 +0900
Revision:
13:8774c07f12a5
Child:
18:61554f238584
add USBHostC270

Who changed what in which revision?

UserRevisionLine numberNew 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 13:8774c07f12a5 36 };
va009039 13:8774c07f12a5 37
va009039 13:8774c07f12a5 38 /**
va009039 13:8774c07f12a5 39 * A class to communicate a Cam
va009039 13:8774c07f12a5 40 */
va009039 13:8774c07f12a5 41 class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG {
va009039 13:8774c07f12a5 42 public:
va009039 13:8774c07f12a5 43 /**
va009039 13:8774c07f12a5 44 * Constructor
va009039 13:8774c07f12a5 45 *
va009039 13:8774c07f12a5 46 */
va009039 13:8774c07f12a5 47 USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL);
va009039 13:8774c07f12a5 48
va009039 13:8774c07f12a5 49 /**
va009039 13:8774c07f12a5 50 * Check if a Cam device is connected
va009039 13:8774c07f12a5 51 *
va009039 13:8774c07f12a5 52 * @return true if a Cam device is connected
va009039 13:8774c07f12a5 53 */
va009039 13:8774c07f12a5 54 bool connected();
va009039 13:8774c07f12a5 55
va009039 13:8774c07f12a5 56 /**
va009039 13:8774c07f12a5 57 * Try to connect to a Cam device
va009039 13:8774c07f12a5 58 *
va009039 13:8774c07f12a5 59 * @return true if connection was successful
va009039 13:8774c07f12a5 60 */
va009039 13:8774c07f12a5 61 bool connect();
va009039 13:8774c07f12a5 62
va009039 13:8774c07f12a5 63 /**
va009039 13:8774c07f12a5 64 * read jpeg image
va009039 13:8774c07f12a5 65 *
va009039 13:8774c07f12a5 66 * @param buf read buffer
va009039 13:8774c07f12a5 67 * @param size buffer size
va009039 13:8774c07f12a5 68 * @param timeout_ms timeout default 15sec
va009039 13:8774c07f12a5 69 * @return jpeg size if read success else -1
va009039 13:8774c07f12a5 70 */
va009039 13:8774c07f12a5 71 int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000);
va009039 13:8774c07f12a5 72
va009039 13:8774c07f12a5 73 protected:
va009039 13:8774c07f12a5 74 //From IUSBEnumerator
va009039 13:8774c07f12a5 75 virtual void setVidPid(uint16_t vid, uint16_t pid);
va009039 13:8774c07f12a5 76 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 77 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 78
va009039 13:8774c07f12a5 79 private:
va009039 13:8774c07f12a5 80 bool dev_connected;
va009039 13:8774c07f12a5 81
va009039 13:8774c07f12a5 82 int cam_intf;
va009039 13:8774c07f12a5 83 bool device_found;
va009039 13:8774c07f12a5 84 bool caminfo_found;
va009039 13:8774c07f12a5 85
va009039 13:8774c07f12a5 86 uint8_t _seq;
va009039 13:8774c07f12a5 87 uint8_t* _buf;
va009039 13:8774c07f12a5 88 int _pos;
va009039 13:8774c07f12a5 89 int _size;
va009039 13:8774c07f12a5 90 CamInfo* CamInfoList;
va009039 13:8774c07f12a5 91 CamInfo* caminfo;
va009039 13:8774c07f12a5 92 uint8_t _caminfo_size;
va009039 13:8774c07f12a5 93 uint8_t _caminfo_option;
va009039 13:8774c07f12a5 94
va009039 13:8774c07f12a5 95 virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG
va009039 13:8774c07f12a5 96 void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len);
va009039 13:8774c07f12a5 97 void init();
va009039 13:8774c07f12a5 98 };