luat_camera.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /******************************************************************************
  2. * CAMERA设备操作抽象层
  3. * @author Dozingfiretruck
  4. * @since 0.0.1
  5. *****************************************************************************/
  6. #ifndef Luat_CAMERA_H
  7. #define Luat_CAMERA_H
  8. #include "luat_base.h"
  9. #ifdef __LUATOS__
  10. #include "luat_lcd.h"
  11. #endif
  12. /**
  13. * @defgroup CAMERA CAMERA设备(CAMERA)
  14. * @{
  15. */
  16. enum
  17. {
  18. LUAT_CAMERA_FRAME_START = 0,
  19. LUAT_CAMERA_FRAME_END,
  20. LUAT_CAMERA_FRAME_RX_DONE,
  21. LUAT_CAMERA_FRAME_ERROR,
  22. LUAT_CAMERA_MODE_AUTO = 0,
  23. LUAT_CAMERA_MODE_SCAN,
  24. LUAT_CAMERA_TYPE_USB = 0x20,
  25. LUAT_CAMERA_TYPE_DVP = 0,
  26. LUAT_CAMERA_PREVIEW_ROTATE_0 = 0,
  27. LUAT_CAMERA_PREVIEW_ROTATE_90,
  28. LUAT_CAMERA_PREVIEW_ROTATE_180,
  29. LUAT_CAMERA_PREVIEW_ROTATE_270,
  30. // H264配置项
  31. LUAT_CAMERA_CONF_H264_BASE = 0x200,
  32. LUAT_CAMERA_CONF_H264_QP_INIT,
  33. LUAT_CAMERA_CONF_H264_QP_I_MAX,
  34. LUAT_CAMERA_CONF_H264_QP_P_MAX,
  35. LUAT_CAMERA_CONF_H264_IMB_BITS,
  36. LUAT_CAMERA_CONF_H264_PMB_BITS,
  37. LUAT_CAMERA_CONF_PREVIEW_BASE = 0x210,
  38. LUAT_CAMERA_CONF_PREVIEW_ENABLE,
  39. LUAT_CAMERA_CONF_PREVIEW_ROTATE,
  40. };
  41. typedef struct luat_camera_conf
  42. {
  43. uint8_t id;
  44. uint8_t zbar_scan;
  45. uint8_t draw_lcd;
  46. uint8_t i2c_id;
  47. uint8_t i2c_addr;
  48. uint8_t pwm_id;
  49. size_t pwm_period;
  50. uint8_t pwm_pulse;
  51. uint16_t sensor_width;
  52. uint16_t sensor_height;
  53. uint16_t pid;
  54. uint16_t vid;
  55. uint8_t color_bit;
  56. uint8_t id_reg;
  57. uint8_t id_value;
  58. uint8_t usb_port;
  59. uint8_t stream;
  60. uint8_t async;
  61. size_t init_cmd_size;
  62. uint8_t *init_cmd;
  63. #ifdef __LUATOS__
  64. luat_lcd_conf_t* lcd_conf;
  65. #else
  66. void *lcd_conf;
  67. #endif
  68. } luat_camera_conf_t;
  69. typedef struct
  70. {
  71. size_t camera_speed; //提供给camera时钟频率
  72. uint16_t sensor_width; //camera的最大宽度
  73. uint16_t sensor_height; //camera的最大高度
  74. uint8_t only_y;
  75. uint8_t rowScaleRatio;
  76. uint8_t colScaleRatio;
  77. uint8_t scaleBytes;
  78. uint8_t spi_mode;
  79. uint8_t is_msb; //0 or 1;
  80. uint8_t is_two_line_rx; //0 or 1;
  81. uint8_t seq_type; //0 or 1
  82. uint8_t plat_param[4];
  83. #ifdef __LUATOS__
  84. luat_lcd_conf_t* lcd_conf;
  85. #else
  86. void *lcd_conf;
  87. #endif
  88. } luat_spi_camera_t;
  89. #ifdef __LUATOS__
  90. int l_camera_handler(lua_State *L, void* ptr);
  91. #endif
  92. /**
  93. * @brief 配置spi camera并且初始化camera
  94. * @param id camera接收数据总线ID,见选型手册,例如AIR780EXXX是0
  95. * @param conf camera相关配置
  96. * @param callback camera接收中断回调,注意这是在中断里的回调
  97. * @param param 中断回调时用户的参数
  98. * @return >=0成功,其他失败
  99. */
  100. int luat_camera_setup(int id, luat_spi_camera_t *conf, void* callback, void *param);
  101. /**
  102. * @brief 配置图像大小
  103. * @param id camera接收数据总线ID
  104. * @param w 图像宽
  105. * @param h 图像高
  106. * @return >=0成功,其他失败
  107. */
  108. int luat_camera_set_image_w_h(int id, uint16_t w, uint16_t h);
  109. /**
  110. * @brief 配置camera并且初始化camera,spi camera不要使用这个
  111. * @param conf camera相关配置
  112. * @return 0成功,其他失败
  113. */
  114. int luat_camera_init(luat_camera_conf_t *conf);
  115. /**
  116. * @brief 关闭camera并且释放资源
  117. * @param id camera接收数据总线ID
  118. * @return 0成功,其他失败
  119. */
  120. int luat_camera_close(int id);
  121. /**
  122. * @brief 摄像头启动开始接收数据,csdk专用
  123. * @param id camera接收数据总线ID
  124. * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  125. * @return 0成功,其他失败
  126. */
  127. int luat_camera_start_with_buffer(int id, void *buf);
  128. /**
  129. * @brief 摄像头切换接收数据缓冲区,csdk专用
  130. * @param id camera接收数据总线ID
  131. * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  132. * @return 0成功,其他失败
  133. */
  134. void luat_camera_continue_with_buffer(int id, void *buf);
  135. /**
  136. * @brief 暂停接收camera数据
  137. * @param id camera接收数据总线ID
  138. * @param is_pause 非0暂停,0恢复
  139. * @return 0成功,其他失败
  140. */
  141. int luat_camera_pause(int id, uint8_t is_pause);
  142. /*
  143. * @brief 扫码库初始化
  144. * @param type 扫码库型号,目前只支持0
  145. * @param stack 扫码库任务的堆栈地址
  146. * @param stack_length 扫码库任务的堆栈深度,type=0时需要至少220KB
  147. * @param priority 扫码库任务优先级
  148. * @return 0成功,其他失败
  149. */
  150. int luat_camera_image_decode_init(uint8_t type, void *stack, uint32_t stack_length, uint32_t priority);
  151. /*
  152. * @brief 扫码库进行一次解码
  153. * @param data 缓冲区
  154. * @param image_w 图像宽
  155. * @param image_h 图像高
  156. * @param timeout 超时
  157. * @param callback 回调函数
  158. * @param param 回调参数
  159. * @return 0成功,其他失败
  160. */
  161. int luat_camera_image_decode_once(uint8_t *data, uint16_t image_w, uint16_t image_h, uint32_t timeout, void *callback, void *param);
  162. /*
  163. * @brief 扫码库反初始化
  164. */
  165. void luat_camera_image_decode_deinit(void);
  166. /*
  167. * @brief 获取解码结果
  168. * @param buf 缓冲区
  169. * @return 1成功,其他失败
  170. */
  171. int luat_camera_image_decode_get_result(uint8_t *buf);
  172. /**********以下是luatos使用,csdk不要使用***********/
  173. /**
  174. * @brief 开始接收camera数据
  175. * @param id camera接收数据总线ID
  176. * @return 0成功,其他失败
  177. */
  178. int luat_camera_start(int id);
  179. /**
  180. * @brief 停止接收camera数据
  181. * @param id camera接收数据总线ID
  182. * @return 0成功,其他失败
  183. */
  184. int luat_camera_stop(int id);
  185. int luat_camera_preview(int id, uint8_t on_off);
  186. int luat_camera_work_mode(int id, int mode);
  187. int luat_camera_capture_config(int id, uint16_t start_x, uint16_t start_y, uint16_t new_w, uint16_t new_h);
  188. int luat_camera_capture(int id, uint8_t quality, const char *path);
  189. int luat_camera_capture_in_ram(int id, uint8_t quality, void *buffer);
  190. int luat_camera_config(int id, int key, int value);
  191. /** @}*/
  192. #endif