luat_camera.h 6.2 KB

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