ov2640_settings.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _OV2640_SETTINGS_H_
  15. #define _OV2640_SETTINGS_H_
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "esp_attr.h"
  19. #include "ov2640_regs.h"
  20. typedef enum {
  21. OV2640_MODE_UXGA, OV2640_MODE_SVGA, OV2640_MODE_CIF, OV2640_MODE_MAX
  22. } ov2640_sensor_mode_t;
  23. typedef struct {
  24. union {
  25. struct {
  26. uint8_t pclk_div:7;
  27. uint8_t pclk_auto:1;
  28. };
  29. uint8_t pclk;
  30. };
  31. union {
  32. struct {
  33. uint8_t clk_div:6;
  34. uint8_t reserved:1;
  35. uint8_t clk_2x:1;
  36. };
  37. uint8_t clk;
  38. };
  39. } ov2640_clk_t;
  40. typedef struct {
  41. uint16_t offset_x;
  42. uint16_t offset_y;
  43. uint16_t max_x;
  44. uint16_t max_y;
  45. } ov2640_ratio_settings_t;
  46. static const DRAM_ATTR ov2640_ratio_settings_t ratio_table[] = {
  47. // ox, oy, mx, my
  48. { 0, 0, 1600, 1200 }, //4x3
  49. { 8, 72, 1584, 1056 }, //3x2
  50. { 0, 100, 1600, 1000 }, //16x10
  51. { 0, 120, 1600, 960 }, //5x3
  52. { 0, 150, 1600, 900 }, //16x9
  53. { 2, 258, 1596, 684 }, //21x9
  54. { 50, 0, 1500, 1200 }, //5x4
  55. { 200, 0, 1200, 1200 }, //1x1
  56. { 462, 0, 676, 1200 } //9x16
  57. };
  58. // 30fps@24MHz
  59. const DRAM_ATTR uint8_t ov2640_settings_cif[][2] = {
  60. {BANK_SEL, BANK_DSP},
  61. {0x2c, 0xff},
  62. {0x2e, 0xdf},
  63. {BANK_SEL, BANK_SENSOR},
  64. {0x3c, 0x32},
  65. {CLKRC, 0x01},
  66. {COM2, COM2_OUT_DRIVE_3x},
  67. {REG04, REG04_DEFAULT},
  68. {COM8, COM8_DEFAULT | COM8_BNDF_EN | COM8_AGC_EN | COM8_AEC_EN},
  69. {COM9, COM9_AGC_SET(COM9_AGC_GAIN_8x)},
  70. {0x2c, 0x0c},
  71. {0x33, 0x78},
  72. {0x3a, 0x33},
  73. {0x3b, 0xfB},
  74. {0x3e, 0x00},
  75. {0x43, 0x11},
  76. {0x16, 0x10},
  77. {0x39, 0x92},
  78. {0x35, 0xda},
  79. {0x22, 0x1a},
  80. {0x37, 0xc3},
  81. {0x23, 0x00},
  82. {ARCOM2, 0xc0},
  83. {0x06, 0x88},
  84. {0x07, 0xc0},
  85. {COM4, 0x87},
  86. {0x0e, 0x41},
  87. {0x4c, 0x00},
  88. {0x4a, 0x81},
  89. {0x21, 0x99},
  90. {AEW, 0x40},
  91. {AEB, 0x38},
  92. {VV, VV_AGC_TH_SET(8,2)},
  93. {0x5c, 0x00},
  94. {0x63, 0x00},
  95. {HISTO_LOW, 0x70},
  96. {HISTO_HIGH, 0x80},
  97. {0x7c, 0x05},
  98. {0x20, 0x80},
  99. {0x28, 0x30},
  100. {0x6c, 0x00},
  101. {0x6d, 0x80},
  102. {0x6e, 0x00},
  103. {0x70, 0x02},
  104. {0x71, 0x94},
  105. {0x73, 0xc1},
  106. {0x3d, 0x34},
  107. {0x5a, 0x57},
  108. {BD50, 0xbb},
  109. {BD60, 0x9c},
  110. {COM7, COM7_RES_CIF},
  111. {HSTART, 0x11},
  112. {HSTOP, 0x43},
  113. {VSTART, 0x00},
  114. {VSTOP, 0x25},
  115. {REG32, 0x89},
  116. {0x37, 0xc0},
  117. {BD50, 0xca},
  118. {BD60, 0xa8},
  119. {0x6d, 0x00},
  120. {0x3d, 0x38},
  121. {BANK_SEL, BANK_DSP},
  122. {0xe5, 0x7f},
  123. {MC_BIST, MC_BIST_RESET | MC_BIST_BOOT_ROM_SEL},
  124. {0x41, 0x24},
  125. {RESET, RESET_JPEG | RESET_DVP},
  126. {0x76, 0xff},
  127. {0x33, 0xa0},
  128. {0x42, 0x20},
  129. {0x43, 0x18},
  130. {0x4c, 0x00},
  131. {CTRL3, CTRL3_WPC_EN | 0x10 },
  132. {0x88, 0x3f},
  133. {0xd7, 0x03},
  134. {0xd9, 0x10},
  135. {R_DVP_SP, R_DVP_SP_AUTO_MODE | 0x02},
  136. {0xc8, 0x08},
  137. {0xc9, 0x80},
  138. {BPADDR, 0x00},
  139. {BPDATA, 0x00},
  140. {BPADDR, 0x03},
  141. {BPDATA, 0x48},
  142. {BPDATA, 0x48},
  143. {BPADDR, 0x08},
  144. {BPDATA, 0x20},
  145. {BPDATA, 0x10},
  146. {BPDATA, 0x0e},
  147. {0x90, 0x00},
  148. {0x91, 0x0e},
  149. {0x91, 0x1a},
  150. {0x91, 0x31},
  151. {0x91, 0x5a},
  152. {0x91, 0x69},
  153. {0x91, 0x75},
  154. {0x91, 0x7e},
  155. {0x91, 0x88},
  156. {0x91, 0x8f},
  157. {0x91, 0x96},
  158. {0x91, 0xa3},
  159. {0x91, 0xaf},
  160. {0x91, 0xc4},
  161. {0x91, 0xd7},
  162. {0x91, 0xe8},
  163. {0x91, 0x20},
  164. {0x92, 0x00},
  165. {0x93, 0x06},
  166. {0x93, 0xe3},
  167. {0x93, 0x05},
  168. {0x93, 0x05},
  169. {0x93, 0x00},
  170. {0x93, 0x04},
  171. {0x93, 0x00},
  172. {0x93, 0x00},
  173. {0x93, 0x00},
  174. {0x93, 0x00},
  175. {0x93, 0x00},
  176. {0x93, 0x00},
  177. {0x93, 0x00},
  178. {0x96, 0x00},
  179. {0x97, 0x08},
  180. {0x97, 0x19},
  181. {0x97, 0x02},
  182. {0x97, 0x0c},
  183. {0x97, 0x24},
  184. {0x97, 0x30},
  185. {0x97, 0x28},
  186. {0x97, 0x26},
  187. {0x97, 0x02},
  188. {0x97, 0x98},
  189. {0x97, 0x80},
  190. {0x97, 0x00},
  191. {0x97, 0x00},
  192. {0xa4, 0x00},
  193. {0xa8, 0x00},
  194. {0xc5, 0x11},
  195. {0xc6, 0x51},
  196. {0xbf, 0x80},
  197. {0xc7, 0x10},
  198. {0xb6, 0x66},
  199. {0xb8, 0xA5},
  200. {0xb7, 0x64},
  201. {0xb9, 0x7C},
  202. {0xb3, 0xaf},
  203. {0xb4, 0x97},
  204. {0xb5, 0xFF},
  205. {0xb0, 0xC5},
  206. {0xb1, 0x94},
  207. {0xb2, 0x0f},
  208. {0xc4, 0x5c},
  209. {CTRL1, 0xfd},
  210. {0x7f, 0x00},
  211. {0xe5, 0x1f},
  212. {0xe1, 0x67},
  213. {0xdd, 0x7f},
  214. {IMAGE_MODE, 0x00},
  215. {RESET, 0x00},
  216. {R_BYPASS, R_BYPASS_DSP_EN},
  217. {0, 0}
  218. };
  219. const DRAM_ATTR uint8_t ov2640_settings_to_cif[][2] = {
  220. {BANK_SEL, BANK_SENSOR},
  221. {COM7, COM7_RES_CIF},
  222. //Set the sensor output window
  223. {COM1, 0x0A},
  224. {REG32, REG32_CIF},
  225. {HSTART, 0x11},
  226. {HSTOP, 0x43},
  227. {VSTART, 0x00},
  228. {VSTOP, 0x25},
  229. //{CLKRC, 0x00},
  230. {BD50, 0xca},
  231. {BD60, 0xa8},
  232. {0x5a, 0x23},
  233. {0x6d, 0x00},
  234. {0x3d, 0x38},
  235. {0x39, 0x92},
  236. {0x35, 0xda},
  237. {0x22, 0x1a},
  238. {0x37, 0xc3},
  239. {0x23, 0x00},
  240. {ARCOM2, 0xc0},
  241. {0x06, 0x88},
  242. {0x07, 0xc0},
  243. {COM4, 0x87},
  244. {0x0e, 0x41},
  245. {0x4c, 0x00},
  246. {BANK_SEL, BANK_DSP},
  247. {RESET, RESET_DVP},
  248. //Set the sensor resolution (UXGA, SVGA, CIF)
  249. {HSIZE8, 0x32},
  250. {VSIZE8, 0x25},
  251. {SIZEL, 0x00},
  252. //Set the image window size >= output size
  253. {HSIZE, 0x64},
  254. {VSIZE, 0x4a},
  255. {XOFFL, 0x00},
  256. {YOFFL, 0x00},
  257. {VHYX, 0x00},
  258. {TEST, 0x00},
  259. {CTRL2, CTRL2_DCW_EN | 0x1D},
  260. {CTRLI, CTRLI_LP_DP | 0x00},
  261. //{R_DVP_SP, 0x08},
  262. {0, 0}
  263. };
  264. const DRAM_ATTR uint8_t ov2640_settings_to_svga[][2] = {
  265. {BANK_SEL, BANK_SENSOR},
  266. {COM7, COM7_RES_SVGA},
  267. //Set the sensor output window
  268. {COM1, 0x0A},
  269. {REG32, REG32_SVGA},
  270. {HSTART, 0x11},
  271. {HSTOP, 0x43},
  272. {VSTART, 0x00},
  273. {VSTOP, 0x4b},
  274. //{CLKRC, 0x00},
  275. {0x37, 0xc0},
  276. {BD50, 0xca},
  277. {BD60, 0xa8},
  278. {0x5a, 0x23},
  279. {0x6d, 0x00},
  280. {0x3d, 0x38},
  281. {0x39, 0x92},
  282. {0x35, 0xda},
  283. {0x22, 0x1a},
  284. {0x37, 0xc3},
  285. {0x23, 0x00},
  286. {ARCOM2, 0xc0},
  287. {0x06, 0x88},
  288. {0x07, 0xc0},
  289. {COM4, 0x87},
  290. {0x0e, 0x41},
  291. {0x42, 0x03},
  292. {0x4c, 0x00},
  293. {BANK_SEL, BANK_DSP},
  294. {RESET, RESET_DVP},
  295. //Set the sensor resolution (UXGA, SVGA, CIF)
  296. {HSIZE8, 0x64},
  297. {VSIZE8, 0x4B},
  298. {SIZEL, 0x00},
  299. //Set the image window size >= output size
  300. {HSIZE, 0xC8},
  301. {VSIZE, 0x96},
  302. {XOFFL, 0x00},
  303. {YOFFL, 0x00},
  304. {VHYX, 0x00},
  305. {TEST, 0x00},
  306. {CTRL2, CTRL2_DCW_EN | 0x1D},
  307. {CTRLI, CTRLI_LP_DP | 0x00},
  308. //{R_DVP_SP, 0x08},
  309. {0, 0}
  310. };
  311. const DRAM_ATTR uint8_t ov2640_settings_to_uxga[][2] = {
  312. {BANK_SEL, BANK_SENSOR},
  313. {COM7, COM7_RES_UXGA},
  314. //Set the sensor output window
  315. {COM1, 0x0F},
  316. {REG32, REG32_UXGA},
  317. {HSTART, 0x11},
  318. {HSTOP, 0x75},
  319. {VSTART, 0x01},
  320. {VSTOP, 0x97},
  321. //{CLKRC, 0x00},
  322. {0x3d, 0x34},
  323. {BD50, 0xbb},
  324. {BD60, 0x9c},
  325. {0x5a, 0x57},
  326. {0x6d, 0x80},
  327. {0x39, 0x82},
  328. {0x23, 0x00},
  329. {0x07, 0xc0},
  330. {0x4c, 0x00},
  331. {0x35, 0x88},
  332. {0x22, 0x0a},
  333. {0x37, 0x40},
  334. {ARCOM2, 0xa0},
  335. {0x06, 0x02},
  336. {COM4, 0xb7},
  337. {0x0e, 0x01},
  338. {0x42, 0x83},
  339. {BANK_SEL, BANK_DSP},
  340. {RESET, RESET_DVP},
  341. //Set the sensor resolution (UXGA, SVGA, CIF)
  342. {HSIZE8, 0xc8},
  343. {VSIZE8, 0x96},
  344. {SIZEL, 0x00},
  345. //Set the image window size >= output size
  346. {HSIZE, 0x90},
  347. {VSIZE, 0x2c},
  348. {XOFFL, 0x00},
  349. {YOFFL, 0x00},
  350. {VHYX, 0x88},
  351. {TEST, 0x00},
  352. {CTRL2, CTRL2_DCW_EN | 0x1d},
  353. {CTRLI, 0x00},
  354. //{R_DVP_SP, 0x06},
  355. {0, 0}
  356. };
  357. const DRAM_ATTR uint8_t ov2640_settings_jpeg3[][2] = {
  358. {BANK_SEL, BANK_DSP},
  359. {RESET, RESET_JPEG | RESET_DVP},
  360. {IMAGE_MODE, IMAGE_MODE_JPEG_EN | IMAGE_MODE_HREF_VSYNC},
  361. {0xD7, 0x03},
  362. {0xE1, 0x77},
  363. {0xE5, 0x1F},
  364. {0xD9, 0x10},
  365. {0xDF, 0x80},
  366. {0x33, 0x80},
  367. {0x3C, 0x10},
  368. {0xEB, 0x30},
  369. {0xDD, 0x7F},
  370. {RESET, 0x00},
  371. {0, 0}
  372. };
  373. static const uint8_t ov2640_settings_yuv422[][2] = {
  374. {BANK_SEL, BANK_DSP},
  375. {RESET, RESET_DVP},
  376. {IMAGE_MODE, IMAGE_MODE_YUV422},
  377. {0xD7, 0x01},
  378. {0xE1, 0x67},
  379. {RESET, 0x00},
  380. {0, 0},
  381. };
  382. static const uint8_t ov2640_settings_rgb565[][2] = {
  383. {BANK_SEL, BANK_DSP},
  384. {RESET, RESET_DVP},
  385. {IMAGE_MODE, IMAGE_MODE_RGB565},
  386. {0xD7, 0x03},
  387. {0xE1, 0x77},
  388. {RESET, 0x00},
  389. {0, 0},
  390. };
  391. #define NUM_BRIGHTNESS_LEVELS (5)
  392. static const uint8_t brightness_regs[NUM_BRIGHTNESS_LEVELS + 1][5] = {
  393. {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA },
  394. {0x00, 0x04, 0x09, 0x00, 0x00 }, /* -2 */
  395. {0x00, 0x04, 0x09, 0x10, 0x00 }, /* -1 */
  396. {0x00, 0x04, 0x09, 0x20, 0x00 }, /* 0 */
  397. {0x00, 0x04, 0x09, 0x30, 0x00 }, /* +1 */
  398. {0x00, 0x04, 0x09, 0x40, 0x00 }, /* +2 */
  399. };
  400. #define NUM_CONTRAST_LEVELS (5)
  401. static const uint8_t contrast_regs[NUM_CONTRAST_LEVELS + 1][7] = {
  402. {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA, BPDATA, BPDATA },
  403. {0x00, 0x04, 0x07, 0x20, 0x18, 0x34, 0x06 }, /* -2 */
  404. {0x00, 0x04, 0x07, 0x20, 0x1c, 0x2a, 0x06 }, /* -1 */
  405. {0x00, 0x04, 0x07, 0x20, 0x20, 0x20, 0x06 }, /* 0 */
  406. {0x00, 0x04, 0x07, 0x20, 0x24, 0x16, 0x06 }, /* +1 */
  407. {0x00, 0x04, 0x07, 0x20, 0x28, 0x0c, 0x06 }, /* +2 */
  408. };
  409. #define NUM_SATURATION_LEVELS (5)
  410. static const uint8_t saturation_regs[NUM_SATURATION_LEVELS + 1][5] = {
  411. {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA },
  412. {0x00, 0x02, 0x03, 0x28, 0x28 }, /* -2 */
  413. {0x00, 0x02, 0x03, 0x38, 0x38 }, /* -1 */
  414. {0x00, 0x02, 0x03, 0x48, 0x48 }, /* 0 */
  415. {0x00, 0x02, 0x03, 0x58, 0x58 }, /* +1 */
  416. {0x00, 0x02, 0x03, 0x68, 0x68 }, /* +2 */
  417. };
  418. #define NUM_SPECIAL_EFFECTS (7)
  419. static const uint8_t special_effects_regs[NUM_SPECIAL_EFFECTS + 1][5] = {
  420. {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA },
  421. {0x00, 0X00, 0x05, 0X80, 0X80 }, /* no effect */
  422. {0x00, 0X40, 0x05, 0X80, 0X80 }, /* negative */
  423. {0x00, 0X18, 0x05, 0X80, 0X80 }, /* black and white */
  424. {0x00, 0X18, 0x05, 0X40, 0XC0 }, /* reddish */
  425. {0x00, 0X18, 0x05, 0X40, 0X40 }, /* greenish */
  426. {0x00, 0X18, 0x05, 0XA0, 0X40 }, /* blue */
  427. {0x00, 0X18, 0x05, 0X40, 0XA6 }, /* retro */
  428. };
  429. #define NUM_WB_MODES (4)
  430. static const uint8_t wb_modes_regs[NUM_WB_MODES + 1][3] = {
  431. {0XCC, 0XCD, 0XCE },
  432. {0x5E, 0X41, 0x54 }, /* sunny */
  433. {0x65, 0X41, 0x4F }, /* cloudy */
  434. {0x52, 0X41, 0x66 }, /* office */
  435. {0x42, 0X3F, 0x71 }, /* home */
  436. };
  437. #define NUM_AE_LEVELS (5)
  438. static const uint8_t ae_levels_regs[NUM_AE_LEVELS + 1][3] = {
  439. { AEW, AEB, VV },
  440. {0x20, 0X18, 0x60 },
  441. {0x34, 0X1C, 0x00 },
  442. {0x3E, 0X38, 0x81 },
  443. {0x48, 0X40, 0x81 },
  444. {0x58, 0X50, 0x92 },
  445. };
  446. const uint8_t agc_gain_tbl[31] = {
  447. 0x00, 0x10, 0x18, 0x30, 0x34, 0x38, 0x3C, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7A, 0x7C, 0x7E, 0xF0,
  448. 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
  449. };
  450. #endif /* _OV2640_SETTINGS_H_ */