SAMV71 Xplained Ultra Software Package 1.3

ov.c

00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2013, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029  
00030  
00031 /*----------------------------------------------------------------------------
00032  *        Headers
00033  *----------------------------------------------------------------------------*/
00034 #include "board.h"
00035 
00036 
00037 const capture_size ov_sizes[] = {
00038         //{width, height}
00039         { 160, 120 },   // QQVGA
00040         { 352, 288 },   // CIF
00041         { 320, 240 },
00042         { 640, 360 },
00043         { 640, 480 },
00044         // SWVGA
00045         { 800, 600 },
00046         /// SXGA
00047         {1280, 960 },
00048         {1280, 720 },
00049         /// UXGA
00050         {1600, 1200 },
00051 };
00052 
00053 /*----------------------------------------------------------------------------
00054  *        Global Functions
00055  *----------------------------------------------------------------------------*/
00056  
00057 /**
00058  * \brief  Configure the OV for a specified image size, pixel format, 
00059  * and frame period.
00060  */
00061 void ov_configure(Twid *pTwid, uint8_t ovType, uint32_t width, uint32_t heigth)
00062 {
00063     const struct ov_reg *reg_conf;
00064     uint8_t goodCaptureSize = 0;
00065     uint8_t i;
00066 
00067     reg_conf = ov5640_yuv_vga;
00068     TRACE_DEBUG("ovxxx_configure\n\r");
00069     for( i = 0; i< sizeof(ov_sizes); i++ ) {
00070         if( ov_sizes[i].width == width ) {
00071             if( ov_sizes[i].height != heigth ) {
00072                 TRACE_INFO("ov configure vsize not define\n\r");
00073             } else {
00074                 goodCaptureSize = 1;
00075                 break;
00076             }
00077         }
00078     }
00079     if( goodCaptureSize == 0 ) {
00080         TRACE_ERROR("Problem size\n\r");
00081         while(1);
00082     }
00083     switch (ovType){
00084     case OV_2640: {
00085          // Default value
00086         reg_conf = ov2640_yuv_qvga;
00087         // common register initialization
00088         switch(width) {
00089         case 320: //VGA
00090             printf("-I- QVGA 640 x 480\n\r");
00091             reg_conf = ov2640_yuv_qvga;
00092             break;
00093         case 640: //VGA
00094             TRACE_INFO("VGA 640 x 480\n\r");
00095             reg_conf = ov2640_yuv_vga;
00096             break;
00097         default:
00098             TRACE_DEBUG("ov2640_configure problem\n\r");
00099             break;
00100         }
00101              break;
00102         }
00103     case OV_7740: {
00104         // Default value
00105         reg_conf = OV7740_VGA_YUV422;
00106         // common register initialization
00107         switch(width) {
00108         case 640: //VGA
00109              TRACE_INFO(" VGA 640 x 480\n\r");
00110              reg_conf = OV7740_VGA_YUV422;
00111              break;
00112 
00113         case 352: //CIF
00114              TRACE_INFO(" VGA 640 x 480\n\r");
00115              reg_conf = OV7740_CIF_YUV422;
00116              break;
00117 
00118         case 320: //QVGA
00119              TRACE_INFO(" QVGA 320 x 240\n\r");
00120              reg_conf = OV7740_QVGA_YUV422;
00121              break;
00122 
00123         case 160: //QQVGA
00124             TRACE_INFO(" QVGA 320 x 240\n\r");
00125              reg_conf = OV7740_QQVGA_YUV422;
00126              break;
00127 
00128         default:
00129              TRACE_DEBUG("ov7740_configure problem\n\r");
00130              break;
00131         }
00132          break;
00133         }
00134     case OV_9740: {
00135          // Default value
00136          reg_conf = ov9740_yuv_vga;
00137          // common register initialization
00138          switch(width) {
00139          case 640: //VGA
00140              TRACE_INFO(" VGA 640 x 360\n\r");
00141              reg_conf = ov9740_yuv_vga;
00142              break;
00143          case 1280: //VGA
00144              TRACE_INFO(" VGA 1280 x 720\n\r");
00145              reg_conf = ov9740_yuv_sxga;
00146              break;
00147          default:
00148              TRACE_DEBUG("ov9740_configure problem\n\r");
00149              break;
00150          }
00151          break;
00152         }
00153     case OV_2643: {
00154          // Default value
00155          reg_conf = ov2643_yuv_vga;
00156          // common register initialization
00157          switch(width) {
00158          case 1600: //UXGA
00159              TRACE_INFO(" UXGA 1600 x 1200 \n\r");
00160              reg_conf = ov2643_yuv_uxga;
00161              break;
00162          case 800: //SWVGA
00163              TRACE_INFO("SWVGA 800 x 600\n\r");
00164              reg_conf = ov2643_yuv_swvga;
00165              break;
00166          case 640: //VGA
00167              TRACE_INFO(" VGA 640 x 480\n\r");
00168              reg_conf = ov2643_yuv_vga;
00169              break; 
00170          default:  
00171              TRACE_DEBUG("ov2643_configure problem\n\r");
00172              break;
00173          }
00174         break;
00175         }
00176     case OV_5640: {
00177          // Default value
00178          reg_conf = ov5640_yuv_vga;
00179          // common register initialization
00180          switch(width) {
00181          case 640: //VGA
00182              TRACE_INFO(" VGA 640 x 480\n\r");
00183              reg_conf = ov5640_yuv_vga;
00184              break;
00185          case 1280: //SXGA
00186              TRACE_INFO(" SXGA 1280 x 720\n\r");
00187              reg_conf = ov5640_yuv_sxga;
00188              break;
00189          default:  
00190              TRACE_DEBUG("ov5640_configure problem\n\r");
00191              break;
00192          }
00193          break;
00194     }
00195     }
00196     if ((ovType == OV_5640) || (ovType == OV_9740))
00197         ov_write_regs16(pTwid, reg_conf);
00198     else 
00199         ov_write_regs8(pTwid, reg_conf);
00200 }
00201 
00202 /**
00203  * \brief  Configure the OV 5640 afc firmware. 
00204  */
00205 void ov_5640Afc_Firmware(Twid *pTwid)
00206 {
00207     const struct ov_reg *reg_conf;
00208     reg_conf = ov5640_afc;
00209     ov_write_regs16(pTwid, reg_conf);
00210 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines