sc03mpd.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * sc03mpd.h
  3. *
  4. * Created on: Jul 12, 2022
  5. * Author: jylew
  6. */
  7. #ifndef INC_SC03MPD_SC03MPD_H_
  8. #define INC_SC03MPD_SC03MPD_H_
  9. /*
  10. * Reference: SC03MPD User Manual (Rev.E)
  11. * 0.3 Mega Pixels Serial JPEG Camera with NTSC Video
  12. */
  13. #include <stdint.h>
  14. #define SC03MPD_DSN_DEF (0x00) // Default Serial Number
  15. #define VC0706_STS_ENON ( 0) // Executing command right
  16. #define VC0706_STS_EDNY (-1) // System don't receive the command
  17. #define VC0706_STS_ELEN (-2) // The data-length is error
  18. #define VC0706_STS_EFMT (-3) // Data format error
  19. #define VC0706_STS_ENAV (-4) // The command can not execute now
  20. #define VC0706_STS_EEXE (-5) // Command received, but executed wrong
  21. #define VC0706_STS_EINT (-6) // Internal Error
  22. #define VC0706_STS_ECOM (-7) // Comm Error
  23. #define SC03MPD_BDR_9600 (0xAEC8)
  24. #define SC03MPD_BDR_19200 (0x56E4)
  25. #define SC03MPD_BDR_38400 (0x2AF2)
  26. #define SC03MPD_BDR_56700 (0x1C4C)
  27. #define SC03MPD_BDR_115200 (0x0DA6)
  28. #define SC03MPD_RES_640_480 (0x00)
  29. #define SC03MPD_RES_320_240 (0x11)
  30. #define SC03MPD_RES_160_120 (0x22)
  31. #define SC03MPD_CLR_AUTO (0x00) // automatically step black-white and color
  32. #define SC03MPD_CLR_COLOR (0x02) // manually step color, select color
  33. #define SC03MPD_CLR_BW (0x03) // manually step color, select black-white
  34. #define SC03MPD_ASSERT(func, msg, label) \
  35. { if (func) { printf("%s\r\n", msg); goto label; } }
  36. struct sc03mpd_ifx;
  37. typedef int32_t (*sc03mpd_ifx_fn)(struct sc03mpd_ifx* ifx, uint8_t* buf, uint16_t len);
  38. typedef struct sc03mpd_ifx
  39. {
  40. void* context;
  41. sc03mpd_ifx_fn sendif;
  42. sc03mpd_ifx_fn recvif;
  43. }
  44. sc03mpd_ifx_t;
  45. /*
  46. * Refer to the chapter 11. 'INITIAL OPERATION PROCESS',
  47. * and chapter 12. 'Capture on image operation process'
  48. */
  49. // Command Protocol: [1] RESET
  50. int32_t sc03mpd_reset(sc03mpd_ifx_t* ifx);
  51. // Command Protocol: [2] CAPTURE A IMAGE
  52. int32_t sc03mpd_capture(sc03mpd_ifx_t* ifx);
  53. // Command Protocol: [3] READ IMAGE DATA LENGTH
  54. int32_t sc03mpd_get_ilen(sc03mpd_ifx_t* ifx, uint16_t* length);
  55. // Command Protocol: [4] READ IMAGE DATA
  56. int32_t sc03mpd_get_idat(sc03mpd_ifx_t* ifx, uint16_t addr, uint16_t size, uint8_t* dbuf);
  57. // Command Protocol: [5] STOP CAPTURE
  58. int32_t sc03mpd_stop(sc03mpd_ifx_t* ifx);
  59. // Command Protocol: [6] SETTING IMAGE COMPRESSIBILITY
  60. // - cmpr : compression ratio (0 - 255)
  61. // = ([cmpr] - 1) * 0.25, if [cmpr] >= 1
  62. // = 0, otherwise
  63. int32_t sc03mpd_set_icmp(sc03mpd_ifx_t* ifx, uint8_t cmpr);
  64. // Command Protocol: [7] SETTING IMAGE RESOLUTION
  65. // - resn : image resolution
  66. // SC03MPD_RES_160_120
  67. // SC03MPD_RES_320_240
  68. // SC03MPD_RES_640_480
  69. int32_t sc03mpd_set_ires(sc03mpd_ifx_t* ifx, uint8_t resn);
  70. // Command Protocol: [8] BAUD RATE (if save = 0)
  71. // [9] CHANGE DEFAULT BAUD RATE (if save > 0)
  72. // - baud : baud rate
  73. // SC03MPD_BDR_9600
  74. // SC03MPD_BDR_19200
  75. // SC03MPD_BDR_38400
  76. // SC03MPD_BDR_56700
  77. // SC03MPD_BDR_115200
  78. int32_t sc03mpd_set_baud(sc03mpd_ifx_t* ifx, uint16_t baud, uint8_t save);
  79. // Command Protocol from VC0706-Protocol: 1.3.2.17.COLOR_CTRL
  80. // - showMode : show different color by UART, it is effective only with UART
  81. // SC03MPD_CLR_AUTO
  82. // SC03MPD_CLR_COLOR
  83. // SC03MPD_CLR_BW
  84. int32_t sc03mpd_set_clr(sc03mpd_ifx_t* ifx, uint8_t showMode);
  85. #endif /* INC_SC03MPD_SC03MPD_H_ */