supported GR-PEACH original: http://developer.mbed.org/users/va009039/code/USBHostC270_example/ The function of Isochronous has moved to USBHost_AddIso library.
Dependencies: USBHost_custom_Addiso
Fork of USBHostC270_example_GR-PEACH by
USBHostCam/USBHostCam.h@15:ac8b6c6dfb3f, 2017-04-21 (annotated)
- Committer:
- Osamu Nakamura
- Date:
- Fri Apr 21 20:09:15 2017 +0900
- Revision:
- 15:ac8b6c6dfb3f
- Parent:
- 12:ea4badc78215
Update main.cpp so that it can run on mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 12:ea4badc78215 | 1 | // USBHostCam.h |
va009039 | 12:ea4badc78215 | 2 | #include "USBHostConf.h" |
va009039 | 12:ea4badc78215 | 3 | #include "USBHost.h" |
va009039 | 12:ea4badc78215 | 4 | #include "USBIsochronous.h" |
va009039 | 12:ea4badc78215 | 5 | #include "BaseUvc.h" |
va009039 | 12:ea4badc78215 | 6 | #include "decodeMJPEG.h" |
va009039 | 12:ea4badc78215 | 7 | #pragma once |
va009039 | 12:ea4badc78215 | 8 | |
va009039 | 12:ea4badc78215 | 9 | #define _160x120 2 |
va009039 | 12:ea4badc78215 | 10 | #define _176x144 3 |
va009039 | 12:ea4badc78215 | 11 | #define _320x176 4 |
va009039 | 12:ea4badc78215 | 12 | #define _320x240 5 |
va009039 | 12:ea4badc78215 | 13 | #define _352x288 6 |
va009039 | 12:ea4badc78215 | 14 | #define _432x240 7 |
va009039 | 12:ea4badc78215 | 15 | #define _640x480 1 |
va009039 | 12:ea4badc78215 | 16 | #define _544x288 8 |
va009039 | 12:ea4badc78215 | 17 | #define _640x360 9 |
va009039 | 12:ea4badc78215 | 18 | #define _752x416 10 |
va009039 | 12:ea4badc78215 | 19 | #define _800x448 11 |
va009039 | 12:ea4badc78215 | 20 | #define _800x600 12 |
va009039 | 12:ea4badc78215 | 21 | |
va009039 | 12:ea4badc78215 | 22 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
va009039 | 12:ea4badc78215 | 23 | |
va009039 | 12:ea4badc78215 | 24 | struct CamInfo { |
va009039 | 12:ea4badc78215 | 25 | uint16_t vid; |
va009039 | 12:ea4badc78215 | 26 | uint16_t pid; |
va009039 | 12:ea4badc78215 | 27 | uint8_t size; |
va009039 | 12:ea4badc78215 | 28 | uint8_t option; |
va009039 | 12:ea4badc78215 | 29 | // |
va009039 | 12:ea4badc78215 | 30 | const char* name; |
va009039 | 12:ea4badc78215 | 31 | uint8_t formatIndex; |
va009039 | 12:ea4badc78215 | 32 | uint8_t frameIndex; |
va009039 | 12:ea4badc78215 | 33 | uint32_t interval; |
va009039 | 12:ea4badc78215 | 34 | uint8_t en; |
va009039 | 12:ea4badc78215 | 35 | uint8_t mps; |
va009039 | 12:ea4badc78215 | 36 | uint8_t if_alt; |
va009039 | 12:ea4badc78215 | 37 | uint8_t frameCount; // ITD frame count 1-8 |
va009039 | 12:ea4badc78215 | 38 | uint8_t queueLimit; // ITD queue limit 1-3 |
va009039 | 12:ea4badc78215 | 39 | }; |
va009039 | 12:ea4badc78215 | 40 | |
va009039 | 12:ea4badc78215 | 41 | /** |
va009039 | 12:ea4badc78215 | 42 | * A class to communicate a Cam |
va009039 | 12:ea4badc78215 | 43 | */ |
va009039 | 12:ea4badc78215 | 44 | class USBHostCam : public IUSBEnumerator, public BaseUvc, public decodeMJPEG { |
va009039 | 12:ea4badc78215 | 45 | public: |
va009039 | 12:ea4badc78215 | 46 | /** |
va009039 | 12:ea4badc78215 | 47 | * Constructor |
va009039 | 12:ea4badc78215 | 48 | * |
va009039 | 12:ea4badc78215 | 49 | */ |
va009039 | 12:ea4badc78215 | 50 | USBHostCam(uint8_t size = _160x120, uint8_t option = 0, CamInfo* user_caminfo = NULL); |
va009039 | 12:ea4badc78215 | 51 | |
va009039 | 12:ea4badc78215 | 52 | /** |
va009039 | 12:ea4badc78215 | 53 | * Check if a Cam device is connected |
va009039 | 12:ea4badc78215 | 54 | * |
va009039 | 12:ea4badc78215 | 55 | * @return true if a Cam device is connected |
va009039 | 12:ea4badc78215 | 56 | */ |
va009039 | 12:ea4badc78215 | 57 | bool connected(); |
va009039 | 12:ea4badc78215 | 58 | |
va009039 | 12:ea4badc78215 | 59 | /** |
va009039 | 12:ea4badc78215 | 60 | * Try to connect to a Cam device |
va009039 | 12:ea4badc78215 | 61 | * |
va009039 | 12:ea4badc78215 | 62 | * @return true if connection was successful |
va009039 | 12:ea4badc78215 | 63 | */ |
va009039 | 12:ea4badc78215 | 64 | bool connect(); |
va009039 | 12:ea4badc78215 | 65 | |
va009039 | 12:ea4badc78215 | 66 | /** |
va009039 | 12:ea4badc78215 | 67 | * read jpeg image |
va009039 | 12:ea4badc78215 | 68 | * |
va009039 | 12:ea4badc78215 | 69 | * @param buf read buffer |
va009039 | 12:ea4badc78215 | 70 | * @param size buffer size |
va009039 | 12:ea4badc78215 | 71 | * @param timeout_ms timeout default 15sec |
va009039 | 12:ea4badc78215 | 72 | * @return jpeg size if read success else -1 |
va009039 | 12:ea4badc78215 | 73 | */ |
va009039 | 12:ea4badc78215 | 74 | int readJPEG(uint8_t* buf, int size, int timeout_ms = 15*1000); |
va009039 | 12:ea4badc78215 | 75 | |
va009039 | 12:ea4badc78215 | 76 | protected: |
va009039 | 12:ea4badc78215 | 77 | //From IUSBEnumerator |
va009039 | 12:ea4badc78215 | 78 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 | 12:ea4badc78215 | 79 | 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 | 12:ea4badc78215 | 80 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 | 12:ea4badc78215 | 81 | |
va009039 | 12:ea4badc78215 | 82 | private: |
va009039 | 12:ea4badc78215 | 83 | bool dev_connected; |
va009039 | 12:ea4badc78215 | 84 | |
va009039 | 12:ea4badc78215 | 85 | int cam_intf; |
va009039 | 12:ea4badc78215 | 86 | bool device_found; |
va009039 | 12:ea4badc78215 | 87 | bool caminfo_found; |
va009039 | 12:ea4badc78215 | 88 | uint8_t _seq; |
va009039 | 12:ea4badc78215 | 89 | uint8_t* _buf; |
va009039 | 12:ea4badc78215 | 90 | int _pos; |
va009039 | 12:ea4badc78215 | 91 | int _size; |
va009039 | 12:ea4badc78215 | 92 | CamInfo* CamInfoList; |
va009039 | 12:ea4badc78215 | 93 | CamInfo* caminfo; |
va009039 | 12:ea4badc78215 | 94 | uint8_t _caminfo_size; |
va009039 | 12:ea4badc78215 | 95 | uint8_t _caminfo_option; |
va009039 | 12:ea4badc78215 | 96 | |
va009039 | 12:ea4badc78215 | 97 | virtual void outputJPEG(uint8_t c, int status); // from decodeMJPEG |
va009039 | 12:ea4badc78215 | 98 | void callback_motion_jpeg(uint16_t frame, uint8_t* buf, int len); |
va009039 | 12:ea4badc78215 | 99 | void init(); |
va009039 | 12:ea4badc78215 | 100 | void onDisconnect(); |
va009039 | 12:ea4badc78215 | 101 | }; |