1 /* 2 * Copyright 2017, 2020, 2023 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_OV7670_H_ 10 #define _FSL_OV7670_H_ 11 12 #include "fsl_common.h" 13 #include "fsl_sccb.h" 14 #include "fsl_camera_device.h" 15 16 /* 17 * Change log: 18 * 19 * 1.0.2 20 * - Fixed dummy line setting bug. 21 * - Disable PCLK during BLANK. 22 * 23 * 1.0.1 24 * - Fixed MISRA-C 2012 issues. 25 * 26 * 1.0.0 27 * - Initial version 28 */ 29 30 /******************************************************************************* 31 * Definitions 32 ******************************************************************************/ 33 34 /*! @brief Register definitions for the OV7670.*/ 35 36 #define OV7670_GAIN_REG 0x00U /*!< Gain lower 8 bits (rest in vref). */ 37 38 #define OV7670_BLUE_REG 0x01U /*!< blue gain. */ 39 40 #define OV7670_RED_REG 0x02U /*!< red gain. */ 41 42 #define OV7670_VREF_REG 0x03U /*!< Pieces of GAIN, VSTART, VSTOP. */ 43 44 #define OV7670_COM1_REG 0x04U /*!< Control 1. */ 45 #define OV7670_COM1_CCIR656_MASK 0x40U /*!< CCIR656 enable. */ 46 47 #define OV7670_BAVE_REG 0x05U /*!< U/B Average level. */ 48 49 #define OV7670_GbAVE_REG 0x06U /*!< Y/Gb Average level. */ 50 51 #define OV7670_AECHH_REG 0x07U /*!< AEC MS 5 bits. */ 52 53 #define OV7670_RAVE_REG 0x08U /*!< V/R Average level. */ 54 55 #define OV7670_COM2_REG 0x09U /*!< Control 2. */ 56 #define OV7670_COM2_SSLEEP_MASK 0x10U /*!< Soft sleep mode. */ 57 58 #define OV7670_PID_REG 0x0AU /*!< Product ID MSB register address. */ 59 #define OV7670_PID_NUM 0x76U /*!< Product ID. */ 60 61 #define OV7670_VER_REG 0x0BU /*!< Product ID LSB register address. */ 62 #define OV7670_VER_NUM 0x73U /*!< Product VERION. */ 63 64 #define OV7670_COM3_REG 0x0CU /*!< Control 3. */ 65 #define OV7670_COM3_SWAP_MASK 0x40U /*!< Byte swap. */ 66 #define OV7670_COM3_SCALEEN_MASK 0x08U /*!< Enable scaling. */ 67 #define OV7670_COM3_DCWEN_MASK 0x04U /*!< Enable downsamp/crop/window. */ 68 69 #define OV7670_COM4_REG 0x0DU /*!< Control 4. */ 70 71 #define OV7670_COM5_REG 0x0EU /*!< All "reserved". */ 72 73 #define OV7670_COM6_REG 0x0FU /*!< Control 6. */ 74 75 #define OV7670_AECH_REG 0x10U /*!< More bits of AEC value. */ 76 77 #define OV7670_CLKRC_REG 0x11U /*!< Clocl control. */ 78 #define OV7670_CLK_EXT_MASK 0x40U /*!< Use external clock directly. */ 79 #define OV7670_CLK_SCALE_MASK 0x3FU /*!< Mask for internal clock scale. */ 80 81 #define OV7670_COM7_REG 0x12U /*!< Control 7. */ 82 #define OV7670_COM7_RESET_MASK 0x80U /*!< Register reset. */ 83 #define OV7670_COM7_FMT_MASK_MASK 0x38U 84 #define OV7670_COM7_FMT_VGA_MASK 0x00U 85 #define OV7670_COM7_FMT_CIF_MASK 0x20U /*!< CIF format. */ 86 #define OV7670_COM7_FMT_QVGA_MASK 0x10U /*!< QVGA format. */ 87 #define OV7670_COM7_FMT_QCIF_MASK 0x08U /*!< QCIF format. */ 88 #define OV7670_COM7_RGB_MASK 0x04U /*!< bits 0 and 2 - RGB format. */ 89 #define OV7670_COM7_YUV_MASK 0x00U /*!< YUV. */ 90 #define OV7670_COM7_BAYER_MASK 0x01U /*!< Bayer format. */ 91 #define OV7670_COM7_PBAYER_MASK 0x05U /*!< "Processed bayer". */ 92 93 #define OV7670_COM8_REG 0x13U /*!< Control 8. */ 94 #define OV7670_COM8_FASTAEC_MASK 0x80U /*!< Enable fast AGC/AEC. */ 95 #define OV7670_COM8_AECSTEP_MASK 0x40U /*!< Unlimited AEC step size. */ 96 #define OV7670_COM8_BFILT_MASK 0x20U /*!< Band filter enable. */ 97 #define OV7670_COM8_AGC_MASK 0x04U /*!< Auto gain enable. */ 98 #define OV7670_COM8_AWB_MASK 0x02U /*!< White balance enable. */ 99 #define OV7670_COM8_AEC_MASK 0x01U /*!< Auto exposure enable. */ 100 101 #define OV7670_COM9_REG 0x14U /*!< Control 9 - gain ceiling. */ 102 103 #define OV7670_COM10_REG 0x15U /*!< Control 10. */ 104 #define OV7670_COM10_HSYNC_MASK 0x40U /*!< HSYNC instead of HREF. */ 105 #define OV7670_COM10_PCLK_HB_MASK 0x20U /*!< Suppress PCLK on horiz blank. */ 106 #define OV7670_COM10_HREF_REV_MASK 0x08U /*!< Reverse HREF. */ 107 #define OV7670_COM10_VS_LEAD_MASK 0x04U /*!< VSYNC on clock leading edge. */ 108 #define OV7670_COM10_VS_NEG_MASK 0x02U /*!< VSYNC negative. */ 109 #define OV7670_COM10_HS_NEG_MASK 0x01U /*!< HSYNC negative. */ 110 111 #define OV7670_RSVD_REG 0x16U /*!< reserved. */ 112 113 #define OV7670_HSTART_REG 0x17U /*!< Horiz start high bits. */ 114 115 #define OV7670_HSTOP_REG 0x18U /*!< Horiz stop high bits. */ 116 117 #define OV7670_VSTART_REG 0x19U /*!< Vert start high bits. */ 118 119 #define OV7670_VSTOP_REG 0x1AU /*!< Vert stop high bits. */ 120 121 #define OV7670_PSHFT_REG 0x1BU /*!< Pixel delay after HREF. */ 122 123 #define OV7670_MIDH_REG 0x1CU /*!< Manuf. ID high. */ 124 125 #define OV7670_MIDL_REG 0x1DU /*!< Manuf. ID low. */ 126 127 #define OV7670_MVFP_REG 0x1EU /*!< Mirror / vflip. */ 128 #define OV7670_MVFP_MIRROR_MASK 0x20U /*!< Mirror image. */ 129 #define OV7670_MVFP_FLIP_MASK 0x10U /*!< Vertical flip. */ 130 131 #define OV7670_LAEC_REG 0x1FU /*!< reserved. */ 132 133 #define OV7670_ADCCTR0_REG 0x20U /*!< ADC control. */ 134 #define OV7670_ADCCTR0_RANGE_ADJ_MASK 0x08U /*!< ADC range adjustment. */ 135 136 #define OV7670_ADCCTR1_REG 0x21U /*!< reserved. */ 137 138 #define OV7670_ADCCTR2_REG 0x22U /*!< reserved. */ 139 140 #define OV7670_ADCCTR3_REG 0x23U /*!< reserved. */ 141 142 #define OV7670_AEW_REG 0x24U /*!< AGC upper limit. */ 143 144 #define OV7670_AEB_REG 0x25U /*!< AGC lower limit. */ 145 146 #define OV7670_VPT_REG 0x26U /*!< AGC/AEC fast mode op region. */ 147 148 #define OV7670_BBIAS_REG 0x27U /*!< B channel signal output bias. */ 149 150 #define OV7670_GbBIAS_REG 0x28U /*!< Gb channel signal output bias. */ 151 152 #define OV7670_RSVD1_REG 0x29U /*!< reserved 1. */ 153 154 #define OV7670_EXHCH_REG 0x2AU /*!< dummy pixel insert MSB. */ 155 156 #define OV7670_EXHCL_REG 0x2BU /*!< dummy pixel insert LSB. */ 157 158 #define OV7670_HSYST_REG 0x30U /*!< HSYNC rising edge delay. */ 159 160 #define OV7670_HSYEN_REG 0x31U /*!< HSYNC falling edge delay. */ 161 162 #define OV7670_HREF_REG 0x32U /*!< HREF pieces. */ 163 164 #define OV7670_CHLF_REG 0x33U /*!< array current control. */ 165 166 #define OV7670_ARBLM_REG 0x34U /*!< array reference control. */ 167 168 #define OV7670_RSVD2_REG 0x35U /*!< reserved 2. */ 169 170 #define OV7670_RSVD3_REG 0x36U /*!< reserved 3. */ 171 172 #define OV7670_ADC_REG 0x37U /*!< ADC control. */ 173 174 #define OV7670_ACOM_REG 0x38U /*!< ADC and Analog common mode control. */ 175 176 #define OV7670_OFON_REG 0x39U /*!< ADC offset control. */ 177 178 #define OV7670_TSLB_REG 0x3AU /*!< lots of stuff. */ 179 #define OV7670_TSLB_YLAST_MASK 0x04U /*!< UYVY or VYUY - see com13. */ 180 181 #define OV7670_COM11_REG 0x3BU /*!< Control 11. */ 182 #define OV7670_COM11_NIGHT_MASK 0x80U /*!< NIght mode enable. */ 183 #define OV7670_COM11_NMFR_MASK 0x60U /*!< Two bit NM frame rate. */ 184 #define OV7670_COM11_HZAUTO_MASK 0x10U /*!< Auto detect 50/60 Hz. */ 185 #define OV7670_COM11_50HZ_MASK 0x08U /*!< Manual 50Hz select. */ 186 #define OV7670_COM11_EXP_MASK 0x02U 187 188 #define OV7670_COM12_REG 0x3CU /*!< Control 12. */ 189 #define OV7670_COM12_HREF_MASK 0x80U /*!< HREF always. */ 190 191 #define OV7670_COM13_REG 0x3DU /*!< Control 13. */ 192 #define OV7670_COM13_GAMMA_MASK 0x80U /*!< Gamma enable. */ 193 #define OV7670_COM13_UVSAT_MASK 0x40U /*!< UV saturation auto adjustment. */ 194 #define OV7670_COM13_UVSWAP_MASK 0x01U /*!< V before U - w/TSLB. */ 195 196 #define OV7670_COM14_REG 0x3EU /*!< Control 14. */ 197 #define OV7670_COM14_DCWEN_MASK 0x10U /*!< DCW/PCLK-scale enable. */ 198 199 #define OV7670_EDGE_REG 0x3FU /*!< Edge enhancement factor. */ 200 201 #define OV7670_COM15_REG 0x40U /*!< Control 15. */ 202 #define OV7670_COM15_R10F0_MASK 0x00U /*!< Data range 10 to F0. */ 203 #define OV7670_COM15_R01FE_MASK 0x80U /*!< 01 to FE. */ 204 #define OV7670_COM15_R00FF_MASK 0xC0U /*!< 00 to FF. */ 205 #define OV7670_COM15_RGB565_MASK 0x10U /*!< RGB565 output. */ 206 #define OV7670_COM15_RGB555_MASK 0x30U /*!< RGB555 output. */ 207 208 #define OV7670_COM16_REG 0x41U /*!< Control 16. */ 209 #define OV7670_COM16_AWBGAIN_MASK 0x08U /*!< AWB gain enable. */ 210 211 #define OV7670_COM17_REG 0x42U /*!< Control 17. */ 212 #define OV7670_COM17_AECWIN_MASK 0xc0U /*!< AEC window - must match COM4. */ 213 #define OV7670_COM17_CBAR_MASK 0x08U /*!< DSP Color bar. */ 214 215 #define OV7670_AWBC1_REG 0x43U /*!< AWB control 1. */ 216 217 #define OV7670_AWBC2_REG 0x44U /*!< AWB control 2. */ 218 219 #define OV7670_AWBC3_REG 0x45U /*!< AWB control 3. */ 220 221 #define OV7670_AWBC4_REG 0x46U /*!< AWB control 4. */ 222 223 #define OV7670_AWBC5_REG 0x47U /*!< AWB control 5. */ 224 225 #define OV7670_AWBC6_REG 0x48U /*!< AWB control 6. */ 226 227 #define OV7670_MTX1_REG 0x4fU /*!< Matrix Coefficient 1. */ 228 229 #define OV7670_MTX2_REG 0x50U /*!< Matrix Coefficient 2. */ 230 231 #define OV7670_MTX3_REG 0x51U /*!< Matrix Coefficient 3. */ 232 233 #define OV7670_MTX4_REG 0x52U /*!< Matrix Coefficient 4. */ 234 235 #define OV7670_MTX5_REG 0x53U /*!< Matrix Coefficient 5. */ 236 237 #define OV7670_MTX6_REG 0x54U /*!< Matrix Coefficient 6. */ 238 239 #define OV7670_BRIGHT_REG 0x55U /*!< Brightness. */ 240 241 #define OV7670_CONTRAS_REG 0x56U /*!< Contrast control. */ 242 243 #define OV7670_CONTRAS_CENTER_REG 0x57U /*!< Contrast cetnter control. */ 244 245 #define OV7670_MTXS_REG 0x58U /*!< Matrix Coefficient Sign. */ 246 #define OV7670_AWBC7_MASK 0x59U /*!< AWB Control 7. */ 247 #define OV7670_AWBC8_MASK 0x5AU /*!< AWB Control 8. */ 248 #define OV7670_AWBC9_MASK 0x5BU /*!< AWB Control 9. */ 249 #define OV7670_AWBC10_MASK 0x5CU /*!< AWB Control 10. */ 250 #define OV7670_AWBC11_MASK 0x5DU /*!< AWB Control 11. */ 251 #define OV7670_AWBC12_MASK 0x5EU /*!< AWB Control 12. */ 252 253 #define OV7670_MANU_REG 0x67U /*!< Manual U value. */ 254 255 #define OV7670_MANV_REG 0x68U /*!< Manual V value. */ 256 257 #define OV7670_GFIX_REG 0x69U /*!< Fix gain control. */ 258 259 #define OV7670_GGAIN_REG 0x6AU /*!< G Channel AWB Gain. */ 260 261 #define OV7670_DBLV_REG 0x6BU 262 263 #define OV7670_AWBCTR3_REG 0x6CU /*!< AWB Control 3. */ 264 265 #define OV7670_AWBCTR2_REG 0x6DU /*!< AWB Control 2. */ 266 267 #define OV7670_AWBCTR1_REG 0x6EU /*!< AWB Control 1. */ 268 269 #define OV7670_AWBCTR0_REG 0x6FU /*!< AWB Control 0. */ 270 271 #define OV7670_SCALING_XSC_REG 0x70U /*!< horizontal scale factor. */ 272 273 #define OV7670_SCALING_YSC_REG 0x71U /*!< vertical scale factor. */ 274 275 #define OV7670_SCALING_DCWCTR_REG 0x72U /*!< DCW control. */ 276 277 #define OV7670_SCALING_PCLK_DIV_REG 0x73U /*!< clock divider control. */ 278 279 #define OV7670_REG74_REG 0x74U /*!< register 74. */ 280 281 #define OV7670_REG76_REG 0x76U /*!< OV's name. */ 282 #define OV7670_REG76_BLKPCOR_MASK 0x80U /*!< Black pixel correction enable. */ 283 #define OV7670_REG76_WHTPCOR_MASK 0x40U /*!< White pixel correction enable. */ 284 285 #define OV7670_SLOP_REG 0x7AU /*!< gamma curve highest segment slop. */ 286 287 #define OV7670_GAM1_REG 0x7BU /*!< gamma curve 1 segment slop. */ 288 #define OV7670_GAM2_REG 0x7CU /*!< gamma curve 2 segment slop. */ 289 #define OV7670_GAM3_REG 0x7DU /*!< gamma curve 3 segment slop. */ 290 #define OV7670_GAM4_REG 0x7EU /*!< gamma curve 4 segment slop. */ 291 #define OV7670_GAM5_REG 0x7FU /*!< gamma curve 5 segment slop. */ 292 #define OV7670_GAM6_REG 0x80U /*!< gamma curve 6 segment slop. */ 293 #define OV7670_GAM7_REG 0x81U /*!< gamma curve 7 segment slop. */ 294 #define OV7670_GAM8_REG 0x82U /*!< gamma curve 8 segment slop. */ 295 #define OV7670_GAM9_REG 0x83U /*!< gamma curve 9 segment slop. */ 296 #define OV7670_GAM10_REG 0x84U /*!< gamma curve 10 segment slop. */ 297 #define OV7670_GAM11_REG 0x85U /*!< gamma curve 11 segment slop. */ 298 #define OV7670_GAM12_REG 0x86U /*!< gamma curve 12 segment slop. */ 299 #define OV7670_GAM13_REG 0x87U /*!< gamma curve 13 segment slop. */ 300 #define OV7670_GAM14_REG 0x88U /*!< gamma curve 14 segment slop. */ 301 #define OV7670_GAM15_REG 0x89U /*!< gamma curve 15 segment slop. */ 302 #define OV7670_RGB444_REG 0x8cU /*!< RGB 444 control. */ 303 #define OV7670_R444_ENABLE_MASK 0x02U /*!< Turn on RGB444, overrides 5x5. */ 304 #define OV7670_R444_RGBX_MASK 0x01U /*!< Empty nibble at end. */ 305 306 #define OV7670_DM_LNL_REG 0x92U /*!< dummy line low 8 bits. */ 307 308 #define OV7670_DM_LNH_REG 0x93U /*!< dummy line high 8 bits. */ 309 310 #define OV7670_BD50ST_REG 0x9dU /*!< 50Hz banding filter value. */ 311 312 #define OV7670_BD60ST_REG 0x9eU /*!< 60Hz banding filter value. */ 313 314 #define OV7670_HAECC1_REG 0x9fU /*!< Hist AEC/AGC control 1. */ 315 316 #define OV7670_HAECC2_REG 0xa0U /*!< Hist AEC/AGC control 2. */ 317 318 #define OV7670_SCALING_PCLK_DELAY_REG 0xa2U /*!< pixel clock delay. */ 319 320 #define OV7670_BD50MAX_REG 0xa5U /*!< 50hz banding step limit. */ 321 322 #define OV7670_HAECC3_REG 0xa6U /*!< Hist AEC/AGC control 3. */ 323 324 #define OV7670_HAECC4_REG 0xa7U /*!< Hist AEC/AGC control 4. */ 325 326 #define OV7670_HAECC5_REG 0xa8U /*!< Hist AEC/AGC control 5. */ 327 328 #define OV7670_HAECC6_REG 0xa9U /*!< Hist AEC/AGC control 6. */ 329 330 #define OV7670_HAECC7_REG 0xaaU /*!< Hist AEC/AGC control 7. */ 331 332 #define OV7670_BD60MAX_REG 0xabU /*!< 60hz banding step limit. */ 333 334 #define OV7670_STR_OPT_REG 0xacU /*!< strobe control. */ 335 336 #define OV7670_STR_R_REG 0xadU /*!< R gain for LED output frame. */ 337 338 #define OV7670_STR_G_REG 0xaeU /*!< G gain for LED output frame. */ 339 340 #define OV7670_STR_B_REG 0xafU /*!< B gain for LED output frame. */ 341 342 #define OV7670_ABLC1_REG 0xb1U /*!< ABLC function control. */ 343 344 #define OV7670_THL_ST_REG 0xb3U /*!< ABLC target. */ 345 346 /*! @} */ 347 348 /*! @brief Configuration of window by setting the starting point configuration structure */ 349 typedef struct ov7670_window_startPoint 350 { 351 uint16_t hstartCoordinate; 352 uint16_t vstartCoordinate; 353 } ov7670_window_start_point_t; 354 355 /*! end of ov7670 handler configuration structure */ 356 357 /*! @brief Output format configuration structure */ 358 typedef struct ov7670_output_format_config 359 { 360 uint8_t com7; 361 uint8_t com15; 362 uint8_t rgb444; 363 } ov7670_output_format_config_t; 364 /*! end of Output format configuration structure */ 365 366 /*! @brief Resolution configuration structure */ 367 typedef struct ov7670_resolution_config 368 { 369 uint8_t com7; 370 uint8_t com3; 371 uint8_t com14; 372 uint8_t scalingXsc; 373 uint8_t scalingYsc; 374 uint8_t scalingDcwctr; 375 uint8_t scalingPclkDiv; 376 uint8_t scalingPclkDelay; 377 } ov7670_resolution_config_t; 378 /*! end of Output format configuration structure */ 379 380 /*! @brief Frame rate configuration data structure */ 381 typedef struct ov7670_frame_rate_config 382 { 383 uint8_t clkrc; 384 uint8_t dblv; 385 uint8_t exhch; 386 uint8_t exhcl; 387 uint8_t dm_lnl; 388 uint8_t dm_lnh; 389 } ov7670_frame_rate_config_t; 390 /*! end of Frame rate configuration data structure */ 391 392 /*! @brief Night mode configuration data structure */ 393 typedef struct ov7670_night_mode_config 394 { 395 uint8_t com11; 396 } ov7670_night_mode_config_t; 397 /*! end of night mode configuration data structure */ 398 399 /*! @brief Banding filter selection data structure */ 400 typedef struct ov7670_filter_config 401 { 402 uint8_t com8; 403 uint8_t bd50st; 404 uint8_t bd60st; 405 uint8_t bd50max; 406 uint8_t bd60max; 407 uint8_t com11; 408 } ov7670_filter_config_t; 409 /*! end of Banding filter selection data structure */ 410 411 /*! @brief White balance configuration structure */ 412 typedef struct ov7670_white_balance_config 413 { 414 uint8_t com8; 415 uint8_t awbctr0; 416 uint8_t awbctr1; 417 uint8_t awbctr2; 418 uint8_t awbctr3; 419 uint8_t awbc1; 420 uint8_t awbc2; 421 uint8_t awbc3; 422 uint8_t awbc4; 423 uint8_t awbc5; 424 uint8_t awbc6; 425 uint8_t com16; 426 } ov7670_white_balance_config_t; 427 /*! end of White balance configuration structure */ 428 429 /*! @brief Light mode configuration structure */ 430 typedef struct ov7670_light_mode_config 431 { 432 uint8_t com8; 433 uint8_t com9; 434 uint8_t red; 435 uint8_t green; 436 uint8_t blue; 437 } ov7670_light_mode_config_t; 438 /*! end of Light mode configuration structure */ 439 440 /*! @brief Color saturation configuration structure */ 441 typedef struct ov7670_color_saturation_config 442 { 443 uint8_t mtx1; 444 uint8_t mtx2; 445 uint8_t mtx3; 446 uint8_t mtx4; 447 uint8_t mtx5; 448 uint8_t mtx6; 449 uint8_t mtxs; 450 uint8_t com16; 451 } ov7670_color_saturation_config_t; 452 /*! end of Color saturation configuration structure */ 453 454 /*! @brief Special effects configuration structure */ 455 typedef struct ov7670_special_effect_config 456 { 457 uint8_t tslb; 458 uint8_t manu; 459 uint8_t manv; 460 } ov7670_special_effect_config_t; 461 /*! end of Special effects configuration structure */ 462 463 /*! @brief Windowing configuration structure */ 464 typedef struct ov7670_windowing_config 465 { 466 uint8_t href; 467 uint8_t hstart; 468 uint8_t hstop; 469 uint8_t vref; 470 uint8_t vstart; 471 uint8_t vstop; 472 } ov7670_windowing_config_t; 473 474 /*! @brief Gamma curve slope configuration structure */ 475 typedef struct ov7670_gammaCurveSlopeConfig 476 { 477 uint8_t slope; 478 uint8_t gam1; 479 uint8_t gam2; 480 uint8_t gam3; 481 uint8_t gam4; 482 uint8_t gam5; 483 uint8_t gam6; 484 uint8_t gam7; 485 uint8_t gam8; 486 uint8_t gam9; 487 uint8_t gam10; 488 uint8_t gam11; 489 uint8_t gam12; 490 uint8_t gam13; 491 uint8_t gam14; 492 uint8_t gam15; 493 } ov7670_gamma_curve_slope_config_t; 494 /*! end of Gamma curve slope configuration structure */ 495 496 /*! @brief Advanced initialization structure of ov7670 */ 497 typedef struct ov7670_advanced_config 498 { 499 ov7670_filter_config_t *filter; 500 ov7670_night_mode_config_t *nightMode; 501 ov7670_white_balance_config_t *whiteBalance; 502 ov7670_light_mode_config_t *lightMode; 503 ov7670_color_saturation_config_t *colorSaturation; 504 ov7670_special_effect_config_t *specialEffect; 505 ov7670_gamma_curve_slope_config_t *gammaCurveSlope; 506 } ov7670_advanced_config_t; 507 508 /*! @brief Initialization structure of ov7670 */ 509 typedef struct ov7670_config 510 { 511 ov7670_output_format_config_t *outputFormat; 512 uint32_t resolution; 513 ov7670_frame_rate_config_t *frameRate; 514 uint8_t contrast; 515 uint8_t brightness; 516 ov7670_advanced_config_t *advancedConfig; 517 } ov7670_config_t; 518 519 /*! @brief ov7670 input clock. */ 520 typedef enum _ov7670_xclock 521 { 522 kOV7670_InputClock24MHZ, /*!< Input clock 24MHZ. */ 523 kOV7670_InputClock26MHZ, /*!< Input clock 26MHZ. */ 524 kOV7670_InputClock12MHZ, /*!< Input clock 12MHZ. */ 525 kOV7670_InputClock13MHZ, /*!< Input clock 13MHZ. */ 526 } ov7670_xclock_t; 527 528 /*! 529 * @brief OV7670 resource. 530 * 531 * Before initialize the OV7670, the resource must be initialized that the SCCB 532 * I2C could start to work. 533 */ 534 typedef struct _ov7670_resource 535 { 536 sccb_i2c_send_func_t i2cSendFunc; /*!< I2C send function. */ 537 sccb_i2c_receive_func_t i2cReceiveFunc; /*!< I2C receive function. */ 538 ov7670_xclock_t xclock; /*!< Input clock for ov7670. */ 539 } ov7670_resource_t; 540 541 /*! @brief OV7670 operation functions. */ 542 extern const camera_device_operations_t ov7670_ops; 543 544 /*! @brief OV7670 resolution options */ 545 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_VGA_DEFAULT; 546 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_QVGA_DEFAULT; 547 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_QQVGA_DEFAULT; 548 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_CIF_DEFAULT; 549 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_QCIF_DEFAULT; 550 extern ov7670_window_start_point_t OV7670_WINDOW_START_POINT_QQCIF_DEFAULT; 551 552 /*! @brief Night mode initialization structure data */ 553 extern ov7670_output_format_config_t OV7670_FORMAT_RawBayerRGB; 554 extern ov7670_output_format_config_t OV7670_FORMAT_ProcessedBayerRGB; 555 extern ov7670_output_format_config_t OV7670_FORMAT_YUV422; 556 extern ov7670_output_format_config_t OV7670_FORMAT_GRB422; 557 extern ov7670_output_format_config_t OV7670_FORMAT_RGB565; 558 extern ov7670_output_format_config_t OV7670_FORMAT_RGB555; 559 extern ov7670_output_format_config_t OV7670_FORMAT_xRGB444; 560 extern ov7670_output_format_config_t OV7670_FORMAT_RGBx444; 561 562 /*! @brief resolution initialization structure data */ 563 extern ov7670_resolution_config_t OV7670_RESOLUTION_VGA; 564 extern ov7670_resolution_config_t OV7670_RESOLUTION_QVGA; 565 extern ov7670_resolution_config_t OV7670_RESOLUTION_QQVGA; 566 567 extern ov7670_resolution_config_t OV7670_RESOLUTION_CIF; 568 extern ov7670_resolution_config_t OV7670_RESOLUTION_QCIF; 569 extern ov7670_resolution_config_t OV7670_RESOLUTION_QQCIF; 570 571 extern ov7670_resolution_config_t OV7670_RESOLUTION_QVGA_ORIGINAL; 572 extern ov7670_resolution_config_t OV7670_RESOLUTION_QCIF_ORIGINAL; 573 574 /*! @brief Special effects configuration initialization structure data */ 575 extern ov7670_windowing_config_t OV7670_WINDOW_VGA; 576 extern ov7670_windowing_config_t OV7670_WINDOW_QVGA; 577 extern ov7670_windowing_config_t OV7670_WINDOW_QQVGA; 578 extern ov7670_windowing_config_t OV7670_WINDOW_CIF; 579 extern ov7670_windowing_config_t OV7670_WINDOW_QCIF; 580 extern ov7670_windowing_config_t OV7670_WINDOW_QQCIF; 581 582 /*! @brief Frame rate initialization structure data */ 583 extern ov7670_frame_rate_config_t OV7670_30FPS_26MHZ_XCLK; 584 extern ov7670_frame_rate_config_t OV7670_25FPS_26MHZ_XCLK; 585 extern ov7670_frame_rate_config_t OV7670_15FPS_26MHZ_XCLK; 586 extern ov7670_frame_rate_config_t OV7670_14FPS_26MHZ_XCLK; 587 588 extern ov7670_frame_rate_config_t OV7670_30FPS_24MHZ_XCLK; 589 extern ov7670_frame_rate_config_t OV7670_25FPS_24MHZ_XCLK; 590 extern ov7670_frame_rate_config_t OV7670_15FPS_24MHZ_XCLK; 591 extern ov7670_frame_rate_config_t OV7670_14FPS_24MHZ_XCLK; 592 593 extern ov7670_frame_rate_config_t OV7670_30FPS_13MHZ_XCLK; 594 extern ov7670_frame_rate_config_t OV7670_25FPS_13MHZ_XCLK; 595 extern ov7670_frame_rate_config_t OV7670_15FPS_13MHZ_XCLK; 596 extern ov7670_frame_rate_config_t OV7670_14FPS_13MHZ_XCLK; 597 598 extern ov7670_frame_rate_config_t OV7670_30FPS_12MHZ_XCLK; 599 extern ov7670_frame_rate_config_t OV7670_25FPS_12MHZ_XCLK; 600 extern ov7670_frame_rate_config_t OV7670_15FPS_12MHZ_XCLK; 601 extern ov7670_frame_rate_config_t OV7670_14FPS_12MHZ_XCLK; 602 603 /*! @brief Night mode initialization structure data */ 604 extern ov7670_night_mode_config_t OV7670_NIGHT_MODE_DISABLED; 605 extern ov7670_night_mode_config_t OV7670_NIGHT_MODE_AUTO_FR_DIVBY2; 606 extern ov7670_night_mode_config_t OV7670_NIGHT_MODE_AUTO_FR_DIVBY4; 607 extern ov7670_night_mode_config_t OV7670_NIGHT_MODE_AUTO_FR_DIVBY8; 608 609 /*! @brief Banding filter initialization structure data */ 610 extern ov7670_filter_config_t OV7670_FILTER_DISABLED; 611 extern ov7670_filter_config_t OV7670_FILTER_30FPS_60HZ; 612 extern ov7670_filter_config_t OV7670_FILTER_15FPS_60HZ; 613 extern ov7670_filter_config_t OV7670_FILTER_25FPS_50HZ; 614 extern ov7670_filter_config_t OV7670_FILTER_14FPS_50HZ; 615 extern ov7670_filter_config_t OV7670_FILTER_30FPS_60HZ_AUTO_LIGHT_FREQ_DETECT; 616 extern ov7670_filter_config_t OV7670_FILTER_15FPS_60HZ_AUTO_LIGHT_FREQ_DETECT; 617 extern ov7670_filter_config_t OV7670_FILTER_25FPS_50HZ_AUTO_LIGHT_FREQ_DETECT; 618 extern ov7670_filter_config_t OV7670_FILTER_14FPS_50HZ_AUTO_LIGHT_FREQ_DETECT; 619 620 /*! @brief White balance initialization structure data */ 621 extern ov7670_white_balance_config_t OV7670_WHITE_BALANCE_DEFAULT; 622 extern ov7670_white_balance_config_t OV7670_WHITE_BALANCE_DISABLED; 623 extern ov7670_white_balance_config_t OV7670_WHITE_BALANCE_SIMPLE; 624 625 /*! @brief Light mode configuration initialization structure data */ 626 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_DISABLED; 627 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_AUTO; 628 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_SUNNY; 629 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_CLOUDY; 630 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_OFFICE; 631 extern ov7670_light_mode_config_t OV7670_LIGHT_MODE_HOME; 632 633 /*! @brief Color saturation configuration initialization structure data */ 634 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_4PLUS; 635 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_3PLUS; 636 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_2PLUS; 637 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_1PLUS; 638 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_0; 639 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_DEFAULT; 640 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_1MINUS; 641 extern ov7670_color_saturation_config_t OV7670_COLOR_SATURATION_2MINUS; 642 643 /*! @brief Special effects configuration initialization structure data */ 644 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_ANTIQUE; 645 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_SEPHIA; 646 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_BLUISH; 647 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_GREENISH; 648 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_REDISH; 649 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_BW; 650 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_NEGATIVE; 651 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_BW_NEGATIVE; 652 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_NORMAL; 653 extern ov7670_special_effect_config_t OV7670_SPECIAL_EFFECT_DISABLED; 654 655 /*! @brief Special effects configuration initialization structure data */ 656 extern ov7670_gamma_curve_slope_config_t OV7670_GAMMA_CURVE_SLOPE_DEFAULT; 657 extern ov7670_gamma_curve_slope_config_t OV7670_GAMMA_CURVE_SLOPE1; 658 659 /******************************************************************************* 660 * API 661 ******************************************************************************/ 662 663 #if defined(__cplusplus) 664 extern "C" { 665 #endif 666 667 /*! 668 * @brief Get ov7670 default configuration. 669 * 670 * config.outputFormat = (ov7670_output_format_config_t *)&OV7670_FORMAT_RGB565; 671 * config.resolution = kVIDEO_ResolutionQQVGA; 672 * config.frameRate = (ov7670_frame_rate_config_t *)&OV7670_25FPS_12MHZ_XCLK, 673 * config.contrast = 0x30; 674 * config.brightness = 0x10; 675 * config.advancedConfig = NULL; 676 * @param config ov7670 configuration structure #ov7670_config_t. 677 */ 678 void OV7670_GetDefaultConfig(ov7670_config_t *config); 679 680 /*! 681 * @brief ov7670 initialize function. 682 * 683 * This function will initialize ov7670 using the configuration user passed in. 684 * Note: If the config pointer is NULL, it would just simply reset ov7670 685 * If config is not NULL but the config->advancedConfig is NULL, it will use the below advanced setting: 686 * advancedConfig = 687 * { \ 688 * .filter = (ov7670_filter_config_t *)&OV7670_FILTER_25FPS_50HZ, \ 689 * .nightMode = (ov7670_night_mode_config_t *)&OV7670_NIGHT_MODE_DISABLED, \ 690 * .whiteBalance = (ov7670_white_balance_config_t *)&OV7670_WHITE_BALANCE_SIMPLE, \ 691 * .lightMode = (ov7670_light_mode_config_t *)&OV7670_LIGHT_MODE_DISABLED, \ 692 * .colorSaturation = (ov7670_color_saturation_config_t *)&OV7670_COLOR_SATURATION_2PLUS, \ 693 * .specialEffect = (ov7670_special_effect_config_t *)&OV7670_SPECIAL_EFFECT_DISABLED, \ 694 * .gammaCurveSlope = (ov7670_gamma_curve_slope_config_t *)&OV7670_GAMMA_CURVE_SLOPE_DEFAULT, \ 695 * } 696 * @param handle Camera device handle. 697 * @param config ov7670 configuration structure #ov7670_config_t. 698 */ 699 700 status_t OV7670_CameraInit(camera_device_handle_t *handle, const ov7670_config_t *config); 701 /*! 702 * @brief Write CONTRAST register to ov7670 using I2C. 703 * @param handle Camera device handle. 704 * @param val contrast value. 705 */ 706 status_t OV7670_ContrastAdjustment(camera_device_handle_t *handle, uint8_t val); 707 708 /*! 709 * @brief Write BRIGHT register to ov7670 using I2C. 710 * @param handle Camera device handle. 711 * @param val brightness value. 712 */ 713 status_t OV7670_BrightnessAdjustment(camera_device_handle_t *handle, uint8_t val); 714 715 /*! 716 * @brief OV7670 configuration. 717 * @param handle Camera device handle. 718 * @param config #ov7670_config_t structure. 719 */ 720 status_t OV7670_Configure(camera_device_handle_t *handle, const ov7670_config_t *config); 721 722 /*! 723 * @brief OV7670 Output format configuration. 724 * @param handle Camera device handle. 725 * @param outputFormatConfig #ov7670_output_format_config_t structure. 726 */ 727 status_t OV7670_OutputFormat(camera_device_handle_t *handle, const ov7670_output_format_config_t *outputFormatConfig); 728 729 /*! 730 * @brief OV7670 Resolution configuration. 731 * @param handle Camera device handle. 732 * @param resolution #video_resolution_t resolution . 733 */ 734 status_t OV7670_Resolution(camera_device_handle_t *handle, uint32_t resolution); 735 736 /*! 737 * @brief OV7670 frame rate adjustment. 738 * @param handle Camera device handle. 739 * @param frameRateConfig #ov7670_frame_rate_config_t structure. 740 */ 741 status_t OV7670_FrameRateAdjustment(camera_device_handle_t *handle, const ov7670_frame_rate_config_t *frameRateConfig); 742 743 /*! 744 * @brief OV7670 night mode configuration. 745 * @param handle Camera device handle. 746 * @param nightModeConfig #ov7670_night_mode_config_t structure. 747 */ 748 status_t OV7670_NightMode(camera_device_handle_t *handle, const ov7670_night_mode_config_t *nightModeConfig); 749 750 /*! 751 * @brief OV7670 Bnading filter selection configuration. 752 * @param handle Camera device handle. 753 * @param filterConfig #ov7670_filter_config_t structure. 754 */ 755 status_t OV7670_BandingFilterSelection(camera_device_handle_t *handle, const ov7670_filter_config_t *filterConfig); 756 757 /*! 758 * @brief OV7670 White balance configuration. 759 * @param handle Camera device handle. 760 * @param whiteBalanceConfig #ov7670_white_balance_config_t structure. 761 */ 762 status_t OV7670_WhiteBalance(camera_device_handle_t *handle, const ov7670_white_balance_config_t *whiteBalanceConfig); 763 764 /*! 765 * @brief OV7670 Light mode configuration. 766 * @param handle Camera device handle. 767 * @param lightModeConfig #ov7670_light_mode_config_t structure. 768 */ 769 status_t OV7670_LightMode(camera_device_handle_t *handle, const ov7670_light_mode_config_t *lightModeConfig); 770 771 /*! 772 * @brief OV7670 Color saturation configuration. 773 * @param handle Camera device handle. 774 * @param colorSaturationConfig #ov7670_color_saturation_config_t structure. 775 */ 776 status_t OV7670_ColorSaturation(camera_device_handle_t *handle, 777 const ov7670_color_saturation_config_t *colorSaturationConfig); 778 779 /*! 780 * @brief OV7670 Special effects configuration. 781 * @param handle Camera device handle. 782 * @param specialEffectConfig #ov7670_special_effect_config_t structure. 783 */ 784 status_t OV7670_SpecialEffects(camera_device_handle_t *handle, 785 const ov7670_special_effect_config_t *specialEffectConfig); 786 787 /*! 788 * @brief OV7670 Windowing configuration. 789 * @param handle Camera device handle. 790 * @param windowingConfig #ov7670_windowing_config_t structure. 791 */ 792 status_t OV7670_SetWindow(camera_device_handle_t *handle, const ov7670_windowing_config_t *windowingConfig); 793 794 /*! 795 * @brief OV7670 Configure the window by setting initial coordinates and 796 * resolution. 797 * @param handle Camera device handle. 798 * @param startPoint #ov7670_window_start_point_t structure. 799 * @param resolution #ovideo_resolution_t resolution. 800 */ 801 status_t OV7670_SetWindowByCoordinates(camera_device_handle_t *handle, 802 ov7670_window_start_point_t *startPoint, 803 uint32_t resolution); 804 805 /*! 806 * @brief OV7670 Gamma curve slope configuration. 807 * @param handle Camera device handle. 808 * @param gammaCurveSlopeConfig #ov7670_gamma_curve_slope_config_t structure. 809 */ 810 status_t OV7670_GammaCurveSlope(camera_device_handle_t *handle, 811 const ov7670_gamma_curve_slope_config_t *gammaCurveSlopeConfig); 812 813 #if defined(__cplusplus) 814 } 815 #endif 816 817 #endif /* _FSL_OV7670_H_ */ 818