sensor.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * This file is part of the OpenMV project.
  3. * Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
  4. * This work is licensed under the MIT license, see the file LICENSE for details.
  5. *
  6. * Sensor abstraction layer.
  7. *
  8. */
  9. #ifndef __SENSOR_H__
  10. #define __SENSOR_H__
  11. #include <stdint.h>
  12. #include <stdbool.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. typedef enum {
  17. OV9650_PID = 0x96,
  18. OV7725_PID = 0x77,
  19. OV2640_PID = 0x26,
  20. OV3660_PID = 0x3660,
  21. OV5640_PID = 0x5640,
  22. OV7670_PID = 0x76,
  23. NT99141_PID = 0x1410,
  24. GC2145_PID = 0x2145,
  25. GC032A_PID = 0x232a,
  26. GC0308_PID = 0x9b,
  27. BF3005_PID = 0x30,
  28. BF20A6_PID = 0x20a6,
  29. } camera_pid_t;
  30. typedef enum {
  31. CAMERA_OV7725,
  32. CAMERA_OV2640,
  33. CAMERA_OV3660,
  34. CAMERA_OV5640,
  35. CAMERA_OV7670,
  36. CAMERA_NT99141,
  37. CAMERA_GC2145,
  38. CAMERA_GC032A,
  39. CAMERA_GC0308,
  40. CAMERA_BF3005,
  41. CAMERA_BF20A6,
  42. CAMERA_MODEL_MAX,
  43. CAMERA_NONE,
  44. } camera_model_t;
  45. typedef enum {
  46. OV2640_SCCB_ADDR = 0x30,// 0x60 >> 1
  47. OV5640_SCCB_ADDR = 0x3C,// 0x78 >> 1
  48. OV3660_SCCB_ADDR = 0x3C,// 0x78 >> 1
  49. OV7725_SCCB_ADDR = 0x21,// 0x42 >> 1
  50. OV7670_SCCB_ADDR = 0x21,// 0x42 >> 1
  51. NT99141_SCCB_ADDR = 0x2A,// 0x54 >> 1
  52. GC2145_SCCB_ADDR = 0x3C,// 0x78 >> 1
  53. GC032A_SCCB_ADDR = 0x21,// 0x42 >> 1
  54. GC0308_SCCB_ADDR = 0x21,// 0x42 >> 1
  55. BF3005_SCCB_ADDR = 0x6E,
  56. BF20A6_SCCB_ADDR = 0x6E,
  57. } camera_sccb_addr_t;
  58. typedef enum {
  59. PIXFORMAT_RGB565, // 2BPP/RGB565
  60. PIXFORMAT_YUV422, // 2BPP/YUV422
  61. PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE
  62. PIXFORMAT_JPEG, // JPEG/COMPRESSED
  63. PIXFORMAT_RGB888, // 3BPP/RGB888
  64. PIXFORMAT_RAW, // RAW
  65. PIXFORMAT_RGB444, // 3BP2P/RGB444
  66. PIXFORMAT_RGB555, // 3BP2P/RGB555
  67. } pixformat_t;
  68. typedef enum {
  69. FRAMESIZE_96X96, // 96x96
  70. FRAMESIZE_QQVGA, // 160x120
  71. FRAMESIZE_QCIF, // 176x144
  72. FRAMESIZE_HQVGA, // 240x176
  73. FRAMESIZE_240X240, // 240x240
  74. FRAMESIZE_QVGA, // 320x240
  75. FRAMESIZE_CIF, // 400x296
  76. FRAMESIZE_HVGA, // 480x320
  77. FRAMESIZE_VGA, // 640x480
  78. FRAMESIZE_SVGA, // 800x600
  79. FRAMESIZE_XGA, // 1024x768
  80. FRAMESIZE_HD, // 1280x720
  81. FRAMESIZE_SXGA, // 1280x1024
  82. FRAMESIZE_UXGA, // 1600x1200
  83. // 3MP Sensors
  84. FRAMESIZE_FHD, // 1920x1080
  85. FRAMESIZE_P_HD, // 720x1280
  86. FRAMESIZE_P_3MP, // 864x1536
  87. FRAMESIZE_QXGA, // 2048x1536
  88. // 5MP Sensors
  89. FRAMESIZE_QHD, // 2560x1440
  90. FRAMESIZE_WQXGA, // 2560x1600
  91. FRAMESIZE_P_FHD, // 1080x1920
  92. FRAMESIZE_QSXGA, // 2560x1920
  93. FRAMESIZE_INVALID
  94. } framesize_t;
  95. typedef struct {
  96. const camera_model_t model;
  97. const char *name;
  98. const camera_sccb_addr_t sccb_addr;
  99. const camera_pid_t pid;
  100. const framesize_t max_size;
  101. const bool support_jpeg;
  102. } camera_sensor_info_t;
  103. typedef enum {
  104. ASPECT_RATIO_4X3,
  105. ASPECT_RATIO_3X2,
  106. ASPECT_RATIO_16X10,
  107. ASPECT_RATIO_5X3,
  108. ASPECT_RATIO_16X9,
  109. ASPECT_RATIO_21X9,
  110. ASPECT_RATIO_5X4,
  111. ASPECT_RATIO_1X1,
  112. ASPECT_RATIO_9X16
  113. } aspect_ratio_t;
  114. typedef enum {
  115. GAINCEILING_2X,
  116. GAINCEILING_4X,
  117. GAINCEILING_8X,
  118. GAINCEILING_16X,
  119. GAINCEILING_32X,
  120. GAINCEILING_64X,
  121. GAINCEILING_128X,
  122. } gainceiling_t;
  123. typedef struct {
  124. uint16_t max_width;
  125. uint16_t max_height;
  126. uint16_t start_x;
  127. uint16_t start_y;
  128. uint16_t end_x;
  129. uint16_t end_y;
  130. uint16_t offset_x;
  131. uint16_t offset_y;
  132. uint16_t total_x;
  133. uint16_t total_y;
  134. } ratio_settings_t;
  135. typedef struct {
  136. const uint16_t width;
  137. const uint16_t height;
  138. const aspect_ratio_t aspect_ratio;
  139. } resolution_info_t;
  140. // Resolution table (in sensor.c)
  141. extern const resolution_info_t resolution[];
  142. // camera sensor table (in sensor.c)
  143. extern const camera_sensor_info_t camera_sensor[];
  144. typedef struct {
  145. uint8_t MIDH;
  146. uint8_t MIDL;
  147. uint16_t PID;
  148. uint8_t VER;
  149. } sensor_id_t;
  150. typedef struct {
  151. framesize_t framesize;//0 - 10
  152. bool scale;
  153. bool binning;
  154. uint8_t quality;//0 - 63
  155. int8_t brightness;//-2 - 2
  156. int8_t contrast;//-2 - 2
  157. int8_t saturation;//-2 - 2
  158. int8_t sharpness;//-2 - 2
  159. uint8_t denoise;
  160. uint8_t special_effect;//0 - 6
  161. uint8_t wb_mode;//0 - 4
  162. uint8_t awb;
  163. uint8_t awb_gain;
  164. uint8_t aec;
  165. uint8_t aec2;
  166. int8_t ae_level;//-2 - 2
  167. uint16_t aec_value;//0 - 1200
  168. uint8_t agc;
  169. uint8_t agc_gain;//0 - 30
  170. uint8_t gainceiling;//0 - 6
  171. uint8_t bpc;
  172. uint8_t wpc;
  173. uint8_t raw_gma;
  174. uint8_t lenc;
  175. uint8_t hmirror;
  176. uint8_t vflip;
  177. uint8_t dcw;
  178. uint8_t colorbar;
  179. } camera_status_t;
  180. typedef struct _sensor sensor_t;
  181. typedef struct _sensor {
  182. sensor_id_t id; // Sensor ID.
  183. uint8_t slv_addr; // Sensor I2C slave address.
  184. pixformat_t pixformat;
  185. camera_status_t status;
  186. int xclk_freq_hz;
  187. // Sensor function pointers
  188. int (*init_status) (sensor_t *sensor);
  189. int (*reset) (sensor_t *sensor);
  190. int (*set_pixformat) (sensor_t *sensor, pixformat_t pixformat);
  191. int (*set_framesize) (sensor_t *sensor, framesize_t framesize);
  192. int (*set_contrast) (sensor_t *sensor, int level);
  193. int (*set_brightness) (sensor_t *sensor, int level);
  194. int (*set_saturation) (sensor_t *sensor, int level);
  195. int (*set_sharpness) (sensor_t *sensor, int level);
  196. int (*set_denoise) (sensor_t *sensor, int level);
  197. int (*set_gainceiling) (sensor_t *sensor, gainceiling_t gainceiling);
  198. int (*set_quality) (sensor_t *sensor, int quality);
  199. int (*set_colorbar) (sensor_t *sensor, int enable);
  200. int (*set_whitebal) (sensor_t *sensor, int enable);
  201. int (*set_gain_ctrl) (sensor_t *sensor, int enable);
  202. int (*set_exposure_ctrl) (sensor_t *sensor, int enable);
  203. int (*set_hmirror) (sensor_t *sensor, int enable);
  204. int (*set_vflip) (sensor_t *sensor, int enable);
  205. int (*set_aec2) (sensor_t *sensor, int enable);
  206. int (*set_awb_gain) (sensor_t *sensor, int enable);
  207. int (*set_agc_gain) (sensor_t *sensor, int gain);
  208. int (*set_aec_value) (sensor_t *sensor, int gain);
  209. int (*set_special_effect) (sensor_t *sensor, int effect);
  210. int (*set_wb_mode) (sensor_t *sensor, int mode);
  211. int (*set_ae_level) (sensor_t *sensor, int level);
  212. int (*set_dcw) (sensor_t *sensor, int enable);
  213. int (*set_bpc) (sensor_t *sensor, int enable);
  214. int (*set_wpc) (sensor_t *sensor, int enable);
  215. int (*set_raw_gma) (sensor_t *sensor, int enable);
  216. int (*set_lenc) (sensor_t *sensor, int enable);
  217. int (*get_reg) (sensor_t *sensor, int reg, int mask);
  218. int (*set_reg) (sensor_t *sensor, int reg, int mask, int value);
  219. int (*set_res_raw) (sensor_t *sensor, int startX, int startY, int endX, int endY, int offsetX, int offsetY, int totalX, int totalY, int outputX, int outputY, bool scale, bool binning);
  220. int (*set_pll) (sensor_t *sensor, int bypass, int mul, int sys, int root, int pre, int seld5, int pclken, int pclk);
  221. int (*set_xclk) (sensor_t *sensor, int timer, int xclk);
  222. } sensor_t;
  223. camera_sensor_info_t *esp_camera_sensor_get_info(sensor_id_t *id);
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif /* __SENSOR_H__ */