Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
dflet
Date:
Tue Aug 25 22:03:00 2015 +0000
Parent:
13:bf45f592c2b6
Child:
15:5433f9d94cd7
Commit message:
I2C now works. 2 Cams added only the ov2640 works for now, many changes everywhere in the cam app. Still filled with debug.

Changed in this revision

FreeRTOS/FreeRTOSConfig.h Show annotated file Show diff for this revision Revisions of this file
camera_app/camera_app.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/camera_app.h Show annotated file Show diff for this revision Revisions of this file
camera_app/httpserverapp/httpserverapp.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/i2cconfig.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/i2cconfig.h Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.h Show annotated file Show diff for this revision Revisions of this file
camera_app/ov2640/ov2640.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/ov2640/ov2640.h Show annotated file Show diff for this revision Revisions of this file
camera_app/ov2640/ov2640_regs.h Show annotated file Show diff for this revision Revisions of this file
camera_app/ov5642/ov5642.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/ov5642/ov5642.h Show annotated file Show diff for this revision Revisions of this file
camera_app/ov5642/ov5642_regs.h Show annotated file Show diff for this revision Revisions of this file
http/server/HttpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
simplelink/cc3100_spi.cpp Show annotated file Show diff for this revision Revisions of this file
stm32f4xx_it.c Show annotated file Show diff for this revision Revisions of this file
stm32f4xx_it.h Show annotated file Show diff for this revision Revisions of this file
utils/app_config.h Show annotated file Show diff for this revision Revisions of this file
utils/cli_uart.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FreeRTOS/FreeRTOSConfig.h	Mon Jul 13 08:20:40 2015 +0000
+++ b/FreeRTOS/FreeRTOSConfig.h	Tue Aug 25 22:03:00 2015 +0000
@@ -86,7 +86,7 @@
 #define configCPU_CLOCK_HZ			( ( unsigned long ) SystemCoreClock )
 #define configTICK_RATE_HZ			( ( portTickType ) 1000 )
 #define configMINIMAL_STACK_SIZE	( ( unsigned short ) 130 )
-#define configTOTAL_HEAP_SIZE		( ( size_t ) (48 * 1024) )
+#define configTOTAL_HEAP_SIZE		( ( size_t ) (36 * 1024) )
 #define configMAX_TASK_NAME_LEN		( 24 )
 #define configUSE_TRACE_FACILITY	1
 #define configUSE_16_BIT_TICKS		0
--- a/camera_app/camera_app.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/camera_app.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -3,35 +3,35 @@
 //
 // camera application macro & APIs
 //
-// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 
-// 
-// 
-//  Redistribution and use in source and binary forms, with or without 
-//  modification, are permitted provided that the following conditions 
+// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
 //  are met:
 //
-//    Redistributions of source code must retain the above copyright 
+//    Redistributions of source code must retain the above copyright
 //    notice, this list of conditions and the following disclaimer.
 //
 //    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the   
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
 //    distribution.
 //
 //    Neither the name of Texas Instruments Incorporated nor the names of
 //    its contributors may be used to endorse or promote products derived
 //    from this software without specific prior written permission.
 //
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 //
 //*****************************************************************************
@@ -50,8 +50,16 @@
 #include "cc3100_simplelink.h"
 
 #include "oslib/osi.h"
+#include "app_config.h"
 #include "camera_app.h"
 #include "mt9d111.h"
+#ifdef OV5642_CAM
+#include "ov5642.h"
+#endif
+#ifdef OV2640_CAM
+#include "ov2640.h"
+#include "ov5642.h"
+#endif
 #include "i2cconfig.h"
 
 #include "cli_uart.h"
@@ -60,13 +68,13 @@
 
 using namespace mbed_cc3100;
 
-#define ENABLE_JPEG
+
 
 //*****************************************************************************
 // Macros
 //*****************************************************************************
 #define USER_FILE_NAME          "www/images/cc3200_camera_capture.jpg"
-#define TOTAL_DMA_ELEMENTS      64
+//#define TOTAL_DMA_ELEMENTS      64
 #define AP_SSID_LEN_MAX         (33)
 #define ROLE_INVALID            (-5)
 //*****************************************************************************
@@ -74,44 +82,47 @@
 //*****************************************************************************
 
 unsigned int g_frame_size_in_bytes;
-unsigned int g_uiDeviceModeConfig = ROLE_AP; //default is AP mode 
+//unsigned int g_uiDeviceModeConfig = ROLE_AP; //default is AP mode
 extern volatile unsigned char g_CaptureImage;
 extern int g_uiIpObtained = 0;
 extern int g_uiSimplelinkRole = ROLE_INVALID;
 unsigned int g_uiIpAddress = 0;
-static unsigned char g_dma_txn_done;
+//static unsigned char g_dma_txn_done;
 volatile static unsigned char g_frame_end;
-static unsigned int g_total_dma_intrpts;
+volatile static uint16_t g_lines;
+//static unsigned int g_total_dma_intrpts;
 
-#ifdef ENABLE_JPEG 
-    int PIXELS_IN_X_AXIS = 640; 
-    int PIXELS_IN_Y_AXIS = 480;
-    int FRAME_SIZE_IN_BYTES = (640 * 480 * 2);
+DCMI_HandleTypeDef phdcmi;
+DMA_HandleTypeDef phdma_dcmi;
+
+#ifdef ENABLE_JPEG
+int PIXELS_IN_X_AXIS = 320;
+int PIXELS_IN_Y_AXIS = 240;
+int FRAME_SIZE_IN_BYTES = (320 * 240 * 2);
 #else
-    int PIXELS_IN_X_AXIS = 240;
-    int PIXELS_IN_Y_AXIS = 256;
-    int FRAME_SIZE_IN_BYTES = (240 * 256 * 2);
-#endif    
+int PIXELS_IN_X_AXIS = 176;
+int PIXELS_IN_Y_AXIS = 144;
+int FRAME_SIZE_IN_BYTES = (176 * 144 * 2);
+#endif
 
-struct ImageBuffer
-{
+struct ImageBuffer {
 #ifdef ENABLE_JPEG
-	char g_header[SMTP_BUF_LEN] /*= {'\0'}*/;
+    char g_header[SMTP_BUF_LEN] /*= {'\0'}*/;
 #endif
 //    uint32_t g_image_buffer[NUM_OF_4B_CHUNKS];//60Kb 15360, 50Kb 12800
-	uint32_t g_image_buffer[((IMAGE_BUF_SIZE)/(sizeof(unsigned int)))];//51Kb
+    uint32_t g_image_buffer[((IMAGE_BUF_SIZE)/(sizeof(unsigned int)))];//51Kb
 };
 
 ImageBuffer g_image;
 
-typedef enum pictureRequest{
+typedef enum pictureRequest {
     NO_PICTURE = 0x00,
     SINGLE_HIGH_RESOLUTION = 0x01,
     STREAM_LOW_RESOLUTION = 0x02
-      
-}e_pictureRequest;
 
-typedef enum pictureFormat{
+} e_pictureRequest;
+
+typedef enum pictureFormat {
     RAW_10BIT = 0,
     ITU_R_BT601,
     YCbCr_4_2_2,
@@ -120,16 +131,16 @@
     RGB_555,
     RGB_444
 
-}e_pictureFormat;
+} e_pictureFormat;
 
-typedef enum pictureResolution{
+typedef enum pictureResolution {
     QVGA = 0,
     VGA,
     SVGA,
     XGA,
     uXGA
 
-}e_pictureResolution;
+} e_pictureResolution;
 
 
 #ifdef ENABLE_JPEG
@@ -137,8 +148,7 @@
 #define FORMAT_YCBCR420   1
 #define FORMAT_MONOCHROME 2
 
-unsigned char JPEG_StdQuantTblY[64] =
-{
+unsigned char JPEG_StdQuantTblY[64] = {
     16,  11,  10,  16,  24,  40,  51,  61,
     12,  12,  14,  19,  26,  58,  60,  55,
     14,  13,  16,  24,  40,  57,  69,  56,
@@ -149,8 +159,7 @@
     72,  92,  95,  98, 112,  100, 103,  99
 };
 
-unsigned char JPEG_StdQuantTblC[64] =
-{
+unsigned char JPEG_StdQuantTblC[64] = {
     17,  18,  24,  47,  99,  99,  99,  99,
     18,  21,  26,  66,  99,  99,  99,  99,
     24,  26,  56,  99,  99,  99,  99,  99,
@@ -162,10 +171,9 @@
 };
 //
 // This table is used for regular-position to zigzagged-position lookup
-//  This is Figure A.6 from the ISO/IEC 10918-1 1993 specification 
+//  This is Figure A.6 from the ISO/IEC 10918-1 1993 specification
 //
-static unsigned char zigzag[64] =
-{
+static unsigned char zigzag[64] = {
     0, 1, 5, 6,14,15,27,28,
     2, 4, 7,13,16,26,29,42,
     3, 8,12,17,25,30,41,43,
@@ -176,8 +184,7 @@
     35,36,48,49,57,58,62,63
 };
 
-unsigned int JPEG_StdHuffmanTbl[384] =
-{
+unsigned int JPEG_StdHuffmanTbl[384] = {
     0x100, 0x101, 0x204, 0x30b, 0x41a, 0x678, 0x7f8, 0x9f6,
     0xf82, 0xf83, 0x30c, 0x41b, 0x679, 0x8f6, 0xaf6, 0xf84,
     0xf85, 0xf86, 0xf87, 0xf88, 0x41c, 0x7f9, 0x9f7, 0xbf4,
@@ -227,24 +234,24 @@
     0x100, 0x101, 0x102, 0x206, 0x30e, 0x41e, 0x53e, 0x67e,
     0x7fe, 0x8fe, 0x9fe, 0xafe, 0xfff, 0xfff, 0xfff, 0xfff
 };
-#endif 
+#endif
 
 //*****************************************************************************
 //
-//!     Start Camera 
+//!     Start Camera
 //!     1. Establishes connection w/ AP//
 //!     2. Initializes the camera sub-components//! GPIO Enable & Configuration
 //!     3. Listens and processes the image capture requests from user-applications
-//!    
-//!	\param[out]                      WriteBuffer - Pointer to the Frame Buffer  
-//!     \return                     None                         
+//!
+//!	\param[out]                      WriteBuffer - Pointer to the Frame Buffer
+//!     \return                     None
 //
 //*****************************************************************************
 
-unsigned short StartCamera(char **WriteBuffer)
+uint32_t StartCamera(char **WriteBuffer)
 {
 //	Uart_Write((uint8_t*)"StartCamera \n\r");
-	unsigned short Writelength;
+    uint32_t Writelength;
     //
     // Waits in the below loop till Capture button is pressed
     //
@@ -255,8 +262,8 @@
 }
 //*****************************************************************************
 //
-//!     InitCameraComponents 
-//!     PinMux, Camera Initialization and Configuration   
+//!     InitCameraComponents
+//!     PinMux, Camera Initialization and Configuration
 //!
 //!	\param[in] width - X-Axis
 //!	\param[in] width - Y-Axis
@@ -266,30 +273,44 @@
 
 void InitCameraComponents(int width, int height)
 {
-//    Uart_Write((uint8_t*)"InitCameraComponents \n\r");
+    Uart_Write((uint8_t*)"InitCameraComponents \n\r");
     //
     // Initialize I2C Interface
-    //   
+    //
     I2CInit();
-    
+#ifdef MT9D111_CAM
+    cam_power_on();    
     getCamId();
     
     //
     // Initialize camera sensor
     //
     CameraSensorInit();
-
 #ifdef ENABLE_JPEG
     //
     // Configure Sensor in Capture Mode
     //
-    PIXELS_IN_X_AXIS = width; 
+    PIXELS_IN_X_AXIS = width;
     PIXELS_IN_Y_AXIS = height;
     FRAME_SIZE_IN_BYTES = PIXELS_IN_X_AXIS * PIXELS_IN_Y_AXIS * BYTES_PER_PIXEL;
 
     StartSensorInJpegMode(width, height);
 
-#endif
+#endif//ENABLE_JPEG
+#endif//MT9D111_CAM    
+    
+#ifdef OV5642_CAM
+    check_camId();
+    init_cam();    
+#endif//OV5642_CAM
+
+#ifdef OV2640_CAM
+    camId();
+    initCam();    
+#endif//OV2640_CAM
+
+    
+    
 }
 
 //*****************************************************************************
@@ -304,10 +325,10 @@
 
 int SetCameraResolution(int width, int height)
 {
-	Uart_Write((uint8_t*)"SetCameraResolution \n\r");
-	int lRetVal = 0;
+    Uart_Write((uint8_t*)"SetCameraResolution \n\r");
+    int lRetVal = 0;
 
-    PIXELS_IN_X_AXIS = width; 
+    PIXELS_IN_X_AXIS = width;
     PIXELS_IN_Y_AXIS = height;
     FRAME_SIZE_IN_BYTES = PIXELS_IN_X_AXIS * PIXELS_IN_Y_AXIS * BYTES_PER_PIXEL;
     lRetVal = CameraSensorResolution(width, height);
@@ -316,282 +337,402 @@
 
 //*****************************************************************************
 //
-//!     CaptureImage 
-//!     Configures DMA and starts the Capture. Post Capture writes to SFLASH 
-//!    
-//!	\param                      None  
+//!     CaptureImage
+//!     Configures DMA and starts the Capture. Post Capture writes to SFLASH
+//!
+//!	\param                      None
 //!     \return                     None
-//!                               
+//!
 //
 //*****************************************************************************
-uint16_t CaptureImage(char** WriteBuffer)
+uint32_t CaptureImage(char** WriteBuffer)
 {
-//    Uart_Write((uint8_t*)"CaptureImage \n\r");
-	DCMI_HandleTypeDef phdcmi;
-    DMA_HandleTypeDef hdma_dcmi;
 
     uint32_t g_header_length = 0;
-//    memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
-    memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
-    uint32_t *p_buffer = &(g_image.g_image_buffer[0]);
+    uint32_t *pbuffer = &(g_image.g_image_buffer[0]);
+    int32_t lRetVal= -1;
+    int32_t err = 0;
     
     DMAConfig();
+    
+    wait(2);
+    
+    /* Send cam capture request, value in frames */
+//    Start_still_capture(1);// Switch to context b
 
     //
-    // Perform Image Capture 
+    // DCMI Perform Image Capture
     //
-//    wait_ms(500);
-
 #ifdef ENABLE_JPEG
-    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
+    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)pbuffer, NUM_OF_4B_CHUNKS);
 #else
-    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
-#endif   
-    g_frame_end = 1;
- 
-    /* Read the number of data items transferred in bytes ((4x) uint = 4 bytes) */
-    g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - hdma_dcmi.Instance->NDTR);
-    if(g_frame_size_in_bytes <= 0 || g_frame_size_in_bytes > (NUM_OF_4B_CHUNKS *4)){
-    	HttpDebug("\r\nFailed to capture or data over-run, check camera connections!\r\n");
-    	HAL_DCMI_MspDeInit(&phdcmi);
-    	while(1){
-    		wait(0.5);
-    	}
-    }	
-    g_dma_txn_done = 1;
-    g_total_dma_intrpts = 1;
+    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)pbuffer, NUM_OF_4B_CHUNKS);
+#endif
+
+    while(g_frame_end == 0);//Set in the Frame complete callback function 
+    HttpDebug("lines %d\r\n",g_lines);
+#ifdef MT9D111_CAM    
+    Stop_still_capture();// Switch to context a
+#endif    
+    /* Read the number of data items transferred in bytes ((4x) uint = bytes) */
+    g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - phdma_dcmi.Instance->NDTR);//NDTR counts down!
+    if(g_frame_size_in_bytes <= 0 || g_frame_size_in_bytes > (NUM_OF_4B_CHUNKS *4)) {
+        err = HAL_DMA_GetState(&phdma_dcmi);
+        HttpDebug("\r\nDMA error! 0x%x\r\n",err);
+        HttpDebug("\r\nDMA error! 0x%x\r\n",phdma_dcmi.ErrorCode);
+        HttpDebug("g_frame_size_in_bytes = 0x%x\n\r",g_frame_size_in_bytes);
+        HttpDebug("\r\nFailed to capture data, check camera connections!\r\n");
+        HAL_DMA_Abort(&phdma_dcmi);
+#ifdef MT9D111_CAM        
+        cam_power_off();
+#endif        
+      	HAL_DCMI_MspDeInit(&phdcmi);
+        HttpDebug("Image Capture failed\n\r");
+#if 1
+        for(int i =0; i< 100; i++) {
+            HttpDebug("0x%x ",(uint8_t*)*pbuffer++);
+        }
+        HttpDebug("\r\n");
+#endif//if 0 
+        while(1) {
+            wait(0.5);
+        }
+    }
+    err = HAL_DMA_GetState(&phdma_dcmi);
+    if(0x11 != err || 0x31 != err){
+       HttpDebug("\r\nDMA state! 0x%x\r\n",err);
+//       while(1);
+    }
+    err = HAL_DMA_GetError(&phdma_dcmi);
+    if(0x00 != err ){
+       HttpDebug("\r\nDMA error! 0x%x\r\n",err);      
+//       while(1);
+    }
+    HttpDebug("g_frame_size_in_bytes %d\n\r",g_frame_size_in_bytes);
     
-//    HttpDebug("frame size = 0x%x \r\n",g_frame_size_in_bytes);
+#if 0
+    for(int i =0; i< 100; i++) {
+        HttpDebug("0x%x ",(uint8_t*)*pbuffer++);
+    }
+    HttpDebug("\r\n");
+#endif//if 0    
     
-    uint8_t* Image = reinterpret_cast<uint8_t*>(&g_image.g_image_buffer);
-//#if 0    
-    for(int i =0;i< 10;i++){
-    	HttpDebug("0x%x ",Image[i]);
+    uint8_t* Image = reinterpret_cast<uint8_t*>(pbuffer);
+    
+#if 0
+    for(int i =0; i< 100; i++) {
+        HttpDebug("0x%x ",*Image++);
     }
-//#endif//if 0    
+    HttpDebug("\r\n");
+#endif//if 0
     //
     // Create JPEG Header
     //
 #ifdef ENABLE_JPEG
     memset(g_image.g_header, '\0', sizeof(g_image.g_header));
-    g_header_length = CreateJpegHeader((char *)&(g_image.g_header[0]), PIXELS_IN_X_AXIS,
-                                       PIXELS_IN_Y_AXIS, 0, 0x0020, 9);
+    g_header_length = CreateJpegHeader((char *)&(g_image.g_header[0]), PIXELS_IN_X_AXIS, PIXELS_IN_Y_AXIS, 0, 0x0020, 9);
 //    HttpDebug("g_header_length = 0x%x \r\n",g_header_length);
     // This pushes the header to the start of the array so that the entire picture can be contiguous in memory
-//    memcpy(Image + g_header_length, Image, g_frame_size_in_bytes);
-//    memcpy(Image, g_image.g_header, g_header_length);
+    memcpy(Image + g_header_length, Image, g_frame_size_in_bytes);
+    memcpy(Image, g_image.g_header, g_header_length);
     // This pushes the header to the end of the array so that the entire picture can be contiguous in memory
-    memcpy(Image + g_frame_size_in_bytes, g_image.g_header, g_header_length);
-#if 0    
-    for(int i =624;i< 725;i++){
-    	HttpDebug("0x%x ",Image[i]);
-    }	 
+//    memcpy((Image + g_frame_size_in_bytes ), g_image.g_header, g_header_length);
+#if 0
+    for(int i =0; i< g_header_length + 100 ; i++) {
+        HttpDebug("0x%x ",*Image++);
+    }
+    HttpDebug("\r\n");
 #endif//if 0
 
 #endif//ENABLE_JPEG
-
+    
     *WriteBuffer = (char*)Image;
 
-	return(g_header_length + g_frame_size_in_bytes);
+    return(g_header_length += g_frame_size_in_bytes);
 }
 //*****************************************************************************
 //
 //!     DMA Config
 //!     Initialize the DMA\DCMI and Setup the DMA transfer
-//!    
-//!	\param                      None  
-//!     \return                     None                  
+//!
+//!	\param                      None
+//!     \return                     None
 //
 //*****************************************************************************
 void DMAConfig()
 {
-	DCMI_HandleTypeDef phdcmi;
-    DMA_HandleTypeDef hdma_dcmi;
-//    Uart_Write((uint8_t*)"DMAConfig \n\r");
-    
-    /* Peripheral DMA init*/
-    /* DMA controller clock enable */
-    __DMA2_CLK_ENABLE();
-  
-    hdma_dcmi.Init.Channel             = DMA_CHANNEL_1;
-    hdma_dcmi.Init.Direction           = DMA_PERIPH_TO_MEMORY;
-    hdma_dcmi.Init.PeriphInc           = DMA_PINC_DISABLE;
-    hdma_dcmi.Init.MemInc              = DMA_MINC_ENABLE;
-    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//Cam is 1 byte wide data (8 bits) should this be word?????
-    hdma_dcmi.Init.MemDataAlignment    = DMA_PDATAALIGN_WORD;//Memory has been defined as uint (1 word)
-    hdma_dcmi.Init.Mode                = DMA_CIRCULAR;
-    hdma_dcmi.Init.Priority            = DMA_PRIORITY_HIGH;
-    hdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
-    hdma_dcmi.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
-    hdma_dcmi.Init.MemBurst            = DMA_MBURST_SINGLE;
-    hdma_dcmi.Init.PeriphBurst         = DMA_PBURST_SINGLE;
-    hdma_dcmi.Instance                 = DMA2_Stream1;
-    
-    __HAL_LINKDMA(&phdcmi, DMA_Handle, hdma_dcmi);
-    
-     /* DMA interrupt init */
-    HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);
-    HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
-    
-    /* Peripheral DCMI init*/
-    
-    /* Peripheral clock enable */
-    __DCMI_CLK_ENABLE();    
- 
+    HttpDebug("DMAConfig \n\r");
+//	DCMI_HandleTypeDef phdcmi;
+
     phdcmi.Init.SynchroMode      = DCMI_SYNCHRO_HARDWARE;
-    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_FALLING;
-//    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;
-    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_HIGH;
-//    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_LOW;
-    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_HIGH;
-//    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_LOW;
+#ifdef OV5642_CAM       
+//    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_FALLING;//Data clocked out on falling edge
+    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge
+    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_LOW;//Active low
+//    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_LOW;//Active low
+    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_HIGH;//Active high
+#endif    
+#ifdef OV2640_CAM    
+    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge
+    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_LOW;//Active low
+    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_LOW;//Active low
+#endif    
+#ifdef MT9D111_CAM
+    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;//Data clocked out on rising edge 
+//    phdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_FALLING;//Data clocked out on falling edge 
+    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_HIGH;//Active high       
+//    phdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_LOW;//Active high
+//    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_LOW;//Active low
+    phdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_HIGH;//Active high    
+#endif        
     phdcmi.Init.CaptureRate      = DCMI_CR_ALL_FRAME;
-    phdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;    
-#ifdef ENABLE_JPEG  
+    phdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;//8 bit data
+#ifdef ENABLE_JPEG
     phdcmi.Init.JPEGMode         = DCMI_JPEG_ENABLE;
 #else
     phdcmi.Init.JPEGMode         = DCMI_JPEG_DISABLE;
 #endif
     phdcmi.Instance              = DCMI;
-    
-  GPIO_InitTypeDef GPIO_InitStruct;
-  if(phdcmi.Instance==DCMI)
-  {
-   __GPIOE_CLK_ENABLE();
-   __GPIOA_CLK_ENABLE();
-   __GPIOB_CLK_ENABLE();
-   __GPIOC_CLK_ENABLE();   
-      
-   /**MCO1/2 GPIO Configuration 
-    PC9     ------> RCC_MCO_2
-    PA8     ------> RCC_MCO_1    
-    */
-  
-    /**DCMI GPIO Configuration
-    PA9     ------> DCMI_D0
-    PA10    ------> DCMI_D1
-    PC8     ------> DCMI_D2
-    PE1     ------> DCMI_D3    
-    PE4     ------> DCMI_D4
-    PB6     ------> DCMI_D5
-    PE5     ------> DCMI_D6
-    PE6     ------> DCMI_D7
-    PA6     ------> DCMI_PIXCK
-    PA4     ------> DCMI_HSYNC
-    PB7     ------> DCMI_VSYNC
-    
-    */
-    /* D3 D4 D6 D7 */
-    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
-    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
-    
-    /* HSYNC PIXCLK D0 D1 */
-    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_9|GPIO_PIN_10;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    
-    /* D2 */
-    GPIO_InitStruct.Pin = GPIO_PIN_8;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
-    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-    
-    /*Configure GPIO pin : GPIO_AF0_MCO PC9 
-    GPIO_InitStruct.Pin = GPIO_PIN_9;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
-    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-*/    
-    /*Configure GPIO pin : GPIO_AF0_MCO PA8 
-    GPIO_InitStruct.Pin = GPIO_PIN_8;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-*/    
-    /* D5 VSYNC */
-    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+    DCMI_MspInit(&phdcmi);
+    HAL_DCMI_Init(&phdcmi);
+     
+}
+/*
+void DCMI_IRQHandler(void) {
+	
+	HAL_DCMI_IRQHandler(&hdcmi);
+}
+
+void DMA2_Stream1_IRQHandler(void){
+	
+	HAL_DMA_IRQHandler(&hdma_dcmi);
+}		
+*/
+void DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
+{
+
+//   Uart_Write((uint8_t*)"DCMI_MspInit\n\r");
+
+    /* Peripheral DCMI init*/
+
+    GPIO_InitTypeDef GPIO_InitStruct;
+    if(hdcmi->Instance==DCMI) {
+        __GPIOA_CLK_ENABLE();
+        __GPIOB_CLK_ENABLE();
+        __GPIOC_CLK_ENABLE();
+        __GPIOE_CLK_ENABLE();
+
+        /* Peripheral clock enable */
+        __DCMI_CLK_ENABLE();
+        /* DMA controller clock enable */
+        __DMA2_CLK_ENABLE();
+
+        /**MCO1 GPIO Configuration
+        PA8     ------> RCC_MCO_1
+        */
+
+        /**DCMI GPIO Configuration
+        PA9     ------> DCMI_D0
+        PA10    ------> DCMI_D1
+        PC8     ------> DCMI_D2
+        PC9     ------> DCMI_D3
+        PE4     ------> DCMI_D4
+        PB6     ------> DCMI_D5
+        PE5     ------> DCMI_D6
+        PE6     ------> DCMI_D7
+        PA6     ------> DCMI_PIXCK
+        PA4     ------> DCMI_HSYNC
+        PB7     ------> DCMI_VSYNC
 
-  /* System interrupt init*/
-    HAL_NVIC_SetPriority(DCMI_IRQn, 0, 0);
-    HAL_NVIC_EnableIRQ(DCMI_IRQn);
+        */
+        /* D4 D6 D7 */
+        GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
+        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+        GPIO_InitStruct.Pull = GPIO_PULLUP;
+        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+        GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
+        HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
+
+        /* HSYNC PIXCLK D0 D1 */
+        GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_9|GPIO_PIN_10;
+        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+        GPIO_InitStruct.Pull = GPIO_PULLUP;
+        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+        GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
+        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+        /* D2 D3 */
+        GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
+        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+        GPIO_InitStruct.Pull = GPIO_PULLUP;
+        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+        GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
+        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
-    HAL_DMA_Init(&hdma_dcmi);
-    HAL_DCMI_Init(&phdcmi);
-    
+        /* D5 VSYNC */
+        GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
+        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+        GPIO_InitStruct.Pull = GPIO_PULLUP;
+        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+        GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
+        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+        phdma_dcmi.Instance                 = DMA2_Stream1;
+        phdma_dcmi.Init.Channel             = DMA_CHANNEL_1;
+        phdma_dcmi.Init.Direction           = DMA_PERIPH_TO_MEMORY;
+        phdma_dcmi.Init.PeriphInc           = DMA_PINC_DISABLE;
+        phdma_dcmi.Init.MemInc              = DMA_MINC_ENABLE;
+        phdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//Cam is 1 byte wide data (8 bits) should this be word?????
+        phdma_dcmi.Init.MemDataAlignment    = DMA_PDATAALIGN_WORD;//Memory has been defined as uint (1 word)
+        phdma_dcmi.Init.Mode                = DMA_NORMAL;
+        phdma_dcmi.Init.Priority            = DMA_PRIORITY_HIGH;
+        phdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
+        phdma_dcmi.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
+        phdma_dcmi.Init.MemBurst            = DMA_MBURST_SINGLE;
+        phdma_dcmi.Init.PeriphBurst         = DMA_PBURST_SINGLE;
+
+        __HAL_LINKDMA(hdcmi, DMA_Handle, phdma_dcmi);
+
+        /*** Configure the NVIC for DCMI and DMA ***/
+        /* NVIC configuration for DCMI transfer complete interrupt */
+        HAL_NVIC_SetPriority(DCMI_IRQn, 1, 0);
+        HAL_NVIC_EnableIRQ(DCMI_IRQn);
+
+        /* NVIC configuration for DMA2 transfer complete interrupt */
+        HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0);
+        HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
+
+        HAL_DMA_Init(&phdma_dcmi);
     }
 
-    g_dma_txn_done = 0;
     g_frame_size_in_bytes = 0;
     g_frame_end = 0;
-    g_total_dma_intrpts = 0;
-}	
+}
+
+/******************************************************************************/
+/* STM32F4xx Peripheral Interrupt Handlers                                    */
+/* Add here the Interrupt Handlers for the used peripherals.                  */
+/* For the available peripheral interrupt handler names,                      */
+/* please refer to the startup file (startup_stm32f4xx.s).                    */
+/******************************************************************************/
 
-void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* phdcmi){
+void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
+{
+    int32_t dcmi_state;
+    int32_t dcmi_error;
+    
+    HAL_DMA_Abort(&phdma_dcmi);
+    
+    HttpDebug("\r\nDCMI_ErrorCallback!\r\n");
+    
+    dcmi_state = HAL_DCMI_GetState(&phdcmi);
+    if(0 == dcmi_state){
+    	HttpDebug("\r\nDCMI not yet initialized or disabled\r\n");
+    }else if(1 == dcmi_state){
+    	HttpDebug("\r\nDCMI initialized and ready for use\r\n");
+    }else if(2 == dcmi_state){
+    	HttpDebug("\r\nDCMI internal processing is ongoing\r\n");
+    }else if(3 == dcmi_state){
+    	HttpDebug("\r\nDCMI timeout state\r\n");
+    }else if(4 == dcmi_state){	
+    	HttpDebug("\r\nDCMI error state\r\n");
+    	dcmi_error = HAL_DCMI_GetError(&phdcmi);
+    	if(1 == dcmi_error){
+    		HttpDebug("\r\nDCMI Synchronisation error\r\n");
+    	}else if(2 == dcmi_error){
+    		HttpDebug("\r\nDCMI Overrun\r\n");
+    	}		
+    }				
+    HttpDebug("\r\nExtra info! \r\n");
+    g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - phdma_dcmi.Instance->NDTR);//NDTR counts down!
+    if(g_frame_size_in_bytes >= 0xC800){
+    	HttpDebug("Bytes captured equals or exceeds buffer size! \r\n");
+    	HttpDebug("Bytes captured 0x%x\r\n",g_frame_size_in_bytes);
+    }else{	
+        HttpDebug("Bytes captured 0x%x\r\n",g_frame_size_in_bytes);
+    }
+    
+    HAL_DMA_Abort(&phdma_dcmi);
+#ifdef MT9D111_CAM    
+    cam_power_off();
+#endif    
+    HAL_DCMI_MspDeInit(&phdcmi);    
+}
 
-  if(phdcmi->Instance==DCMI)
-  {
+void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
+{
+    g_lines++;
+    //HttpDebug("\r\nDCMI_LineEventCallback! 0x%x\r\n",hdcmi->ErrorCode);
+
+}
 
-    /* Peripheral clock disable */
-    __DCMI_CLK_DISABLE();
-  
-    /**DCMI GPIO Configuration    
-    PE4     ------> DCMI_D4
-    PE5     ------> DCMI_D6
-    PE6     ------> DCMI_D7
-    PA4     ------> DCMI_HSYNC
-    PA6     ------> DCMI_PIXCK
-    PC8     ------> DCMI_D2
-    PE1     ------> DCMI_D3
-    PA9     ------> DCMI_D0
-    PA10    ------> DCMI_D1
-    PB6     ------> DCMI_D5
-    PB7     ------> DCMI_VSYNC 
+void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
+{
+    g_lines = 0;
+//    printf("\r\nVsyncEventCallback\r\n");
+
+}
+
+void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
+{
+    HAL_DMA_Abort(&phdma_dcmi);
+    g_frame_end = 1;
     
-    PE1     ------> MCO2
-    */    
-    
-    HAL_GPIO_DeInit(GPIOE, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
+    HttpDebug("\r\nDCMI Frame Capture complete! \r\n");
+
+}
+
+void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
+{
+    if(hdcmi->Instance==DCMI) {
+
+        /* Peripheral clock disable */
+        __DCMI_CLK_DISABLE();
 
-    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_9|GPIO_PIN_10);
-
-    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_9|GPIO_PIN_8);
+        /**DCMI GPIO Configuration
+        PE4     ------> DCMI_D4
+        PE5     ------> DCMI_D6
+        PE6     ------> DCMI_D7
+        PA4     ------> DCMI_HSYNC
+        PA6     ------> DCMI_PIXCK
+        PC8     ------> DCMI_D2
+        PC9     ------> DCMI_D3
+        PA9     ------> DCMI_D0
+        PA10    ------> DCMI_D1
+        PB6     ------> DCMI_D5
+        PB7     ------> DCMI_VSYNC
 
-    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
+        PA8     ------> MCO1
+        */
+
+        HAL_GPIO_DeInit(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
 
-    /* Peripheral DMA DeInit*/
-    HAL_DMA_DeInit(phdcmi->DMA_Handle);
+        HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
+
+        HAL_GPIO_DeInit(GPIOC, GPIO_PIN_9|GPIO_PIN_8);
+
+        HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
 
-    /* Peripheral interrupt DeInit*/
-    HAL_NVIC_DisableIRQ(DCMI_IRQn);
+        /* Peripheral DMA DeInit*/
+        HAL_DMA_DeInit(hdcmi->DMA_Handle);
+
+        /* Peripheral interrupt DeInit*/
+        HAL_NVIC_DisableIRQ(DCMI_IRQn);
 
-  }
+        HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8);
+        HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9);
+    }
 
-}		
+
+}
 
 //*****************************************************************************
 //
-//!     JfifApp0Marker 
-//!    
-//!	\param                      Pointer to the output buffer  
-//!     \return                     Length of the Marker                        
+//!     JfifApp0Marker
+//!
+//!	\param                      Pointer to the output buffer
+//!     \return                     Length of the Marker
 //
 //*****************************************************************************
 
@@ -599,24 +740,24 @@
 static int JfifApp0Marker(char *pbuf)
 {
 //    Uart_Write((uint8_t*)"JfifApp0Marker \n\r");
-    *pbuf++= 0xFF;                  // APP0 marker 
+    *pbuf++= 0xFF;                  // APP0 marker
     *pbuf++= 0xE0;
-    *pbuf++= 0x00;                  // length 
+    *pbuf++= 0x00;                  // length
     *pbuf++= 0x10;
-    *pbuf++= 0x4A;                  // JFIF identifier 
+    *pbuf++= 0x4A;                  // JFIF identifier
     *pbuf++= 0x46;
     *pbuf++= 0x49;
     *pbuf++= 0x46;
     *pbuf++= 0x00;
-    *pbuf++= 0x01;                  // version 
+    *pbuf++= 0x01;                  // version
     *pbuf++= 0x02;
-    *pbuf++= 0x00;                  // units 
-    *pbuf++= 0x00;                  // X density 
+    *pbuf++= 0x00;                  // units
+    *pbuf++= 0x00;                  // X density
     *pbuf++= 0x01;
-    *pbuf++= 0x00;                  // Y density 
+    *pbuf++= 0x00;                  // Y density
     *pbuf++= 0x01;
-    *pbuf++= 0x00;                  // X thumbnail 
-    *pbuf++= 0x00;                  // Y thumbnail 
+    *pbuf++= 0x00;                  // X thumbnail
+    *pbuf++= 0x00;                  // Y thumbnail
     return 18;
 }
 
@@ -624,13 +765,13 @@
 //*****************************************************************************
 //
 //!    FrameHeaderMarker
-//!    
-//!	\param1                      pointer to the output buffer  
-//!	\param2                      width   
-//!	\param3                      height 
+//!
+//!	\param1                      pointer to the output buffer
+//!	\param2                      width
+//!	\param3                      height
 //!	\param4                      format
 //!
-//!     \return                       Length of the header marker                       
+//!     \return                       Length of the header marker
 //
 //*****************************************************************************
 static int FrameHeaderMarker(char *pbuf, int width, int height, int format)
@@ -642,48 +783,43 @@
     else
         length = 17;
 
-    *pbuf++= 0xFF;                      // start of frame: baseline DCT 
+    *pbuf++= 0xFF;                      // start of frame: baseline DCT
     *pbuf++= 0xC0;
-    *pbuf++= length>>8;                 // length field 
+    *pbuf++= length>>8;                 // length field
     *pbuf++= length&0xFF;
-    *pbuf++= 0x08;                      // sample precision 
-    *pbuf++= height>>8;                 // number of lines 
+    *pbuf++= 0x08;                      // sample precision
+    *pbuf++= height>>8;                 // number of lines
     *pbuf++= height&0xFF;
-    *pbuf++= width>>8;                  // number of samples per line 
+    *pbuf++= width>>8;                  // number of samples per line
     *pbuf++= width&0xFF;
 
-    if (format == FORMAT_MONOCHROME)    // monochrome 
-    {
-        *pbuf++= 0x01;                  // number of image components in frame 
-        *pbuf++= 0x00;                  // component identifier: Y 
-        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Y 
-        *pbuf++= 0x00;                  // quantization table selector: Y 
-    }
-    else if (format == FORMAT_YCBCR422) // YCbCr422
-    {
-        *pbuf++= 0x03;                  // number of image components in frame 
-        *pbuf++= 0x00;                  // component identifier: Y 
-        *pbuf++= 0x21;                  // horizontal | vertical sampling factor: Y 
-        *pbuf++= 0x00;                  // quantization table selector: Y 
-        *pbuf++= 0x01;                  // component identifier: Cb 
-        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cb 
-        *pbuf++= 0x01;                  // quantization table selector: Cb 
-        *pbuf++= 0x02;                  // component identifier: Cr 
-        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cr 
-        *pbuf++= 0x01;                  // quantization table selector: Cr 
-    }
-    else                                // YCbCr420 
-    {
-        *pbuf++= 0x03;                  // number of image components in frame 
-        *pbuf++= 0x00;                  // component identifier: Y 
-        *pbuf++= 0x22;                  // horizontal | vertical sampling factor: Y 
-        *pbuf++= 0x00;                  // quantization table selector: Y 
-        *pbuf++= 0x01;                  // component identifier: Cb 
-        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cb 
-        *pbuf++= 0x01;                  // quantization table selector: Cb 
-        *pbuf++= 0x02;                  // component identifier: Cr 
-        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cr 
-        *pbuf++= 0x01;                  // quantization table selector: Cr 
+    if (format == FORMAT_MONOCHROME) {  // monochrome
+        *pbuf++= 0x01;                  // number of image components in frame
+        *pbuf++= 0x00;                  // component identifier: Y
+        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Y
+        *pbuf++= 0x00;                  // quantization table selector: Y
+    } else if (format == FORMAT_YCBCR422) { // YCbCr422
+        *pbuf++= 0x03;                  // number of image components in frame
+        *pbuf++= 0x00;                  // component identifier: Y
+        *pbuf++= 0x21;                  // horizontal | vertical sampling factor: Y
+        *pbuf++= 0x00;                  // quantization table selector: Y
+        *pbuf++= 0x01;                  // component identifier: Cb
+        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cb
+        *pbuf++= 0x01;                  // quantization table selector: Cb
+        *pbuf++= 0x02;                  // component identifier: Cr
+        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cr
+        *pbuf++= 0x01;                  // quantization table selector: Cr
+    } else {                            // YCbCr420
+        *pbuf++= 0x03;                  // number of image components in frame
+        *pbuf++= 0x00;                  // component identifier: Y
+        *pbuf++= 0x22;                  // horizontal | vertical sampling factor: Y
+        *pbuf++= 0x00;                  // quantization table selector: Y
+        *pbuf++= 0x01;                  // component identifier: Cb
+        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cb
+        *pbuf++= 0x01;                  // quantization table selector: Cb
+        *pbuf++= 0x02;                  // component identifier: Cr
+        *pbuf++= 0x11;                  // horizontal | vertical sampling factor: Cr
+        *pbuf++= 0x01;                  // quantization table selector: Cr
     }
 
     return (length+2);
@@ -694,10 +830,10 @@
 //
 //!     ScanHeaderMarker
 //!
-//!	\param1                     pointer to output buffer  
-//!	\param2                     Format 
+//!	\param1                     pointer to output buffer
+//!	\param2                     Format
 //!
-//!     \return                     Length                             
+//!     \return                     Length
 //
 //*****************************************************************************
 static int ScanHeaderMarker(char *pbuf, int format)
@@ -708,30 +844,27 @@
     else
         length = 12;
 
-    *pbuf++= 0xFF;                  // start of scan 
+    *pbuf++= 0xFF;                  // start of scan
     *pbuf++= 0xDA;
-    *pbuf++= length>>8;             // length field 
+    *pbuf++= length>>8;             // length field
     *pbuf++= length&0xFF;
-    if (format == FORMAT_MONOCHROME)// monochrome 
-    {
-        *pbuf++= 0x01;              // number of image components in scan 
-        *pbuf++= 0x00;              // scan component selector: Y 
-        *pbuf++= 0x00;              // DC | AC huffman table selector: Y 
-    }
-    else                            // YCbCr
-    {
-        *pbuf++= 0x03;              // number of image components in scan 
-        *pbuf++= 0x00;              // scan component selector: Y 
-        *pbuf++= 0x00;              // DC | AC huffman table selector: Y 
-        *pbuf++= 0x01;              // scan component selector: Cb 
-        *pbuf++= 0x11;              // DC | AC huffman table selector: Cb 
-        *pbuf++= 0x02;              // scan component selector: Cr 
-        *pbuf++= 0x11;              // DC | AC huffman table selector: Cr 
+    if (format == FORMAT_MONOCHROME) { // monochrome
+        *pbuf++= 0x01;              // number of image components in scan
+        *pbuf++= 0x00;              // scan component selector: Y
+        *pbuf++= 0x00;              // DC | AC huffman table selector: Y
+    } else {                        // YCbCr
+        *pbuf++= 0x03;              // number of image components in scan
+        *pbuf++= 0x00;              // scan component selector: Y
+        *pbuf++= 0x00;              // DC | AC huffman table selector: Y
+        *pbuf++= 0x01;              // scan component selector: Cb
+        *pbuf++= 0x11;              // DC | AC huffman table selector: Cb
+        *pbuf++= 0x02;              // scan component selector: Cr
+        *pbuf++= 0x11;              // DC | AC huffman table selector: Cr
     }
 
-    *pbuf++= 0x00;                  // Ss: start of predictor selector 
-    *pbuf++= 0x3F;                  // Se: end of spectral selector 
-    *pbuf++= 0x00;                  // Ah | Al: successive approximation bit position 
+    *pbuf++= 0x00;                  // Ss: start of predictor selector
+    *pbuf++= 0x3F;                  // Se: end of spectral selector
+    *pbuf++= 0x00;                  // Ah | Al: successive approximation bit position
 
     return (length+2);
 }
@@ -739,38 +872,38 @@
 
 //*****************************************************************************
 //
-//!     DefineQuantizationTableMarker 
+//!     DefineQuantizationTableMarker
 //!      Calculate and write the quantisation tables
-//!      qscale is the customised scaling factor - see MT9D131 developer guide page 78 
-//!    
-//!	\param1                      pointer to the output buffer  
-//!	\param2                      Quantization Scale  
-//!	\param3                      Format 
+//!      qscale is the customised scaling factor - see MT9D131 developer guide page 78
 //!
-//!     \return                      Length of the Marker                       
+//!	\param1                      pointer to the output buffer
+//!	\param2                      Quantization Scale
+//!	\param3                      Format
+//!
+//!     \return                      Length of the Marker
 //
 //*****************************************************************************
 static int DefineQuantizationTableMarker (unsigned char *pbuf, int qscale, int format)
 {
 //    Uart_Write((uint8_t*)"DefineQuantizationTableMarker \n\r");
     int i, length, temp;
-    unsigned char newtbl[64];           // temporary array to store scaled zigzagged quant entries 
+    unsigned char newtbl[64];           // temporary array to store scaled zigzagged quant entries
 
-    if (format == FORMAT_MONOCHROME)    // monochrome 
+    if (format == FORMAT_MONOCHROME)    // monochrome
         length  =  67;
     else
         length  =  132;
 
-    *pbuf++  =  0xFF;                   // define quantization table marker 
+    *pbuf++  =  0xFF;                   // define quantization table marker
     *pbuf++  =  0xDB;
-    *pbuf++  =  length>>8;              // length field 
+    *pbuf++  =  length>>8;              // length field
     *pbuf++  =  length&0xFF;
-    *pbuf++  =  0;                      // quantization table precision | identifier for luminance 
+    *pbuf++  =  0;                      // quantization table precision | identifier for luminance
 
-    // calculate scaled zigzagged luminance quantisation table entries 
+    // calculate scaled zigzagged luminance quantisation table entries
     for (i=0; i<64; i++) {
         temp = (JPEG_StdQuantTblY[i] * qscale + 16) / 32;
-        // limit the values to the valid range 
+        // limit the values to the valid range
         if (temp <= 0)
             temp = 1;
         if (temp > 255)
@@ -778,20 +911,20 @@
         newtbl[zigzag[i]] = (unsigned char) temp;
     }
 
-    // write the resulting luminance quant table to the output buffer 
+    // write the resulting luminance quant table to the output buffer
     for (i=0; i<64; i++)
         *pbuf++ = newtbl[i];
 
-    // if format is monochrome we're finished, otherwise continue on, to do chrominance quant table 
+    // if format is monochrome we're finished, otherwise continue on, to do chrominance quant table
     if (format == FORMAT_MONOCHROME)
         return (length+2);
 
-    *pbuf++ = 1;                        // quantization table precision | identifier for chrominance 
+    *pbuf++ = 1;                        // quantization table precision | identifier for chrominance
 
-    // calculate scaled zigzagged chrominance quantisation table entries 
+    // calculate scaled zigzagged chrominance quantisation table entries
     for (i=0; i<64; i++) {
         temp = (JPEG_StdQuantTblC[i] * qscale + 16) / 32;
-        // limit the values to the valid range 
+        // limit the values to the valid range
         if (temp <= 0)
             temp = 1;
         if (temp > 255)
@@ -799,7 +932,7 @@
         newtbl[zigzag[i]] = (unsigned char) temp;
     }
 
-    // write the resulting chrominance quant table to the output buffer 
+    // write the resulting chrominance quant table to the output buffer
     for (i=0; i<64; i++)
         *pbuf++ = newtbl[i];
 
@@ -809,13 +942,13 @@
 
 //*****************************************************************************
 //
-//!     DefineHuffmanTableMarkerDC 
-//!    
-//!	\param1                      pointer to Marker buffer  
-//!	\param2                      Huffman table  
-//!	\param3                      Class Identifier 
-//!  
-//!     \return                      Length of the marker                            
+//!     DefineHuffmanTableMarkerDC
+//!
+//!	\param1                      pointer to Marker buffer
+//!	\param2                      Huffman table
+//!	\param3                      Class Identifier
+//!
+//!     \return                      Length of the marker
 //
 //*****************************************************************************
 static int DefineHuffmanTableMarkerDC(char *pbuf, unsigned int *htable, int class_id)
@@ -825,38 +958,33 @@
     int length;
     char *plength;
 
-    *pbuf++= 0xFF;                  // define huffman table marker 
+    *pbuf++= 0xFF;                  // define huffman table marker
     *pbuf++= 0xC4;
-    plength = pbuf;                 // place holder for length field 
+    plength = pbuf;                 // place holder for length field
     *pbuf++;
     *pbuf++;
-    *pbuf++= class_id;              // huffman table class | identifier 
+    *pbuf++= class_id;              // huffman table class | identifier
 
-    for (l = 0; l < 16; l++)
-    {
+    for (l = 0; l < 16; l++) {
         count = 0;
-        for (i = 0; i < 12; i++)
-        {
+        for (i = 0; i < 12; i++) {
             if ((htable[i] >> 8) == l)
                 count++;
         }
-        *pbuf++= count;             // number of huffman codes of length l+1 
+        *pbuf++= count;             // number of huffman codes of length l+1
     }
 
     length = 19;
-    for (l = 0; l < 16; l++)
-    {
-        for (i = 0; i < 12; i++)
-        {
-            if ((htable[i] >> 8) == l)
-            {
-                *pbuf++= i;         // HUFFVAL with huffman codes of length l+1 
+    for (l = 0; l < 16; l++) {
+        for (i = 0; i < 12; i++) {
+            if ((htable[i] >> 8) == l) {
+                *pbuf++= i;         // HUFFVAL with huffman codes of length l+1
                 length++;
             }
         }
     }
 
-    *plength++= length>>8;          // length field 
+    *plength++= length>>8;          // length field
     *plength = length&0xFF;
 
     return (length + 2);
@@ -865,17 +993,17 @@
 
 //*****************************************************************************
 //
-//!     DefineHuffmanTableMarkerAC 
+//!     DefineHuffmanTableMarkerAC
 //!     1. Establishes connection w/ AP//
 //!     2. Initializes the camera sub-components//! GPIO Enable & Configuration
 //!     3. Listens and processes the image capture requests from user-applications
-//!    
-//!	\param1                      pointer to Marker buffer  
-//!	\param2                      Huffman table  
-//!	\param3                      Class Identifier 
+//!
+//!	\param1                      pointer to Marker buffer
+//!	\param2                      Huffman table
+//!	\param3                      Class Identifier
 //!
 //!     \return                      Length of the Marker
-//!                               
+//!
 //
 //*****************************************************************************
 static int DefineHuffmanTableMarkerAC(char *pbuf, unsigned int *htable, int class_id)
@@ -885,68 +1013,59 @@
     char *plength;
     int length;
 
-    *pbuf++= 0xFF;                      // define huffman table marker 
+    *pbuf++= 0xFF;                      // define huffman table marker
     *pbuf++= 0xC4;
-    plength = pbuf;                     // place holder for length field 
+    plength = pbuf;                     // place holder for length field
     *pbuf++;
     *pbuf++;
-    *pbuf++= class_id;                  // huffman table class | identifier 
+    *pbuf++= class_id;                  // huffman table class | identifier
 
-    for (l = 0; l < 16; l++)
-    {
+    for (l = 0; l < 16; l++) {
         count = 0;
-        for (i = 0; i < 162; i++)
-        {
+        for (i = 0; i < 162; i++) {
             if ((htable[i] >> 8) == l)
                 count++;
         }
 
-        *pbuf++= count;                 // number of huffman codes of length l+1 
+        *pbuf++= count;                 // number of huffman codes of length l+1
     }
 
     length = 19;
-    for (l = 0; l < 16; l++)
-    {
-        // check EOB: 0|0 
-        if ((htable[160] >> 8) == l)
-        {
-            *pbuf++= 0;                 // HUFFVAL with huffman codes of length l+1 
+    for (l = 0; l < 16; l++) {
+        // check EOB: 0|0
+        if ((htable[160] >> 8) == l) {
+            *pbuf++= 0;                 // HUFFVAL with huffman codes of length l+1
             length++;
         }
 
-        // check HUFFVAL: 0|1 to E|A 
-        for (i = 0; i < 150; i++)
-        {
-            if ((htable[i] >> 8) == l)
-            {
+        // check HUFFVAL: 0|1 to E|A
+        for (i = 0; i < 150; i++) {
+            if ((htable[i] >> 8) == l) {
                 a = i/10;
                 b = i%10;
-                *pbuf++= (a<<4)|(b+1);  // HUFFVAL with huffman codes of length l+1 
+                *pbuf++= (a<<4)|(b+1);  // HUFFVAL with huffman codes of length l+1
                 length++;
             }
         }
 
-        // check ZRL: F|0 
-        if ((htable[161] >> 8) == l)
-        {
-            *pbuf++= 0xF0;              // HUFFVAL with huffman codes of length l+1 
+        // check ZRL: F|0
+        if ((htable[161] >> 8) == l) {
+            *pbuf++= 0xF0;              // HUFFVAL with huffman codes of length l+1
             length++;
         }
 
-        // check HUFFVAL: F|1 to F|A 
-        for (i = 150; i < 160; i++)
-        {
-            if ((htable[i] >> 8) == l)
-            {
+        // check HUFFVAL: F|1 to F|A
+        for (i = 150; i < 160; i++) {
+            if ((htable[i] >> 8) == l) {
                 a = i/10;
                 b = i%10;
-                *pbuf++= (a<<4)|(b+1);  // HUFFVAL with huffman codes of length l+1 
+                *pbuf++= (a<<4)|(b+1);  // HUFFVAL with huffman codes of length l+1
                 length++;
             }
         }
     }
 
-    *plength++= length>>8;              // length field 
+    *plength++= length>>8;              // length field
     *plength = length&0xFF;
     return (length + 2);
 }
@@ -955,21 +1074,21 @@
 //*****************************************************************************
 //
 //!     DefineRestartIntervalMarker
-//!    
-//!	\param1                      pointer to Marker buffer  
+//!
+//!	\param1                      pointer to Marker buffer
 //!	\param2                      return interval
 //!
-//!     \return                      Length                                
+//!     \return                      Length
 //
 //*****************************************************************************
 static int DefineRestartIntervalMarker(char *pbuf, int ri)
 {
 //    Uart_Write((uint8_t*)"DefineRestartIntervalMarker \n\r");
-    *pbuf++= 0xFF;                  // define restart interval marker 
+    *pbuf++= 0xFF;                  // define restart interval marker
     *pbuf++= 0xDD;
-    *pbuf++= 0x00;                  // length 
+    *pbuf++= 0x00;                  // length
     *pbuf++= 0x04;
-    *pbuf++= ri >> 8;               // restart interval 
+    *pbuf++= ri >> 8;               // restart interval
     *pbuf++= ri & 0xFF;
     return 6;
 }
@@ -977,15 +1096,15 @@
 //
 //!     CreateJpegHeader
 //!     Create JPEG Header in JFIF format
-//!    
-//!	\param1                     header - pointer to JPEG header buffer  
-//!	\param2                     width - image width 
-//!	\param3                     height - image height  
-//!	\param4                     format - color format (0 = YCbCr422, 1 = YCbCr420, 2 = monochrome)  
-//!	\param5                     restart_int - restart marker interval  
+//!
+//!	\param1                     header - pointer to JPEG header buffer
+//!	\param2                     width - image width
+//!	\param3                     height - image height
+//!	\param4                     format - color format (0 = YCbCr422, 1 = YCbCr420, 2 = monochrome)
+//!	\param5                     restart_int - restart marker interval
 //!	\param6                     qscale - quantization table scaling factor
 //!
-//!     \return                     length of JPEG header (bytes)                             
+//!     \return                     length of JPEG header (bytes)
 //
 //*****************************************************************************
 
@@ -996,49 +1115,47 @@
     char *pbuf = header;
     int length;
 
-    // SOI 
+    // SOI
     *pbuf++= 0xFF;
     *pbuf++= 0xD8;
     length = 2;
 
-    // JFIF APP0 
+    // JFIF APP0
     length += JfifApp0Marker(pbuf);
 
-    // Quantization Tables 
+    // Quantization Tables
     pbuf = header + length;
     length += DefineQuantizationTableMarker((unsigned char *)pbuf, qscale, format);
 
-    // Frame Header 
+    // Frame Header
     pbuf = header + length;
     length += FrameHeaderMarker(pbuf, width, height, format);
 
-    // Huffman Table DC 0 for Luma 
+    // Huffman Table DC 0 for Luma
     pbuf = header + length;
     length += DefineHuffmanTableMarkerDC(pbuf, &JPEG_StdHuffmanTbl[352], 0x00);
 
-    // Huffman Table AC 0 for Luma 
+    // Huffman Table AC 0 for Luma
     pbuf = header + length;
     length += DefineHuffmanTableMarkerAC(pbuf, &JPEG_StdHuffmanTbl[0], 0x10);
 
-    if (format != FORMAT_MONOCHROME)// YCbCr
-    {
-        // Huffman Table DC 1 for Chroma 
+    if (format != FORMAT_MONOCHROME) { // YCbCr
+        // Huffman Table DC 1 for Chroma
         pbuf = header + length;
         length += DefineHuffmanTableMarkerDC(pbuf, &JPEG_StdHuffmanTbl[368], 0x01);
 
-        // Huffman Table AC 1 for Chroma 
+        // Huffman Table AC 1 for Chroma
         pbuf = header + length;
         length += DefineHuffmanTableMarkerAC(pbuf, &JPEG_StdHuffmanTbl[176], 0x11);
     }
 
-    // Restart Interval 
-    if (restart_int > 0)
-    {
+    // Restart Interval
+    if (restart_int > 0) {
         pbuf = header + length;
         length += DefineRestartIntervalMarker(pbuf, restart_int);
     }
 
-    // Scan Header 
+    // Scan Header
     pbuf = header + length;
     length += ScanHeaderMarker(pbuf, format);
 
@@ -1055,3 +1172,8 @@
 //
 //*****************************************************************************
 
+
+
+
+
+
--- a/camera_app/camera_app.h	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/camera_app.h	Tue Aug 25 22:03:00 2015 +0000
@@ -96,14 +96,15 @@
 // APIs
 //******************************************************************************
 
-unsigned short StartCamera(char **WriteBuffer);
+uint32_t StartCamera(char **WriteBuffer);
 int SetCameraResolution(int width, int height);
 void InitCameraComponents(int width, int height);
 
 static void CamControllerInit(void);
 static void CameraIntHandler(void);
-uint16_t CaptureImage(char **WriteBuffer);
+uint32_t CaptureImage(char **WriteBuffer);
 void DMAConfig(void);
+void DCMI_MspInit(DCMI_HandleTypeDef* hdcmi);
 
 /****************************************************************************/
 /*                      LOCAL FUNCTION PROTOTYPES                           */
--- a/camera_app/httpserverapp/httpserverapp.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/httpserverapp/httpserverapp.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -96,6 +96,7 @@
 	struct HttpBlob Write;
 #ifdef ENABLE_JPEG
 	InitCameraComponents(640, 480);
+//	InitCameraComponents(320, 240);
 #else
     InitCameraComponents(240, 256);
 #endif    
--- a/camera_app/mt9d111/i2cconfig.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/mt9d111/i2cconfig.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -49,8 +49,10 @@
 #include "cli_uart.h"
 #include "myBoardInit.h"
 
+
+
 I2C i2c(PB_9, PB_8);
-int fail_count;
+
 
 //*****************************************************************************
 //
@@ -62,8 +64,8 @@
 //*****************************************************************************
 uint32_t I2CInit()
 {
-//    Uart_Write((uint8_t*)"I2CInit \n\r");
-    i2c.frequency (400000); 
+
+    i2c.frequency (100000); 
 
     return 0;
 }
@@ -87,29 +89,30 @@
 int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer,
                             int32_t ulSize, unsigned char ucFlags)
 {
-//	Uart_Write((uint8_t*)"I2CBufferRead \n\r");
-//    uint32_t ulNdx;
-    int ack;
-//    if(ucFlags == I2C_SEND_START){
-    	i2c.start(); 	   
-//    }
+//  Uart_Write((uint8_t*)"I2CBufferRead \n\r");
+/*   
+    i2c.start();       
     
-    // Set I2C slave address
-    ack = i2c.read(ucDevAddr, (char*)ucBuffer, ulSize);
-    wait_us(20);
-    if(ucFlags == I2C_SEND_STOP){
-    	i2c.stop();
-    }
+    // Set I2C slave read address
+    i2c.write(ucDevAddr);
+    if(ulSize == 1){
+    	ucBuffer[0] = i2c.read(0);
+    }else{	
+        for(int i=0;i<ulSize;i++){
+           ucBuffer[i] = i2c.read(0);
+        }
+    }    
     
-//    for(int i = 0;i<ulSize;i++){
-//    	printf("0x%x ",ucBuffer[i]);
-//    }
-//    printf("\r\n");	
-    if(ack != 0){
-    	printf("NAK returned\r\n");
-    	return -1;
+    i2c.stop();
+*/
+    int32_t err = 0;
+    
+    err = i2c.read(ucDevAddr,(char*)ucBuffer,ulSize);
+    if(err == 1){
+       Uart_Write((uint8_t*)"Return error I2C read\n\r");
+       return -1;
     }
-    
+    wait_ms(1);   
     return 0;
 }
 //****************************************************************************
@@ -132,55 +135,34 @@
 int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer,
                              int32_t ulSize,unsigned char ucFlags)
 {
-//	Uart_Write((uint8_t*)"I2CBufferWrite \n\r");
-//    uint32_t ulNdx;
-    
-    int ack;
-//    if(ucFlags == I2C_SEND_START){
-    	i2c.start(); 	   
-//    }
-    
-   // Set I2C slave address
-    ack = i2c.write(ucDevAddr, (char*)ucBuffer, ulSize);
-    wait_us(20);
-    if(ucFlags == I2C_SEND_STOP){
-    	i2c.stop();
+//  Uart_Write((uint8_t*)"I2CBufferWrite \n\r");
+/*
+    i2c.start();       
+   
+   // Set I2C slave write address
+    i2c.write(ucDevAddr);
+
+    if(ulSize == 1){
+    	i2c.write(ucBuffer[0]);
+    }else{	
+        for(int i=0;i<ulSize;i++){
+           i2c.write(ucBuffer[i]);
+        }
+    }    
+
+        i2c.stop();
+*/        
+    int32_t err = 0;
+          
+    err = i2c.write(ucDevAddr,(char*)ucBuffer,ulSize);
+    if(err == 1){
+    	Uart_Write((uint8_t*)"Return error I2C write\n\r");
+    	return -1;   	
     }
-    fail_count++;
-/*
-   for(int i = 0;i<ulSize;i++){
-    	printf("0x%x ",ucBuffer[i]);
-    }
-    printf("\r\n");	
-*/    
-    if(ack != 0){
-    	printf("NAK returned on write %d\r\n",fail_count);
-    	return -1;
-    }
-
+    wait_ms(1);		
     return 0;
 }
 
-void I2CBufferWriteByte(char dat){
-    
-    int ack, ack2 = 0;
-    
-//    i2c.start();
-	ack = i2c.write((int)dat);
-	wait_us(20);
-	if(ack == 1){		
-		ack2 = i2c.write((int)0x00);
-		wait_us(20);
-//		i2c.stop();
-	}else{
-//		i2c.stop();
-		printf("NAK received\r\n");
-	}
-	if(ack2 != 1){
-		printf("NAK received\r\n");
-	}		
-}	
-
 //*****************************************************************************
 //
 // Close the Doxygen group.
@@ -188,3 +170,4 @@
 //
 //*****************************************************************************
 
+
--- a/camera_app/mt9d111/i2cconfig.h	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/mt9d111/i2cconfig.h	Tue Aug 25 22:03:00 2015 +0000
@@ -64,7 +64,6 @@
                             int32_t ulSize,unsigned char ucFlags);
 int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer,
                              int32_t ulSize,unsigned char ucFlags);
-void I2CBufferWriteByte(char dat);
 //*****************************************************************************
 //
 // Mark the end of the C bindings section for C++ compilers.
--- a/camera_app/mt9d111/mt9d111.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -3,35 +3,35 @@
 //
 // Micron MT9D111 camera sensor driver
 //
-// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 
-// 
-// 
-//  Redistribution and use in source and binary forms, with or without 
-//  modification, are permitted provided that the following conditions 
+// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+//
+//
+//  Redistribution and use in source and binary forms, with or without
+//  modification, are permitted provided that the following conditions
 //  are met:
 //
-//    Redistributions of source code must retain the above copyright 
+//    Redistributions of source code must retain the above copyright
 //    notice, this list of conditions and the following disclaimer.
 //
 //    Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the   
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the
 //    distribution.
 //
 //    Neither the name of Texas Instruments Incorporated nor the names of
 //    its contributors may be used to endorse or promote products derived
 //    from this software without specific prior written permission.
 //
-//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+//  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+//  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+//  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 //
 //*****************************************************************************
@@ -45,18 +45,34 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include "mbed.h"
+#include "cc3100_sl_common.h"
 #include "mt9d111.h"
 
 #include "i2cconfig.h"
-#include "cc3100_sl_common.h"
 #include "cli_uart.h"
 #include "HttpDebug.h"
+#include "app_config.h"
 
 #define RET_OK                  0
 #define RET_ERROR               -1
 #define SENSOR_PAGE_REG         0xF0
-#define CAM_I2C_SLAVE_WRITE     0x5D//((0xBA >> 1))//Write
-#define CAM_I2C_SLAVE_READ      0x5E//((0xBB >> 1))//Read
+#define CAM_I2C_SLAVE_WRITE     0xBA//Write
+#define CAM_I2C_SLAVE_READ      0xBB//Read
+
+#ifdef MT9D111_CAM
+DigitalOut standby(PA_3);
+#endif
+
+extern DCMI_HandleTypeDef phdcmi;
+
+/* Soft Reset Sequence */
+static const s_RegList soft_reset_cmd_list[]= {
+    {0, 0x65, 0xA000    },  // Bypass the PLL
+    {1, 0xC3, 0x0501    },  // Perform MCU reset
+    {0, 0x0D, 0x0021    },  // Enable soft reset
+    {0, 0x0D, 0x0000    },  // Disable soft reset
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
+};
 
 #ifndef ENABLE_JPEG
 static const s_RegList preview_on_cmd_list[]= {
@@ -70,88 +86,181 @@
     {1, 0xC8, 0x0006    },  // SEQ_CMD-refresh
     {1, 0xC6, 0xA104    },  // SEQ_CMD
     {111, 0xC8, 0x0003  },  // SEQ_CMD, Do Preview
-    {100, 0x00, 0x01E0  },  // Delay = 500ms
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
 };
 
 static  const s_RegList freq_setup_cmd_List[]= {
     {1, 0xC6, 0x276D    },  // MODE_FIFO_CONF1_A
-    {1, 0xC8, 0xE4E2    },  // MODE_FIFO_CONF1_A
+    {1, 0xC8, 0xE4E2    },  // MODE_FIFO_CONF1_A =(58594)
     {1, 0xC6, 0xA76F    },  // MODE_FIFO_CONF2_A
-    {1, 0xC8, 0x00E8    },  // MODE_FIFO_CONF2_A
+    {1, 0xC8, 0x00E8    },  // MODE_FIFO_CONF2_A =(232)
+    (1, 0xC6, 0x2774    ),  // MODE_FIFO_CONF1_B **
+    (1, 0xC8, 0xE4E2    ),  // MODE_FIFO_CONF1_B ** =(58594)
+    (1, 0xC6, 0xA776    ),  // MODE_FIFO_CONF2_B **
+    (1, 0xC8, 0x00E8    ),  // MODE_FIFO_CONF2_B ** =(232)
     {1, 0xC6, 0xA103    },  // SEQ_CMD
     {1, 0xC8, 0x0005    },  // SEQ_CMD (Refresh)
-   // Set maximum integration time to get a minimum of 15 fps at 45MHz
+    // Set maximum integration time to get a minimum of 15 fps at 45MHz
     {1, 0xC6, 0xA20E    },  // AE_MAX_INDEX
     {1, 0xC8, 0x0004},      // AE_MAX_INDEX
     {1, 0xC6, 0xA102    },  // SEQ_MODE
     {1, 0xC8, 0x0001    },  // SEQ_MODE
     {1, 0xC6, 0xA102    },  // SEQ_MODE
     {1, 0xC8, 0x0005    },  // SEQ_MODE
-   // Set minimum integration time to get a maximum of 15 fps at 45MHz
+    // Set minimum integration time to get a maximum of 15 fps at 45MHz
     {1, 0xC6, 0xA20D    },  // AE_MAX_INDEX
     {1, 0xC8, 0x0004    },  // AE_MAX_INDEX
     {1, 0xC6, 0xA103    },  // SEQ_CMD
     {1, 0xC8, 0x0005    },  // SEQ_CMD (Refresh)
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
 };
 
-static  const s_RegList image_size_240_320_preview_cmds_list[]=
-{
+static  const s_RegList image_size_240_320_preview_cmds_list[]= {
     {0, 0x07, 0x00FE    },  // HORZ_BLANK_A
     {0, 0x08, 0x02A0    },  // VERT_BLANK_A
     {0, 0x20, 0x0303    },  // READ_MODE_B (Image flip settings)
     {0, 0x21, 0x8400    },  // READ_MODE_A (1ADC)
     {1, 0xC6, 0x2703    },  // MODE_OUTPUT_WIDTH_A
-    {1, 0xC8, 0x00F0    },  // MODE_OUTPUT_WIDTH_A
+    {1, 0xC8, 0x00F0    },  // MODE_OUTPUT_WIDTH_A = 0xF0 (240)
     {1, 0xC6, 0x2705    },  // MODE_OUTPUT_HEIGHT_A
-    {1, 0xC8, 0x0140    },  // MODE_OUTPUT_HEIGHT_A
+    {1, 0xC8, 0x0140    },  // MODE_OUTPUT_HEIGHT_A = 0x0140 (320)
     {1, 0xC6, 0x2727    },  // MODE_CROP_X0_A
-    {1, 0xC8, 0x0000    },  // MODE_CROP_X0_A
+    {1, 0xC8, 0x0000    },  // MODE_CROP_X0_A = 0x00
     {1, 0xC6, 0x2729    },  // MODE_CROP_X1_A
-    {1, 0xC8, 0x00F0    },  // MODE_CROP_X1_A
+    {1, 0xC8, 0x00F0    },  // MODE_CROP_X1_A = 0xF0
     {1, 0xC6, 0x272B    },  // MODE_CROP_Y0_A
-    {1, 0xC8, 0x0000    },  // MODE_CROP_Y0_A
+    {1, 0xC8, 0x0000    },  // MODE_CROP_Y0_A = 0xF0
     {1, 0xC6, 0x272D    },  // MODE_CROP_Y1_A
-    {1, 0xC8, 0x0140    },  // MODE_CROP_Y1_A
+    {1, 0xC8, 0x0140    },  // MODE_CROP_Y1_A = 0x0140
     {1, 0xC6, 0x270F    },  // MODE_SENSOR_ROW_START_A
-    {1, 0xC8, 0x001C    },  // MODE_SENSOR_ROW_START_A
+    {1, 0xC8, 0x001C    },  // MODE_SENSOR_ROW_START_A = 0x001C (28)
     {1, 0xC6, 0x2711    },  // MODE_SENSOR_COL_START_A
-    {1, 0xC8, 0x003C    },  // MODE_SENSOR_COL_START_A
+    {1, 0xC8, 0x003C    },  // MODE_SENSOR_COL_START_A = 0x003C (60)
     {1, 0xC6, 0x2713    },  // MODE_SENSOR_ROW_HEIGHT_A
-    {1, 0xC8, 0x0280    },  // MODE_SENSOR_ROW_HEIGHT_A
+    {1, 0xC8, 0x0280    },  // MODE_SENSOR_ROW_HEIGHT_A = 0x0280 (640)
     {1, 0xC6, 0x2715    },  // MODE_SENSOR_COL_WIDTH_A
-    {1, 0xC8, 0x03C0    },  // MODE_SENSOR_COL_WIDTH_A
+    {1, 0xC8, 0x03C0    },  // MODE_SENSOR_COL_WIDTH_A = 0x03C0 (960)
     {1, 0xC6, 0x2717    },  // MODE_SENSOR_X_DELAY_A
-    {1, 0xC8, 0x0088    },  // MODE_SENSOR_X_DELAY_A
+    {1, 0xC8, 0x0088    },  // MODE_SENSOR_X_DELAY_A = 0x0088
     {1, 0xC6, 0x2719    },  // MODE_SENSOR_ROW_SPEED_A
-    {1, 0xC8, 0x0011    },  // MODE_SENSOR_ROW_SPEED_A
+    {1, 0xC8, 0x0011    },  // MODE_SENSOR_ROW_SPEED_A = 0x0011
     {1, 0xC6, 0xA103    },  // SEQ_CMD
-    {1, 0xC8, 0x0005    },  // SEQ_CMD
+    {1, 0xC8, 0x0005    },  // SEQ_CMD = 0x0005
     {1, 0xC6, 0xA103    },  // SEQ_CMD
-    {1, 0xC8, 0x0006    },  // SEQ_CMD
+    {1, 0xC8, 0x0006    },  // SEQ_CMD = 0x0006
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
 };
 
 static  const s_RegList preview_cmds_list[]= {
 
     {1, 0xC6, 0xA77D    },  // MODE_OUTPUT_FORMAT_A
-    {1, 0xC8, 0x0020    },  // MODE_OUTPUT_FORMAT_A; RGB565
+    {1, 0xC8, 0x0020    },  // MODE_OUTPUT_FORMAT_A; RGB565 = 0x0020
     {1, 0xC6, 0x270B    },  // MODE_CONFIG
-    {1, 0xC8, 0x0030    },  // MODE_CONFIG, JPEG disabled for A and B
+    {1, 0xC8, 0x0030    },  // MODE_CONFIG, JPEG disabled for A and B = 0x0030
     {1, 0xC6, 0xA103    },  // SEQ_CMD
-    {1, 0xC8, 0x0005    }   // SEQ_CMD, refresh
+    {1, 0xC8, 0x0005    }   // SEQ_CMD, refresh = 0x0005
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
 };
-#else 
-static  const s_RegList capture_cmds_list[]= {
+#else
+static const s_RegList pll_cmds_list[]= {
     {0, 0x65, 0xA000    },  // Disable PLL
+//    {100, 0x00, 0x0064  },  // Delay =100ms
     {0, 0x65, 0xE000    },  // Power DOWN PLL
     {100, 0x00, 0x01F4  },  // Delay =500ms
-    {0,  0x66,  0x500B  },
-    {0,  0x67,  0x0500  },
+//    {0,  0x66,  0x3003  },  // M = 48 N = 3 PLL  fIN = 8MHz fOUT = 24MHz
+    {0,  0x66,  0x7801  },  // M = 120 N = 1 PLL  fIN = 8MHz fOUT = 60MHz
+    {0,  0x67,  0x0501  },  // P = 1
     {0, 0x65,   0xA000  },  // Disable PLL
+    {100, 0x00, 0x01F4  },  // Delay =500ms
     {0,  0x65,  0x2000  },  // Enable PLL
+    {100, 0x00, 0x01F4  },  // Delay =500ms
+};
+
+static  const s_RegList capture_cmds_list[]= {
+//    {0, 0x65, 0xA000    },  // Disable PLL
+//    {100, 0x00, 0x0064  },  // Delay =500ms
+//    {0, 0x65, 0xE000    },  // Power DOWN PLL
+//    {100, 0x00, 0x0064  },  // Delay =500ms
+//    {0,  0x66,  0x3003  },  // M = 48 N = 3 PLL  fIN = 8MHz fOUT = 24MHz
+//    {0,  0x67,  0x0201  },  // P = 1
+//    {0, 0x65,   0xA000  },  // Disable PLL
+//    {100, 0x00, 0x0064  },  // Delay =500ms
+//    {0,  0x65,  0x2000  },  // Enable PLL
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
     {0, 0x20, 0x0000    },  // READ_MODE_B (Image flip settings)
-    {100, 0x00, 0x01F4  },  // Delay =500ms
-    {100, 0x00, 0x01F4  },  // Delay =500ms
-    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+    {1, 0xC6, 0xA102    },  // SEQ_MODE
+    {1, 0xC8, 0x0001    },  // SEQ_MODE
+    {1, 0xC6, 0xA102    },  // SEQ_MODE
+    {1, 0xC8, 0x0005    },  // SEQ_MODE
+    {1,  0xC6, 0xA120   },  // Enable Capture video
+    {1,  0xC8, 0x0002   },
+    {1,  0xC6, 0x270B   },  // Mode config, disable JPEG bypass
+    {1,  0xC8, 0x0000   },
+    {1,  0xC6, 0x2702   },  // FIFO_config0b, no spoof, adaptive clock
+    {1,  0xC8, 0x001E   },
+    {1,  0xC6, 0xA907   },  // JPEG mode config, video
+    {1,  0xC8, 0x0035   },
+    {1,  0xC6, 0xA906   },  // Format YCbCr422
+    {1,  0xC8, 0x0000   },
+    {1,  0xC6, 0xA90A   },  // Set the qscale1
+    {1,  0xC8, 0x0089   },
+    {1,  0xC6, 0x2908   },  // Set the restartInt
+    {1,  0xC8, 0x0020   },
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+    {1, 0xC6, 0x2707    },  // MODE_OUTPUT_WIDTH_B
+#ifdef XGA_FRAME
+    {1, 0xC8, 1024      },
+#endif    
+#ifdef VGA_FRAME
+    {1, 0xC8, 640       },
+#endif    
+#ifdef QVGA_FRAME
+    {1, 0xC8, 240       },
+#endif
+    {1, 0xC6, 0x2709    },  // MODE_OUTPUT_HEIGHT_B
+#ifdef XGA_FRAME
+    {1, 0xC8, 768       },
+#endif    
+#ifdef VGA_FRAME
+    {1, 0xC8, 480       },
+#endif    
+#ifdef QVGA_FRAME
+    {1, 0xC8, 320       },
+#endif
+    {1, 0xC6, 0x2735    },  // MODE_CROP_X0_B
+    {1, 0xC8, 0x0000    },
+    {1, 0xC6, 0x2737    },  // MODE_CROP_X1_B
+    {1, 0xC8, 1600      },
+    {1, 0xC6, 0x2739    },  // MODE_CROP_Y0_B
+    {1, 0xC8, 0x0000    },
+    {1, 0xC6, 0x273B    },  // MODE_CROP_Y1_B
+    {1, 0xC8, 1200      },
+//    {1, 0xC6, 0xA103    }, //SEQ_CMD
+//    {1, 0xC8, 0x0005    }, //SEQ_CMD, refresh
+//    {1, 0xC6, 0xA103    },  // SEQ_CMD, Do capture
+//    {1, 0xC8, 0x0002    },
+//    {100, 0x00, 0x01f4  },  // Delay = 500ms
+//    {111, 0xC8,0x0002   }, //Wait for sequencer change
+};
+
+/*
+static const s_RegList capture_cmds_list[]= {
+//    {0, 0x65, 0xA000    },  // Disable PLL
+//    {0, 0x65, 0xE000    },  // Power DOWN PLL
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {0,  0x66,  0x500B  },
+//    {0,  0x67,  0x0500  },
+//    {0, 0x65,   0xA000  },  // Disable PLL
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {0,  0x65,  0x2000  },  // Enable PLL
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+    {0, 0x20, 0x0000    },  // READ_MODE_B (Image flip settings)
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
+//    {100, 0x00, 0x01F4  },  // Delay =500ms
     {1, 0xC6, 0xA102    },  // SEQ_MODE
     {1, 0xC8, 0x0001    },  // SEQ_MODE
     {1, 0xC6, 0xA102    },  // SEQ_MODE
@@ -170,18 +279,43 @@
     {1,  0xC8, 0x0089   },
     {1,  0xC6, 0x2908   },  // Set the restartInt
     {1,  0xC8, 0x0020   },
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
+};
+*/
+
+static const s_RegList bypass_pll_list[]= {
+    {0, 0x65, 0xA000   },  // Disable PLL
+    {100, 0x00, 0x01F4 }, // Delay =500ms
+};
+
+static const s_RegList enable_pll_list[]= {
+    {0, 0x65, 0x2000   },  // Enable PLL
+    {100, 0x00, 0x01F4 }, // Delay =500ms
+};
+
+static const s_RegList context_a_list[]= {
+    {1, 0xC6, 0xA103   }, //SEQ_CMD
+    {1, 0xC8, 0x0001   }, //SEQ_CMD, Do Preview
 };
 
-static s_RegList start_jpeg_capture_cmd_list[]={
-    {1, 0xC6, 0xA103    },  // SEQ_CMD, Do capture
-    {1, 0xC8, 0x0002    },
-    {100, 0x00, 0x01F4  },  // Delay =500ms
+static const s_RegList enter_standby_list[]= {
+   {1, 0xC6, 0xA103    }, //SEQ_CMD
+   {1, 0xC8, 0x0003    }, //SEQ_CMD, standby
 };
 
-static s_RegList stop_jpeg_capture_cmd_list[]={
+static const s_RegList context_b_list[]= {
+    {1, 0xC6, 0xA103    },  // SEQ_CMD, Do capture
+    {1, 0xC8, 0x0002    },  // Start capture
+};
+
+static const s_RegList start_capture_cmd_list[]= {
     {1, 0xC6, 0xA103    },  // SEQ_CMD, Do capture
-    {1, 0xC8, 0x0001    },
-    {100, 0x00, 0x01F4  },  // Delay =500ms
+    {1, 0xC8, 0x0002    },  // Start capture
+};
+
+static const s_RegList stop_capture_cmd_list[]= {
+    {1, 0xC6, 0xA103    },  // SEQ_CMD, Do capture
+    {1, 0xC8, 0x0001    },  // Stop capture
 };
 
 #define INDEX_CROP_X0           1
@@ -190,8 +324,8 @@
 #define INDEX_CROP_Y1           7
 #define INDEX_SIZE_WIDTH        12//9
 #define INDEX_SIZE_HEIGHT       14//11
-static  s_RegList resolution_cmds_list[]= {
-    {100, 0x00, 0x01F4      },  // Delay =500ms
+static s_RegList resolution_cmds_list[]= {
+//    {100, 0x00, 0x01F4      },  // Delay =500ms
     {1, 0xC6, 0x2735        }, //MODE_CROP_X0_A
     {1, 0xC8, 0x0000        }, //MODE_CROP_X0_A
     {1, 0xC6, 0x2737        }, //MODE_CROP_X1_A
@@ -199,23 +333,731 @@
     {1, 0xC6, 0x2739        }, //MODE_CROP_Y0_A
     {1, 0xC8, 0x0000        }, //MODE_CROP_Y0_A
     {1, 0xC6, 0x273B        }, //MODE_CROP_Y1_A
-    {1, 0xC8, 1200          }, //MODE_CROP_Y1_A   
-    {1, 0xC6, 0xA103        },  // SEQ_CMD, Do capture  
+    {1, 0xC8, 1200          }, //MODE_CROP_Y1_A
+    {1, 0xC6, 0xA103        },  // SEQ_CMD, Do capture
     {1, 0xC8, 0x0005        },
-    
+
     {1, 0xC6, 0x2707        }, //MODE_OUTPUT_WIDTH_B
     {1, 0xC8, 640           }, //MODE_OUTPUT_WIDTH_B
     {1, 0xC6, 0x2709        }, //MODE_OUTPUT_HEIGHT_B
-    {1, 0xC8, 480           }, //MODE_OUTPUT_HEIGHT_B   
+    {1, 0xC8, 480           }, //MODE_OUTPUT_HEIGHT_B
+    {100, 0x00, 0x01f4      },  // Delay = 500ms
 };
-#endif 
+#endif
+static const s_RegList init_cmds_list[]= {
+    {0, 0x33, 0x0343        }, // RESERVED_CORE_33
+    {1, 0xC6, 0xA115        }, //SEQ_LLMODE
+    {1, 0xC8, 0x0020        }, //SEQ_LLMODE
+    {0, 0x38, 0x0866        }, // RESERVED_CORE_38
+    {100, 0x00, 0x0064      }, // Delay =100ms
+    {2, 0x80, 0x0168        }, // LENS_CORRECTION_CONTROL
+    {2, 0x81, 0x6432        }, // ZONE_BOUNDS_X1_X2
+    {2, 0x82, 0x3296        }, // ZONE_BOUNDS_X0_X3
+    {2, 0x83, 0x9664        }, // ZONE_BOUNDS_X4_X5
+    {2, 0x84, 0x5028        }, // ZONE_BOUNDS_Y1_Y2
+    {2, 0x85, 0x2878        }, // ZONE_BOUNDS_Y0_Y3
+    {2, 0x86, 0x7850        }, // ZONE_BOUNDS_Y4_Y5
+    {2, 0x87, 0x0000        }, // CENTER_OFFSET
+    {2, 0x88, 0x0152        }, // FX_RED
+    {2, 0x89, 0x015C        }, // FX_GREEN
+    {2, 0x8A, 0x00F4        }, // FX_BLUE
+    {2, 0x8B, 0x0108        }, // FY_RED
+    {2, 0x8C, 0x00FA        }, // FY_GREEN
+    {2, 0x8D, 0x00CF        }, // FY_BLUE
+    {2, 0x8E, 0x09AD        }, // DF_DX_RED
+    {2, 0x8F, 0x091E        }, // DF_DX_GREEN
+    {2, 0x90, 0x0B3F        }, // DF_DX_BLUE
+    {2, 0x91, 0x0C85        }, // DF_DY_RED
+    {2, 0x92, 0x0CFF        }, // DF_DY_GREEN
+    {2, 0x93, 0x0D86        }, // DF_DY_BLUE
+    {2, 0x94, 0x163A        }, // SECOND_DERIV_ZONE_0_RED
+    {2, 0x95, 0x0E47        }, // SECOND_DERIV_ZONE_0_GREEN
+    {2, 0x96, 0x103C        }, // SECOND_DERIV_ZONE_0_BLUE
+    {2, 0x97, 0x1D35        }, // SECOND_DERIV_ZONE_1_RED
+    {2, 0x98, 0x173E        }, // SECOND_DERIV_ZONE_1_GREEN
+    {2, 0x99, 0x1119        }, // SECOND_DERIV_ZONE_1_BLUE
+    {2, 0x9A, 0x1663        }, // SECOND_DERIV_ZONE_2_RED
+    {2, 0x9B, 0x1569        }, // SECOND_DERIV_ZONE_2_GREEN
+    {2, 0x9C, 0x104C        }, // SECOND_DERIV_ZONE_2_BLUE
+    {2, 0x9D, 0x1015        }, // SECOND_DERIV_ZONE_3_RED
+    {2, 0x9E, 0x1010        }, // SECOND_DERIV_ZONE_3_GREEN
+    {2, 0x9F, 0x0B0A        }, // SECOND_DERIV_ZONE_3_BLUE
+    {2, 0xA0, 0x0D53        }, // SECOND_DERIV_ZONE_4_RED
+    {2, 0xA1, 0x0D51        }, // SECOND_DERIV_ZONE_4_GREEN
+    {2, 0xA2, 0x0A44        }, // SECOND_DERIV_ZONE_4_BLUE
+    {2, 0xA3, 0x1545        }, // SECOND_DERIV_ZONE_5_RED
+    {2, 0xA4, 0x1643        }, // SECOND_DERIV_ZONE_5_GREEN
+    {2, 0xA5, 0x1231        }, // SECOND_DERIV_ZONE_5_BLUE
+    {2, 0xA6, 0x0047        }, // SECOND_DERIV_ZONE_6_RED
+    {2, 0xA7, 0x035C        }, // SECOND_DERIV_ZONE_6_GREEN
+    {2, 0xA8, 0xFE30        }, // SECOND_DERIV_ZONE_6_BLUE
+    {2, 0xA9, 0x4625        }, // SECOND_DERIV_ZONE_7_RED
+    {2, 0xAA, 0x47F3        }, // SECOND_DERIV_ZONE_7_GREEN
+    {2, 0xAB, 0x5859        }, // SECOND_DERIV_ZONE_7_BLUE
+    {2, 0xAC, 0x0000        }, // X2_FACTORS
+    {2, 0xAD, 0x0000        }, // GLOBAL_OFFSET_FXY_FUNCTION
+    {2, 0xAE, 0x0000        }, // K_FACTOR_IN_K_FX_FY
+    {1, 0x08, 0x01FC        }, // COLOR_PIPELINE_CONTROL
+    {100, 0x00, 0x0064      }, // Delay =100ms
+    {1, 0xBE, 0x0004        }, // YUV_YCBCR_CONTROL
+/**/    {0, 0x65, 0xA000        }, // PLL CLOCK_ENABLING
+/**/    {100, 0x00, 0x0064      }, // Delay =100ms
+    {1, 0xC6, 0x104C        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0000        }, // MCU_DATA_0
+    {1, 0xC6, 0x0400        }, // MCU_ADDRESS
+    {1, 0xC8, 0x3736        }, // MCU_DATA_0
+    {1, 0xC9, 0x3C3C        }, // MCU_DATA_1
+    {1, 0xCA, 0x3C3C        }, // MCU_DATA_2
+    {1, 0xCB, 0x30EC        }, // MCU_DATA_3
+    {1, 0xCC, 0x08BD        }, // MCU_DATA_4
+    {1, 0xCD, 0xA1B6        }, // MCU_DATA_5
+    {1, 0xCE, 0xD6A9        }, // MCU_DATA_6
+    {1, 0xCF, 0xF102        }, // MCU_DATA_7
+    {1, 0xC6, 0x0410        }, // MCU_ADDRESS
+    {1, 0xC8, 0xBD22        }, // MCU_DATA_0
+    {1, 0xC9, 0x6DF6        }, // MCU_DATA_1
+    {1, 0xCA, 0x02BE        }, // MCU_DATA_2
+    {1, 0xCB, 0x4F30        }, // MCU_DATA_3
+    {1, 0xCC, 0xED06        }, // MCU_DATA_4
+    {1, 0xCD, 0xF602        }, // MCU_DATA_5
+    {1, 0xCE, 0xC1ED        }, // MCU_DATA_6
+    {1, 0xCF, 0x04EC        }, // MCU_DATA_7
+    {1, 0xC6, 0x0420        }, // MCU_ADDRESS
+    {1, 0xC8, 0x06A3        }, // MCU_DATA_0
+    {1, 0xC9, 0x04ED        }, // MCU_DATA_1
+    {1, 0xCA, 0x02D6        }, // MCU_DATA_2
+    {1, 0xCB, 0xA94F        }, // MCU_DATA_3
+    {1, 0xCC, 0xED00        }, // MCU_DATA_4
+    {1, 0xCD, 0xF602        }, // MCU_DATA_5
+    {1, 0xCE, 0xBDBD        }, // MCU_DATA_6
+    {1, 0xCF, 0xD268        }, // MCU_DATA_7
+    {1, 0xC6, 0x0430        }, // MCU_ADDRESS
+    {1, 0xC8, 0xF602        }, // MCU_DATA_0
+    {1, 0xC9, 0xBE30        }, // MCU_DATA_1
+    {1, 0xCA, 0xE003        }, // MCU_DATA_2
+    {1, 0xCB, 0xF702        }, // MCU_DATA_3
+    {1, 0xCC, 0xC7F6        }, // MCU_DATA_4
+    {1, 0xCD, 0x02BF        }, // MCU_DATA_5
+    {1, 0xCE, 0x4FED        }, // MCU_DATA_6
+    {1, 0xCF, 0x06F6        }, // MCU_DATA_7
+    {1, 0xC6, 0x0440        }, // MCU_ADDRESS
+    {1, 0xC8, 0x02C2        }, // MCU_DATA_0
+    {1, 0xC9, 0xED04        }, // MCU_DATA_1
+    {1, 0xCA, 0xEC06        }, // MCU_DATA_2
+    {1, 0xCB, 0xA304        }, // MCU_DATA_3
+    {1, 0xCC, 0xED02        }, // MCU_DATA_4
+    {1, 0xCD, 0xD6A9        }, // MCU_DATA_5
+    {1, 0xCE, 0x4FED        }, // MCU_DATA_6
+    {1, 0xCF, 0x00F6        }, // MCU_DATA_7
+    {1, 0xC6, 0x0450        }, // MCU_ADDRESS
+    {1, 0xC8, 0x02BD        }, // MCU_DATA_0
+    {1, 0xC9, 0xBDD2        }, // MCU_DATA_1
+    {1, 0xCA, 0x68F6        }, // MCU_DATA_2
+    {1, 0xCB, 0x02BF        }, // MCU_DATA_3
+    {1, 0xCC, 0x30E0        }, // MCU_DATA_4
+    {1, 0xCD, 0x03F7        }, // MCU_DATA_5
+    {1, 0xCE, 0x02C8        }, // MCU_DATA_6
+    {1, 0xCF, 0xF602        }, // MCU_DATA_7
+    {1, 0xC6, 0x0460        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC04F        }, // MCU_DATA_0
+    {1, 0xC9, 0xED06        }, // MCU_DATA_1
+    {1, 0xCA, 0xF602        }, // MCU_DATA_2
+    {1, 0xCB, 0xC3ED        }, // MCU_DATA_3
+    {1, 0xCC, 0x04EC        }, // MCU_DATA_4
+    {1, 0xCD, 0x06A3        }, // MCU_DATA_5
+    {1, 0xCE, 0x04ED        }, // MCU_DATA_6
+    {1, 0xCF, 0x02D6        }, // MCU_DATA_7
+    {1, 0xC6, 0x0470        }, // MCU_ADDRESS
+    {1, 0xC8, 0xA94F        }, // MCU_DATA_0
+    {1, 0xC9, 0xED00        }, // MCU_DATA_1
+    {1, 0xCA, 0xF602        }, // MCU_DATA_2
+    {1, 0xCB, 0xBDBD        }, // MCU_DATA_3
+    {1, 0xCC, 0xD268        }, // MCU_DATA_4
+    {1, 0xCD, 0xF602        }, // MCU_DATA_5
+    {1, 0xCE, 0xC07E        }, // MCU_DATA_6
+    {1, 0xCF, 0x050B        }, // MCU_DATA_7
+    {1, 0xC6, 0x0480        }, // MCU_ADDRESS
+    {1, 0xC8, 0xF602        }, // MCU_DATA_0
+    {1, 0xC9, 0xC44F        }, // MCU_DATA_1
+    {1, 0xCA, 0x30ED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06F6        }, // MCU_DATA_3
+    {1, 0xCC, 0x02C1        }, // MCU_DATA_4
+    {1, 0xCD, 0xED04        }, // MCU_DATA_5
+    {1, 0xCE, 0xEC06        }, // MCU_DATA_6
+    {1, 0xCF, 0xA304        }, // MCU_DATA_7
+    {1, 0xC6, 0x0490        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED02        }, // MCU_DATA_0
+    {1, 0xC9, 0xD6A8        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06D6        }, // MCU_DATA_3
+    {1, 0xCC, 0xA9ED        }, // MCU_DATA_4
+    {1, 0xCD, 0x04EC        }, // MCU_DATA_5
+    {1, 0xCE, 0x06A3        }, // MCU_DATA_6
+    {1, 0xCF, 0x04ED        }, // MCU_DATA_7
+    {1, 0xC6, 0x04A0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x00F6        }, // MCU_DATA_0
+    {1, 0xC9, 0x02BD        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FBD        }, // MCU_DATA_2
+    {1, 0xCB, 0xD268        }, // MCU_DATA_3
+    {1, 0xCC, 0xF602        }, // MCU_DATA_4
+    {1, 0xCD, 0xC430        }, // MCU_DATA_5
+    {1, 0xCE, 0xE003        }, // MCU_DATA_6
+    {1, 0xCF, 0xF702        }, // MCU_DATA_7
+    {1, 0xC6, 0x04B0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC7F6        }, // MCU_DATA_0
+    {1, 0xC9, 0x02C5        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06F6        }, // MCU_DATA_3
+    {1, 0xCC, 0x02C2        }, // MCU_DATA_4
+    {1, 0xCD, 0xED04        }, // MCU_DATA_5
+    {1, 0xCE, 0xEC06        }, // MCU_DATA_6
+    {1, 0xCF, 0xA304        }, // MCU_DATA_7
+    {1, 0xC6, 0x04C0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED02        }, // MCU_DATA_0
+    {1, 0xC9, 0xD6A8        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06D6        }, // MCU_DATA_3
+    {1, 0xCC, 0xA9ED        }, // MCU_DATA_4
+    {1, 0xCD, 0x04EC        }, // MCU_DATA_5
+    {1, 0xCE, 0x06A3        }, // MCU_DATA_6
+    {1, 0xCF, 0x04ED        }, // MCU_DATA_7
+    {1, 0xC6, 0x04D0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x00F6        }, // MCU_DATA_0
+    {1, 0xC9, 0x02BD        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FBD        }, // MCU_DATA_2
+    {1, 0xCB, 0xD268        }, // MCU_DATA_3
+    {1, 0xCC, 0xF602        }, // MCU_DATA_4
+    {1, 0xCD, 0xC530        }, // MCU_DATA_5
+    {1, 0xCE, 0xE003        }, // MCU_DATA_6
+    {1, 0xCF, 0xF702        }, // MCU_DATA_7
+    {1, 0xC6, 0x04E0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC8F6        }, // MCU_DATA_0
+    {1, 0xC9, 0x02C6        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06F6        }, // MCU_DATA_3
+    {1, 0xCC, 0x02C3        }, // MCU_DATA_4
+    {1, 0xCD, 0xED04        }, // MCU_DATA_5
+    {1, 0xCE, 0xEC06        }, // MCU_DATA_6
+    {1, 0xCF, 0xA304        }, // MCU_DATA_7
+    {1, 0xC6, 0x04F0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED02        }, // MCU_DATA_0
+    {1, 0xC9, 0xD6A8        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FED        }, // MCU_DATA_2
+    {1, 0xCB, 0x06D6        }, // MCU_DATA_3
+    {1, 0xCC, 0xA9ED        }, // MCU_DATA_4
+    {1, 0xCD, 0x04EC        }, // MCU_DATA_5
+    {1, 0xCE, 0x06A3        }, // MCU_DATA_6
+    {1, 0xCF, 0x04ED        }, // MCU_DATA_7
+    {1, 0xC6, 0x0500        }, // MCU_ADDRESS
+    {1, 0xC8, 0x00F6        }, // MCU_DATA_0
+    {1, 0xC9, 0x02BD        }, // MCU_DATA_1
+    {1, 0xCA, 0x4FBD        }, // MCU_DATA_2
+    {1, 0xCB, 0xD268        }, // MCU_DATA_3
+    {1, 0xCC, 0xF602        }, // MCU_DATA_4
+    {1, 0xCD, 0xC630        }, // MCU_DATA_5
+    {1, 0xCE, 0xE003        }, // MCU_DATA_6
+    {1, 0xCF, 0xF702        }, // MCU_DATA_7
+    {1, 0xC6, 0x0510        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC9EE        }, // MCU_DATA_0
+    {1, 0xC9, 0x08EC        }, // MCU_DATA_1
+    {1, 0xCA, 0x0030        }, // MCU_DATA_2
+    {1, 0xCB, 0xED02        }, // MCU_DATA_3
+    {1, 0xCC, 0xF602        }, // MCU_DATA_4
+    {1, 0xCD, 0xC74F        }, // MCU_DATA_5
+    {1, 0xCE, 0xED00        }, // MCU_DATA_6
+    {1, 0xCF, 0xCC00        }, // MCU_DATA_7
+    {1, 0xC6, 0x0520        }, // MCU_ADDRESS
+    {1, 0xC8, 0x80BD        }, // MCU_DATA_0
+    {1, 0xC9, 0xD268        }, // MCU_DATA_1
+    {1, 0xCA, 0x301A        }, // MCU_DATA_2
+    {1, 0xCB, 0xEE08        }, // MCU_DATA_3
+    {1, 0xCC, 0xEC02        }, // MCU_DATA_4
+    {1, 0xCD, 0x18ED        }, // MCU_DATA_5
+    {1, 0xCE, 0x00EE        }, // MCU_DATA_6
+    {1, 0xCF, 0x08EC        }, // MCU_DATA_7
+    {1, 0xC6, 0x0530        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0230        }, // MCU_DATA_0
+    {1, 0xC9, 0xED02        }, // MCU_DATA_1
+    {1, 0xCA, 0xF602        }, // MCU_DATA_2
+    {1, 0xCB, 0xC84F        }, // MCU_DATA_3
+    {1, 0xCC, 0xED00        }, // MCU_DATA_4
+    {1, 0xCD, 0xCC00        }, // MCU_DATA_5
+    {1, 0xCE, 0x80BD        }, // MCU_DATA_6
+    {1, 0xCF, 0xD268        }, // MCU_DATA_7
+    {1, 0xC6, 0x0540        }, // MCU_ADDRESS
+    {1, 0xC8, 0x301A        }, // MCU_DATA_0
+    {1, 0xC9, 0xEE08        }, // MCU_DATA_1
+    {1, 0xCA, 0xEC02        }, // MCU_DATA_2
+    {1, 0xCB, 0x18ED        }, // MCU_DATA_3
+    {1, 0xCC, 0x02EE        }, // MCU_DATA_4
+    {1, 0xCD, 0x08EC        }, // MCU_DATA_5
+    {1, 0xCE, 0x0430        }, // MCU_DATA_6
+    {1, 0xCF, 0xED02        }, // MCU_DATA_7
+    {1, 0xC6, 0x0550        }, // MCU_ADDRESS
+    {1, 0xC8, 0xF602        }, // MCU_DATA_0
+    {1, 0xC9, 0xC94F        }, // MCU_DATA_1
+    {1, 0xCA, 0xED00        }, // MCU_DATA_2
+    {1, 0xCB, 0xCC00        }, // MCU_DATA_3
+    {1, 0xCC, 0x80BD        }, // MCU_DATA_4
+    {1, 0xCD, 0xD268        }, // MCU_DATA_5
+    {1, 0xCE, 0x301A        }, // MCU_DATA_6
+    {1, 0xCF, 0xEE08        }, // MCU_DATA_7
+    {1, 0xC6, 0x0560        }, // MCU_ADDRESS
+    {1, 0xC8, 0xEC02        }, // MCU_DATA_0
+    {1, 0xC9, 0x18ED        }, // MCU_DATA_1
+    {1, 0xCA, 0x0430        }, // MCU_DATA_2
+    {1, 0xCB, 0xC60A        }, // MCU_DATA_3
+    {1, 0xCC, 0x3A35        }, // MCU_DATA_4
+    {1, 0xCD, 0x3930        }, // MCU_DATA_5
+    {1, 0xCE, 0x8FC3        }, // MCU_DATA_6
+    {1, 0xCF, 0xFFE5        }, // MCU_DATA_7
+    {1, 0xC6, 0x0570        }, // MCU_ADDRESS
+    {1, 0xC8, 0x8F35        }, // MCU_DATA_0
+    {1, 0xC9, 0x6F1A        }, // MCU_DATA_1
+    {1, 0xCA, 0xDC8C        }, // MCU_DATA_2
+    {1, 0xCB, 0x2C02        }, // MCU_DATA_3
+    {1, 0xCC, 0x6C1A        }, // MCU_DATA_4
+    {1, 0xCD, 0xDC8E        }, // MCU_DATA_5
+    {1, 0xCE, 0x2C06        }, // MCU_DATA_6
+    {1, 0xCF, 0xE61A        }, // MCU_DATA_7
+    {1, 0xC6, 0x0580        }, // MCU_ADDRESS
+    {1, 0xC8, 0xCB02        }, // MCU_DATA_0
+    {1, 0xC9, 0xE71A        }, // MCU_DATA_1
+    {1, 0xCA, 0xDC90        }, // MCU_DATA_2
+    {1, 0xCB, 0x2C06        }, // MCU_DATA_3
+    {1, 0xCC, 0xE61A        }, // MCU_DATA_4
+    {1, 0xCD, 0xCB04        }, // MCU_DATA_5
+    {1, 0xCE, 0xE71A        }, // MCU_DATA_6
+    {1, 0xCF, 0xDC94        }, // MCU_DATA_7
+    {1, 0xC6, 0x0590        }, // MCU_ADDRESS
+    {1, 0xC8, 0x2C06        }, // MCU_DATA_0
+    {1, 0xC9, 0xE61A        }, // MCU_DATA_1
+    {1, 0xCA, 0xCB08        }, // MCU_DATA_2
+    {1, 0xCB, 0xE71A        }, // MCU_DATA_3
+    {1, 0xCC, 0xDC96        }, // MCU_DATA_4
+    {1, 0xCD, 0x2C06        }, // MCU_DATA_5
+    {1, 0xCE, 0xE61A        }, // MCU_DATA_6
+    {1, 0xCF, 0xCB10        }, // MCU_DATA_7
+    {1, 0xC6, 0x05A0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xE71A        }, // MCU_DATA_0
+    {1, 0xC9, 0xDC98        }, // MCU_DATA_1
+    {1, 0xCA, 0x2C06        }, // MCU_DATA_2
+    {1, 0xCB, 0xE61A        }, // MCU_DATA_3
+    {1, 0xCC, 0xCB20        }, // MCU_DATA_4
+    {1, 0xCD, 0xE71A        }, // MCU_DATA_5
+    {1, 0xCE, 0x5F4F        }, // MCU_DATA_6
+    {1, 0xCF, 0xED0D        }, // MCU_DATA_7
+    {1, 0xC6, 0x05B0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED0B        }, // MCU_DATA_0
+    {1, 0xC9, 0xC608        }, // MCU_DATA_1
+    {1, 0xCA, 0xE709        }, // MCU_DATA_2
+    {1, 0xCB, 0x4FE6        }, // MCU_DATA_3
+    {1, 0xCC, 0x092A        }, // MCU_DATA_4
+    {1, 0xCD, 0x0143        }, // MCU_DATA_5
+    {1, 0xCE, 0x058F        }, // MCU_DATA_6
+    {1, 0xCF, 0xEC8A        }, // MCU_DATA_7
+    {1, 0xC6, 0x05C0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x30ED        }, // MCU_DATA_0
+    {1, 0xC9, 0x0F2C        }, // MCU_DATA_1
+    {1, 0xCA, 0x065F        }, // MCU_DATA_2
+    {1, 0xCB, 0x4FA3        }, // MCU_DATA_3
+    {1, 0xCC, 0x0FED        }, // MCU_DATA_4
+    {1, 0xCD, 0x0FC6        }, // MCU_DATA_5
+    {1, 0xCE, 0x04E7        }, // MCU_DATA_6
+    {1, 0xCF, 0x0A20        }, // MCU_DATA_7
+    {1, 0xC6, 0x05D0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x07EC        }, // MCU_DATA_0
+    {1, 0xC9, 0x0F04        }, // MCU_DATA_1
+    {1, 0xCA, 0xED0F        }, // MCU_DATA_2
+    {1, 0xCB, 0x6A0A        }, // MCU_DATA_3
+    {1, 0xCC, 0x6D0F        }, // MCU_DATA_4
+    {1, 0xCD, 0x2704        }, // MCU_DATA_5
+    {1, 0xCE, 0x6D0A        }, // MCU_DATA_6
+    {1, 0xCF, 0x26F1        }, // MCU_DATA_7
+    {1, 0xC6, 0x05E0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x4FE6        }, // MCU_DATA_0
+    {1, 0xC9, 0x092A        }, // MCU_DATA_1
+    {1, 0xCA, 0x0143        }, // MCU_DATA_2
+    {1, 0xCB, 0xED06        }, // MCU_DATA_3
+    {1, 0xCC, 0x8FC3        }, // MCU_DATA_4
+    {1, 0xCD, 0x0011        }, // MCU_DATA_5
+    {1, 0xCE, 0x30E3        }, // MCU_DATA_6
+    {1, 0xCF, 0x0618        }, // MCU_DATA_7
+    {1, 0xC6, 0x05F0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x8FE6        }, // MCU_DATA_0
+    {1, 0xC9, 0x1018        }, // MCU_DATA_1
+    {1, 0xCA, 0xE700        }, // MCU_DATA_2
+    {1, 0xCB, 0xE609        }, // MCU_DATA_3
+    {1, 0xCC, 0xC104        }, // MCU_DATA_4
+    {1, 0xCD, 0x2F10        }, // MCU_DATA_5
+    {1, 0xCE, 0xEC0B        }, // MCU_DATA_6
+    {1, 0xCF, 0x0505        }, // MCU_DATA_7
+    {1, 0xC6, 0x0600        }, // MCU_ADDRESS
+    {1, 0xC8, 0x05ED        }, // MCU_DATA_0
+    {1, 0xC9, 0x0BE6        }, // MCU_DATA_1
+    {1, 0xCA, 0x0A4F        }, // MCU_DATA_2
+    {1, 0xCB, 0xE30B        }, // MCU_DATA_3
+    {1, 0xCC, 0xED0B        }, // MCU_DATA_4
+    {1, 0xCD, 0x200E        }, // MCU_DATA_5
+    {1, 0xCE, 0xEC0D        }, // MCU_DATA_6
+    {1, 0xCF, 0x0505        }, // MCU_DATA_7
+    {1, 0xC6, 0x0610        }, // MCU_ADDRESS
+    {1, 0xC8, 0x05ED        }, // MCU_DATA_0
+    {1, 0xC9, 0x0DE6        }, // MCU_DATA_1
+    {1, 0xCA, 0x0A4F        }, // MCU_DATA_2
+    {1, 0xCB, 0xE30D        }, // MCU_DATA_3
+    {1, 0xCC, 0xED0D        }, // MCU_DATA_4
+    {1, 0xCD, 0x6A09        }, // MCU_DATA_5
+    {1, 0xCE, 0x6D09        }, // MCU_DATA_6
+    {1, 0xCF, 0x2C96        }, // MCU_DATA_7
+    {1, 0xC6, 0x0620        }, // MCU_ADDRESS
+    {1, 0xC8, 0xCC01        }, // MCU_DATA_0
+    {1, 0xC9, 0x60ED        }, // MCU_DATA_1
+    {1, 0xCA, 0x00EC        }, // MCU_DATA_2
+    {1, 0xCB, 0x0DBD        }, // MCU_DATA_3
+    {1, 0xCC, 0xD350        }, // MCU_DATA_4
+    {1, 0xCD, 0xCC01        }, // MCU_DATA_5
+    {1, 0xCE, 0x6130        }, // MCU_DATA_6
+    {1, 0xCF, 0xED00        }, // MCU_DATA_7
+    {1, 0xC6, 0x0630        }, // MCU_ADDRESS
+    {1, 0xC8, 0xEC0B        }, // MCU_DATA_0
+    {1, 0xC9, 0xBDD3        }, // MCU_DATA_1
+    {1, 0xCA, 0x5030        }, // MCU_DATA_2
+    {1, 0xCB, 0xE612        }, // MCU_DATA_3
+    {1, 0xCC, 0x4F17        }, // MCU_DATA_4
+    {1, 0xCD, 0x5FED        }, // MCU_DATA_5
+    {1, 0xCE, 0x0FE6        }, // MCU_DATA_6
+    {1, 0xCF, 0x114F        }, // MCU_DATA_7
+    {1, 0xC6, 0x0640        }, // MCU_ADDRESS
+    {1, 0xC8, 0xE30F        }, // MCU_DATA_0
+    {1, 0xC9, 0xED0F        }, // MCU_DATA_1
+    {1, 0xCA, 0xCC01        }, // MCU_DATA_2
+    {1, 0xCB, 0x62ED        }, // MCU_DATA_3
+    {1, 0xCC, 0x00EC        }, // MCU_DATA_4
+    {1, 0xCD, 0x0FBD        }, // MCU_DATA_5
+    {1, 0xCE, 0xD350        }, // MCU_DATA_6
+    {1, 0xCF, 0x30E6        }, // MCU_DATA_7
+    {1, 0xC6, 0x0650        }, // MCU_ADDRESS
+    {1, 0xC8, 0x144F        }, // MCU_DATA_0
+    {1, 0xC9, 0x175F        }, // MCU_DATA_1
+    {1, 0xCA, 0xED0F        }, // MCU_DATA_2
+    {1, 0xCB, 0xE613        }, // MCU_DATA_3
+    {1, 0xCC, 0x4FE3        }, // MCU_DATA_4
+    {1, 0xCD, 0x0FED        }, // MCU_DATA_5
+    {1, 0xCE, 0x0FCC        }, // MCU_DATA_6
+    {1, 0xCF, 0x0163        }, // MCU_DATA_7
+    {1, 0xC6, 0x0660        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED00        }, // MCU_DATA_0
+    {1, 0xC9, 0xEC0F        }, // MCU_DATA_1
+    {1, 0xCA, 0xBDD3        }, // MCU_DATA_2
+    {1, 0xCB, 0x5030        }, // MCU_DATA_3
+    {1, 0xCC, 0xE616        }, // MCU_DATA_4
+    {1, 0xCD, 0x4F17        }, // MCU_DATA_5
+    {1, 0xCE, 0x5FED        }, // MCU_DATA_6
+    {1, 0xCF, 0x0FE6        }, // MCU_DATA_7
+    {1, 0xC6, 0x0670        }, // MCU_ADDRESS
+    {1, 0xC8, 0x154F        }, // MCU_DATA_0
+    {1, 0xC9, 0xE30F        }, // MCU_DATA_1
+    {1, 0xCA, 0xED0F        }, // MCU_DATA_2
+    {1, 0xCB, 0xCC01        }, // MCU_DATA_3
+    {1, 0xCC, 0x64ED        }, // MCU_DATA_4
+    {1, 0xCD, 0x00EC        }, // MCU_DATA_5
+    {1, 0xCE, 0x0FBD        }, // MCU_DATA_6
+    {1, 0xCF, 0xD350        }, // MCU_DATA_7
+    {1, 0xC6, 0x0680        }, // MCU_ADDRESS
+    {1, 0xC8, 0x30E6        }, // MCU_DATA_0
+    {1, 0xC9, 0x184F        }, // MCU_DATA_1
+    {1, 0xCA, 0x175F        }, // MCU_DATA_2
+    {1, 0xCB, 0xED0F        }, // MCU_DATA_3
+    {1, 0xCC, 0xE617        }, // MCU_DATA_4
+    {1, 0xCD, 0x4FE3        }, // MCU_DATA_5
+    {1, 0xCE, 0x0FED        }, // MCU_DATA_6
+    {1, 0xCF, 0x0FCC        }, // MCU_DATA_7
+    {1, 0xC6, 0x0690        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0165        }, // MCU_DATA_0
+    {1, 0xC9, 0xED00        }, // MCU_DATA_1
+    {1, 0xCA, 0xEC0F        }, // MCU_DATA_2
+    {1, 0xCB, 0xBDD3        }, // MCU_DATA_3
+    {1, 0xCC, 0x5030        }, // MCU_DATA_4
+    {1, 0xCD, 0xE61A        }, // MCU_DATA_5
+    {1, 0xCE, 0x4F17        }, // MCU_DATA_6
+    {1, 0xCF, 0x5FED        }, // MCU_DATA_7
+    {1, 0xC6, 0x06A0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0FE6        }, // MCU_DATA_0
+    {1, 0xC9, 0x194F        }, // MCU_DATA_1
+    {1, 0xCA, 0xE30F        }, // MCU_DATA_2
+    {1, 0xCB, 0xED0F        }, // MCU_DATA_3
+    {1, 0xCC, 0xCC01        }, // MCU_DATA_4
+    {1, 0xCD, 0x66ED        }, // MCU_DATA_5
+    {1, 0xCE, 0x00EC        }, // MCU_DATA_6
+    {1, 0xCF, 0x0FBD        }, // MCU_DATA_7
+    {1, 0xC6, 0x06B0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xD350        }, // MCU_DATA_0
+    {1, 0xC9, 0x13AB        }, // MCU_DATA_1
+    {1, 0xCA, 0x0406        }, // MCU_DATA_2
+    {1, 0xCB, 0xCC7F        }, // MCU_DATA_3
+    {1, 0xCC, 0x8030        }, // MCU_DATA_4
+    {1, 0xCD, 0x207A        }, // MCU_DATA_5
+    {1, 0xCE, 0xDC9C        }, // MCU_DATA_6
+    {1, 0xCF, 0x30ED        }, // MCU_DATA_7
+    {1, 0xC6, 0x06C0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x02D6        }, // MCU_DATA_0
+    {1, 0xC9, 0xA44F        }, // MCU_DATA_1
+    {1, 0xCA, 0xED00        }, // MCU_DATA_2
+    {1, 0xCB, 0xCC00        }, // MCU_DATA_3
+    {1, 0xCC, 0x80BD        }, // MCU_DATA_4
+    {1, 0xCD, 0xD268        }, // MCU_DATA_5
+    {1, 0xCE, 0x30E6        }, // MCU_DATA_6
+    {1, 0xCF, 0x03E7        }, // MCU_DATA_7
+    {1, 0xC6, 0x06D0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x11DC        }, // MCU_DATA_0
+    {1, 0xC9, 0x9EED        }, // MCU_DATA_1
+    {1, 0xCA, 0x02D6        }, // MCU_DATA_2
+    {1, 0xCB, 0xA64F        }, // MCU_DATA_3
+    {1, 0xCC, 0xED00        }, // MCU_DATA_4
+    {1, 0xCD, 0xCC00        }, // MCU_DATA_5
+    {1, 0xCE, 0x80BD        }, // MCU_DATA_6
+    {1, 0xCF, 0xD268        }, // MCU_DATA_7
+    {1, 0xC6, 0x06E0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x30E6        }, // MCU_DATA_0
+    {1, 0xC9, 0x03E7        }, // MCU_DATA_1
+    {1, 0xCA, 0x12E6        }, // MCU_DATA_2
+    {1, 0xCB, 0x11A6        }, // MCU_DATA_3
+    {1, 0xCC, 0x123D        }, // MCU_DATA_4
+    {1, 0xCD, 0xED0F        }, // MCU_DATA_5
+    {1, 0xCE, 0x6F0A        }, // MCU_DATA_6
+    {1, 0xCF, 0x2007        }, // MCU_DATA_7
+    {1, 0xC6, 0x06F0        }, // MCU_ADDRESS
+    {1, 0xC8, 0xEC0F        }, // MCU_DATA_0
+    {1, 0xC9, 0x04ED        }, // MCU_DATA_1
+    {1, 0xCA, 0x0F6C        }, // MCU_DATA_2
+    {1, 0xCB, 0x0AEC        }, // MCU_DATA_3
+    {1, 0xCC, 0x0F1A        }, // MCU_DATA_4
+    {1, 0xCD, 0x8300        }, // MCU_DATA_5
+    {1, 0xCE, 0x2024        }, // MCU_DATA_6
+    {1, 0xCF, 0xF183        }, // MCU_DATA_7
+    {1, 0xC6, 0x0700        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0010        }, // MCU_DATA_0
+    {1, 0xC9, 0xED0F        }, // MCU_DATA_1
+    {1, 0xCA, 0xC3E8        }, // MCU_DATA_2
+    {1, 0xCB, 0xFB8F        }, // MCU_DATA_3
+    {1, 0xCC, 0xE600        }, // MCU_DATA_4
+    {1, 0xCD, 0x30E7        }, // MCU_DATA_5
+    {1, 0xCE, 0x08E6        }, // MCU_DATA_6
+    {1, 0xCF, 0x0A86        }, // MCU_DATA_7
+    {1, 0xC6, 0x0710        }, // MCU_ADDRESS
+    {1, 0xC8, 0x203D        }, // MCU_DATA_0
+    {1, 0xC9, 0xEB08        }, // MCU_DATA_1
+    {1, 0xCA, 0xC040        }, // MCU_DATA_2
+    {1, 0xCB, 0xE708        }, // MCU_DATA_3
+    {1, 0xCC, 0xD6BA        }, // MCU_DATA_4
+    {1, 0xCD, 0x4FED        }, // MCU_DATA_5
+    {1, 0xCE, 0x06E6        }, // MCU_DATA_6
+    {1, 0xCF, 0x08ED        }, // MCU_DATA_7
+    {1, 0xC6, 0x0720        }, // MCU_ADDRESS
+    {1, 0xC8, 0x04E3        }, // MCU_DATA_0
+    {1, 0xC9, 0x06ED        }, // MCU_DATA_1
+    {1, 0xCA, 0x0F17        }, // MCU_DATA_2
+    {1, 0xCB, 0x5FED        }, // MCU_DATA_3
+    {1, 0xCC, 0x0FD6        }, // MCU_DATA_4
+    {1, 0xCD, 0xB94F        }, // MCU_DATA_5
+    {1, 0xCE, 0xED06        }, // MCU_DATA_6
+    {1, 0xCF, 0xE608        }, // MCU_DATA_7
+    {1, 0xC6, 0x0730        }, // MCU_ADDRESS
+    {1, 0xC8, 0xED04        }, // MCU_DATA_0
+    {1, 0xC9, 0xE306        }, // MCU_DATA_1
+    {1, 0xCA, 0xE30F        }, // MCU_DATA_2
+    {1, 0xCB, 0xED0F        }, // MCU_DATA_3
+    {1, 0xCC, 0xCC01        }, // MCU_DATA_4
+    {1, 0xCD, 0x52ED        }, // MCU_DATA_5
+    {1, 0xCE, 0x00EC        }, // MCU_DATA_6
+    {1, 0xCF, 0x0FBD        }, // MCU_DATA_7
+    {1, 0xC6, 0x0740        }, // MCU_ADDRESS
+    {1, 0xC8, 0xD350        }, // MCU_DATA_0
+    {1, 0xC9, 0x30C6        }, // MCU_DATA_1
+    {1, 0xCA, 0x1B3A        }, // MCU_DATA_2
+    {1, 0xCB, 0x3539        }, // MCU_DATA_3
+    {1, 0xCC, 0x3C3C        }, // MCU_DATA_4
+    {1, 0xCD, 0x34C6        }, // MCU_DATA_5
+    {1, 0xCE, 0x18F7        }, // MCU_DATA_6
+    {1, 0xCF, 0x02BD        }, // MCU_DATA_7
+    {1, 0xC6, 0x0750        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC6B4        }, // MCU_DATA_0
+    {1, 0xC9, 0xF702        }, // MCU_DATA_1
+    {1, 0xCA, 0xBEC6        }, // MCU_DATA_2
+    {1, 0xCB, 0x96F7        }, // MCU_DATA_3
+    {1, 0xCC, 0x02BF        }, // MCU_DATA_4
+    {1, 0xCD, 0xC680        }, // MCU_DATA_5
+    {1, 0xCE, 0xF702        }, // MCU_DATA_6
+    {1, 0xCF, 0xC0F7        }, // MCU_DATA_7
+    {1, 0xC6, 0x0760        }, // MCU_ADDRESS
+    {1, 0xC8, 0x02C1        }, // MCU_DATA_0
+    {1, 0xC9, 0xF702        }, // MCU_DATA_1
+    {1, 0xCA, 0xC2F7        }, // MCU_DATA_2
+    {1, 0xCB, 0x02C3        }, // MCU_DATA_3
+    {1, 0xCC, 0xF702        }, // MCU_DATA_4
+    {1, 0xCD, 0xC4F7        }, // MCU_DATA_5
+    {1, 0xCE, 0x02C5        }, // MCU_DATA_6
+    {1, 0xCF, 0xF702        }, // MCU_DATA_7
+    {1, 0xC6, 0x0770        }, // MCU_ADDRESS
+    {1, 0xC8, 0xC6CC        }, // MCU_DATA_0
+    {1, 0xC9, 0x02AB        }, // MCU_DATA_1
+    {1, 0xCA, 0x30ED        }, // MCU_DATA_2
+    {1, 0xCB, 0x02FE        }, // MCU_DATA_3
+    {1, 0xCC, 0x1050        }, // MCU_DATA_4
+    {1, 0xCD, 0xEC06        }, // MCU_DATA_5
+    {1, 0xCE, 0xFD02        }, // MCU_DATA_6
+    {1, 0xCF, 0xA7FE        }, // MCU_DATA_7
+    {1, 0xC6, 0x0780        }, // MCU_ADDRESS
+    {1, 0xC8, 0x02A7        }, // MCU_DATA_0
+    {1, 0xC9, 0xEC00        }, // MCU_DATA_1
+    {1, 0xCA, 0xFD02        }, // MCU_DATA_2
+    {1, 0xCB, 0xA930        }, // MCU_DATA_3
+    {1, 0xCC, 0x6F04        }, // MCU_DATA_4
+    {1, 0xCD, 0xE604        }, // MCU_DATA_5
+    {1, 0xCE, 0x4F05        }, // MCU_DATA_6
+    {1, 0xCF, 0xF302        }, // MCU_DATA_7
+    {1, 0xC6, 0x0790        }, // MCU_ADDRESS
+    {1, 0xC8, 0xA98F        }, // MCU_DATA_0
+    {1, 0xC9, 0xEC00        }, // MCU_DATA_1
+    {1, 0xCA, 0x30ED        }, // MCU_DATA_2
+    {1, 0xCB, 0x00E6        }, // MCU_DATA_3
+    {1, 0xCC, 0x044F        }, // MCU_DATA_4
+    {1, 0xCD, 0x05E3        }, // MCU_DATA_5
+    {1, 0xCE, 0x0218        }, // MCU_DATA_6
+    {1, 0xCF, 0x8FEC        }, // MCU_DATA_7
+    {1, 0xC6, 0x07A0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x0018        }, // MCU_DATA_0
+    {1, 0xC9, 0xED00        }, // MCU_DATA_1
+    {1, 0xCA, 0x6C04        }, // MCU_DATA_2
+    {1, 0xCB, 0xE604        }, // MCU_DATA_3
+    {1, 0xCC, 0xC109        }, // MCU_DATA_4
+    {1, 0xCD, 0x25DE        }, // MCU_DATA_5
+    {1, 0xCE, 0xEE02        }, // MCU_DATA_6
+    {1, 0xCF, 0xCC05        }, // MCU_DATA_7
+    {1, 0xC6, 0x07B0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x6BED        }, // MCU_DATA_0
+    {1, 0xC9, 0x0830        }, // MCU_DATA_1
+    {1, 0xCA, 0xEE02        }, // MCU_DATA_2
+    {1, 0xCB, 0xCC04        }, // MCU_DATA_3
+    {1, 0xCC, 0x00ED        }, // MCU_DATA_4
+    {1, 0xCD, 0x0ECC        }, // MCU_DATA_5
+    {1, 0xCE, 0x02AB        }, // MCU_DATA_6
+    {1, 0xCF, 0xDD58        }, // MCU_DATA_7
+    {1, 0xC6, 0x07C0        }, // MCU_ADDRESS
+    {1, 0xC8, 0x3838        }, // MCU_DATA_0
+    {1, 0xC9, 0x3139        }, // MCU_DATA_1
+    {1, 0xC6, 0x2003        }, //MON_ARG1
+    {1, 0xC8, 0x0748        }, //MON_ARG1
+    {1, 0xC6, 0xA002        }, //MON_CMD
+    {1, 0xC8, 0x0001        }, //MON_CMD
+    {100, 0x00, 0x01F4      }, //Delay = 500ms
+    {1, 0xC6, 0xA361        }, //AWB_TG_MIN0
+    {1, 0xC8, 0x00E2        }, //AWB_TG_MIN0
+    {1, 0x1F, 0x0018        }, // RESERVED_SOC1_1F
+    {1, 0x51, 0x7F40        }, // RESERVED_SOC1_51
+    {100, 0x00, 0x01F4       }, //Delay = 1000ms
+    {0, 0x33, 0x0343        }, // RESERVED_CORE_33
+    {0, 0x38, 0x0868        }, // RESERVED_CORE_38
+    {1, 0xC6, 0xA10F        }, //SEQ_RESET_LEVEL_TH
+    {1, 0xC8, 0x0042        }, //SEQ_RESET_LEVEL_TH
+    {1, 0x1F, 0x0020        }, // RESERVED_SOC1_1F
+    {1, 0xC6, 0xAB04        }, //HG_MAX_DLEVEL
+    {1, 0xC8, 0x0008        }, //HG_MAX_DLEVEL
+    {1, 0xC6, 0xA120        }, //SEQ_CAP_MODE
+    {1, 0xC8, 0x0002        }, //SEQ_CAP_MODE
+    {1, 0xC6, 0xA103        }, //SEQ_CMD
+    {1, 0xC8, 0x0001        }, //SEQ_CMD
+    {100, 0x00, 0x01F4      }, // Delay =1000ms
+    {1, 0xC6, 0xA102        }, //SEQ_MODE
+    {1, 0xC8, 0x001F        }, //SEQ_MODE
+    {1, 0x08, 0x01FC        }, // COLOR_PIPELINE_CONTROL
+    {1, 0x08, 0x01EC        }, // COLOR_PIPELINE_CONTROL
+    {1, 0x08, 0x01FC        }, // COLOR_PIPELINE_CONTROL
+    {1, 0x36, 0x0F08        }, // APERTURE_PARAMETERS
+    {1, 0xC6, 0x270B        }, //MODE_CONFIG
+    {1, 0xC8, 0x0030        }, //MODE_CONFIG, JPEG disabled for A and B
+    {1, 0xC6, 0xA121        }, //SEQ_CAP_MODE
+    {1, 0xC8, 0x007f        }, //SEQ_CAP_MODE (127 frames before switching to Preview)
+    {0, 0x05, 0x011E        }, // HORZ_BLANK_B
+    {0, 0x06, 0x006F        }, // VERT_BLANK_B
+    {0, 0x07, 0xFE          }, // HORZ_BLANK_A
+    {0, 0x08, 19            }, // VERT_BLANK_A
+    {0, 0x20, 0x0303        }, // READ_MODE_B (Image flip settings)
+    {0, 0x21, 0x8400        }, // READ_MODE_A (1ADC)
+    {1, 0xC6, 0x2717        }, //MODE_SENSOR_X_DELAY_A
+    {1, 0xC8, 792           }, //MODE_SENSOR_X_DELAY_A
+    {1, 0xC6, 0x270F        }, //MODE_SENSOR_ROW_START_A
+    {1, 0xC8, 0x001C        }, //MODE_SENSOR_ROW_START_A
+    {1, 0xC6, 0x2711        }, //MODE_SENSOR_COL_START_A
+    {1, 0xC8, 0x003C        }, //MODE_SENSOR_COL_START_A
+    {1, 0xC6, 0x2713        }, //MODE_SENSOR_ROW_HEIGHT_A
+    {1, 0xC8, 0x04B0        }, //MODE_SENSOR_ROW_HEIGHT_A
+    {1, 0xC6, 0x2715        }, //MODE_SENSOR_COL_WIDTH_A
+    {1, 0xC8, 0x0640        }, //MODE_SENSOR_COL_WIDTH_A
+    {1, 0xC6, 0x2719        }, //MODE_SENSOR_ROW_SPEED_A
+    {1, 0xC8, 0x0011        }, //MODE_SENSOR_ROW_SPEED_A
+    {1, 0xC6, 0x2707        }, //MODE_OUTPUT_WIDTH_B
+    {1, 0xC8, 0x0640        }, //MODE_OUTPUT_WIDTH_B
+    {1, 0xC6, 0x2709        }, //MODE_OUTPUT_HEIGHT_B
+    {1, 0xC8, 0x04B0        }, //MODE_OUTPUT_HEIGHT_B
+    {1, 0xC6, 0x271B        }, //MODE_SENSOR_ROW_START_B
+    {1, 0xC8, 0x001C        }, //MODE_SENSOR_ROW_START_B
+    {1, 0xC6, 0x271D        }, //MODE_SENSOR_COL_START_B
+    {1, 0xC8, 0x003C        }, //MODE_SENSOR_COL_START_B
+    {1, 0xC6, 0x271F        }, //MODE_SENSOR_ROW_HEIGHT_B
+    {1, 0xC8, 0x04B0        }, //MODE_SENSOR_ROW_HEIGHT_B
+    {1, 0xC6, 0x2721        }, //MODE_SENSOR_COL_WIDTH_B
+    {1, 0xC8, 0x0640        }, //MODE_SENSOR_COL_WIDTH_B
+    {1, 0xC6, 0x2723        }, //MODE_SENSOR_X_DELAY_B
+    {1, 0xC8, 0x0716        }, //MODE_SENSOR_X_DELAY_B
+    {1, 0xC6, 0x2725        }, //MODE_SENSOR_ROW_SPEED_B
+    {1, 0xC8, 0x0011        }, //MODE_SENSOR_ROW_SPEED_B
+    //Maximum Slew-Rate on IO-Pads (for Mode A)
+    {1, 0xC6, 0x276B        }, //MODE_FIFO_CONF0_A
+    {1, 0xC8, 0x0027        }, //MODE_FIFO_CONF0_A
+    {1, 0xC6, 0x276D        }, //MODE_FIFO_CONF1_A
+    {1, 0xC8, 0xE1E1        }, //MODE_FIFO_CONF1_A
+    {1, 0xC6, 0xA76F        }, //MODE_FIFO_CONF2_A
+    {1, 0xC8, 0x00E1        }, //MODE_FIFO_CONF2_A
+    //Maximum Slew-Rate on IO-Pads (for Mode B)
+    {1, 0xC6, 0x2772        }, //MODE_FIFO_CONF0_B
+    {1, 0xC8, 0x0027        }, //MODE_FIFO_CONF0_B
+    {1, 0xC6, 0x2774        }, //MODE_FIFO_CONF1_B
+    {1, 0xC8, 0xE1E1        }, //MODE_FIFO_CONF1_B
+    {1, 0xC6, 0xA776        }, //MODE_FIFO_CONF2_B
+    {1, 0xC8, 0x00E1        }, //MODE_FIFO_CONF2_B
+    //Set maximum integration time to get a minimum of 15 fps at 45MHz
+    {1, 0xC6, 0xA20E        }, //AE_MAX_INDEX
+    {1, 0xC8, 0x0004        }, //AE_MAX_INDEX
+    //Set minimum integration time to get a maximum of 15 fps at 45MHz
+    {1, 0xC6, 0xA20D        }, //AE_MAX_INDEX
+    {1, 0xC8, 0x0004        }, //AE_MAX_INDEX
+    // Configue all GPIO for output and set low to save power
+    {1, 0xC6, 0x9078        },
+    {1, 0xC8, 0x0000        },
+    {1, 0xC6, 0x9079        },
+    {1, 0xC8, 0x0000        },
+    {1, 0xC6, 0x9070        },
+    {1, 0xC8, 0x0000        },
+    {1, 0xC6, 0x9071        },
+    {1, 0xC8, 0x0000        },
+    // gamma and contrast
+    {1, 0xC6, 0xA743        }, // MODE_GAM_CONT_A
+    {1, 0xC8, 0x0003        }, // MODE_GAM_CONT_A
+    {1, 0xC6, 0xA744        }, // MODE_GAM_CONT_B
+    {1, 0xC8, 0x0003        }, // MODE_GAM_CONT_B
+    {100, 0x00, 0x01f4      }, // Delay =500ms
 
+};
+/*
 static  const s_RegList init_cmds_list[]= {
-    {100,0x00,0x01F4    },
+//    {100,0x00,0x01F4    },
     {0, 0x33, 0x0343    }, // RESERVED_CORE_33
     {1, 0xC6, 0xA115    }, // SEQ_LLMODE
     {1, 0xC8, 0x0020    }, // SEQ_LLMODE
     {0, 0x38, 0x0866    }, // RESERVED_CORE_38
+    {100, 0x00, 0x0064  },  // Delay = 100ms
     {2, 0x80, 0x0168    }, // LENS_CORRECTION_CONTROL
     {2, 0x81, 0x6432    }, // ZONE_BOUNDS_X1_X2
     {2, 0x82, 0x3296    }, // ZONE_BOUNDS_X0_X3
@@ -268,11 +1110,13 @@
     {1, 0xC8, 0x0748    }, // MON_ARG1
     {1, 0xC6, 0xA002    }, // MON_CMD
     {1, 0xC8, 0x0001    }, // MON_CMD
-    {111, 0xC8,0x0000 },
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
+    {111, 0xC8,0x0000   },
     {1, 0xC6, 0xA361    }, // AWB_TG_MIN0
     {1, 0xC8, 0x00E2    }, // AWB_TG_MIN0
     {1, 0x1F, 0x0018    }, // RESERVED_SOC1_1F
     {1, 0x51, 0x7F40    }, // RESERVED_SOC1_51
+    {100, 0x00, 0x03e8  },  // Delay = 1000ms
     {0, 0x33, 0x0343    }, // RESERVED_CORE_33
     {0, 0x38, 0x0868    }, // RESERVED_CORE_38
     {1, 0xC6, 0xA10F    }, // SEQ_RESET_LEVEL_TH
@@ -283,6 +1127,7 @@
     {1, 0xC6, 0xA103    }, // SEQ_CMD
     {1, 0xC8, 0x0005    }, // SEQ_CMD
     {1, 0xC6, 0xA104    }, // SEQ_CMD
+    {100, 0x00, 0x03e8  },  // Delay = 1000ms
     {111, 0xC8,0x0003   },
     {1, 0x08, 0x01FC    }, // COLOR_PIPELINE_CONTROL
     {1, 0x08, 0x01EC    }, // COLOR_PIPELINE_CONTROL
@@ -290,28 +1135,37 @@
     {1, 0x36, 0x0F08    }, // APERTURE_PARAMETERS
     {1, 0xC6, 0xA103    }, // SEQ_CMD
     {1, 0xC8, 0x0005    }, // SEQ_CMD
+    {100, 0x00, 0x01f4  },  // Delay = 500ms
 };
+*/
+void getCamId()
+{
 
-void getCamId(){
-    
     uint16_t Id = 0;
     uint8_t ucBuffer[20];
-    
+
     ucBuffer[0] = 0x00;
     ucBuffer[1] = 0x00;
-//    i2c.start();
-    I2CBufferWrite(CAM_I2C_SLAVE_WRITE,ucBuffer,1,1);
-//    I2CBufferWrite(CAM_I2C_SLAVE_WRITE,);
-//    i2c.stop();
-//    i2c.start();
-//    I2CBufferWriteByte();            
-    I2CBufferRead(CAM_I2C_SLAVE_READ,ucBuffer,2,1);
-//    i2c.stop();    
+
+    int lRetVal = -1;
+
+    lRetVal = RegLstWrite((s_RegList *)soft_reset_cmd_list, sizeof(soft_reset_cmd_list)/sizeof(s_RegList));
+    wait(1);
+    I2CBufferWrite(CAM_I2C_SLAVE_WRITE,ucBuffer,1,I2C_SEND_STOP);
+    I2CBufferRead(CAM_I2C_SLAVE_READ,ucBuffer,2,I2C_SEND_STOP);
+
     Id = (uint16_t)ucBuffer[0] << 8 | (uint16_t)ucBuffer[1];
 
     HttpDebug("\r\nCamera ID = 0x%x\r\n",Id);
-    
-}    
+
+    if(Id != 0x1519) {
+        HttpDebug("MT9D111 Camera not found! I2C read/write failed. \n\r");
+        HAL_DCMI_MspDeInit(&phdcmi);
+        while(1);
+    }
+
+
+}
 
 //*****************************************************************************
 //
@@ -326,28 +1180,33 @@
 
 int CameraSensorInit()
 {
-//    Uart_Write((uint8_t*)"CameraSensorInit \n\r");
+    HttpDebug("CameraSensorInit \n\r");
     int lRetVal = -1;
-    
+
     lRetVal = RegLstWrite((s_RegList *)init_cmds_list, \
-                                    sizeof(init_cmds_list)/sizeof(s_RegList));
+                          sizeof(init_cmds_list)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
 
+    lRetVal = RegLstWrite((s_RegList *)pll_cmds_list, \
+                          sizeof(pll_cmds_list)/sizeof(s_RegList));
+    ASSERT_ON_ERROR(lRetVal);                          
+
 #ifndef ENABLE_JPEG
+
     lRetVal = RegLstWrite((s_RegList *)preview_cmds_list,
-                      sizeof(preview_cmds_list)/sizeof(s_RegList));
+                          sizeof(preview_cmds_list)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
     lRetVal = RegLstWrite((s_RegList *)image_size_240_320_preview_cmds_list, \
-                    sizeof(image_size_240_320_preview_cmds_list)/ \
-                    sizeof(s_RegList));
+                          sizeof(image_size_240_320_preview_cmds_list)/ \
+                          sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
     lRetVal = RegLstWrite((s_RegList *)freq_setup_cmd_List,
-                    sizeof(freq_setup_cmd_List)/sizeof(s_RegList));
+                          sizeof(freq_setup_cmd_List)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
     lRetVal = RegLstWrite((s_RegList *)preview_on_cmd_list,
-                    sizeof(preview_on_cmd_list)/sizeof(s_RegList));
+                          sizeof(preview_on_cmd_list)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
-#endif 
+#endif
     return 0;
 }
 
@@ -364,24 +1223,50 @@
 //*****************************************************************************
 int StartSensorInJpegMode(int width, int height)
 {
-//    Uart_Write((uint8_t*)"\n\rStartSensorInJpegMode \n\r");
+
 #ifdef ENABLE_JPEG
     int lRetVal = -1;
-
+    HttpDebug("\n\rStartSensorInJpegMode \n\r");
     lRetVal = RegLstWrite((s_RegList *)capture_cmds_list,
-                        sizeof(capture_cmds_list)/sizeof(s_RegList));
-    ASSERT_ON_ERROR(lRetVal);    
-    
-    resolution_cmds_list[INDEX_SIZE_WIDTH].usValue = width;
-    resolution_cmds_list[INDEX_SIZE_HEIGHT].usValue = height;
-    lRetVal = RegLstWrite((s_RegList *)resolution_cmds_list,
-                        sizeof(resolution_cmds_list)/sizeof(s_RegList));
+                          sizeof(capture_cmds_list)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
-    
-    lRetVal = RegLstWrite((s_RegList *)start_jpeg_capture_cmd_list,
-                        sizeof(start_jpeg_capture_cmd_list)/sizeof(s_RegList));
-    ASSERT_ON_ERROR(lRetVal);    
-#endif 
+
+//    resolution_cmds_list[INDEX_SIZE_WIDTH].usValue = width;
+//    resolution_cmds_list[INDEX_SIZE_HEIGHT].usValue = height;
+//    lRetVal = RegLstWrite((s_RegList *)resolution_cmds_list,
+//                        sizeof(resolution_cmds_list)/sizeof(s_RegList));
+//    ASSERT_ON_ERROR(lRetVal);
+
+//    CameraSensorResolution(width, height);
+
+//    lRetVal = RegLstWrite((s_RegList *)start_jpeg_capture_cmd_list,
+//                        sizeof(start_jpeg_capture_cmd_list)/sizeof(s_RegList));
+//    ASSERT_ON_ERROR(lRetVal);
+#endif
+    return 0;
+}
+
+int StartCaptureCmd()
+{
+
+    int32_t lRetVal= -1;
+
+#ifdef ENABLE_JPEG
+    lRetVal = RegLstWrite((s_RegList *)start_capture_cmd_list,
+                          sizeof(start_capture_cmd_list)/sizeof(s_RegList));
+#endif
+    return 0;
+}
+
+int StopCaptureCmd()
+{
+
+    int32_t lRetVal= -1;
+
+#ifdef ENABLE_JPEG
+    lRetVal = RegLstWrite((s_RegList *)stop_capture_cmd_list,
+                          sizeof(stop_capture_cmd_list)/sizeof(s_RegList));
+#endif
     return 0;
 }
 
@@ -398,29 +1283,29 @@
 //*****************************************************************************
 int CameraSensorResolution(int width, int height)
 {
-    Uart_Write((uint8_t*)"CameraSensorResolution \n\r");
+    HttpDebug("CameraSensorResolution \n\r");
 #ifdef ENABLE_JPEG
     int lRetVal = -1;
 
-    lRetVal = RegLstWrite((s_RegList *)stop_jpeg_capture_cmd_list,
-                        sizeof(stop_jpeg_capture_cmd_list)/sizeof(s_RegList));
-    ASSERT_ON_ERROR(lRetVal);    
-    
+    lRetVal = RegLstWrite((s_RegList *)stop_capture_cmd_list,
+                          sizeof(stop_capture_cmd_list)/sizeof(s_RegList));
+    ASSERT_ON_ERROR(lRetVal);
+
     resolution_cmds_list[INDEX_SIZE_WIDTH].usValue = width;
     resolution_cmds_list[INDEX_SIZE_HEIGHT].usValue = height;
     lRetVal = RegLstWrite((s_RegList *)resolution_cmds_list,
-                        sizeof(resolution_cmds_list)/sizeof(s_RegList));
+                          sizeof(resolution_cmds_list)/sizeof(s_RegList));
     ASSERT_ON_ERROR(lRetVal);
-    
-    lRetVal = RegLstWrite((s_RegList *)start_jpeg_capture_cmd_list,
-                        sizeof(start_jpeg_capture_cmd_list)/sizeof(s_RegList));
-    ASSERT_ON_ERROR(lRetVal);    
+
+    lRetVal = RegLstWrite((s_RegList *)start_capture_cmd_list,
+                          sizeof(start_capture_cmd_list)/sizeof(s_RegList));
+    ASSERT_ON_ERROR(lRetVal);
 
 
 #else
     if(width != 240 || height != 256)
         return -1;
-#endif  
+#endif
     return 0;
 }
 
@@ -444,67 +1329,39 @@
     uint8_t       ucBuffer[20];
     unsigned int       ulSize;
     int lRetVal = -1;
+    int l = 0;
 
-    if(pRegLst == NULL)
-    {
+    if(pRegLst == NULL) {
         return RET_ERROR;
     }
-    
-    for(ulNdx = 0; ulNdx < ulNofItems; ulNdx++)
-    {
-        if(pRegLst->ucPageAddr == 100)
-        {
-            // PageAddr == 100, insret a delay equal to reg value 
-            wait_ms(pRegLst->usValue);// * 80000/3);
-//            HttpDebug("usValue = 0x%x \n\r",pRegLst->usValue);
-        }
-        else if(pRegLst->ucPageAddr == 111)
-        {
-            // PageAddr == 111, wait for specified register value 
-            do
-            {
-                ucBuffer[0] = pRegLst->ucRegAddr;
-                printf("pRegLst->ucRegAddr = 0x%x \r\n",pRegLst->ucRegAddr);
-                lRetVal = I2CBufferWrite(CAM_I2C_SLAVE_WRITE,ucBuffer,1,I2C_SEND_STOP);
-                ASSERT_ON_ERROR(lRetVal);
-                if(0 != I2CBufferWrite(CAM_I2C_SLAVE_READ,ucBuffer,2,I2C_SEND_STOP))
-                {
-                    Uart_Write((uint8_t*)"\n\rError reading pRegLst->ucRegAddr \n\r");
-                    return RET_ERROR;
-                }
 
-                usTemp = ucBuffer[0] << 8;
-                usTemp |= ucBuffer[1];
-//                usTemp = pRegLst->usValue;//Temp debug
-            }while(usTemp != pRegLst->usValue);
-        }
-        else
-        {
-            // Set the page 
+    for(ulNdx = 0; ulNdx < ulNofItems; ulNdx++) {
+        if(pRegLst->ucPageAddr == 100) {
+            // PageAddr == 100, insret a delay equal to reg value
+            wait_ms(pRegLst->usValue);
+        } else {
+            // Set the page
             ucBuffer[0] = SENSOR_PAGE_REG;//0xF0
             ucBuffer[1] = 0x00;
             ucBuffer[2] = pRegLst->ucPageAddr;
-            printf("pRegLst->ucRegAddr = 0x%x \r\n",pRegLst->ucRegAddr);
-            if(0 != I2CBufferWrite(CAM_I2C_SLAVE_WRITE, ucBuffer, 3, I2C_SEND_STOP))
-            {
-                Uart_Write((uint8_t*)"\n\rError writing SENSOR_PAGE_REG \n\r");
+
+            if(0 != I2CBufferWrite(CAM_I2C_SLAVE_WRITE, ucBuffer, 3, I2C_SEND_STOP)) {
+                HttpDebug("\n\rError writing SENSOR_PAGE_REG \n\r");
                 return RET_ERROR;
             }
 
             ucBuffer[0] = SENSOR_PAGE_REG;
-            lRetVal = I2CBufferWrite(CAM_I2C_SLAVE_WRITE, ucBuffer, 1, I2C_SEND_STOP);
+            lRetVal = I2CBufferWrite(CAM_I2C_SLAVE_WRITE, ucBuffer, 1, 0);
             ASSERT_ON_ERROR(lRetVal);
-            lRetVal = I2CBufferWrite(CAM_I2C_SLAVE_READ, ucBuffer, 2, I2C_SEND_STOP);
+            lRetVal = I2CBufferRead(CAM_I2C_SLAVE_READ, ucBuffer, 2, I2C_SEND_STOP);
             ASSERT_ON_ERROR(lRetVal);
 
             ucBuffer[0] = pRegLst->ucRegAddr;
 
-            if(pRegLst->ucPageAddr  == 0x1 && pRegLst->ucRegAddr == 0xC8)
-            {
+            if(pRegLst->ucPageAddr  == 0x1 && pRegLst->ucRegAddr == 0xC8) {
                 usTemp = 0xC8;
                 i=1;
-                while(pRegLst->ucRegAddr == usTemp)
-                {
+                while(pRegLst->ucRegAddr == usTemp) {
                     ucBuffer[i] = (unsigned char)(pRegLst->usValue >> 8);
                     ucBuffer[i+1] = (unsigned char)(pRegLst->usValue & 0xFF);
                     i += 2;
@@ -516,18 +1373,14 @@
                 ulSize = (i-2)*2 + 1;
                 ulNdx--;
                 pRegLst--;
-            }
-            else
-            {
+            } else {
                 ulSize = 3;
                 ucBuffer[1] = (unsigned char)(pRegLst->usValue >> 8);
                 ucBuffer[2] = (unsigned char)(pRegLst->usValue & 0xFF);
             }
 
-            if(0 != I2CBufferWrite(CAM_I2C_SLAVE_WRITE,ucBuffer,
-                                                      ulSize,I2C_SEND_STOP))
-            {
-                Uart_Write((uint8_t*)"\n\rError i2c write \n\r");
+            if(0 != I2CBufferWrite(CAM_I2C_SLAVE_WRITE,ucBuffer, ulSize,I2C_SEND_STOP)) {
+                HttpDebug("\n\rError i2c write \n\r");
                 return RET_ERROR;
             }
         }
@@ -539,6 +1392,190 @@
     return RET_OK;
 }
 
+static int wait_for_seq_state(int state)
+{
+    int i, new_state;
+           
+    for (i = 0; i < 1000; i++) {
+        new_state = read_firmware_var(SEQ_DRV_ID, SEQ_STATE_OFFSET, 1);
+ //     HttpDebug("seq state %d\r\n", new_state);
+        if (new_state == state){
+            return 0;
+        }    
+        wait_ms(2);
+    }
+    HttpDebug("Timeout waiting for seq_state %d\r\n", state);
+     return 1;
+}
+
+/*
+ * Read a 8/16-bit value from a firmware driver given the driver ID and the
+ * var offset. It assumes logic address.
+ * The value is returned if successful, or 1 otherwise.
+ */
+static uint16_t read_firmware_var(int id, int offset, int byte)
+{
+    uint16_t val;
+    uint8_t       ucBuffer[20];       
+    /* always use logical address */
+    val = VAR_ADDRESS_TYPE_LOGIC << VAR_ADDRESS_TYPE_SHIFT;
+    val |= (byte << VAR_LENGTH_SHIFT);
+    val |= (id << VAR_DRV_ID_SHIFT);
+    val |= (offset << VAR_ADDRESS_SHIFT);
+    
+    ucBuffer[0] = REG_PAGE;//0xF0
+    ucBuffer[1] = 0x00;
+    ucBuffer[2] = PAGE_IFP1;//1
+    
+    /* setup page pointer */
+    if (I2CBufferWrite(CAM_I2C_SLAVE_WRITE, (uint8_t*)ucBuffer, 3, I2C_SEND_STOP)){
+            return 1;
+    }
+    ucBuffer[0] = REG_VAR_ADDR;//0xC6
+    ucBuffer[1] = val >> 8;
+    ucBuffer[2] = val & 0x00FF;
+       
+    /* setup var pointer */
+    if (I2CBufferWrite(CAM_I2C_SLAVE_WRITE, (uint8_t*)ucBuffer, 3, I2C_SEND_STOP)){
+            return 1;
+    }
+    ucBuffer[0] = REG_VAR_DATA;//0xC8 
+    if (I2CBufferWrite(CAM_I2C_SLAVE_WRITE, (uint8_t*)ucBuffer, 1, I2C_SEND_STOP)){
+            return 1;
+    }            
+
+    /* read the var */
+    if (I2CBufferRead(CAM_I2C_SLAVE_READ, ucBuffer, 2, I2C_SEND_STOP)){
+            return 1;
+    }
+    val = ucBuffer[0] << 8;
+    val |= ucBuffer[1];
+            
+    return val;
+}
+
+int Start_still_capture(int frames)
+{
+    int err = 1;
+    
+//    HttpDebug("Context B comamnd sequence ...");
+//    err = StartCaptureCmd();
+    err = RegLstWrite((s_RegList *)context_b_list, sizeof(context_b_list)/sizeof(s_RegList));
+    if (err){
+        return err;
+    }
+    /* wait until the seq driver state change */
+    err = wait_for_seq_state(SEQ_STATE_CAPTURE);
+    if (err == 1){
+        return err;
+    }
+    /* need a few frames delay to stablize the output */
+    wait_ms(500);
+
+    return 0;
+}
+
+int Stop_still_capture(){
+    int err = 1;
+    
+//    HttpDebug("Context A comamnd sequence ...");
+//    err = StopCaptureCmd();
+    
+    err = RegLstWrite((s_RegList *)context_a_list, sizeof(context_a_list)/sizeof(s_RegList));
+    if (err){
+        return err;
+    }    
+    /* wait until the seq driver state change */
+    err = wait_for_seq_state(SEQ_STATE_PREVIEW);
+    if (err == 1){
+        return err;
+    }
+    return 0;
+}
+
+int cam_power_on(void)
+{
+
+    int err;
+    HttpDebug("cam_power_on \r\n");
+    /* the caller already enabled our XCLK, wait to make sure it is stable */
+    wait_us(100);
+    /* release STANDBY line */
+    cam_exit_standby();
+    /* wait 1ms before enable PLL per Micron Tech. Note */
+    wait_ms(1);
+    
+    err = RegLstWrite((s_RegList *)pll_cmds_list, sizeof(pll_cmds_list)/sizeof(s_RegList));
+    if (err){
+        return err;
+    }
+    err = RegLstWrite((s_RegList *)context_a_list, sizeof(context_a_list)/sizeof(s_RegList));    
+    if (err){
+        return err;
+    }    
+    err = wait_for_seq_state(SEQ_STATE_PREVIEW);
+    return err;
+}
+
+int cam_power_off(void)
+{
+            
+    int err;
+    
+    /* have to check sequencer is in preview mode */
+    if (read_firmware_var(SEQ_DRV_ID, SEQ_STATE_OFFSET, 1) != SEQ_STATE_PREVIEW) {
+//        printf("Calling power_off while not in preview state!\r\n");
+        /* Put sequencer in preview mode */
+        err = RegLstWrite((s_RegList *)context_a_list, sizeof(context_a_list)/sizeof(s_RegList));    
+        if (err){
+            HttpDebug("Error writing context_a_list!\r\n");
+            return err;
+        }    
+        err = wait_for_seq_state(SEQ_STATE_PREVIEW);
+        if (err){
+            HttpDebug("Cannot place cam in preview state!\r\n");    
+            return err;
+        }
+    }
+                   
+    /* Issue standby command to sequencer */
+    err = RegLstWrite((s_RegList *)enter_standby_list, sizeof(enter_standby_list)/sizeof(s_RegList));    
+    if (err){
+        return err;
+    }         
+    /* Poll the sequencer until it enters standby state */
+     err = wait_for_seq_state(SEQ_STATE_STANDBY);
+    if (err){
+        return err;
+    }    
+    /* bypass PLL */
+    err = RegLstWrite((s_RegList *)bypass_pll_list, sizeof(bypass_pll_list)/sizeof(s_RegList));
+    if (err){
+        return err;     
+    }       
+    /* assert STANDBY line */
+    cam_enter_standby();
+    /* the caller can cut off XCLK now */
+    return 0;
+}
+
+void cam_exit_standby(void)
+{
+#ifdef MT9D111_CAM    
+    HttpDebug("cam_exit_standby \r\n");
+    standby = 0;
+#endif    
+}
+
+void cam_enter_standby(void)
+{
+#ifdef MT9D111_CAM    
+    HttpDebug("cam_enter_standby \r\n");       
+    standby = 1;
+    wait(1);
+#endif    
+}
+
 //*****************************************************************************
 //
 // Close the Doxygen group.
--- a/camera_app/mt9d111/mt9d111.h	Mon Jul 13 08:20:40 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.h	Tue Aug 25 22:03:00 2015 +0000
@@ -12,6 +12,54 @@
 {
 #endif
 
+#define MT9D111_ID                      0x1519
+  /* firmware drivers ID */
+#define MON_DRV_ID                      0
+#define SEQ_DRV_ID                      1
+#define AE_DRV_ID                       2
+#define AWB_DRV_ID                      3
+#define FD_DRV_ID                       4
+#define AF_DRV_ID                       5
+#define AFM_DRV_ID                      6
+#define MODE_DRV_ID                     7
+  
+  /* Monitor driver variables */
+#define MON_VER_OFFSET                  12
+  
+  /* Sequencer driver variables */
+#define SEQ_MODE_OFFSET                 2
+#define SEQ_STATE_OFFSET                4
+  
+  /* Sequencer Driver states */
+#define SEQ_STATE_INIT                  0
+#define SEQ_STATE_TO_PREVIEW            1
+#define SEQ_STATE_ENTER_PREVIEW         2
+#define SEQ_STATE_PREVIEW               3
+#define SEQ_STATE_LEAVE_PREVIEW         4
+#define SEQ_STATE_TO_CAPTURE            5
+#define SEQ_STATE_ENTER_CAPTURE         6
+#define SEQ_STATE_CAPTURE               7
+#define SEQ_STATE_LEAVE_CAPTURE         8
+#define SEQ_STATE_STANDBY               9
+
+/* pages */
+#define PAGE_SENSOR_CORE                0
+#define PAGE_IFP1                       1
+#define PAGE_IFP2                       2
+
+#define REG_PAGE                        0xF0
+#define REG_VAR_ADDR                    0xC6
+#define REG_VAR_DATA                    0xC8 
+
+/* Bits for Microcontroller variable access using logic address */
+#define VAR_LENGTH_16BIT                0
+#define VAR_LENGTH_8BIT                 1
+#define VAR_LENGTH_SHIFT                15
+#define VAR_ADDRESS_TYPE_LOGIC          1
+#define VAR_ADDRESS_TYPE_SHIFT          13
+#define VAR_DRV_ID_SHIFT                8
+#define VAR_ADDRESS_SHIFT               0
+
 typedef struct MT9D111RegLst
 {
     unsigned char ucPageAddr;
@@ -20,6 +68,14 @@
 } s_RegList;
 
 void getCamId(void);
+static int wait_for_seq_state(int state);
+static uint16_t read_firmware_var(int id, int offset, int byte);
+int Start_still_capture(int frames);
+int Stop_still_capture(void);
+int cam_power_on(void);
+int cam_power_off(void);
+void cam_exit_standby(void);
+void cam_enter_standby(void);
 
 /*!
     \brief                      This function initilizes the camera sensor
@@ -46,6 +102,7 @@
     \warning
 */
 int StartSensorInJpegMode(int width, int height);
+int StartCaptureCmd(void);
 int CameraSensorResolution(int width, int height);
 static int RegLstWrite(s_RegList *pRegLst, unsigned int ulNofItems);
 //*****************************************************************************
@@ -60,3 +117,4 @@
 
 #endif //__MT9D111_H__
 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov2640/ov2640.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,47 @@
+
+#include "mbed.h"
+#include "i2cconfig.h"
+#include "ov2640_regs.h"
+#include "ov2640.h"
+#include "ov5642.h"
+#include "camera_app.h"
+#include "app_config.h"
+
+
+extern DCMI_HandleTypeDef phdcmi;
+ 
+void camId(){
+    uint8_t vid, pid;
+    
+    rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
+    rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
+    if((vid != 0x26) || (pid != 0x42)){
+        printf("Can't find OV2640 module! vid 0x%x pid 0x%x\r\n",vid, pid);      
+        HAL_DCMI_MspDeInit(&phdcmi);
+        while(1);
+    }else{
+      printf("OV2640 detected\r\n");
+    }
+}
+void initCam(){
+#if defined OV2640_CAM
+            wrSensorReg8_8(0xff, 0x01);
+            wrSensorReg8_8(0x12, 0x80);
+            wait_ms(100);
+#ifdef ENABLE_JPEG             
+            wrSensorRegs8_8(OV2640_JPEG_INIT);
+            wrSensorRegs8_8(OV2640_YUV422);
+            wrSensorRegs8_8(OV2640_JPEG);
+            wrSensorReg8_8(0xff, 0x01);
+            wrSensorReg8_8(0x15, 0x00);
+            wrSensorRegs8_8(OV2640_320x240_JPEG);               
+#else                        
+            wrSensorRegs8_8(OV2640_QVGA);
+            
+#endif//ENABLE_JPEG 
+#endif//OV2640_CAM                  
+}
+
+
+
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov2640/ov2640.h	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,14 @@
+
+
+#ifndef OV2640_H
+#define OV2640_H
+
+    /****************************************************************/
+    /* define a structure for sensor register initialization values */
+    /****************************************************************/
+
+void camId(void);
+void initCam(void);
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov2640/ov2640_regs.h	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,865 @@
+#ifndef OV2640_REGS_H
+#define OV2640_REGS_H
+
+#include "mbed.h"
+#include "ov2640.h"
+#include "ov5642.h"
+
+#define OV2640_CHIPID_HIGH 	0x0A
+#define OV2640_CHIPID_LOW 	0x0B
+
+const struct sensor_reg OV2640_QVGA[] =
+{
+	{0xff, 0x0}, 
+	{0x2c, 0xff}, 
+	{0x2e, 0xdf}, 
+	{0xff, 0x1}, 
+	{0x3c, 0x32}, 
+	{0x11, 0x0}, 
+	{0x9, 0x2}, 
+	{0x4, 0xa8}, 
+	{0x13, 0xe5}, 
+	{0x14, 0x48}, 
+	{0x2c, 0xc}, 
+	{0x33, 0x78}, 
+	{0x3a, 0x33}, 
+	{0x3b, 0xfb}, 
+	{0x3e, 0x0}, 
+	{0x43, 0x11}, 
+	{0x16, 0x10}, 
+	{0x39, 0x2}, 
+	{0x35, 0x88}, 
+
+	{0x22, 0xa}, 
+	{0x37, 0x40}, 
+	{0x23, 0x0}, 
+	{0x34, 0xa0}, 
+	{0x6, 0x2}, 
+	{0x6, 0x88}, 
+	{0x7, 0xc0}, 
+	{0xd, 0xb7}, 
+	{0xe, 0x1}, 
+	{0x4c, 0x0}, 
+	{0x4a, 0x81}, 
+	{0x21, 0x99}, 
+	{0x24, 0x40}, 
+	{0x25, 0x38}, 
+	{0x26, 0x82}, 
+	{0x5c, 0x0}, 
+	{0x63, 0x0}, 
+	{0x46, 0x22}, 
+	{0xc, 0x3a}, 
+	{0x5d, 0x55}, 
+	{0x5e, 0x7d}, 
+	{0x5f, 0x7d}, 
+	{0x60, 0x55}, 
+	{0x61, 0x70}, 
+	{0x62, 0x80}, 
+	{0x7c, 0x5}, 
+	{0x20, 0x80}, 
+	{0x28, 0x30}, 
+	{0x6c, 0x0}, 
+	{0x6d, 0x80}, 
+	{0x6e, 0x0}, 
+	{0x70, 0x2}, 
+	{0x71, 0x94}, 
+	{0x73, 0xc1}, 
+	{0x3d, 0x34}, 
+	{0x12, 0x4}, 
+	{0x5a, 0x57}, 
+	{0x4f, 0xbb}, 
+	{0x50, 0x9c}, 
+	{0xff, 0x0}, 
+	{0xe5, 0x7f}, 
+	{0xf9, 0xc0}, 
+	{0x41, 0x24}, 
+	{0xe0, 0x14}, 
+	{0x76, 0xff}, 
+	{0x33, 0xa0}, 
+	{0x42, 0x20}, 
+	{0x43, 0x18}, 
+	{0x4c, 0x0}, 
+	{0x87, 0xd0}, 
+	{0x88, 0x3f}, 
+	{0xd7, 0x3}, 
+	{0xd9, 0x10}, 
+	{0xd3, 0x82}, 
+	{0xc8, 0x8}, 
+	{0xc9, 0x80}, 
+	{0x7c, 0x0}, 
+	{0x7d, 0x0}, 
+	{0x7c, 0x3}, 
+	{0x7d, 0x48}, 
+	{0x7d, 0x48}, 
+	{0x7c, 0x8}, 
+	{0x7d, 0x20}, 
+	{0x7d, 0x10}, 
+	{0x7d, 0xe}, 
+	{0x90, 0x0}, 
+	{0x91, 0xe}, 
+	{0x91, 0x1a}, 
+	{0x91, 0x31}, 
+	{0x91, 0x5a}, 
+	{0x91, 0x69}, 
+	{0x91, 0x75}, 
+	{0x91, 0x7e}, 
+	{0x91, 0x88}, 
+	{0x91, 0x8f}, 
+	{0x91, 0x96}, 
+	{0x91, 0xa3}, 
+	{0x91, 0xaf}, 
+	{0x91, 0xc4}, 
+	{0x91, 0xd7}, 
+	{0x91, 0xe8}, 
+	{0x91, 0x20}, 
+	{0x92, 0x0}, 
+
+	{0x93, 0x6}, 
+	{0x93, 0xe3}, 
+	{0x93, 0x3}, 
+	{0x93, 0x3}, 
+	{0x93, 0x0}, 
+	{0x93, 0x2}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x93, 0x0}, 
+	{0x96, 0x0}, 
+	{0x97, 0x8}, 
+	{0x97, 0x19}, 
+	{0x97, 0x2}, 
+	{0x97, 0xc}, 
+	{0x97, 0x24}, 
+	{0x97, 0x30}, 
+	{0x97, 0x28}, 
+	{0x97, 0x26}, 
+	{0x97, 0x2}, 
+	{0x97, 0x98}, 
+	{0x97, 0x80}, 
+	{0x97, 0x0}, 
+	{0x97, 0x0}, 
+	{0xa4, 0x0}, 
+	{0xa8, 0x0}, 
+	{0xc5, 0x11}, 
+	{0xc6, 0x51}, 
+	{0xbf, 0x80}, 
+	{0xc7, 0x10}, 
+	{0xb6, 0x66}, 
+	{0xb8, 0xa5}, 
+	{0xb7, 0x64}, 
+	{0xb9, 0x7c}, 
+	{0xb3, 0xaf}, 
+	{0xb4, 0x97}, 
+	{0xb5, 0xff}, 
+	{0xb0, 0xc5}, 
+	{0xb1, 0x94}, 
+	{0xb2, 0xf}, 
+	{0xc4, 0x5c}, 
+	{0xa6, 0x0}, 
+	{0xa7, 0x20}, 
+	{0xa7, 0xd8}, 
+	{0xa7, 0x1b}, 
+	{0xa7, 0x31}, 
+	{0xa7, 0x0}, 
+	{0xa7, 0x18}, 
+	{0xa7, 0x20}, 
+	{0xa7, 0xd8}, 
+	{0xa7, 0x19}, 
+	{0xa7, 0x31}, 
+	{0xa7, 0x0}, 
+	{0xa7, 0x18}, 
+	{0xa7, 0x20}, 
+	{0xa7, 0xd8}, 
+	{0xa7, 0x19}, 
+	{0xa7, 0x31}, 
+	{0xa7, 0x0}, 
+	{0xa7, 0x18}, 
+	{0x7f, 0x0}, 
+	{0xe5, 0x1f}, 
+	{0xe1, 0x77}, 
+	{0xdd, 0x7f}, 
+	{0xc2, 0xe}, 
+	
+	{0xff, 0x0}, 
+	{0xe0, 0x4}, 
+	{0xc0, 0xc8}, 
+	{0xc1, 0x96}, 
+	{0x86, 0x3d}, 
+	{0x51, 0x90}, 
+	{0x52, 0x2c}, 
+	{0x53, 0x0}, 
+	{0x54, 0x0}, 
+	{0x55, 0x88}, 
+	{0x57, 0x0}, 
+	
+	{0x50, 0x92}, 
+	{0x5a, 0x50}, 
+	{0x5b, 0x3c}, 
+	{0x5c, 0x0}, 
+	{0xd3, 0x4}, 
+	{0xe0, 0x0}, 
+	
+	{0xff, 0x0}, 
+	{0x5, 0x0}, 
+	
+	{0xda, 0x8}, 
+	{0xd7, 0x3}, 
+	{0xe0, 0x0}, 
+	
+	{0x5, 0x0}, 
+
+	
+	{0xff,0xff},
+};        
+
+const struct sensor_reg OV2640_JPEG_INIT[] =
+{
+  { 0xff, 0x00 },
+  { 0x2c, 0xff },
+  { 0x2e, 0xdf },
+  { 0xff, 0x01 },
+  { 0x3c, 0x32 },
+  { 0x11, 0x00 },	
+  { 0x09, 0x02 },
+  { 0x04, 0x28 },
+  { 0x13, 0xe5 },
+  { 0x14, 0x48 },
+  { 0x2c, 0x0c },
+  { 0x33, 0x78 },
+  { 0x3a, 0x33 },
+  { 0x3b, 0xfB },
+  { 0x3e, 0x00 },
+  { 0x43, 0x11 },
+  { 0x16, 0x10 },
+  { 0x39, 0x92 },
+  { 0x35, 0xda },
+  { 0x22, 0x1a },
+  { 0x37, 0xc3 },
+  { 0x23, 0x00 },
+  { 0x34, 0xc0 },
+  { 0x36, 0x1a },
+  { 0x06, 0x88 },
+  { 0x07, 0xc0 },
+  { 0x0d, 0x87 },
+  { 0x0e, 0x41 },
+  { 0x4c, 0x00 },
+  { 0x48, 0x00 },
+  { 0x5B, 0x00 },
+  { 0x42, 0x03 },
+  { 0x4a, 0x81 },
+  { 0x21, 0x99 },
+  { 0x24, 0x40 },
+  { 0x25, 0x38 },
+  { 0x26, 0x82 },
+  { 0x5c, 0x00 },
+  { 0x63, 0x00 },
+  { 0x61, 0x70 },
+  { 0x62, 0x80 },
+  { 0x7c, 0x05 },
+  { 0x20, 0x80 },
+  { 0x28, 0x30 },
+  { 0x6c, 0x00 },
+  { 0x6d, 0x80 },
+  { 0x6e, 0x00 },
+  { 0x70, 0x02 },
+  { 0x71, 0x94 },
+  { 0x73, 0xc1 },
+  { 0x12, 0x40 },
+  { 0x17, 0x11 },
+  { 0x18, 0x43 },
+  { 0x19, 0x00 },
+  { 0x1a, 0x4b },
+  { 0x32, 0x09 },
+  { 0x37, 0xc0 },
+  { 0x4f, 0x60 },
+  { 0x50, 0xa8 },
+  { 0x6d, 0x00 },
+  { 0x3d, 0x38 },
+  { 0x46, 0x3f },
+  { 0x4f, 0x60 },
+  { 0x0c, 0x3c },
+  { 0xff, 0x00 },
+  { 0xe5, 0x7f },
+  { 0xf9, 0xc0 },
+  { 0x41, 0x24 },
+  { 0xe0, 0x14 },
+  { 0x76, 0xff },
+  { 0x33, 0xa0 },
+  { 0x42, 0x20 },
+  { 0x43, 0x18 },
+  { 0x4c, 0x00 },
+  { 0x87, 0xd5 },
+  { 0x88, 0x3f },
+  { 0xd7, 0x03 },
+  { 0xd9, 0x10 },
+  { 0xd3, 0x82 },
+  { 0xc8, 0x08 },
+  { 0xc9, 0x80 },
+  { 0x7c, 0x00 },
+  { 0x7d, 0x00 },
+  { 0x7c, 0x03 },
+  { 0x7d, 0x48 },
+  { 0x7d, 0x48 },
+  { 0x7c, 0x08 },
+  { 0x7d, 0x20 },
+  { 0x7d, 0x10 },
+  { 0x7d, 0x0e },
+  { 0x90, 0x00 },
+  { 0x91, 0x0e },
+  { 0x91, 0x1a },
+  { 0x91, 0x31 },
+  { 0x91, 0x5a },
+  { 0x91, 0x69 },
+  { 0x91, 0x75 },
+  { 0x91, 0x7e },
+  { 0x91, 0x88 },
+  { 0x91, 0x8f },
+  { 0x91, 0x96 },
+  { 0x91, 0xa3 },
+  { 0x91, 0xaf },
+  { 0x91, 0xc4 },
+  { 0x91, 0xd7 },
+  { 0x91, 0xe8 },
+  { 0x91, 0x20 },
+  { 0x92, 0x00 },
+  { 0x93, 0x06 },
+  { 0x93, 0xe3 },
+  { 0x93, 0x05 },
+  { 0x93, 0x05 },
+  { 0x93, 0x00 },
+  { 0x93, 0x04 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x93, 0x00 },
+  { 0x96, 0x00 },
+  { 0x97, 0x08 },
+  { 0x97, 0x19 },
+  { 0x97, 0x02 },
+  { 0x97, 0x0c },
+  { 0x97, 0x24 },
+  { 0x97, 0x30 },
+  { 0x97, 0x28 },
+  { 0x97, 0x26 },
+  { 0x97, 0x02 },
+  { 0x97, 0x98 },
+  { 0x97, 0x80 },
+  { 0x97, 0x00 },
+  { 0x97, 0x00 },
+  { 0xc3, 0xed },
+  { 0xa4, 0x00 },
+  { 0xa8, 0x00 },
+  { 0xc5, 0x11 },
+  { 0xc6, 0x51 },
+  { 0xbf, 0x80 },
+  { 0xc7, 0x10 },
+  { 0xb6, 0x66 },
+  { 0xb8, 0xA5 },
+  { 0xb7, 0x64 },
+  { 0xb9, 0x7C },
+  { 0xb3, 0xaf },
+  { 0xb4, 0x97 },
+  { 0xb5, 0xFF },
+  { 0xb0, 0xC5 },
+  { 0xb1, 0x94 },
+  { 0xb2, 0x0f },
+  { 0xc4, 0x5c },
+  { 0xc0, 0x64 },
+  { 0xc1, 0x4B },
+  { 0x8c, 0x00 },
+  { 0x86, 0x3D },
+  { 0x50, 0x00 },
+  { 0x51, 0xC8 },
+  { 0x52, 0x96 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x5a, 0xC8 },
+  { 0x5b, 0x96 },
+  { 0x5c, 0x00 },
+  { 0xd3, 0x00 },	//{ 0xd3, 0x7f },
+  { 0xc3, 0xed },
+  { 0x7f, 0x00 },
+  { 0xda, 0x00 },
+  { 0xe5, 0x1f },
+  { 0xe1, 0x67 },
+  { 0xe0, 0x00 },
+  { 0xdd, 0x7f },
+  { 0x05, 0x00 },
+               
+  { 0x12, 0x40 },
+  { 0xd3, 0x04 },	//{ 0xd3, 0x7f },
+  { 0xc0, 0x16 },
+  { 0xC1, 0x12 },
+  { 0x8c, 0x00 },
+  { 0x86, 0x3d },
+  { 0x50, 0x00 },
+  { 0x51, 0x2C },
+  { 0x52, 0x24 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x5A, 0x2c },
+  { 0x5b, 0x24 },
+  { 0x5c, 0x00 },
+  { 0xff, 0xff },
+};             
+
+const struct sensor_reg OV2640_YUV422[] =
+{
+  { 0xFF, 0x00 },
+  { 0x05, 0x00 },
+  { 0xDA, 0x10 },
+  { 0xD7, 0x03 },
+  { 0xDF, 0x00 },
+  { 0x33, 0x80 },
+  { 0x3C, 0x40 },
+  { 0xe1, 0x77 },
+  { 0x00, 0x00 },
+  { 0xff, 0xff },
+};
+
+const struct sensor_reg OV2640_JPEG[] = 
+{
+  { 0xe0, 0x14 },
+  { 0xe1, 0x77 },
+  { 0xe5, 0x1f },
+  { 0xd7, 0x03 },
+  { 0xda, 0x10 },
+  { 0xe0, 0x00 },
+  { 0xFF, 0x01 },
+  { 0x04, 0x08 },
+  { 0xff, 0xff },
+}; 
+
+/* JPG 160x120 */
+const struct sensor_reg OV2640_160x120_JPEG[] =  
+{
+  { 0xff, 0x01 },
+  { 0x12, 0x40 },
+  { 0x17, 0x11 },
+  { 0x18, 0x43 },
+  { 0x19, 0x00 },
+  { 0x1a, 0x4b },
+  { 0x32, 0x09 },
+  { 0x4f, 0xca },
+  { 0x50, 0xa8 },
+  { 0x5a, 0x23 },
+  { 0x6d, 0x00 },
+  { 0x39, 0x12 },
+  { 0x35, 0xda },
+  { 0x22, 0x1a },
+  { 0x37, 0xc3 },
+  { 0x23, 0x00 },
+  { 0x34, 0xc0 },
+  { 0x36, 0x1a },
+  { 0x06, 0x88 },
+  { 0x07, 0xc0 },
+  { 0x0d, 0x87 },
+  { 0x0e, 0x41 },
+  { 0x4c, 0x00 },
+  { 0xff, 0x00 },
+  { 0xe0, 0x04 },
+  { 0xc0, 0x64 },
+  { 0xc1, 0x4b },
+  { 0x86, 0x35 },
+  { 0x50, 0x92 },
+  { 0x51, 0xc8 },
+  { 0x52, 0x96 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x57, 0x00 },
+  { 0x5a, 0x28 },
+  { 0x5b, 0x1e },
+  { 0x5c, 0x00 },
+  { 0xe0, 0x00 },
+  { 0xff, 0xff },
+};
+
+/* JPG, 0x176x144 */
+
+const struct sensor_reg OV2640_176x144_JPEG[] = 
+{
+  { 0xff, 0x01 },
+  { 0x12, 0x40 },
+  { 0x17, 0x11 },
+  { 0x18, 0x43 },
+  { 0x19, 0x00 },
+  { 0x1a, 0x4b },
+  { 0x32, 0x09 },
+  { 0x4f, 0xca },
+  { 0x50, 0xa8 },
+  { 0x5a, 0x23 },
+  { 0x6d, 0x00 },
+  { 0x39, 0x12 },
+  { 0x35, 0xda },
+  { 0x22, 0x1a },
+  { 0x37, 0xc3 },
+  { 0x23, 0x00 },
+  { 0x34, 0xc0 },
+  { 0x36, 0x1a },
+  { 0x06, 0x88 },
+  { 0x07, 0xc0 },
+  { 0x0d, 0x87 },
+  { 0x0e, 0x41 },
+  { 0x4c, 0x00 },
+  { 0xff, 0x00 },
+  { 0xe0, 0x04 },
+  { 0xc0, 0x64 },
+  { 0xc1, 0x4b },
+  { 0x86, 0x35 },
+  { 0x50, 0x92 },
+  { 0x51, 0xc8 },
+  { 0x52, 0x96 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x57, 0x00 },
+  { 0x5a, 0x2c },
+  { 0x5b, 0x24 },
+  { 0x5c, 0x00 },
+  { 0xe0, 0x00 },
+  { 0xff, 0xff },
+};
+
+/* JPG 320x240 */
+
+const struct sensor_reg OV2640_320x240_JPEG[] = 
+{
+  { 0xff, 0x01 },
+  { 0x12, 0x40 },
+  { 0x17, 0x11 },
+  { 0x18, 0x43 },
+  { 0x19, 0x00 },
+  { 0x1a, 0x4b },
+  { 0x32, 0x09 },
+  { 0x4f, 0xca },
+  { 0x50, 0xa8 },
+  { 0x5a, 0x23 },
+  { 0x6d, 0x00 },
+  { 0x39, 0x12 },
+  { 0x35, 0xda },
+  { 0x22, 0x1a },
+  { 0x37, 0xc3 },
+  { 0x23, 0x00 },
+  { 0x34, 0xc0 },
+  { 0x36, 0x1a },
+  { 0x06, 0x88 },
+  { 0x07, 0xc0 },
+  { 0x0d, 0x87 },
+  { 0x0e, 0x41 },
+  { 0x4c, 0x00 },
+  { 0xff, 0x00 },
+  { 0xe0, 0x04 },
+  { 0xc0, 0x64 },
+  { 0xc1, 0x4b },
+  { 0x86, 0x35 },
+  { 0x50, 0x89 },
+  { 0x51, 0xc8 },
+  { 0x52, 0x96 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x57, 0x00 },
+  { 0x5a, 0x50 },
+  { 0x5b, 0x3c },
+  { 0x5c, 0x00 },
+  { 0xe0, 0x00 },
+  { 0xff, 0xff },
+};
+
+/* JPG 352x288 */
+
+const struct sensor_reg OV2640_352x288_JPEG[] = 
+
+{
+  { 0xff, 0x01 },
+  { 0x12, 0x40 },
+  { 0x17, 0x11 },
+  { 0x18, 0x43 },
+  { 0x19, 0x00 },
+  { 0x1a, 0x4b },
+  { 0x32, 0x09 },
+  { 0x4f, 0xca },
+  { 0x50, 0xa8 },
+  { 0x5a, 0x23 },
+  { 0x6d, 0x00 },
+  { 0x39, 0x12 },
+  { 0x35, 0xda },
+  { 0x22, 0x1a },
+  { 0x37, 0xc3 },
+  { 0x23, 0x00 },
+  { 0x34, 0xc0 },
+  { 0x36, 0x1a },
+  { 0x06, 0x88 },
+  { 0x07, 0xc0 },
+  { 0x0d, 0x87 },
+  { 0x0e, 0x41 },
+  { 0x4c, 0x00 },
+  { 0xff, 0x00 },
+  { 0xe0, 0x04 },
+  { 0xc0, 0x64 },
+  { 0xc1, 0x4b },
+  { 0x86, 0x35 },
+  { 0x50, 0x89 },
+  { 0x51, 0xc8 },
+  { 0x52, 0x96 },
+  { 0x53, 0x00 },
+  { 0x54, 0x00 },
+  { 0x55, 0x00 },
+  { 0x57, 0x00 },
+  { 0x5a, 0x58 },
+  { 0x5b, 0x48 },
+  { 0x5c, 0x00 },
+  { 0xe0, 0x00 },  
+  { 0xff, 0xff },
+};
+
+/* JPG 640x480 */
+const struct sensor_reg OV2640_640x480_JPEG[] = 
+{
+	{0xff, 0x01},
+	{0x11, 0x01},
+	{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����
+	{0x17, 0x11}, // HREFST[10:3]
+	{0x18, 0x75}, // HREFEND[10:3]
+	{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]
+	{0x19, 0x01}, // VSTRT[9:2]
+	{0x1a, 0x97}, // VEND[9:2]
+	{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]
+	{0x37, 0x40},
+	{0x4f, 0xbb},
+	{0x50, 0x9c},
+	{0x5a, 0x57},
+	{0x6d, 0x80},
+	{0x3d, 0x34},
+	{0x39, 0x02},
+	{0x35, 0x88},
+	{0x22, 0x0a},
+	{0x37, 0x40},
+	{0x34, 0xa0},
+	{0x06, 0x02},
+	{0x0d, 0xb7},
+	{0x0e, 0x01},
+	
+	{0xff, 0x00}, 		      
+	{0xe0, 0x04},       
+	{0xc0, 0xc8},       
+	{0xc1, 0x96},       
+	{0x86, 0x3d},       
+	{0x50, 0x89},       
+	{0x51, 0x90},       
+	{0x52, 0x2c},       
+	{0x53, 0x00},       
+	{0x54, 0x00},       
+	{0x55, 0x88},       
+	{0x57, 0x00},       
+	{0x5a, 0xa0},       
+	{0x5b, 0x78},       
+	{0x5c, 0x00},       
+	{0xd3, 0x04},       
+	{0xe0, 0x00},       
+                      
+  	{0xff, 0xff},
+};     
+    
+/* JPG 800x600 */
+const struct sensor_reg OV2640_800x600_JPEG[] = 
+{
+	{0xff, 0x01},
+	{0x11, 0x01},
+	{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����
+	{0x17, 0x11}, // HREFST[10:3]
+	{0x18, 0x75}, // HREFEND[10:3]
+	{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]
+	{0x19, 0x01}, // VSTRT[9:2]
+	{0x1a, 0x97}, // VEND[9:2]
+	{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]
+	{0x37, 0x40},
+	{0x4f, 0xbb},
+	{0x50, 0x9c},
+	{0x5a, 0x57},
+	{0x6d, 0x80},
+	{0x3d, 0x34},
+	{0x39, 0x02},
+	{0x35, 0x88},
+	{0x22, 0x0a},
+	{0x37, 0x40},
+	{0x34, 0xa0},
+	{0x06, 0x02},
+	{0x0d, 0xb7},
+	{0x0e, 0x01},
+	
+	{0xff, 0x00},
+	{0xe0, 0x04},
+	{0xc0, 0xc8},
+	{0xc1, 0x96},
+	{0x86, 0x35},
+	{0x50, 0x89},
+	{0x51, 0x90},
+	{0x52, 0x2c},
+	{0x53, 0x00},
+	{0x54, 0x00},
+	{0x55, 0x88},
+	{0x57, 0x00},
+	{0x5a, 0xc8},
+	{0x5b, 0x96},
+	{0x5c, 0x00},
+	{0xd3, 0x02},
+	{0xe0, 0x00},
+                      
+  	{0xff, 0xff},
+};     
+       
+/* JPG 1024x768 */
+const struct sensor_reg OV2640_1024x768_JPEG[] = 
+{
+	{0xff, 0x01},
+	{0x11, 0x01},
+	{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����
+	{0x17, 0x11}, // HREFST[10:3]
+	{0x18, 0x75}, // HREFEND[10:3]
+	{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]
+	{0x19, 0x01}, // VSTRT[9:2]
+	{0x1a, 0x97}, // VEND[9:2]
+	{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]
+	{0x37, 0x40},
+	{0x4f, 0xbb},
+	{0x50, 0x9c},
+	{0x5a, 0x57},
+	{0x6d, 0x80},
+	{0x3d, 0x34},
+	{0x39, 0x02},
+	{0x35, 0x88},
+	{0x22, 0x0a},
+	{0x37, 0x40},
+	{0x34, 0xa0},
+	{0x06, 0x02},
+	{0x0d, 0xb7},
+	{0x0e, 0x01},
+	
+	{0xff, 0x00},		  
+	{0xc0, 0xC8},          
+	{0xc1, 0x96},          
+	{0x8c, 0x00},          
+	{0x86, 0x3D},          
+	{0x50, 0x00},          
+	{0x51, 0x90},          
+	{0x52, 0x2C},          
+	{0x53, 0x00},          
+	{0x54, 0x00},          
+	{0x55, 0x88},          
+	{0x5a, 0x00},          
+	{0x5b, 0xC0},          
+	{0x5c, 0x01},          
+	{0xd3, 0x02},          
+
+                      
+  {0xff, 0xff},
+};  
+
+   /* JPG 1280x1024 */
+const struct sensor_reg OV2640_1280x1024_JPEG[] =
+{
+	{0xff, 0x01},
+	{0x11, 0x01},
+	{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����
+	{0x17, 0x11}, // HREFST[10:3]
+	{0x18, 0x75}, // HREFEND[10:3]
+	{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]
+	{0x19, 0x01}, // VSTRT[9:2]
+	{0x1a, 0x97}, // VEND[9:2]
+	{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]
+	{0x37, 0x40},
+	{0x4f, 0xbb},
+	{0x50, 0x9c},
+	{0x5a, 0x57},
+	{0x6d, 0x80},
+	{0x3d, 0x34},
+	{0x39, 0x02},
+	{0x35, 0x88},
+	{0x22, 0x0a},
+	{0x37, 0x40},
+	{0x34, 0xa0},
+	{0x06, 0x02},
+	{0x0d, 0xb7},
+	{0x0e, 0x01},
+	
+	{0xff, 0x00},     		      
+	{0xe0, 0x04},           
+	{0xc0, 0xc8},           
+	{0xc1, 0x96},           
+	{0x86, 0x3d},           
+	{0x50, 0x00},           
+	{0x51, 0x90},           
+	{0x52, 0x2c},           
+	{0x53, 0x00},           
+	{0x54, 0x00},           
+	{0x55, 0x88},           
+	{0x57, 0x00},           
+	{0x5a, 0x40},           
+	{0x5b, 0xf0},           
+	{0x5c, 0x01},           
+	{0xd3, 0x02},           
+	{0xe0, 0x00},           
+                      
+  	{0xff, 0xff},
+};         
+       
+   /* JPG 1600x1200 */
+const struct sensor_reg OV2640_1600x1200_JPEG[] = 
+{
+	{0xff, 0x01},
+	{0x11, 0x01},
+	{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����
+	{0x17, 0x11}, // HREFST[10:3]
+	{0x18, 0x75}, // HREFEND[10:3]
+	{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]
+	{0x19, 0x01}, // VSTRT[9:2]
+	{0x1a, 0x97}, // VEND[9:2]
+	{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]
+	{0x37, 0x40},
+	{0x4f, 0xbb},
+	{0x50, 0x9c},
+	{0x5a, 0x57},
+	{0x6d, 0x80},
+	{0x3d, 0x34},
+	{0x39, 0x02},
+	{0x35, 0x88},
+	{0x22, 0x0a},
+	{0x37, 0x40},
+	{0x34, 0xa0},
+	{0x06, 0x02},
+	{0x0d, 0xb7},
+	{0x0e, 0x01},
+	
+	{0xff, 0x00},        	                              
+	{0xe0, 0x04},                                   
+	{0xc0, 0xc8},                                   
+	{0xc1, 0x96},                                   
+	{0x86, 0x3d},                                   
+	{0x50, 0x00},                                   
+	{0x51, 0x90},                                   
+	{0x52, 0x2c},                                   
+	{0x53, 0x00},                                   
+	{0x54, 0x00},                                   
+	{0x55, 0x88},                                   
+	{0x57, 0x00},                                   
+	{0x5a, 0x90},                                   
+	{0x5b, 0x2C},                                   
+	{0x5c, 0x05},              //bit2->1;bit[1:0]->1
+	{0xd3, 0x02},                                   
+	{0xe0, 0x00},                                   
+                      
+  	{0xff, 0xff},
+};  
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov5642/ov5642.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,256 @@
+
+#include "mbed.h"
+#include "i2cconfig.h"
+#include "ov5642_regs.h"
+#include "ov5642.h"
+#include "camera_app.h"
+#include "app_config.h"
+
+
+extern DCMI_HandleTypeDef phdcmi;
+ 
+void check_camId(){
+    uint8_t vid, pid;
+    
+    rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);
+    rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);
+    if((vid != 0x56) || (pid != 0x42)){
+        printf("Can't find OV5642 module! vid 0x%x pid 0x%x\r\n",vid, pid);      
+        HAL_DCMI_MspDeInit(&phdcmi);
+        while(1);
+    }else{
+      printf("OV5642 detected\r\n");
+    }
+}
+void init_cam(){
+#if defined OV5642_CAM
+            wrSensorReg16_8(0x3008, 0x80);
+            wait_ms(100);
+#ifdef ENABLE_JPEG             
+            wrSensorRegs16_8(ov5642_dvp_fmt_global_init); 
+            wait_ms(100);
+            OV5642_set_JPEG_size(); 
+//            wrSensorRegs16_8(ov5642_dvp_fmt_jpeg_vga);
+            wrSensorRegs16_8(ov5642_dvp_fmt_jpeg_qvga); 
+            wrSensorReg16_8(0x4407,0x0C);                
+#else                        
+            wrSensorRegs16_8(OV5642_RGB_QVGA);
+            rdSensorReg16_8(0x3818, &reg_val);
+            wrSensorReg16_8(0x3818, (reg_val | 0x60) & 0xff);
+            rdSensorReg16_8(0x3621, &reg_val);
+            wrSensorReg16_8(0x3621, reg_val & 0xdf);
+            
+#endif//ENABLE_JPEG 
+#endif//OV5642_CAM                  
+}
+
+void OV5642_set_JPEG_size(){
+    
+    wrSensorRegs16_8(ov5642_dvp_fmt_global_init);
+    wait_ms(100);        
+    wrSensorRegs16_8(ov5642_dvp_fmt_jpeg_qvga);
+    wrSensorReg16_8(0x4407, 0x04);
+    wrSensorReg16_8(0x3818, 0xA8); 
+    wrSensorReg16_8(0x3621, 0x10); 
+    wrSensorReg16_8(0x3801, 0x98);
+    wait_ms(100); 
+}
+
+//I2C Write 8bit address, 8bit data
+uint8_t wrSensorReg8_8(int regID, int regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID;
+    buff[1] = regDat;
+    I2CBufferWrite(sensor_addr,buff,2, I2C_SEND_STOP);
+
+//    wait_ms(1);
+  return(1);
+}
+
+//I2C Read 8bit address, 8bit data
+uint8_t rdSensorReg8_8(uint8_t regID, uint8_t* regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID;
+    
+    I2CBufferWrite(sensor_addr,buff,1, I2C_SEND_STOP);
+    I2CBufferRead(sensor_addr+1,buff,1, I2C_SEND_STOP);
+    *regDat = buff[0];
+
+ //   wait_ms(1);
+  return(1);
+}
+
+//I2C Write 8bit address, 16bit data
+uint8_t wrSensorReg8_16(int regID, int regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID;
+    buff[1] = regDat >> 8;
+    buff[2] = regDat & 0x00FF;
+    I2CBufferWrite(sensor_addr,buff,3, I2C_SEND_STOP);
+
+//    wait_ms(1);
+    return(1);
+}
+
+//I2C Read 8bit address, 16bit data
+uint8_t rdSensorReg8_16(uint8_t regID, uint16_t* regDat)
+{
+//    uint8_t temp;
+    uint8_t buff[20];
+    buff[0] = regID;
+    
+    I2CBufferWrite(sensor_addr,buff,1, I2C_SEND_STOP);
+    I2CBufferRead(sensor_addr+1,buff, 2, I2C_SEND_STOP);
+    *regDat = (buff[0] << 8) | buff[1];
+
+//    wait_ms(1);
+    return(1);
+}
+
+//I2C Write 16bit address, 8bit data
+uint8_t wrSensorReg16_8(int regID, int regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID >> 8;
+    buff[1] = regID & 0x00FF;
+    buff[2] = regDat;
+    I2CBufferWrite(sensor_addr,buff,3, I2C_SEND_STOP);
+
+//    wait_ms(1);
+  return(1);
+}
+
+//I2C Read 16bit address, 8bit data
+uint8_t rdSensorReg16_8(uint16_t regID, uint8_t* regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID >> 8;
+    buff[1] = regID & 0x00FF;
+    I2CBufferWrite(sensor_addr,buff,2, I2C_SEND_STOP);
+    I2CBufferRead(sensor_addr+1,buff, 1, I2C_SEND_STOP);
+    *regDat = buff[0];
+
+//    wait_ms(1);
+  return(1);
+}
+
+//I2C Write 16bit address, 16bit data
+uint8_t wrSensorReg16_16(int regID, int regDat)
+{
+    uint8_t buff[20];
+    buff[0] = regID >> 8;
+    buff[1] = regID & 0x00FF;
+    buff[2] = regDat >> 8;
+    buff[3] = regID & 0x00FF;
+    I2CBufferWrite(sensor_addr,buff,4, I2C_SEND_STOP);
+
+//    wait_ms(1);
+  return(1);
+}
+
+//I2C Read 16bit address, 16bit data
+uint8_t rdSensorReg16_16(uint16_t regID, uint16_t* regDat)
+{
+//    uint8_t temp;
+    uint8_t buff[20];
+    buff[0] = regID >> 8;
+    buff[1] = regID & 0x00FF;
+    I2CBufferWrite(sensor_addr,buff,2, I2C_SEND_STOP);
+    I2CBufferRead(sensor_addr+1,buff, 1, I2C_SEND_STOP);
+    *regDat = (buff[0] << 8) | buff[1];
+
+//    wait_ms(1);
+  return(1);
+}
+
+//I2C Array Write 8bit address, 8bit data
+int wrSensorRegs8_8(const struct sensor_reg reglist[])
+{
+//    int err = 0;
+    uint16_t reg_addr = 0;
+    uint16_t reg_val = 0;
+    const struct sensor_reg *next = reglist;
+    
+    while ((reg_addr != 0xff) | (reg_val != 0xff))
+    {       
+        reg_addr = next->reg;
+        reg_val = next->val;
+        wrSensorReg8_8(reg_addr, reg_val);
+    next++;
+        
+    } 
+    
+    return 1;
+}
+
+//I2C Array Write 8bit address, 16bit data
+int wrSensorRegs8_16(const struct sensor_reg reglist[])
+{
+//    int err = 0;
+    
+    uint32_t reg_addr = 0;
+    uint32_t reg_val = 0;
+    const struct sensor_reg *next = reglist;
+    
+    while ((reg_addr != 0xff) | (reg_val != 0xffff))
+    {       
+        reg_addr = next->reg;
+        reg_val = next->val;
+        wrSensorReg8_16(reg_addr, reg_val);
+        //  if (!err)
+        //return err;
+        next++;
+    }  
+    
+    return 1;
+}
+
+//I2C Array Write 16bit address, 8bit data
+int wrSensorRegs16_8(const struct sensor_reg reglist[])
+{
+//    int err = 0;
+    
+    uint32_t reg_addr = 0;
+    uint8_t reg_val = 0;
+    const struct sensor_reg *next = reglist;
+    
+    while ((reg_addr != 0xffff) | (reg_val != 0xff))
+    {       
+        reg_addr = next->reg;
+        reg_val = next->val;
+        wrSensorReg16_8(reg_addr, reg_val);
+        //if (!err)
+        //return err;
+       next++;
+    } 
+    
+    return 1;
+}
+
+//I2C Array Write 16bit address, 16bit data
+int wrSensorRegs16_16(const struct sensor_reg reglist[])
+{
+//    int err = 0;
+    
+    uint32_t reg_addr = 0;
+    uint32_t reg_val = 0;
+    const struct sensor_reg *next = reglist;
+    
+    while ((reg_addr != 0xffff) | (reg_val != 0xffff))
+    {       
+        reg_addr = next->reg;
+        reg_val = next->val;
+        wrSensorReg16_16(reg_addr, reg_val);
+        //if (!err)
+        //   return err;
+       next++;
+    } 
+    
+    return 1;
+}
+
+
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov5642/ov5642.h	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,38 @@
+
+
+#ifndef OV5642_H
+#define OV5642_H
+
+    /****************************************************************/
+    /* define a structure for sensor register initialization values */
+    /****************************************************************/
+struct sensor_reg {
+    uint16_t reg;
+    uint16_t val;
+};
+
+    void check_camId(void);
+    void init_cam(void);
+    void OV5642_set_JPEG_size(void);
+    int wrSensorRegs(const struct sensor_reg*);
+    int wrSensorRegs8_8(const struct sensor_reg*);
+    int wrSensorRegs8_16(const struct sensor_reg*);
+    int wrSensorRegs16_8(const struct sensor_reg*);
+    int wrSensorRegs16_16(const struct sensor_reg*);
+        
+    uint8_t wrSensorReg(int regID, int regDat);
+    uint8_t wrSensorReg8_8(int regID, int regDat);
+    uint8_t wrSensorReg8_16(int regID, int regDat);
+    uint8_t wrSensorReg16_8(int regID, int regDat);
+    uint8_t wrSensorReg16_16(int regID, int regDat);
+        
+    uint8_t rdSensorReg8_8(uint8_t regID, uint8_t* regDat);
+    uint8_t rdSensorReg16_8(uint16_t regID, uint8_t* regDat);
+    uint8_t rdSensorReg8_16(uint8_t regID, uint16_t* regDat);
+    uint8_t rdSensorReg16_16(uint16_t regID, uint16_t* regDat);
+
+
+
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_app/ov5642/ov5642_regs.h	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,2963 @@
+#ifndef OV5642_REGS_H
+#define OV5642_REGS_H
+
+#include "mbed.h"
+#include "ov5642.h"
+
+#define OV5642_CHIPID_HIGH 0x300a
+#define OV5642_CHIPID_LOW 0x300b
+
+const struct sensor_reg ov5642_dvp_fmt_jpeg_qvga[] =
+{
+	{0x3819, 0x81},
+	{0x3503, 0x00},	//AWE Manual Mode Control //0x07
+	{0x3002, 0x00},
+	{0x3003, 0x00},
+	{0x3005, 0xff},
+	{0x3006, 0xff},
+	{0x3007 ,0x3f},
+	{0x3602 ,0xe4},
+	{0x3603 ,0x27},
+	{0x3604 ,0x60},
+	{0x3612 ,0xac},
+	{0x3613 ,0x44},
+	{0x3622 ,0x08},
+	{0x3623 ,0x22},
+	{0x3621 ,0x27},
+	{0x3705 ,0xda},
+	{0x370a ,0x80},
+	{0x3800 ,0x01},
+	{0x3801 ,0x8a},
+	{0x3802 ,0x00},
+	{0x3803 ,0x0a},
+	{0x3804 ,0x0a},
+	{0x3805 ,0x20},
+	{0x3806 ,0x07},
+	{0x3807 ,0x98},
+
+	{0x3808 ,0x01},
+	{0x3809 ,0x40},
+	{0x380a ,0x00},
+	{0x380b ,0xf0},
+
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x3810 ,0xc2},
+	{0x3815 ,0x44},
+	{0x3818 ,0xa8},
+	{0x3824 ,0x01},
+	{0x3827 ,0x0a},
+	{0x3a00 ,0x78},
+	{0x3a0d ,0x10},
+	{0x3a0e ,0x0d},
+	{0x3a00 ,0x78},
+	{0x460b ,0x35},
+	{0x471d ,0x00},
+	{0x471c ,0x50},
+	{0x5682 ,0x0a},
+	{0x5683 ,0x20},
+	{0x5686 ,0x07},
+	{0x5687 ,0x98},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x4407 ,0x04},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4300 ,0x32},
+	{0x460b ,0x35},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4713 ,0x02},
+	{0x4600 ,0x80},
+	{0x4721 ,0x02},
+	{0x471c ,0x40},
+	{0x4408 ,0x00},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x3818 ,0xe8},//c8
+	{0x501f ,0x00},
+	{0x5002 ,0xe0},
+	{0x440a ,0x01},
+	{0x4402 ,0x90},
+	{0x3811 ,0xf0},		//4:3 thumbnail 				// 0x size sensor.....
+
+	{0x471c ,0x50},
+	{0x3815 ,0x44},
+	{0x3818 ,0xe8},//c8
+	{0x4740 ,0x20},
+	{0x3030 ,0x0b},//2b
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x5001 ,0xFF},
+	{0x3010 ,0x30},
+
+    {0x460d,0xdd},//  dummy data
+
+/* test color bar */
+//  {0x503d , 0x80},
+//  {0x503e, 0x00},
+
+//11 fps
+	{0x300F, 0x0a},
+	{0x3010 ,0x00},
+	{0x3011, 0x06},
+	{0x3012 ,0x00},
+
+	//{0x4407 ,0x00},
+
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg ov5642_dvp_fmt_jpeg_qxga[] =
+{
+	{0x3819, 0x81},
+	{0x3503, 0x00},	//AWE Manual Mode Control //0x07
+	{0x3002, 0x00},
+	{0x3003, 0x00},
+	{0x3005, 0xff},
+	{0x3006, 0xff},
+	{0x3007 ,0x3f},
+	{0x3602 ,0xe4},
+	{0x3603 ,0x27},
+	{0x3604 ,0x60},
+	{0x3612 ,0xac},
+	{0x3613 ,0x44},
+	{0x3622 ,0x08},
+	{0x3623 ,0x22},
+	{0x3621 ,0x27},
+	{0x3705 ,0xda},
+	{0x370a ,0x80},
+	{0x3800 ,0x01},
+	{0x3801 ,0x8a},
+	{0x3802 ,0x00},
+	{0x3803 ,0x0a},
+	{0x3804 ,0x0a},
+	{0x3805 ,0x20},
+	{0x3806 ,0x07},
+	{0x3807 ,0x98},
+
+	{0x3808 ,0x08},
+	{0x3809 ,0x00},
+	{0x380a ,0x06},
+	{0x380b ,0x00},
+
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x3810 ,0xc2},
+	{0x3815 ,0x44},
+	{0x3818 ,0xa8},
+	{0x3824 ,0x01},
+	{0x3827 ,0x0a},
+	{0x3a00 ,0x78},
+	{0x3a0d ,0x10},
+	{0x3a0e ,0x0d},
+	{0x3a00 ,0x78},
+	{0x460b ,0x35},
+	{0x471d ,0x00},
+	{0x471c ,0x50},
+	{0x5682 ,0x0a},
+	{0x5683 ,0x20},
+	{0x5686 ,0x07},
+	{0x5687 ,0x98},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x4407 ,0x04},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4300 ,0x32},
+	{0x460b ,0x35},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4713 ,0x02},
+	{0x4600 ,0x80},
+	{0x4721 ,0x02},
+	{0x471c ,0x40},
+	{0x4408 ,0x00},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x3818 ,0xc8},
+	{0x501f ,0x00},
+	{0x5002 ,0xe0},
+	{0x440a ,0x01},
+	{0x4402 ,0x90},
+	{0x3811 ,0xf0},		//4:3 thumbnail 				// 0x size sensor.....
+
+	{0x471c ,0x50},
+	{0x3815 ,0x44},
+	{0x3818 ,0xc8},
+	{0x4740 ,0x20},
+	{0x3030 ,0x0b},//2b
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x5001 ,0xFF},
+	{0x3010 ,0x30},
+
+	{0x460d,0xdd},//  dummy data
+
+/* test color bar */
+  //{0x503d , 0x80},
+ // {0x503e, 0x00},
+
+//11 fps
+	{0x300F, 0x0a},
+	{0x3010 ,0x00},
+	{0x3011, 0x06},
+	{0x3012 ,0x00},
+
+
+
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg ov5642_dvp_fmt_jpeg_vga[] =
+{
+	{0x3819, 0x81},
+	{0x3503, 0x00},	//AWE Manual Mode Control //0x07
+	{0x3002, 0x00},
+	{0x3003, 0x00},
+	{0x3005, 0xff},
+	{0x3006, 0xff},
+	{0x3007 ,0x3f},
+	{0x3602 ,0xe4},
+	{0x3603 ,0x27},
+	{0x3604 ,0x60},
+	{0x3612 ,0xac},
+	{0x3613 ,0x44},
+	{0x3622 ,0x08},
+	{0x3623 ,0x22},
+	{0x3621 ,0x27},
+	{0x3705 ,0xda},
+	{0x370a ,0x80},
+	{0x3800 ,0x01},
+	{0x3801 ,0x8a},
+	{0x3802 ,0x00},
+	{0x3803 ,0x0a},
+	{0x3804 ,0x0a},
+	{0x3805 ,0x20},
+	{0x3806 ,0x07},
+	{0x3807 ,0x98},
+
+	{0x3808, 0x02},
+	{0x3809, 0x80},
+	{0x380A, 0x01},
+	{0x380B, 0xE0},
+
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x3810 ,0xc2},
+	{0x3815 ,0x44},
+	{0x3818 ,0xa8},
+	{0x3824 ,0x01},
+	{0x3827 ,0x0a},
+	{0x3a00 ,0x78},
+	{0x3a0d ,0x10},
+	{0x3a0e ,0x0d},
+	{0x3a00 ,0x78},
+	{0x460b ,0x35},
+	{0x471d ,0x00},
+	{0x471c ,0x50},
+	{0x5682 ,0x0a},
+	{0x5683 ,0x20},
+	{0x5686 ,0x07},
+	{0x5687 ,0x98},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x4407 ,0x04},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4300 ,0x32},
+	{0x460b ,0x35},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4713 ,0x02},
+	{0x4600 ,0x80},
+	{0x4721 ,0x02},
+	{0x471c ,0x40},
+	{0x4408 ,0x00},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x3818 ,0xc8},
+	{0x501f ,0x00},
+	{0x5002 ,0xe0},
+	{0x440a ,0x01},
+	{0x4402 ,0x90},
+	{0x3811 ,0xf0},		//4:3 thumbnail 				// 0x size sensor.....
+
+	{0x471c ,0x50},
+	{0x3815 ,0x44},
+	{0x3818 ,0xc8},
+	{0x4740 ,0x20},
+	{0x3030 ,0x0b},//2b
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x5001 ,0xFF},
+	{0x3010 ,0x30},
+
+    {0x460d,0xdd},//  dummy data
+
+/* test color bar */
+  //{0x503d , 0x80},
+ // {0x503e, 0x00},
+
+//11 fps
+	{0x300F, 0x0a},
+	{0x3010 ,0x00},
+	{0x3011, 0x06},
+	{0x3012 ,0x00},
+
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg ov5642_dvp_fmt_jpeg_5M[] =
+{
+/* captuer setting for jpeg */
+
+	{0x3819, 0x81},
+	{0x3503, 0x00},	//AWE Manual Mode Control //0x07
+	{0x3002, 0x00},
+	{0x3003, 0x00},
+	{0x3005, 0xff},
+	{0x3006, 0xff},
+	{0x3007 ,0x3f},
+	{0x3602 ,0xe4},
+	{0x3603 ,0x27},
+	{0x3604 ,0x60},
+	{0x3612 ,0xac},
+	{0x3613 ,0x44},
+	{0x3622 ,0x08},
+	{0x3623 ,0x22},
+	{0x3621 ,0x27},
+	{0x3705 ,0xda},
+	{0x370a ,0x80},
+	{0x3800 ,0x01},
+	{0x3801 ,0x8a},
+	{0x3802 ,0x00},
+	{0x3803 ,0x0a},
+	{0x3804 ,0x0a},
+	{0x3805 ,0x20},
+	{0x3806 ,0x07},
+	{0x3807 ,0x98},
+	{0x3808 ,0x0a},
+	{0x3809 ,0x20},
+	{0x380a ,0x07},
+	{0x380b ,0x98},
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x3810 ,0xc2},
+	{0x3815 ,0x44},
+	{0x3818 ,0xa8},
+	{0x3824 ,0x01},
+	{0x3827 ,0x0a},
+	{0x3a00 ,0x78},
+	{0x3a0d ,0x10},
+	{0x3a0e ,0x0d},
+	{0x3a00 ,0x78},
+	{0x460b ,0x35},
+	{0x471d ,0x00},
+	{0x471c ,0x50},
+	{0x5682 ,0x0a},
+	{0x5683 ,0x20},
+	{0x5686 ,0x07},
+	{0x5687 ,0x98},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x4407 ,0x04},//0x04
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4300 ,0x32},
+	{0x460b ,0x35},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4713 ,0x02},
+	{0x4600 ,0x80},
+	{0x4721 ,0x02},
+	{0x471c ,0x40},
+	{0x4408 ,0x00},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x3818 ,0xc8},
+	{0x501f ,0x00},
+	{0x5002 ,0xe0},
+	{0x440a ,0x01},
+	{0x4402 ,0x90},
+	{0x3811 ,0xf0},		//4:3 thumbnail 				// 0x size sensor.....
+
+	{0x471c ,0x50},
+	{0x3815 ,0x44},
+	{0x3818 ,0xe8},//c8
+	{0x4740 ,0x20},
+	{0x3030 ,0x0b},//2b
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x5001 ,0xFF},
+	{0x3010 ,0x30},
+
+	{0x460d,0xdd},//  dummy data
+/*
+	{0x4300, 0x30},
+	{0x460b, 0x37},
+	{0x3002, 0x0c},
+	{0x3002, 0x00},
+	{0x4713, 0x02},
+	{0x4600, 0xa0},
+	{0x4721, 0x02},
+	{0x471c, 0x40},
+	{0x4408, 0x00},
+	{0x460c, 0x22},
+	{0x3815, 0x04},
+	{0x3818, 0xc8},// ;TN_dis
+	{0x501f, 0x00},
+	{0x5002, 0xe0},
+	{0x440a, 0x01},
+	{0x4402, 0x90},
+	{0x4602, 0x04},
+	{0x4603, 0x00},
+	{0x4604, 0x06},
+	{0x4605, 0x00},
+*/
+/* test color bar */
+  //{0x503d , 0x80},
+  //{0x503e, 0x00},
+
+//11 fps
+	{0x300F, 0x0a},
+	{0x3010 ,0x00},
+	{0x3011, 0x08},//06
+	{0x3012 ,0x00},
+
+	{0xffff, 0xff},
+};  
+
+const struct sensor_reg ov5642_dvp_fmt_global_init[] =
+{
+	{0x3103, 0x93},
+	{0x3008, 0x82},
+	{0x3017, 0x7f},
+	{0x3018, 0xfc},
+	{0x3810, 0xc2},
+	{0x3615, 0xf0},
+	{0x3000, 0x00},
+	{0x3001, 0x00},
+	{0x3002, 0x00},
+	{0x3003, 0x00},
+	{0x3000, 0xf8},
+	{0x3001, 0x48},
+	{0x3002, 0x5c},
+	{0x3003, 0x02},
+	{0x3004, 0x07},
+	{0x3005, 0xb7},
+	{0x3006, 0x43},
+	{0x3007, 0x37},
+	{0x3011, 0x07},
+
+// fps	25fps
+	//{0x300F, 0x0a},
+	//{0x3010 ,0x00},
+	//{0x3011, 0x07},
+	//{0x3012 ,0x00},
+
+	{0x370c, 0xa0},
+	{0x3602, 0xfc},
+	{0x3612, 0xff},
+	{0x3634, 0xc0},
+	{0x3613, 0x00},
+	{0x3605, 0x7c},
+	{0x3622, 0x60},
+	{0x3604, 0x40},
+	{0x3603, 0xa7},
+	{0x3603, 0x27},
+	{0x4000, 0x21},
+	{0x401d, 0x22},
+	{0x3600, 0x54},
+	{0x3605, 0x04},
+	{0x3606, 0x3f},
+	{0x3c01, 0x80},
+	{0x5000, 0x4f},
+	{0x5020, 0x04},
+	{0x5500, 0x0a},
+	{0x5504, 0x00},
+	{0x5505, 0x7f},
+	{0x5080, 0x08},
+	{0x300e, 0x18},
+	{0x4610, 0x00},
+	{0x471d, 0x05},
+	{0x4708, 0x06},
+	{0x4300, 0x32},
+	{0x3503, 0x07},
+	{0x3501, 0x73},
+	{0x3502, 0x80},
+	{0x350b, 0x00},
+	{0x3503, 0x07},
+	//{0x3824, 0x11},
+	{0x3501, 0x1e},
+	{0x3502, 0x80},
+	{0x350b, 0x7f},
+	{0x3a0d, 0x04},
+	{0x3a0e, 0x03},
+	{0x3705, 0xdb},
+	{0x370a, 0x81},
+	{0x3801, 0x80},
+	{0x3801, 0x50},
+	{0x3803, 0x08},
+	//{0x3827, 0x08},
+	{0x3810, 0x40},
+	{0x3a00, 0x78},
+	{0x3a1a, 0x05},
+	{0x3a13, 0x30},
+	{0x3a18, 0x00},
+	{0x3a19, 0x7c},
+	{0x3a08, 0x12},
+	{0x3a09, 0xc0},
+	{0x3a0a, 0x0f},
+	{0x3a0b, 0xa0},
+	{0x3004, 0xff},
+	{0x350c, 0x07},
+	{0x350d, 0xd0},
+	{0x3500, 0x00},
+	{0x3501, 0x00},
+	{0x3502, 0x00},
+	{0x350a, 0x00},
+	{0x350b, 0x00},
+	{0x3503, 0x00},
+	{0x3a0f, 0x3c},
+	{0x3a10, 0x30},
+	{0x3a1b, 0x3c},
+	{0x3a1e, 0x30},
+	{0x3a11, 0x70},
+	{0x3a1f, 0x10},
+	{0x3030, 0x0b},//2b
+	{0x3a02, 0x00},
+	{0x3a03, 0x7d},
+	{0x3a04, 0x00},
+	{0x3a14, 0x00},
+	{0x3a15, 0x7d},
+	{0x3a16, 0x00},
+	{0x3a00, 0x78},
+	{0x3a08, 0x09},
+	{0x3a09, 0x60},
+	{0x3a0a, 0x07},
+	{0x3a0b, 0xd0},
+	{0x3a0d, 0x08},
+	{0x3a0e, 0x06},
+	{0x5193, 0x70},
+	{0x589b, 0x04},
+	{0x589a, 0xc5},
+	{0x401e, 0x20},
+	{0x4001, 0x42},
+	{0x401c, 0x04},
+	{0x5300, 0x00},
+	{0x5301, 0x20},
+	{0x5302, 0x00},
+	{0x5303, 0x7c},
+	{0x530c, 0x00},
+	{0x530d, 0x0c},
+	{0x530e, 0x20},
+	{0x530f, 0x80},
+	{0x5310, 0x20},
+	{0x5311, 0x80},
+	{0x5308, 0x20},
+	{0x5309, 0x40},
+	{0x5304, 0x00},
+	{0x5305, 0x30},
+	{0x5306, 0x00},
+	{0x5307, 0x80},
+	{0x5314, 0x08},
+	{0x5315, 0x20},
+	{0x5319, 0x30},
+	{0x5316, 0x10},
+	{0x5317, 0x08},
+	{0x5318, 0x02},
+
+	//color matrix
+	{0x5380, 0x1 },
+	{0x5381, 0x0 },
+	{0x5382, 0x0 },
+	{0x5383, 0x1a},
+	{0x5384, 0x0 },
+	{0x5385, 0x1a},
+	{0x5386, 0x0 },
+	{0x5387, 0x0 },
+	{0x5388, 0x1 },
+	{0x5389, 0x3c},
+	{0x538a, 0x0 },
+	{0x538b, 0x35},
+	{0x538c, 0x0 },
+	{0x538d, 0x0 },
+	{0x538e, 0x0 },
+	{0x538f, 0x05},
+	{0x5390, 0x0 },
+	{0x5391, 0xe8},
+	{0x5392, 0x0 },
+	{0x5393, 0xa2},
+	{0x5394, 0x8 },
+
+	//gamma
+	{0x5480, 0xd },
+	{0x5481, 0x18},
+	{0x5482, 0x2a},
+	{0x5483, 0x49},
+	{0x5484, 0x56},
+	{0x5485, 0x62},
+	{0x5486, 0x6c},
+	{0x5487, 0x76},
+	{0x5488, 0x80},
+	{0x5489, 0x88},
+	{0x548a, 0x96},
+	{0x548b, 0xa2},
+	{0x548c, 0xb8},
+	{0x548d, 0xcc},
+	{0x548e, 0xe0},
+	{0x548f, 0x10},
+	{0x5490, 0x3 },
+	{0x5491, 0x40},
+	{0x5492, 0x3 },
+	{0x5493, 0x0 },
+	{0x5494, 0x2 },
+	{0x5495, 0xa0},
+	{0x5496, 0x2 },
+	{0x5497, 0x48},
+	{0x5498, 0x2 },
+	{0x5499, 0x26},
+	{0x549a, 0x2 },
+	{0x549b, 0xb },
+	{0x549c, 0x1 },
+	{0x549d, 0xee},
+	{0x549e, 0x1 },
+	{0x549f, 0xd8},
+	{0x54a0, 0x1 },
+	{0x54a1, 0xc7},
+	{0x54a2, 0x1 },
+	{0x54a3, 0xb3},
+	{0x54a4, 0x1 },
+	{0x54a5, 0x90},
+	{0x54a6, 0x1 },
+	{0x54a7, 0x62},
+	{0x54a8, 0x1 },
+	{0x54a9, 0x27},
+	{0x54aa, 0x01},
+	{0x54ab, 0x09},
+	{0x54ac, 0x01},
+	{0x54ad, 0x00},
+	{0x54ae, 0x0 },
+	{0x54af, 0x40},
+	{0x54b0, 0x1 },
+	{0x54b1, 0x20},
+	{0x54b2, 0x1 },
+	{0x54b3, 0x40},
+	{0x54b4, 0x0 },
+	{0x54b5, 0xf0},
+	{0x54b6, 0x1 },
+	{0x54b7, 0xdf},
+
+	//saturation
+	{0x5583, 0x3a}, //ken 20100106
+	{0x5584, 0x3a}, //ken 20100106
+
+	{0x5580, 0x02},
+	{0x5000, 0xcf},
+
+	//for sunny
+	//lens shading
+	{0x5800, 0x35},
+	{0x5801, 0x20},
+	{0x5802, 0x17},
+	{0x5803, 0x17},
+	{0x5804, 0x18},
+	{0x5805, 0x1E},
+	{0x5806, 0x2D},
+	{0x5807, 0x47},
+	{0x5808, 0x17},
+	{0x5809, 0x11},
+	{0x580a, 0xC },
+	{0x580b, 0xB },
+	{0x580c, 0xC },
+	{0x580d, 0x10},
+	{0x580e, 0x17},
+	{0x580f, 0x23},
+	{0x5810, 0x10},
+	{0x5811, 0xA },
+	{0x5812, 0x5 },
+	{0x5813, 0x3 },
+	{0x5814, 0x4 },
+	{0x5815, 0x8 },
+	{0x5816, 0xF },
+	{0x5817, 0x19},
+	{0x5818, 0xE },
+	{0x5819, 0x7 },
+	{0x581a, 0x2 },
+	{0x581b, 0x3 },
+	{0x581c, 0x3 },
+	{0x581d, 0x4 },
+	{0x581e, 0xD },
+	{0x581f, 0x16},
+	{0x5820, 0xF },
+	{0x5821, 0x8 },
+	{0x5822, 0x2 },
+	{0x5823, 0x3 },
+	{0x5824, 0x3 },
+	{0x5825, 0x5 },
+	{0x5826, 0xE },
+	{0x5827, 0x19},
+	{0x5828, 0x11},
+	{0x5829, 0xB },
+	{0x582a, 0x6 },
+	{0x582b, 0x3 },
+	{0x582c, 0x4 },
+	{0x582d, 0x8 },
+	{0x582e, 0x10},
+	{0x582f, 0x19},
+	{0x5830, 0x19},
+	{0x5831, 0x11},
+	{0x5832, 0xC },
+	{0x5833, 0xB },
+	{0x5834, 0xB },
+	{0x5835, 0x10},
+	{0x5836, 0x17},
+	{0x5837, 0x23},
+	{0x5838, 0x35},
+	{0x5839, 0x1F},
+	{0x583a, 0x16},
+	{0x583b, 0x12},
+	{0x583c, 0x14},
+	{0x583d, 0x19},
+	{0x583e, 0x26},
+	{0x583f, 0x3D},
+	{0x5840, 0xF },
+	{0x5841, 0xE },
+	{0x5842, 0xD },
+	{0x5843, 0xD },
+	{0x5844, 0xE },
+	{0x5845, 0x10},
+	{0x5846, 0xF },
+	{0x5847, 0xE },
+	{0x5848, 0xE },
+	{0x5849, 0xE },
+	{0x584a, 0xE },
+	{0x584b, 0xD },
+	{0x584c, 0xE },
+	{0x584d, 0xF },
+	{0x584e, 0x10},
+	{0x584f, 0xF },
+	{0x5850, 0xF },
+	{0x5851, 0xD },
+	{0x5852, 0xE },
+	{0x5853, 0xF },
+	{0x5854, 0xF },
+	{0x5855, 0xF },
+	{0x5856, 0xF },
+	{0x5857, 0xD },
+	{0x5858, 0x10},
+	{0x5859, 0xE },
+	{0x585a, 0xF },
+	{0x585b, 0xF },
+	{0x585c, 0xE },
+	{0x585d, 0xD },
+	{0x585e, 0xD },
+	{0x585f, 0xC },
+	{0x5860, 0xB },
+	{0x5861, 0xC },
+	{0x5862, 0xC },
+	{0x5863, 0xD },
+	{0x5864, 0x12},
+	{0x5865, 0x13},
+	{0x5866, 0x14},
+	{0x5867, 0x14},
+	{0x5868, 0x12},
+	{0x5869, 0x11},
+	{0x586a, 0x14},
+	{0x586b, 0x11},
+	{0x586c, 0x10},
+	{0x586d, 0x10},
+	{0x586e, 0x11},
+	{0x586f, 0x14},
+	{0x5870, 0x14},
+	{0x5871, 0xF },
+	{0x5872, 0xF },
+	{0x5873, 0xF },
+	{0x5874, 0xF },
+	{0x5875, 0x12},
+	{0x5876, 0x14},
+	{0x5877, 0xF },
+	{0x5878, 0xF },
+	{0x5879, 0xF },
+	{0x587a, 0xF },
+	{0x587b, 0x13},
+	{0x587c, 0x14},
+	{0x587d, 0x12},
+	{0x587e, 0x10},
+	{0x587f, 0x10},
+	{0x5880, 0x11},
+	{0x5881, 0x13},
+	{0x5882, 0x13},
+	{0x5883, 0x13},
+	{0x5884, 0x16},
+	{0x5885, 0x16},
+	{0x5886, 0x13},
+	{0x5887, 0x13},
+
+	{0x3710, 0x10},
+	{0x3632, 0x51},
+	{0x3702, 0x10},
+	{0x3703, 0xb2},
+	{0x3704, 0x18},
+	{0x370b, 0x40},
+	{0x370d, 0x03},
+	{0x3631, 0x01},
+	{0x3632, 0x52},
+	{0x3606, 0x24},
+	{0x3620, 0x96},
+	{0x5785, 0x07},
+	{0x3a13, 0x30},
+	{0x3600, 0x52},
+	{0x3604, 0x48},
+	{0x3606, 0x1b},
+	{0x370d, 0x0b},
+	{0x370f, 0xc0},
+	{0x3709, 0x01},
+	{0x3823, 0x00},
+	{0x5007, 0x00},
+	{0x5009, 0x00},
+	{0x5011, 0x00},
+	{0x5013, 0x00},
+	{0x519e, 0x00},
+	{0x5086, 0x00},
+	{0x5087, 0x00},
+	{0x5088, 0x00},
+	{0x5089, 0x00},
+	{0x302b, 0x00},
+
+	{0x4740, 0x20},
+	{0x3c00, 0x04},
+	{0x3012, 0x00},
+
+	//denoise YUV
+	{0x528a, 0x02},
+	{0x528b, 0x06},
+	{0x528c, 0x20},
+	{0x528d, 0x30},
+	{0x528e, 0x40},
+	{0x528f, 0x50},
+	{0x5290, 0x60},
+	{0x5292, 0x00},
+	{0x5293, 0x02},
+	{0x5294, 0x00},
+	{0x5295, 0x04},
+	{0x5296, 0x00},
+	{0x5297, 0x08},
+	{0x5298, 0x00},
+	{0x5299, 0x10},
+	{0x529a, 0x00},
+	{0x529b, 0x20},
+	{0x529c, 0x00},
+	{0x529d, 0x28},
+	{0x529e, 0x00},
+	{0x529f, 0x30},
+	{0x5282, 0x00},
+
+	{0x350b, 0x0f},
+	{0x3a19, 0x00},
+	{0x3001, 0x48},
+	{0x3002, 0x5c},
+	{0x3003, 0x02},
+	{0x3004, 0xFF},
+	{0x3005, 0xb7},
+	{0x3006, 0x43},
+	{0x3007, 0x37},
+	{0x3a19, 0xff},
+	{0x350c, 0x07},
+	{0x350d, 0xd0},
+	{0x3602, 0xfc},
+	{0x3612, 0xff},
+	{0x3613, 0x00},
+	{0x3621, 0x87},
+	{0x3622, 0x60},
+	{0x3623, 0x01},
+	{0x3604, 0x48},
+	{0x3705, 0xdb},
+	{0x370a, 0x81},
+	{0x3801, 0x50},
+	{0x3803, 0x08},
+	{0x3804, 0x05},
+	{0x3805, 0x00},
+	{0x3806, 0x03},
+	{0x3807, 0xc0},
+	{0x3808, 0x01},
+	{0x3809, 0x40},
+	{0x380a, 0x00},
+	{0x380b, 0xf0},
+	{0x380c, 0x0c},
+	{0x380d, 0x80},
+
+	{0x380E, 0x03},
+	{0x380F, 0xe8},
+
+	{0x3810, 0x40},
+	{0x3824, 0x11},
+	{0x3827, 0x08},
+	{0x3a00, 0x78},
+	{0x3a0d, 0x08},
+	{0x3a0e, 0x06},
+	{0x3a11, 0xd0},
+	{0x3a1f, 0x40},
+	{0x460b, 0x37},
+	{0x471d, 0x05},
+	{0x4713, 0x02},
+	{0x471c, 0xd0},
+	{0x5001, 0xff},
+	{0x589b, 0x04},
+	{0x589a, 0xc5},
+	{0x4407, 0x0c},
+	{0x3002, 0x5c},
+	{0x3002, 0x5c},
+	{0x3503, 0x00},
+	{0x460c, 0x22},
+	{0x460b, 0x37},
+	{0x471c, 0xd0},
+	{0x471d, 0x05},
+	{0x3818, 0xc1},
+	{0x501f, 0x00},
+	{0x3002, 0x5c},
+	{0x3819, 0x80},
+	{0x5002, 0xe0},
+	{0x3503, 0x00},
+	//ex weight
+	{0x5688, 0x11},
+	{0x5689, 0x11},
+	{0x568a, 0x11},
+	{0x568b, 0x11},
+	{0x568c, 0x11},
+	{0x568d, 0x11},
+	{0x568e, 0x11},
+	{0x568f, 0x11},
+
+	{0x350b, 0x3f},
+	{0x3503, 0x00},
+	{0x3a19, 0x7c},
+	//ex window
+	{0x5680, 0x00},
+	{0x5681, 0x00},
+	{0x5682, 0x05},
+	{0x5683, 0x00},
+	{0x5684, 0x00},
+	{0x5685, 0x00},
+	{0x5686, 0x03},
+	{0x5687, 0xc0},
+
+	//awb 20100205 kenxu
+	{0x5180, 0xff},
+	{0x5181, 0x52},
+	{0x5182, 0x11},
+	{0x5183, 0x14},
+	{0x5184, 0x25},
+	{0x5185, 0x24},
+	{0x5186, 0x0c},
+	{0x5187, 0x16},
+	{0x5188, 0x10},
+	{0x5189, 0x64},
+	{0x518a, 0x69},
+	{0x518b, 0xff},
+	{0x518c, 0x84},
+	{0x518d, 0x3b},
+	{0x518e, 0x41},
+	{0x518f, 0x4f},
+	{0x5190, 0x50},
+	{0x5191, 0xf8},
+	{0x5192, 0x04},
+	{0x5193, 0x70},
+	{0x5194, 0xf0},
+	{0x5195, 0xf0},
+	{0x5196, 0x03},
+	{0x5197, 0x01},
+	{0x5198, 0x06},
+	{0x5199, 0x12},
+	{0x519a, 0x04},
+	{0x519b, 0x00},
+	{0x519c, 0x05},
+	{0x519d, 0x9b},
+	{0x519e, 0x00},
+
+	//ken modify 20091208
+
+	{0x3010, 0x10},
+	{0x3815, 0x07}, //24M DVP CLOCK
+
+	//AEC/AGC setting
+	//Make sure use AEC/AGC source before gamma (0x5025 = 0x80)
+	{0x5025, 0x80},
+	{0x3a0f, 0x48},
+	{0x3a10, 0x40},
+	{0x3a1b, 0x4a},
+	{0x3a1e, 0x3e},
+	{0x3a11, 0x70},
+	{0x3a1f, 0x20},
+
+	//Gamma related setting
+	{0x54B0, 0x1 }, //ADD
+	{0x54B1, 0x20},
+	{0x54B2, 0x0},
+	{0x54B3, 0x10},
+	{0x54B4, 0x0},
+	{0x54B5, 0xf0},
+	{0x54B6, 0x0},
+	{0x54B7, 0xDF},
+
+	//De-noise setting
+	{0x5317, 0x00}, //08
+
+	//Auto Sharpness    +1
+	{0x530c, 0x04},
+	{0x530d, 0x18},
+	{0x5312, 0x20},
+
+	{0xffff, 0xff},
+};
+
+
+const struct sensor_reg  ov5642_res_5M[] = {
+	/* 2592 x 1944 */
+	{0x5001 , 0xcf},
+	{0x3808 , 0x0a},
+	{0x3809 , 0x20},
+	{0x380a , 0x07},
+	{0x380b , 0x98},
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg   ov5642_res_1080P[] = {
+	/* 1920x1080 */
+	{0x5001, 0xff},
+	{0x3808 ,0x07},
+	{0x3809 ,0x80},
+	{0x380a ,0x04},
+	{0x380b ,0x38},
+
+	{0xFFFF, 0xFF}
+};
+
+const struct sensor_reg   ov5642_res_720P[] = {
+	/* 1280x720 */
+	{0x5001, 0xff},
+	{0x3808 ,0x05},
+	{0x3809 ,0x00},
+	{0x380a ,0x02},
+	{0x380b ,0xd0},
+
+	{0xFFFF, 0xFF}
+};
+
+
+const struct sensor_reg ov5642_dvp_zoom8[] =
+{
+
+	{0x3800 ,0x5 },
+	{0x3801 ,0xf8},
+	{0x3802 ,0x3 },
+	{0x3803 ,0x5c},
+	{0x3804 ,0x1 },
+	{0x3805 ,0x44},
+	{0x3806 ,0x0 },
+	{0x3807 ,0xf0},
+	{0x3808 ,0x1 },
+	{0x3809 ,0x40},
+	{0x380a ,0x0 },
+	{0x380b ,0xf0},
+	{0x380c ,0xc },
+	{0x380d ,0x80},
+	{0x380e ,0x7 },
+	{0x380f ,0xd0},
+	
+	{0x5001 ,0x7f},
+	{0x5680 ,0x0 },
+	{0x5681 ,0x0 },
+	{0x5682 ,0x1 },
+	{0x5683 ,0x44},
+	{0x5684 ,0x0 },
+	{0x5685 ,0x0 },
+	{0x5686 ,0x0 },
+	{0x5687 ,0xf3},
+	/*
+	{0x381c ,0x21},
+	{0x3524 ,0x0 },
+	{0x3825 ,0x0 },
+	{0x3826 ,0x0 },
+	{0x3827 ,0x0 },
+	{0x3010 ,0x70},
+*/
+
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg OV5642_RGB_QVGA[] =
+{
+	
+	{0x3103 ,0x93},
+	{0x3008 ,0x82},
+	{0x3017 ,0x7f},
+	{0x3018 ,0xfc},
+	{0x3810 ,0xc2},
+	{0x3615 ,0xf0},
+	{0x3000 ,0x00},
+	{0x3001 ,0x00},
+	{0x3002 ,0x5c},
+	{0x3003 ,0x00},
+	{0x3004 ,0xff},
+	{0x3005 ,0xff},
+	{0x3006 ,0x43},
+	{0x3007 ,0x37},
+	{0x3011 ,0x08},
+	{0x3010 ,0x10},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x370c ,0xa0},
+	{0x3602 ,0xfc},
+	{0x3612 ,0xff},
+	{0x3634 ,0xc0},
+	{0x3613 ,0x00},
+	{0x3605 ,0x7c},
+	{0x3621 ,0x09},
+	{0x3622 ,0x60},
+	{0x3604 ,0x40},
+	{0x3603 ,0xa7},
+	{0x3603 ,0x27},
+	{0x4000 ,0x21},
+	{0x401d ,0x22},
+	{0x3600 ,0x54},
+	{0x3605 ,0x04},
+	{0x3606 ,0x3f},
+	{0x3c01 ,0x80},
+	{0x5000 ,0x4f},
+	{0x5020 ,0x04},
+	{0x5181 ,0x79},
+	{0x5182 ,0x00},
+	{0x5185 ,0x22},
+	{0x5197 ,0x01},
+	{0x5001 ,0xff},
+	{0x5500 ,0x0a},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	{0x5080 ,0x08},
+	{0x300e ,0x18},
+	{0x4610 ,0x00},
+	{0x471d ,0x05},
+	{0x4708 ,0x06},
+	{0x3808 ,0x02},
+	{0x3809 ,0x80},
+	{0x380a ,0x01},
+	{0x380b ,0xe0},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x501f ,0x00},
+	{0x5000 ,0x4f},
+	{0x4300 ,0x30},
+	{0x3503 ,0x07},
+	{0x3501 ,0x73},
+	{0x3502 ,0x80},
+	{0x350b ,0x00},
+	{0x3503 ,0x07},
+	{0x3824 ,0x11},
+	{0x3501 ,0x1e},
+	{0x3502 ,0x80},
+	{0x350b ,0x7f},
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x03},
+	{0x380f ,0xe8},
+	{0x3a0d ,0x04},
+	{0x3a0e ,0x03},
+	{0x3818 ,0xc1},
+	{0x3705 ,0xdb},
+	{0x370a ,0x81},
+	{0x3801 ,0x80},
+	{0x3621 ,0x87},
+	{0x3801 ,0x50},
+	{0x3803 ,0x08},
+	{0x3827 ,0x08},
+	{0x3810 ,0x40},
+	{0x3804 ,0x05},
+	{0x3805 ,0x00},
+	{0x5682 ,0x05},
+	{0x5683 ,0x00},
+	{0x3806 ,0x03},
+	{0x3807 ,0xc0},
+	{0x5686 ,0x03},
+	{0x5687 ,0xbc},
+	{0x3a00 ,0x78},
+	{0x3a1a ,0x05},
+	{0x3a13 ,0x30},
+	{0x3a18 ,0x00},
+	{0x3a19 ,0x7c},
+	{0x3a08 ,0x12},
+	{0x3a09 ,0xc0},
+	{0x3a0a ,0x0f},
+	{0x3a0b ,0xa0},
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x3500 ,0x00},
+	{0x3501 ,0x00},
+	{0x3502 ,0x00},
+	{0x350a ,0x00},
+	{0x350b ,0x00},
+	{0x3503 ,0x00},
+	{0x528a ,0x02},
+	{0x528b ,0x04},
+	{0x528c ,0x08},
+	{0x528d ,0x08},
+	{0x528e ,0x08},
+	{0x528f ,0x10},
+	{0x5290 ,0x10},
+	{0x5292 ,0x00},
+	{0x5293 ,0x02},
+	{0x5294 ,0x00},
+	{0x5295 ,0x02},
+	{0x5296 ,0x00},
+	{0x5297 ,0x02},
+	{0x5298 ,0x00},
+	{0x5299 ,0x02},
+	{0x529a ,0x00},
+	{0x529b ,0x02},
+	{0x529c ,0x00},
+	{0x529d ,0x02},
+	{0x529e ,0x00},
+	{0x529f ,0x02},
+	{0x3030 ,0x2b},
+	{0x3a02 ,0x00},
+	{0x3a03 ,0x7d},
+	{0x3a04 ,0x00},
+	{0x3a14 ,0x00},
+	{0x3a15 ,0x7d},
+	{0x3a16 ,0x00},
+	{0x3a00 ,0x78},
+	{0x3a08 ,0x09},
+	{0x3a09 ,0x60},
+	{0x3a0a ,0x07},
+	{0x3a0b ,0xd0},
+	{0x3a0d ,0x08},
+	{0x3a0e ,0x06},
+	{0x5193 ,0x70},
+	{0x589b ,0x04},
+	{0x589a ,0xc5},
+	{0x401e ,0x20},
+	{0x4001 ,0x42},
+	{0x401c ,0x04},
+	{0x528a ,0x01},
+	{0x528b ,0x04},
+	{0x528c ,0x08},
+	{0x528d ,0x10},
+	{0x528e ,0x20},
+	{0x528f ,0x28},
+	{0x5290 ,0x30},
+	{0x5292 ,0x00},
+	{0x5293 ,0x01},
+	{0x5294 ,0x00},
+	{0x5295 ,0x04},
+	{0x5296 ,0x00},
+	{0x5297 ,0x08},
+	{0x5298 ,0x00},
+	{0x5299 ,0x10},
+	{0x529a ,0x00},
+	{0x529b ,0x20},
+	{0x529c ,0x00},
+	{0x529d ,0x28},
+	{0x529e ,0x00},
+	{0x529f ,0x30},
+	{0x5282 ,0x00},
+	{0x5300 ,0x00},
+	{0x5301 ,0x20},
+	{0x5302 ,0x00},
+	{0x5303 ,0x7c},
+	{0x530c ,0x00},
+	{0x530d ,0x0c},
+	{0x530e ,0x20},
+	{0x530f ,0x80},
+	{0x5310 ,0x20},
+	{0x5311 ,0x80},
+	{0x5308 ,0x20},
+	{0x5309 ,0x40},
+	{0x5304 ,0x00},
+	{0x5305 ,0x30},
+	{0x5306 ,0x00},
+	{0x5307 ,0x80},
+	{0x5314 ,0x08},
+	{0x5315 ,0x20},
+	{0x5319 ,0x30},
+	{0x5316 ,0x10},
+	{0x5317 ,0x00},
+	{0x5318 ,0x02},
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	{0x3406 ,0x00},
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x06},
+	{0x5187 ,0x08},
+	{0x5188 ,0x08},
+	{0x5189 ,0x7c},
+	{0x518a ,0x60},
+	{0x518b ,0xb2},
+	{0x518c ,0xb2},
+	{0x518d ,0x44},
+	{0x518e ,0x3d},
+	{0x518f ,0x58},
+	{0x5190 ,0x46},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x04},
+	{0x5199 ,0x12},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0x82},
+	{0x519e ,0x00},
+	{0x5025 ,0x80},
+	{0x5583 ,0x40},
+	{0x5584 ,0x40},
+	{0x5580 ,0x02},
+	{0x5000 ,0xcf},
+	{0x3710 ,0x10},
+	{0x3632 ,0x51},
+	{0x3702 ,0x10},
+	{0x3703 ,0xb2},
+	{0x3704 ,0x18},
+	{0x370b ,0x40},
+	{0x370d ,0x03},
+	{0x3631 ,0x01},
+	{0x3632 ,0x52},
+	{0x3606 ,0x24},
+	{0x3620 ,0x96},
+	{0x5785 ,0x07},
+	{0x3a13 ,0x30},
+	{0x3600 ,0x52},
+	{0x3604 ,0x48},
+	{0x3606 ,0x1b},
+	{0x370d ,0x0b},
+	{0x370f ,0xc0},
+	{0x3709 ,0x01},
+	{0x3823 ,0x00},
+	{0x5007 ,0x00},
+	{0x5009 ,0x00},
+	{0x5011 ,0x00},
+	{0x5013 ,0x00},
+	{0x519e ,0x00},
+	{0x5086 ,0x00},
+	{0x5087 ,0x00},
+	{0x5088 ,0x00},
+	{0x5089 ,0x00},
+	{0x302b ,0x00},
+	{0x3808 ,0x01},
+	{0x3809 ,0x40},
+	{0x380a ,0x00},
+	{0x380b ,0xf0},
+	{0x3a00 ,0x78},
+	{0x5001 ,0xFF},
+	{0x5583 ,0x50},
+	{0x5584 ,0x50},
+	{0x5580 ,0x02},
+	{0x3c01 ,0x80},
+	{0x3c00 ,0x04},
+	//;LENS
+	{0x5800 ,0x48},
+	{0x5801 ,0x31},
+	{0x5802 ,0x21},
+	{0x5803 ,0x1b},
+	{0x5804 ,0x1a},
+	{0x5805 ,0x1e},
+	{0x5806 ,0x29},
+	{0x5807 ,0x38},
+	{0x5808 ,0x26},
+	{0x5809 ,0x17},
+	{0x580a ,0x11},
+	{0x580b ,0xe },
+	{0x580c ,0xd },
+	{0x580d ,0xe },
+	{0x580e ,0x13},
+	{0x580f ,0x1a},
+	{0x5810 ,0x15},
+	{0x5811 ,0xd },
+	{0x5812 ,0x8 },
+	{0x5813 ,0x5 },
+	{0x5814 ,0x4 },
+	{0x5815 ,0x5 },
+	{0x5816 ,0x9 },
+	{0x5817 ,0xd },
+	{0x5818 ,0x11},
+	{0x5819 ,0xa },
+	{0x581a ,0x4 },
+	{0x581b ,0x0 },
+	{0x581c ,0x0 },
+	{0x581d ,0x1 },
+	{0x581e ,0x6 },
+	{0x581f ,0x9 },
+	{0x5820 ,0x12},
+	{0x5821 ,0xb },
+	{0x5822 ,0x4 },
+	{0x5823 ,0x0 },
+	{0x5824 ,0x0 },
+	{0x5825 ,0x1 },
+	{0x5826 ,0x6 },
+	{0x5827 ,0xa },
+	{0x5828 ,0x17},
+	{0x5829 ,0xf },
+	{0x582a ,0x9 },
+	{0x582b ,0x6 },
+	{0x582c ,0x5 },
+	{0x582d ,0x6 },
+	{0x582e ,0xa },
+	{0x582f ,0xe },
+	{0x5830 ,0x28},
+	{0x5831 ,0x1a},
+	{0x5832 ,0x11},
+	{0x5833 ,0xe },
+	{0x5834 ,0xe },
+	{0x5835 ,0xf },
+	{0x5836 ,0x15},
+	{0x5837 ,0x1d},
+	{0x5838 ,0x6e},
+	{0x5839 ,0x39},
+	{0x583a ,0x27},
+	{0x583b ,0x1f},
+	{0x583c ,0x1e},
+	{0x583d ,0x23},
+	{0x583e ,0x2f},
+	{0x583f ,0x41},
+	{0x5840 ,0xe },
+	{0x5841 ,0xc },
+	{0x5842 ,0xd },
+	{0x5843 ,0xc },
+	{0x5844 ,0xc },
+	{0x5845 ,0xc },
+	{0x5846 ,0xc },
+	{0x5847 ,0xc },
+	{0x5848 ,0xd },
+	{0x5849 ,0xe },
+	{0x584a ,0xe },
+	{0x584b ,0xa },
+	{0x584c ,0xe },
+	{0x584d ,0xe },
+	{0x584e ,0x10},
+	{0x584f ,0x10},
+	{0x5850 ,0x11},
+	{0x5851 ,0xa },
+	{0x5852 ,0xf },
+	{0x5853 ,0xe },
+	{0x5854 ,0x10},
+	{0x5855 ,0x10},
+	{0x5856 ,0x10},
+	{0x5857 ,0xa },
+	{0x5858 ,0xe },
+	{0x5859 ,0xe },
+	{0x585a ,0xf },
+	{0x585b ,0xf },
+	{0x585c ,0xf },
+	{0x585d ,0xa },
+	{0x585e ,0x9 },
+	{0x585f ,0xd },
+	{0x5860 ,0xc },
+	{0x5861 ,0xb },
+	{0x5862 ,0xd },
+	{0x5863 ,0x7 },
+	{0x5864 ,0x17},
+	{0x5865 ,0x14},
+	{0x5866 ,0x18},
+	{0x5867 ,0x18},
+	{0x5868 ,0x16},
+	{0x5869 ,0x12},
+	{0x586a ,0x1b},
+	{0x586b ,0x1a},
+	{0x586c ,0x16},
+	{0x586d ,0x16},
+	{0x586e ,0x18},
+	{0x586f ,0x1f},
+	{0x5870 ,0x1c},
+	{0x5871 ,0x16},
+	{0x5872 ,0x10},
+	{0x5873 ,0xf },
+	{0x5874 ,0x13},
+	{0x5875 ,0x1c},
+	{0x5876 ,0x1e},
+	{0x5877 ,0x17},
+	{0x5878 ,0x11},
+	{0x5879 ,0x11},
+	{0x587a ,0x14},
+	{0x587b ,0x1e},
+	{0x587c ,0x1c},
+	{0x587d ,0x1c},
+	{0x587e ,0x1a},
+	{0x587f ,0x1a},
+	{0x5880 ,0x1b},
+	{0x5881 ,0x1f},
+	{0x5882 ,0x14},
+	{0x5883 ,0x1a},
+	{0x5884 ,0x1d},
+	{0x5885 ,0x1e},
+	{0x5886 ,0x1a},
+	{0x5887 ,0x1a},
+	//;AWB
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x14},
+	{0x5187 ,0x14},
+	{0x5188 ,0x14},
+	{0x5189 ,0x69},
+	{0x518a ,0x60},
+	{0x518b ,0xa2},
+	{0x518c ,0x9c},
+	{0x518d ,0x36},
+	{0x518e ,0x34},
+	{0x518f ,0x54},
+	{0x5190 ,0x4c},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x05},
+	{0x5199 ,0x2f},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0xa0},
+	{0x519e ,0xa0},
+	//;D/S
+	{0x528a ,0x00},
+	{0x528b ,0x01},
+	{0x528c ,0x04},
+	{0x528d ,0x08},
+	{0x528e ,0x10},
+	{0x528f ,0x20},
+	{0x5290 ,0x30},
+	{0x5292 ,0x00},
+	{0x5293 ,0x00},
+	{0x5294 ,0x00},
+	{0x5295 ,0x01},
+	{0x5296 ,0x00},
+	{0x5297 ,0x04},
+	{0x5298 ,0x00},
+	{0x5299 ,0x08},
+	{0x529a ,0x00},
+	{0x529b ,0x10},
+	{0x529c ,0x00},
+	{0x529d ,0x20},
+	{0x529e ,0x00},
+	{0x529f ,0x30},
+	{0x5282 ,0x00},
+	{0x5300 ,0x00},
+	{0x5301 ,0x20},
+	{0x5302 ,0x00},
+	{0x5303 ,0x7c},
+	{0x530c ,0x00},
+	{0x530d ,0x10},
+	{0x530e ,0x20},
+	{0x530f ,0x80},
+	{0x5310 ,0x20},
+	{0x5311 ,0x80},
+	{0x5308 ,0x20},
+	{0x5309 ,0x40},
+	{0x5304 ,0x00},
+	{0x5305 ,0x30},
+	{0x5306 ,0x00},
+	{0x5307 ,0x80},
+	{0x5314 ,0x08},
+	{0x5315 ,0x20},
+	{0x5319 ,0x30},
+	{0x5316 ,0x10},
+	{0x5317 ,0x00},
+	{0x5318 ,0x02},
+	//;CMX
+	{0x5380 ,0x01},
+	{0x5381 ,0x00},
+	{0x5382 ,0x00},
+	{0x5383 ,0x1f},
+	{0x5384 ,0x00},
+	{0x5385 ,0x06},
+	{0x5386 ,0x00},
+	{0x5387 ,0x00},
+	{0x5388 ,0x00},
+	{0x5389 ,0xE1},
+	{0x538A ,0x00},
+	{0x538B ,0x2B},
+	{0x538C ,0x00},
+	{0x538D ,0x00},
+	{0x538E ,0x00},
+	{0x538F ,0x10},
+	{0x5390 ,0x00},
+	{0x5391 ,0xB3},
+	{0x5392 ,0x00},
+	{0x5393 ,0xA6},
+	{0x5394 ,0x08},
+	//;GAMMA
+	{0x5480 ,0x0c},
+	{0x5481 ,0x18},
+	{0x5482 ,0x2f},
+	{0x5483 ,0x55},
+	{0x5484 ,0x64},
+	{0x5485 ,0x71},
+	{0x5486 ,0x7d},
+	{0x5487 ,0x87},
+	{0x5488 ,0x91},
+	{0x5489 ,0x9a},
+	{0x548A ,0xaa},
+	{0x548B ,0xb8},
+	{0x548C ,0xcd},
+	{0x548D ,0xdd},
+	{0x548E ,0xea},
+	{0x548F ,0x1d},
+	{0x5490 ,0x05},
+	{0x5491 ,0x00},
+	{0x5492 ,0x04},
+	{0x5493 ,0x20},
+	{0x5494 ,0x03},
+	{0x5495 ,0x60},
+	{0x5496 ,0x02},
+	{0x5497 ,0xB8},
+	{0x5498 ,0x02},
+	{0x5499 ,0x86},
+	{0x549A ,0x02},
+	{0x549B ,0x5B},
+	{0x549C ,0x02},
+	{0x549D ,0x3B},
+	{0x549E ,0x02},
+	{0x549F ,0x1C},
+	{0x54A0 ,0x02},
+	{0x54A1 ,0x04},
+	{0x54A2 ,0x01},
+	{0x54A3 ,0xED},
+	{0x54A4 ,0x01},
+	{0x54A5 ,0xC5},
+	{0x54A6 ,0x01},
+	{0x54A7 ,0xA5},
+	{0x54A8 ,0x01},
+	{0x54A9 ,0x6C},
+	{0x54AA ,0x01},
+	{0x54AB ,0x41},
+	{0x54AC ,0x01},
+	{0x54AD ,0x20},
+	{0x54AE ,0x00},
+	{0x54AF ,0x16},
+	{0x54B0 ,0x01},
+	{0x54B1 ,0x20},
+	{0x54B2 ,0x00},
+	{0x54B3 ,0x10},
+	{0x54B4 ,0x00},
+	{0x54B5 ,0xf0},
+	{0x54B6 ,0x00},
+	{0x54B7 ,0xDF},
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	//;UV ADJUST
+	{0x5500 ,0x10},
+	{0x5502 ,0x00},
+	{0x5503 ,0x06},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	//;AE
+	{0x5025 ,0x80},
+	{0x3a0f ,0x30},
+	{0x3a10 ,0x28},
+	{0x3a1b ,0x30},
+	{0x3a1e ,0x28},
+	{0x3a11 ,0x61},
+	{0x3a1f ,0x10},
+	{0x5688 ,0xfd},
+	{0x5689 ,0xdf},
+	{0x568a ,0xfe},
+	{0x568b ,0xef},
+	{0x568c ,0xfe},
+	{0x568d ,0xef},
+	{0x568e ,0xaa},
+	{0x568f ,0xaa},
+	
+	{0x4740,0x21},
+	{0x501e,0x2a},
+	{0x5002,0xf8},
+	{0x501f,0x01},
+	{0x4300,0x61},
+
+	{0xffff,0xff},
+};        
+
+const struct sensor_reg OV5642_JPEG_Capture_QSXGA[] =
+{
+	// OV5642_ QSXGA _YUV7.5 fps
+	// 24 MHz input clock, 24Mhz pclk
+	// jpeg mode 7.5fps
+
+	{0x3503 ,0x07},	//AEC Manual Mode Control
+	{0x3000 ,0x00},	//SYSTEM RESET00
+	{0x3001 ,0x00},	//Reset for Individual Block
+	{0x3002 ,0x00},	//Reset for Individual Block
+	{0x3003 ,0x00},	//Reset for Individual Block
+	{0x3005 ,0xff},	//Clock Enable Control
+	{0x3006 ,0xff},	//Clock Enable Control
+	{0x3007 ,0x3f},	//Clock Enable Control
+	{0x350c ,0x07},	//AEC VTS Output high bits
+	{0x350d ,0xd0},	//AEC VTS Output low bits
+	{0x3602 ,0xe4},	//Analog Control Registers
+	{0x3612 ,0xac},	//Analog Control Registers
+	{0x3613 ,0x44},	//Analog Control Registers
+	{0x3621 ,0x27},	//Array Control 01
+	{0x3622 ,0x08},	//Analog Control Registers
+	{0x3623 ,0x22},	//Analog Control Registers
+	{0x3604 ,0x60},	//Analog Control Registers	
+	{0x3705 ,0xda},	//Analog Control Registers
+	{0x370a ,0x80},	//Analog Control Registers
+	{0x3801 ,0x8a},	//HS      
+	{0x3803 ,0x0a},	//VS      
+	{0x3804 ,0x0a},	//HW      
+	{0x3805 ,0x20},	//HW      
+	{0x3806 ,0x07},	//VH      
+	{0x3807 ,0x98},	//VH      
+	{0x3808 ,0x0a},	//DVPHO   
+	{0x3809 ,0x20},	//DVPHO   
+	{0x380a ,0x07},	//DVPVO   
+	{0x380b ,0x98},	//DVPVO   
+	{0x380c ,0x0c},	//HTS     
+	{0x380d ,0x80},	//HTS     
+	{0x380e ,0x07},	//VTS     
+	{0x380f ,0xd0},	//VTS     
+	{0x3810 ,0xc2},
+	{0x3815 ,0x44},
+	{0x3818 ,0xc8},	//Mirror NO, Compression enable
+	{0x3824 ,0x01},	//RSV 
+	{0x3827 ,0x0a},	//RSV
+	{0x3a00 ,0x78},	//AEC System Control 0
+	{0x3a0d ,0x10},	//60 Hz Max Bands in One Frame
+	{0x3a0e ,0x0d},	//50 Hz Max Bands in One Frame
+	{0x3a10 ,0x32},	//Stable Range Low Limit (enter)
+	{0x3a1b ,0x3c},	//Stable Range High Limit (go out)
+	{0x3a1e ,0x32},	//Stable Range Low Limit (go out)
+	{0x3a11 ,0x80},	//Step Manual Mode, Fast Zone High Limit
+	{0x3a1f ,0x20},	//Step Manual Mode, Fast Zone Low Limit
+	{0x3a00 ,0x78},	//AEC System Control 0
+	{0x460b ,0x35},	//RSV VFIFO Control 0B
+	{0x471d ,0x00},	//DVP CONTROL 1D
+	{0x4713 ,0x03},	//COMPRESSION MODE SELECT mode3
+	{0x471c ,0x50},	//RSV
+	{0x5682 ,0x0a},	//AVG X END
+	{0x5683 ,0x20},	//AVG X END
+	{0x5686 ,0x07},	//AVG Y END
+	{0x5687 ,0x98},	//AVG Y END
+	{0x5001 ,0x4f},	//ISP CONTROL 01, UV adjust/Line stretch/UV average/Color matrix/AWB enable
+	{0x589b ,0x00}, //RSV
+	{0x589a ,0xc0},	//RSV
+	{0x4407 ,0x08},	//COMPRESSION CTRL07 Bit[5:0]: Quantization scale  0x02
+	{0x589b ,0x00},	//RSV
+	{0x589a ,0xc0},	//RSV
+	{0x3002 ,0x0c},	//Reset for Individual Block, Reset SFIFO/compression
+	{0x3002 ,0x00},	//Reset for Individual Block
+	{0x3503 ,0x00},	//AEC Manual Mode Control, Auto enable
+	
+	{0xffff, 0xff},
+
+};
+
+const struct sensor_reg OV5642_VGA_preview_setting[] = 
+{
+
+	{0x3103 ,0x93},
+	{0x3008 ,0x82},
+	{0x3017 ,0x7f},
+	{0x3018 ,0xfc},
+	{0x3810 ,0xc2},
+	{0x3615 ,0xf0},
+	{0x3000 ,0x00},
+	{0x3001 ,0x00},
+	{0x3002 ,0x5c},
+	{0x3003 ,0x00},
+	{0x3004 ,0xff},
+	{0x3005 ,0xff},
+	{0x3006 ,0x43},
+	{0x3007 ,0x37},
+	{0x3011 ,0x08},
+	{0x3010 ,0x10},
+	{0x460c ,0x22},
+	{0x3815 ,0x04},
+	{0x370c ,0xa0},
+	{0x3602 ,0xfc},
+	{0x3612 ,0xff},
+	{0x3634 ,0xc0},
+	{0x3613 ,0x00},
+	{0x3605 ,0x7c},
+	{0x3621 ,0x09},
+	{0x3622 ,0x60},
+	{0x3604 ,0x40},
+	{0x3603 ,0xa7},
+	{0x3603 ,0x27},
+	{0x4000 ,0x21},
+	{0x401d ,0x22},
+	{0x3600 ,0x54},
+	{0x3605 ,0x04},
+	{0x3606 ,0x3f},
+	{0x3c01 ,0x80},
+	{0x5000 ,0x4f},
+	{0x5020 ,0x04},
+	{0x5181 ,0x79},
+	{0x5182 ,0x00},
+	{0x5185 ,0x22},
+	{0x5197 ,0x01},
+	{0x5001 ,0xff},
+	{0x5500 ,0x0a},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	{0x5080 ,0x08},
+	{0x300e ,0x18},
+	{0x4610 ,0x00},
+	{0x471d ,0x05},
+	{0x4708 ,0x06},
+	{0x3808 ,0x02},
+	{0x3809 ,0x80},
+	{0x380a ,0x01},
+	{0x380b ,0xe0},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x501f ,0x00},
+	{0x5000 ,0x4f},
+	{0x4300 ,0x30},
+	{0x3503 ,0x07},
+	{0x3501 ,0x73},
+	{0x3502 ,0x80},
+	{0x350b ,0x00},
+	{0x3503 ,0x07},
+	{0x3824 ,0x11},
+	{0x3501 ,0x1e},
+	{0x3502 ,0x80},
+	{0x350b ,0x7f},
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x03},
+	{0x380f ,0xe8},
+	{0x3a0d ,0x04},
+	{0x3a0e ,0x03},
+	{0x3818 ,0xc1},
+	{0x3705 ,0xdb},
+	{0x370a ,0x81},
+	{0x3801 ,0x80},
+	{0x3621 ,0x87},
+	{0x3801 ,0x50},
+	{0x3803 ,0x08},
+	{0x3827 ,0x08},
+	{0x3810 ,0x40},
+	{0x3804 ,0x05},
+	{0x3805 ,0x00},
+	{0x5682 ,0x05},
+	{0x5683 ,0x00},
+	{0x3806 ,0x03},
+	{0x3807 ,0xc0},
+	{0x5686 ,0x03},
+	{0x5687 ,0xbc},
+	{0x3a00 ,0x78},
+	{0x3a1a ,0x05},
+	{0x3a13 ,0x30},
+	{0x3a18 ,0x00},
+	{0x3a19 ,0x7c},
+	{0x3a08 ,0x12},
+	{0x3a09 ,0xc0},
+	{0x3a0a ,0x0f},
+	{0x3a0b ,0xa0},
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x3500 ,0x00},
+	{0x3501 ,0x00},
+	{0x3502 ,0x00},
+	{0x350a ,0x00},
+	{0x350b ,0x00},
+	{0x3503 ,0x00},
+	{0x528a ,0x02},
+	{0x528b ,0x04},
+	{0x528c ,0x08},
+	{0x528d ,0x08},
+	{0x528e ,0x08},
+	{0x528f ,0x10},
+	{0x5290 ,0x10},
+	{0x5292 ,0x00},
+	{0x5293 ,0x02},
+	{0x5294 ,0x00},
+	{0x5295 ,0x02},
+	{0x5296 ,0x00},
+	{0x5297 ,0x02},
+	{0x5298 ,0x00},
+	{0x5299 ,0x02},
+	{0x529a ,0x00},
+	{0x529b ,0x02},
+	{0x529c ,0x00},
+	{0x529d ,0x02},
+	{0x529e ,0x00},
+	{0x529f ,0x02},
+	{0x3030 ,0x2b},
+	{0x3a02 ,0x00},
+	{0x3a03 ,0x7d},
+	{0x3a04 ,0x00},
+	{0x3a14 ,0x00},
+	{0x3a15 ,0x7d},
+	{0x3a16 ,0x00},
+	{0x3a00 ,0x78},
+	{0x3a08 ,0x09},
+	{0x3a09 ,0x60},
+	{0x3a0a ,0x07},
+	{0x3a0b ,0xd0},
+	{0x3a0d ,0x08},
+	{0x3a0e ,0x06},
+	{0x5193 ,0x70},
+	{0x589b ,0x04},
+	{0x589a ,0xc5},
+	{0x401e ,0x20},
+	{0x4001 ,0x42},
+	{0x401c ,0x04},
+	{0x528a ,0x01},
+	{0x528b ,0x04},
+	{0x528c ,0x08},
+	{0x528d ,0x10},
+	{0x528e ,0x20},
+	{0x528f ,0x28},
+	{0x5290 ,0x30},
+	{0x5292 ,0x00},
+	{0x5293 ,0x01},
+	{0x5294 ,0x00},
+	{0x5295 ,0x04},
+	{0x5296 ,0x00},
+	{0x5297 ,0x08},
+	{0x5298 ,0x00},
+	{0x5299 ,0x10},
+	{0x529a ,0x00},
+	{0x529b ,0x20},
+	{0x529c ,0x00},
+	{0x529d ,0x28},
+	{0x529e ,0x00},
+	{0x529f ,0x30},
+	{0x5282 ,0x00},
+	{0x5300 ,0x00},
+	{0x5301 ,0x20},
+	{0x5302 ,0x00},
+	{0x5303 ,0x7c},
+	{0x530c ,0x00},
+	{0x530d ,0x0c},
+	{0x530e ,0x20},
+	{0x530f ,0x80},
+	{0x5310 ,0x20},
+	{0x5311 ,0x80},
+	{0x5308 ,0x20},
+	{0x5309 ,0x40},
+	{0x5304 ,0x00},
+	{0x5305 ,0x30},
+	{0x5306 ,0x00},
+	{0x5307 ,0x80},
+	{0x5314 ,0x08},
+	{0x5315 ,0x20},
+	{0x5319 ,0x30},
+	{0x5316 ,0x10},
+	{0x5317 ,0x00},
+	{0x5318 ,0x02},
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	{0x3406 ,0x00},
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x06},
+	{0x5187 ,0x08},
+	{0x5188 ,0x08},
+	{0x5189 ,0x7c},
+	{0x518a ,0x60},
+	{0x518b ,0xb2},
+	{0x518c ,0xb2},
+	{0x518d ,0x44},
+	{0x518e ,0x3d},
+	{0x518f ,0x58},
+	{0x5190 ,0x46},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x04},
+	{0x5199 ,0x12},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0x82},
+	{0x519e ,0x00},
+	{0x5025 ,0x80},
+	{0x5583 ,0x40},
+	{0x5584 ,0x40},
+	{0x5580 ,0x02},
+	{0x5000 ,0xcf},
+	{0x3710 ,0x10},
+	{0x3632 ,0x51},
+	{0x3702 ,0x10},
+	{0x3703 ,0xb2},
+	{0x3704 ,0x18},
+	{0x370b ,0x40},
+	{0x370d ,0x03},
+	{0x3631 ,0x01},
+	{0x3632 ,0x52},
+	{0x3606 ,0x24},
+	{0x3620 ,0x96},
+	{0x5785 ,0x07},
+	{0x3a13 ,0x30},
+	{0x3600 ,0x52},
+	{0x3604 ,0x48},
+	{0x3606 ,0x1b},
+	{0x370d ,0x0b},
+	{0x370f ,0xc0},
+	{0x3709 ,0x01},
+	{0x3823 ,0x00},
+	{0x5007 ,0x00},
+	{0x5009 ,0x00},
+	{0x5011 ,0x00},
+	{0x5013 ,0x00},
+	{0x519e ,0x00},
+	{0x5086 ,0x00},
+	{0x5087 ,0x00},
+	{0x5088 ,0x00},
+	{0x5089 ,0x00},
+	{0x302b ,0x00},
+	{0x5001 ,0xFF},
+	{0x5583 ,0x50},
+	{0x5584 ,0x50},
+	{0x5580 ,0x02},
+	{0x3c01 ,0x80},
+	{0x3c00 ,0x04},
+	//;LENS
+	{0x5800 ,0x48},
+	{0x5801 ,0x31},
+	{0x5802 ,0x21},
+	{0x5803 ,0x1b},
+	{0x5804 ,0x1a},
+	{0x5805 ,0x1e},
+	{0x5806 ,0x29},
+	{0x5807 ,0x38},
+	{0x5808 ,0x26},
+	{0x5809 ,0x17},
+	{0x580a ,0x11},
+	{0x580b ,0xe },
+	{0x580c ,0xd },
+	{0x580d ,0xe },
+	{0x580e ,0x13},
+	{0x580f ,0x1a},
+	{0x5810 ,0x15},
+	{0x5811 ,0xd },
+	{0x5812 ,0x8 },
+	{0x5813 ,0x5 },
+	{0x5814 ,0x4 },
+	{0x5815 ,0x5 },
+	{0x5816 ,0x9 },
+	{0x5817 ,0xd },
+	{0x5818 ,0x11},
+	{0x5819 ,0xa },
+	{0x581a ,0x4 },
+	{0x581b ,0x0 },
+	{0x581c ,0x0 },
+	{0x581d ,0x1 },
+	{0x581e ,0x6 },
+	{0x581f ,0x9 },
+	{0x5820 ,0x12},
+	{0x5821 ,0xb },
+	{0x5822 ,0x4 },
+	{0x5823 ,0x0 },
+	{0x5824 ,0x0 },
+	{0x5825 ,0x1 },
+	{0x5826 ,0x6 },
+	{0x5827 ,0xa },
+	{0x5828 ,0x17},
+	{0x5829 ,0xf },
+	{0x582a ,0x9 },
+	{0x582b ,0x6 },
+	{0x582c ,0x5 },
+	{0x582d ,0x6 },
+	{0x582e ,0xa },
+	{0x582f ,0xe },
+	{0x5830 ,0x28},
+	{0x5831 ,0x1a},
+	{0x5832 ,0x11},
+	{0x5833 ,0xe },
+	{0x5834 ,0xe },
+	{0x5835 ,0xf },
+	{0x5836 ,0x15},
+	{0x5837 ,0x1d},
+	{0x5838 ,0x6e},
+	{0x5839 ,0x39},
+	{0x583a ,0x27},
+	{0x583b ,0x1f},
+	{0x583c ,0x1e},
+	{0x583d ,0x23},
+	{0x583e ,0x2f},
+	{0x583f ,0x41},
+	{0x5840 ,0xe },
+	{0x5841 ,0xc },
+	{0x5842 ,0xd },
+	{0x5843 ,0xc },
+	{0x5844 ,0xc },
+	{0x5845 ,0xc },
+	{0x5846 ,0xc },
+	{0x5847 ,0xc },
+	{0x5848 ,0xd },
+	{0x5849 ,0xe },
+	{0x584a ,0xe },
+	{0x584b ,0xa },
+	{0x584c ,0xe },
+	{0x584d ,0xe },
+	{0x584e ,0x10},
+	{0x584f ,0x10},
+	{0x5850 ,0x11},
+	{0x5851 ,0xa },
+	{0x5852 ,0xf },
+	{0x5853 ,0xe },
+	{0x5854 ,0x10},
+	{0x5855 ,0x10},
+	{0x5856 ,0x10},
+	{0x5857 ,0xa },
+	{0x5858 ,0xe },
+	{0x5859 ,0xe },
+	{0x585a ,0xf },
+	{0x585b ,0xf },
+	{0x585c ,0xf },
+	{0x585d ,0xa },
+	{0x585e ,0x9 },
+	{0x585f ,0xd },
+	{0x5860 ,0xc },
+	{0x5861 ,0xb },
+	{0x5862 ,0xd },
+	{0x5863 ,0x7 },
+	{0x5864 ,0x17},
+	{0x5865 ,0x14},
+	{0x5866 ,0x18},
+	{0x5867 ,0x18},
+	{0x5868 ,0x16},
+	{0x5869 ,0x12},
+	{0x586a ,0x1b},
+	{0x586b ,0x1a},
+	{0x586c ,0x16},
+	{0x586d ,0x16},
+	{0x586e ,0x18},
+	{0x586f ,0x1f},
+	{0x5870 ,0x1c},
+	{0x5871 ,0x16},
+	{0x5872 ,0x10},
+	{0x5873 ,0xf },
+	{0x5874 ,0x13},
+	{0x5875 ,0x1c},
+	{0x5876 ,0x1e},
+	{0x5877 ,0x17},
+	{0x5878 ,0x11},
+	{0x5879 ,0x11},
+	{0x587a ,0x14},
+	{0x587b ,0x1e},
+	{0x587c ,0x1c},
+	{0x587d ,0x1c},
+	{0x587e ,0x1a},
+	{0x587f ,0x1a},
+	{0x5880 ,0x1b},
+	{0x5881 ,0x1f},
+	{0x5882 ,0x14},
+	{0x5883 ,0x1a},
+	{0x5884 ,0x1d},
+	{0x5885 ,0x1e},
+	{0x5886 ,0x1a},
+	{0x5887 ,0x1a},
+	//;AWB
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x14},
+	{0x5187 ,0x14},
+	{0x5188 ,0x14},
+	{0x5189 ,0x69},
+	{0x518a ,0x60},
+	{0x518b ,0xa2},
+	{0x518c ,0x9c},
+	{0x518d ,0x36},
+	{0x518e ,0x34},
+	{0x518f ,0x54},
+	{0x5190 ,0x4c},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x05},
+	{0x5199 ,0x2f},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0xa0},
+	{0x519e ,0xa0},
+	//;D/S
+	{0x528a ,0x00},
+	{0x528b ,0x01},
+	{0x528c ,0x04},
+	{0x528d ,0x08},
+	{0x528e ,0x10},
+	{0x528f ,0x20},
+	{0x5290 ,0x30},
+	{0x5292 ,0x00},
+	{0x5293 ,0x00},
+	{0x5294 ,0x00},
+	{0x5295 ,0x01},
+	{0x5296 ,0x00},
+	{0x5297 ,0x04},
+	{0x5298 ,0x00},
+	{0x5299 ,0x08},
+	{0x529a ,0x00},
+	{0x529b ,0x10},
+	{0x529c ,0x00},
+	{0x529d ,0x20},
+	{0x529e ,0x00},
+	{0x529f ,0x30},
+	{0x5282 ,0x00},
+	{0x5300 ,0x00},
+	{0x5301 ,0x20},
+	{0x5302 ,0x00},
+	{0x5303 ,0x7c},
+	{0x530c ,0x00},
+	{0x530d ,0x10},
+	{0x530e ,0x20},
+	{0x530f ,0x80},
+	{0x5310 ,0x20},
+	{0x5311 ,0x80},
+	{0x5308 ,0x20},
+	{0x5309 ,0x40},
+	{0x5304 ,0x00},
+	{0x5305 ,0x30},
+	{0x5306 ,0x00},
+	{0x5307 ,0x80},
+	{0x5314 ,0x08},
+	{0x5315 ,0x20},
+	{0x5319 ,0x30},
+	{0x5316 ,0x10},
+	{0x5317 ,0x00},
+	{0x5318 ,0x02},
+	//;CMX //color matrix    
+	{0x5380 ,0x01},
+	{0x5381 ,0x00},
+	{0x5382 ,0x00},
+	{0x5383 ,0x1f},
+	{0x5384 ,0x00},
+	{0x5385 ,0x06},
+	{0x5386 ,0x00},
+	{0x5387 ,0x00},
+	{0x5388 ,0x00},
+	{0x5389 ,0xE1},
+	{0x538A ,0x00},
+	{0x538B ,0x2B},
+	{0x538C ,0x00},
+	{0x538D ,0x00},
+	{0x538E ,0x00},
+	{0x538F ,0x10},
+	{0x5390 ,0x00},
+	{0x5391 ,0xB3},
+	{0x5392 ,0x00},
+	{0x5393 ,0xA6},
+	{0x5394 ,0x08},
+	//;GAMMA
+	{0x5480 ,0x0c},
+	{0x5481 ,0x18},
+	{0x5482 ,0x2f},
+	{0x5483 ,0x55},
+	{0x5484 ,0x64},
+	{0x5485 ,0x71},
+	{0x5486 ,0x7d},
+	{0x5487 ,0x87},
+	{0x5488 ,0x91},
+	{0x5489 ,0x9a},
+	{0x548A ,0xaa},
+	{0x548B ,0xb8},
+	{0x548C ,0xcd},
+	{0x548D ,0xdd},
+	{0x548E ,0xea},
+	{0x548F ,0x1d},
+	{0x5490 ,0x05},
+	{0x5491 ,0x00},
+	{0x5492 ,0x04},
+	{0x5493 ,0x20},
+	{0x5494 ,0x03},
+	{0x5495 ,0x60},
+	{0x5496 ,0x02},
+	{0x5497 ,0xB8},
+	{0x5498 ,0x02},
+	{0x5499 ,0x86},
+	{0x549A ,0x02},
+	{0x549B ,0x5B},
+	{0x549C ,0x02},
+	{0x549D ,0x3B},
+	{0x549E ,0x02},
+	{0x549F ,0x1C},
+	{0x54A0 ,0x02},
+	{0x54A1 ,0x04},
+	{0x54A2 ,0x01},
+	{0x54A3 ,0xED},
+	{0x54A4 ,0x01},
+	{0x54A5 ,0xC5},
+	{0x54A6 ,0x01},
+	{0x54A7 ,0xA5},
+	{0x54A8 ,0x01},
+	{0x54A9 ,0x6C},
+	{0x54AA ,0x01},
+	{0x54AB ,0x41},
+	{0x54AC ,0x01},
+	{0x54AD ,0x20},
+	{0x54AE ,0x00},
+	{0x54AF ,0x16},
+	{0x54B0 ,0x01},
+	{0x54B1 ,0x20},
+	{0x54B2 ,0x00},
+	{0x54B3 ,0x10},
+	{0x54B4 ,0x00},
+	{0x54B5 ,0xf0},
+	{0x54B6 ,0x00},
+	{0x54B7 ,0xDF},
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	//;UV ADJUST
+	{0x5500 ,0x10},
+	{0x5502 ,0x00},
+	{0x5503 ,0x06},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	//;AE
+	{0x5025 ,0x80},
+	{0x3a0f ,0x30},
+	{0x3a10 ,0x28},
+	{0x3a1b ,0x30},
+	{0x3a1e ,0x28},
+	{0x3a11 ,0x61},
+	{0x3a1f ,0x10},
+	{0x5688 ,0xfd},
+	{0x5689 ,0xdf},
+	{0x568a ,0xfe},
+	{0x568b ,0xef},
+	{0x568c ,0xfe},
+	{0x568d ,0xef},
+	{0x568e ,0xaa},
+	{0x568f ,0xaa},
+	
+	//SVGA preview
+	{0x3800 ,0x1 },
+	{0x3801 ,0x50},
+	{0x3802 ,0x0 },
+	{0x3803 ,0x8 },
+	{0x3804 ,0x5 },
+	{0x3805 ,0x0 },
+	{0x3806 ,0x3 },
+	{0x3807 ,0xc0},
+	{0x3808 ,0x3 },
+	{0x3809 ,0x20},
+	{0x380a ,0x2 },
+	{0x380b ,0x58},
+	{0x380c ,0xc },
+	{0x380d ,0x80},
+	{0x380e ,0x3 },
+	{0x380f ,0xe8},
+	{0x5001 ,0x7f},
+	{0x5680 ,0x0 },
+	{0x5681 ,0x0 },
+	{0x5682 ,0x5 },
+	{0x5683 ,0x0 },
+	{0x5684 ,0x0 },
+	{0x5685 ,0x0 },
+	{0x5686 ,0x3 },
+	{0x5687 ,0xc0},
+	{0x5687 ,0xc0},
+	{0x3815 ,0x02},
+
+
+	{0xffff, 0xff},
+};
+
+const struct sensor_reg OV5642_1080P_Video_setting[] = {
+
+	{0x3103 ,0x93},
+	{0x3008 ,0x82},
+	{0x3017 ,0x7f},
+	{0x3018 ,0xfc},
+	{0x3810 ,0xc2},
+	{0x3615 ,0xf0},
+	{0x3000 ,0x00},
+	{0x3001 ,0x00},
+	{0x3002 ,0x00},
+	{0x3003 ,0x00},
+	{0x3004 ,0xff},
+	{0x3030 ,0x2b},
+	{0x3011 ,0x08},
+	{0x3010 ,0x10},
+	{0x3604 ,0x60},
+	{0x3622 ,0x60},
+	{0x3621 ,0x09},
+	{0x3709 ,0x00},
+	{0x4000 ,0x21},
+	{0x401d ,0x22},
+	{0x3600 ,0x54},
+	{0x3605 ,0x04},
+	{0x3606 ,0x3f},
+	{0x3c01 ,0x80},
+	{0x300d ,0x22},
+	{0x3623 ,0x22},
+	{0x5000 ,0x4f},
+	{0x5020 ,0x04},
+	{0x5181 ,0x79},
+	{0x5182 ,0x00},
+	{0x5185 ,0x22},
+	{0x5197 ,0x01},
+	{0x5500 ,0x0a},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	{0x5080 ,0x08},
+	{0x300e ,0x18},
+	{0x4610 ,0x00},
+	{0x471d ,0x05},
+	{0x4708 ,0x06},
+	{0x370c ,0xa0},
+	{0x3808 ,0x0a},
+	{0x3809 ,0x20},
+	{0x380a ,0x07},
+	{0x380b ,0x98},
+	{0x380c ,0x0c},
+	{0x380d ,0x80},
+	{0x380e ,0x07},
+	{0x380f ,0xd0},
+	{0x5687 ,0x94},
+	{0x501f ,0x00},
+	{0x5000 ,0x4f},
+	{0x5001 ,0xcf},
+	{0x4300 ,0x30},
+	{0x4300 ,0x30},
+	{0x460b ,0x35},
+	{0x471d ,0x00},
+	{0x3002 ,0x0c},
+	{0x3002 ,0x00},
+	{0x4713 ,0x03},
+	{0x471c ,0x50},
+	{0x4721 ,0x02},
+	{0x4402 ,0x90},
+	{0x460c ,0x22},
+	{0x3815 ,0x44},
+	{0x3503 ,0x07},
+	{0x3501 ,0x73},
+	{0x3502 ,0x80},
+	{0x350b ,0x00},
+	{0x3818 ,0xc8},
+	{0x3801 ,0x88},
+	{0x3824 ,0x11},
+	{0x3a00 ,0x78},
+	{0x3a1a ,0x04},
+	{0x3a13 ,0x30},
+	{0x3a18 ,0x00},
+	{0x3a19 ,0x7c},
+	{0x3a08 ,0x12},
+	{0x3a09 ,0xc0},
+	{0x3a0a ,0x0f},
+	{0x3a0b ,0xa0},
+	{0x350c ,0x07},
+	{0x350d ,0xd0},
+	{0x3a0d ,0x08},
+	{0x3a0e ,0x06},
+	{0x3500 ,0x00},
+	{0x3501 ,0x00},
+	{0x3502 ,0x00},
+	{0x350a ,0x00},
+	{0x350b ,0x00},
+	{0x3503 ,0x00},
+	{0x3030 ,0x2b},
+	{0x3a02 ,0x00},
+	{0x3a03 ,0x7d},
+	{0x3a04 ,0x00},
+	{0x3a14 ,0x00},
+	{0x3a15 ,0x7d},
+	{0x3a16 ,0x00},
+	{0x3a00 ,0x78},
+	{0x3a08 ,0x09},
+	{0x3a09 ,0x60},
+	{0x3a0a ,0x07},
+	{0x3a0b ,0xd0},
+	{0x3a0d ,0x10},
+	{0x3a0e ,0x0d},
+	{0x4407 ,0x04},
+	{0x5193 ,0x70},
+	{0x589b ,0x00},
+	{0x589a ,0xc0},
+	{0x401e ,0x20},
+	{0x4001 ,0x42},
+	{0x401c ,0x06},
+	{0x3825 ,0xac},
+	{0x3827 ,0x0c},
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	{0x3406 ,0x00},
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x06},
+	{0x5187 ,0x08},
+	{0x5188 ,0x08},
+	{0x5189 ,0x7c},
+	{0x518a ,0x60},
+	{0x518b ,0xb2},
+	{0x518c ,0xb2},
+	{0x518d ,0x44},
+	{0x518e ,0x3d},
+	{0x518f ,0x58},
+	{0x5190 ,0x46},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x04},
+	{0x5199 ,0x12},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0x82},
+	{0x519e ,0x00},
+	{0x5025 ,0x80},
+	{0x5583 ,0x40},
+	{0x5584 ,0x40},
+	{0x5580 ,0x02},
+	{0x5000 ,0xcf},
+	{0x3710 ,0x10},
+	{0x3632 ,0x51},
+	{0x3702 ,0x10},
+	{0x3703 ,0xb2},
+	{0x3704 ,0x18},
+	{0x370b ,0x40},
+	{0x370d ,0x03},
+	{0x3631 ,0x01},
+	{0x3632 ,0x52},
+	{0x3606 ,0x24},
+	{0x3620 ,0x96},
+	{0x5785 ,0x07},
+	{0x3a13 ,0x30},
+	{0x3600 ,0x52},
+	{0x3604 ,0x48},
+	{0x3606 ,0x1b},
+	{0x370d ,0x0b},
+	{0x370f ,0xc0},
+	{0x3709 ,0x01},
+	{0x3823 ,0x00},
+	{0x5007 ,0x00},
+	{0x5009 ,0x00},
+	{0x5011 ,0x00},
+	{0x5013 ,0x00},
+	{0x519e ,0x00},
+	{0x5086 ,0x00},
+	{0x5087 ,0x00},
+	{0x5088 ,0x00},
+	{0x5089 ,0x00},
+	{0x302b ,0x00},
+	{0x3503 ,0x07},
+	{0x3011 ,0x07},
+	{0x350c ,0x04},
+	{0x350d ,0x58},
+	{0x3801 ,0x8a},
+	{0x3803 ,0x0a},
+	{0x3804 ,0x07},
+	{0x3805 ,0x80},
+	{0x3806 ,0x04},
+	{0x3807 ,0x38},
+	{0x3808 ,0x07},
+	{0x3809 ,0x80},
+	{0x380a ,0x04},
+	{0x380b ,0x38},
+	{0x380c ,0x09},
+	{0x380d ,0xd6},
+	{0x380e ,0x04},
+	{0x380f ,0x58},
+	{0x381c ,0x11},
+	{0x381d ,0xba},
+	{0x381e ,0x04},
+	{0x381f ,0x48},
+	{0x3820 ,0x04},
+	{0x3821 ,0x18},
+	{0x3a08 ,0x14},
+	{0x3a09 ,0xe0},
+	{0x3a0a ,0x11},
+	{0x3a0b ,0x60},
+	{0x3a0d ,0x04},
+	{0x3a0e ,0x03},
+	{0x5682 ,0x07},
+	{0x5683 ,0x60},
+	{0x5686 ,0x04},
+	{0x5687 ,0x1c},
+	{0x5001 ,0x7f},
+	{0x3503 ,0x00},
+	{0x3010 ,0x10},
+	{0x5001 ,0xFF},
+	{0x5583 ,0x50},
+	{0x5584 ,0x50},
+	{0x5580 ,0x02},
+	{0x3c01 ,0x80},
+	{0x3c00 ,0x04},
+	//LENS
+	{0x5800 ,0x48},
+	{0x5801 ,0x31},
+	{0x5802 ,0x21},
+	{0x5803 ,0x1b},
+	{0x5804 ,0x1a},
+	{0x5805 ,0x1e},
+	{0x5806 ,0x29},
+	{0x5807 ,0x38},
+	{0x5808 ,0x26},
+	{0x5809 ,0x17},
+	{0x580a ,0x11},
+	{0x580b ,0xe },
+	{0x580c ,0xd },
+	{0x580d ,0xe },
+	{0x580e ,0x13},
+	{0x580f ,0x1a},
+	{0x5810 ,0x15},
+	{0x5811 ,0xd },
+	{0x5812 ,0x8 },
+	{0x5813 ,0x5 },
+	{0x5814 ,0x4 },
+	{0x5815 ,0x5 },
+	{0x5816 ,0x9 },
+	{0x5817 ,0xd },
+	{0x5818 ,0x11},
+	{0x5819 ,0xa },
+	{0x581a ,0x4 },
+	{0x581b ,0x0 },
+	{0x581c ,0x0 },
+	{0x581d ,0x1 },
+	{0x581e ,0x6 },
+	{0x581f ,0x9 },
+	{0x5820 ,0x12},
+	{0x5821 ,0xb },
+	{0x5822 ,0x4 },
+	{0x5823 ,0x0 },
+	{0x5824 ,0x0 },
+	{0x5825 ,0x1 },
+	{0x5826 ,0x6 },
+	{0x5827 ,0xa },
+	{0x5828 ,0x17},
+	{0x5829 ,0xf },
+	{0x582a ,0x9 },
+	{0x582b ,0x6 },
+	{0x582c ,0x5 },
+	{0x582d ,0x6 },
+	{0x582e ,0xa },
+	{0x582f ,0xe },
+	{0x5830 ,0x28},
+	{0x5831 ,0x1a},
+	{0x5832 ,0x11},
+	{0x5833 ,0xe },
+	{0x5834 ,0xe },
+	{0x5835 ,0xf },
+	{0x5836 ,0x15},
+	{0x5837 ,0x1d},
+	{0x5838 ,0x6e},
+	{0x5839 ,0x39},
+	{0x583a ,0x27},
+	{0x583b ,0x1f},
+	{0x583c ,0x1e},
+	{0x583d ,0x23},
+	{0x583e ,0x2f},
+	{0x583f ,0x41},
+	{0x5840 ,0xe },
+	{0x5841 ,0xc },
+	{0x5842 ,0xd },
+	{0x5843 ,0xc },
+	{0x5844 ,0xc },
+	{0x5845 ,0xc },
+	{0x5846 ,0xc },
+	{0x5847 ,0xc },
+	{0x5848 ,0xd },
+	{0x5849 ,0xe },
+	{0x584a ,0xe },
+	{0x584b ,0xa },
+	{0x584c ,0xe },
+	{0x584d ,0xe },
+	{0x584e ,0x10},
+	{0x584f ,0x10},
+	{0x5850 ,0x11},
+	{0x5851 ,0xa },
+	{0x5852 ,0xf },
+	{0x5853 ,0xe },
+	{0x5854 ,0x10},
+	{0x5855 ,0x10},
+	{0x5856 ,0x10},
+	{0x5857 ,0xa },
+	{0x5858 ,0xe },
+	{0x5859 ,0xe },
+	{0x585a ,0xf },
+	{0x585b ,0xf },
+	{0x585c ,0xf },
+	{0x585d ,0xa },
+	{0x585e ,0x9 },
+	{0x585f ,0xd },
+	{0x5860 ,0xc },
+	{0x5861 ,0xb },
+	{0x5862 ,0xd },
+	{0x5863 ,0x7 },
+	{0x5864 ,0x17},
+	{0x5865 ,0x14},
+	{0x5866 ,0x18},
+	{0x5867 ,0x18},
+	{0x5868 ,0x16},
+	{0x5869 ,0x12},
+	{0x586a ,0x1b},
+	{0x586b ,0x1a},
+	{0x586c ,0x16},
+	{0x586d ,0x16},
+	{0x586e ,0x18},
+	{0x586f ,0x1f},
+	{0x5870 ,0x1c},
+	{0x5871 ,0x16},
+	{0x5872 ,0x10},
+	{0x5873 ,0xf },
+	{0x5874 ,0x13},
+	{0x5875 ,0x1c},
+	{0x5876 ,0x1e},
+	{0x5877 ,0x17},
+	{0x5878 ,0x11},
+	{0x5879 ,0x11},
+	{0x587a ,0x14},
+	{0x587b ,0x1e},
+	{0x587c ,0x1c},
+	{0x587d ,0x1c},
+	{0x587e ,0x1a},
+	{0x587f ,0x1a},
+	{0x5880 ,0x1b},
+	{0x5881 ,0x1f},
+	{0x5882 ,0x14},
+	{0x5883 ,0x1a},
+	{0x5884 ,0x1d},
+	{0x5885 ,0x1e},
+	{0x5886 ,0x1a},
+	{0x5887 ,0x1a},
+	//
+	//AWB
+	{0x5180 ,0xff},
+	{0x5181 ,0x52},
+	{0x5182 ,0x11},
+	{0x5183 ,0x14},
+	{0x5184 ,0x25},
+	{0x5185 ,0x24},
+	{0x5186 ,0x14},
+	{0x5187 ,0x14},
+	{0x5188 ,0x14},
+	{0x5189 ,0x69},
+	{0x518a ,0x60},
+	{0x518b ,0xa2},
+	{0x518c ,0x9c},
+	{0x518d ,0x36},
+	{0x518e ,0x34},
+	{0x518f ,0x54},
+	{0x5190 ,0x4c},
+	{0x5191 ,0xf8},
+	{0x5192 ,0x04},
+	{0x5193 ,0x70},
+	{0x5194 ,0xf0},
+	{0x5195 ,0xf0},
+	{0x5196 ,0x03},
+	{0x5197 ,0x01},
+	{0x5198 ,0x05},
+	{0x5199 ,0x2f},
+	{0x519a ,0x04},
+	{0x519b ,0x00},
+	{0x519c ,0x06},
+	{0x519d ,0xa0},
+	{0x519e ,0xa0},
+	//
+	//D/S
+	{0x528a ,0x00},
+	{0x528b ,0x01},
+	{0x528c ,0x04},
+	{0x528d ,0x08},
+	{0x528e ,0x10},
+	{0x528f ,0x20},
+	{0x5290 ,0x30},
+	{0x5292 ,0x00},
+	{0x5293 ,0x00},
+	{0x5294 ,0x00},
+	{0x5295 ,0x01},
+	{0x5296 ,0x00},
+	{0x5297 ,0x04},
+	{0x5298 ,0x00},
+	{0x5299 ,0x08},
+	{0x529a ,0x00},
+	{0x529b ,0x10},
+	{0x529c ,0x00},
+	{0x529d ,0x20},
+	{0x529e ,0x00},
+	{0x529f ,0x30},
+	{0x5282 ,0x00},
+	{0x5300 ,0x00},
+	{0x5301 ,0x20},
+	{0x5302 ,0x00},
+	{0x5303 ,0x7c},
+	{0x530c ,0x00},
+	{0x530d ,0x10},
+	{0x530e ,0x20},
+	{0x530f ,0x80},
+	{0x5310 ,0x20},
+	{0x5311 ,0x80},
+	{0x5308 ,0x20},
+	{0x5309 ,0x40},
+	{0x5304 ,0x00},
+	{0x5305 ,0x30},
+	{0x5306 ,0x00},
+	{0x5307 ,0x80},
+	{0x5314 ,0x08},
+	{0x5315 ,0x20},
+	{0x5319 ,0x30},
+	{0x5316 ,0x10},
+	{0x5317 ,0x00},
+	{0x5318 ,0x02},
+	//
+	//CMX //color matrix
+	{0x5380 ,0x01},
+	{0x5381 ,0x00},
+	{0x5382 ,0x00},
+	{0x5383 ,0x1f},
+	{0x5384 ,0x00},
+	{0x5385 ,0x06},
+	{0x5386 ,0x00},
+	{0x5387 ,0x00},
+	{0x5388 ,0x00},
+	{0x5389 ,0xE1},
+	{0x538A ,0x00},
+	{0x538B ,0x2B},
+	{0x538C ,0x00},
+	{0x538D ,0x00},
+	{0x538E ,0x00},
+	{0x538F ,0x10},
+	{0x5390 ,0x00},
+	{0x5391 ,0xB3},
+	{0x5392 ,0x00},
+	{0x5393 ,0xA6},
+	{0x5394 ,0x08},
+	//
+	//GAMMA
+	{0x5480 ,0x0c},
+	{0x5481 ,0x18},
+	{0x5482 ,0x2f},
+	{0x5483 ,0x55},
+	{0x5484 ,0x64},
+	{0x5485 ,0x71},
+	{0x5486 ,0x7d},
+	{0x5487 ,0x87},
+	{0x5488 ,0x91},
+	{0x5489 ,0x9a},
+	{0x548A ,0xaa},
+	{0x548B ,0xb8},
+	{0x548C ,0xcd},
+	{0x548D ,0xdd},
+	{0x548E ,0xea},
+	{0x548F ,0x1d},
+	{0x5490 ,0x05},
+	{0x5491 ,0x00},
+	{0x5492 ,0x04},
+	{0x5493 ,0x20},
+	{0x5494 ,0x03},
+	{0x5495 ,0x60},
+	{0x5496 ,0x02},
+	{0x5497 ,0xB8},
+	{0x5498 ,0x02},
+	{0x5499 ,0x86},
+	{0x549A ,0x02},
+	{0x549B ,0x5B},
+	{0x549C ,0x02},
+	{0x549D ,0x3B},
+	{0x549E ,0x02},
+	{0x549F ,0x1C},
+	{0x54A0 ,0x02},
+	{0x54A1 ,0x04},
+	{0x54A2 ,0x01},
+	{0x54A3 ,0xED},
+	{0x54A4 ,0x01},
+	{0x54A5 ,0xC5},
+	{0x54A6 ,0x01},
+	{0x54A7 ,0xA5},
+	{0x54A8 ,0x01},
+	{0x54A9 ,0x6C},
+	{0x54AA ,0x01},
+	{0x54AB ,0x41},
+	{0x54AC ,0x01},
+	{0x54AD ,0x20},
+	{0x54AE ,0x00},
+	{0x54AF ,0x16},
+	{0x54B0 ,0x01},
+	{0x54B1 ,0x20},
+	{0x54B2 ,0x00},
+	{0x54B3 ,0x10},
+	{0x54B4 ,0x00},
+	{0x54B5 ,0xf0},
+	{0x54B6 ,0x00},
+	{0x54B7 ,0xDF},
+	//
+	{0x5402 ,0x3f},
+	{0x5403 ,0x00},
+	//
+	//UV ADJUST
+	{0x5500 ,0x10},
+	{0x5502 ,0x00},
+	{0x5503 ,0x06},
+	{0x5504 ,0x00},
+	{0x5505 ,0x7f},
+	//AE
+	{0x5025 ,0x80},
+	{0x3a0f ,0x30},
+	{0x3a10 ,0x28},
+	{0x3a1b ,0x30},
+	{0x3a1e ,0x28},
+	{0x3a11 ,0x61},
+	{0x3a1f ,0x10},
+	{0x5688 ,0xfd},
+	{0x5689 ,0xdf},
+	{0x568a ,0xfe},
+	{0x568b ,0xef},
+	{0x568c ,0xfe},
+	{0x568d ,0xef},
+	{0x568e ,0xaa},
+	{0x568f ,0xaa},
+	
+	{0xffff, 0xff},
+};
+
+#endif
+
+
--- a/http/server/HttpSocket.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/http/server/HttpSocket.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -215,7 +215,7 @@
 
 int ClientSocketSend(long socket, char * buffer, unsigned int len)
 {
-  HttpDebug("\r\n ClientSocketSend\n\r");
+//  HttpDebug("\r\n ClientSocketSend\n\r");
   int send_len = 0, Ittr = 0;
 
   do
--- a/main.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/main.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -64,80 +64,12 @@
 
 using namespace mbed_cc3100;
 
-static void SystemClock_Config(void);
+extern DCMI_HandleTypeDef hdcmi;
+extern DMA_HandleTypeDef hdma_dcmi;
 
 void DCMI_IRQHandler(void);
 void DMA2_Stream1_IRQHandler(void);
 
-/** System Clock Configuration
-*/
-static void SystemClock_Config(void)
-{
-  
-//  SystemCoreClockUpdate();
-/*  
-  RCC_OscInitTypeDef RCC_OscInitStruct;
-  RCC_ClkInitTypeDef RCC_ClkInitStruct;
-//  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;//Used for ov7670 test
-  
-  __PWR_CLK_ENABLE();
-//  __GPIOH_CLK_ENABLE(); //Enable HSE Clock 8MHz 
-  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
-
-  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
-  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
-  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-  RCC_OscInitStruct.PLL.PLLM = 8;
-  RCC_OscInitStruct.PLL.PLLN = 336;
-  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
-  RCC_OscInitStruct.PLL.PLLQ = 7;
-  HAL_RCC_OscConfig(&RCC_OscInitStruct);
-
-  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
-                              |RCC_CLOCKTYPE_PCLK2;
-  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
-  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
-  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
-  
-  //Used for ov7670 test
-//  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_PLLI2S;//|RCC_PERIPHCLK_I2S;
-//  PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
-//  PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
-//  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
-*/  
-  /* RCC_MCODIV_5 33.6MHz mco2 output on pin PC_9 (cam xclk) */
-  /* RCC_MCODIV_4 42MHz mco2 output on pin PC_9 (cam xclk) */
-  /* RCC_MCODIV_3 56MHz mco2 output on pin PC_9 (cam xclk) */
-//  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4);
-
-  /* RCC_MCODIV_1 16MHz mco1 output on pin PA_8 (cam xclk) */
-//  HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
-
-  /* RCC_MCODIV_1 8MHz mco2 output on pin PC_9 (cam xclk) */ 
-  /* RCC_MCODIV_2 4MHz mco2 output on pin PC_9 (cam xclk) */ 
-  /* RCC_MCODIV_4 2MHz mco2 output on pin PC_9 (cam xclk) */  
-  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_HSE, RCC_MCODIV_1);
-
-  //Used for ov7670 test
-  /* RCC_MCODIV_4 24MHz mco2 output on pin PC_9 (cam xclk) */
-//  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_4);
-
-//  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
-  
-//  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
-
-/* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported  */
-//  if (HAL_GetREVID() == 0x1001)
-//  {
-    /* Enable the Flash prefetch */
-//    __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
-//  }
-  
-}
-
 /* Warning if pin changes are made below then the same changes have to be made in the following files.
  * httpserverapp.cpp
  * HttpCore.cpp
@@ -149,9 +81,10 @@
 /* Off board leds */
   DigitalOut led1(PB_15);
   DigitalOut led2(PB_14);
-
+//Serial pc(USBTX, USBRX);
 cc3100 _cc3100(NC, NC, PD_12, PD_13, PD_11, SPI(PB_5, PB_4, PB_3));//Seeed_Arch_Max  irq, nHib, cs, mosi, miso, sck
 
+static void Start_MCO1(void);
 void initLEDs(void);
 void toggleLed(int ind);
 static void DisplayBanner(char * AppName);
@@ -173,6 +106,30 @@
 	
 }
 
+static void Start_MCO1()
+{
+    
+    GPIO_InitTypeDef GPIO_InitStruct;
+    __GPIOA_CLK_ENABLE();
+    
+    /*Configure GPIO pin : GPIO_AF0_MCO PA8 */     
+    GPIO_InitStruct.Pin = GPIO_PIN_8;
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+    GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    
+#if defined OV5642_CAM || defined OV2640_CAM
+    /* MCO1 output 16MHz */   
+    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
+#else 
+    /* MCO1 output 8MHz */   
+    HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2);
+#endif
+    wait_ms(500);
+}
+
 void toggleLed(int ind){
 	
 	if(ind == 1){
@@ -215,24 +172,28 @@
    SCB->SHCSR |= 0x00070000; 
    int rv = 0;
    
-//   HAL_Init();
-   
-   SystemClock_Config();
-//   DMAConfig();
-   
    //
    // Configuring UART
    //
    CLI_Configure();
+   
+#if defined OV5642_CAM   
+   Uart_Write((uint8_t*)"\n\rOV5642 Camera \n\r");
+#elif defined OV2640_CAM 
+   Uart_Write((uint8_t*)"\n\rOV2640 Camera \n\r");
+#elif defined MT9D111_CAM     
+   Uart_Write((uint8_t*)"\n\rMT9D111 Camera \n\r");
+#endif
+   
+   /* Start Camera Master Clock */
+   Start_MCO1();
+   
+   
+   
    initLEDs();
 
 //   toggleLed(1);
 //#ifndef NOTERM
-
-	//
-	// Configuring UART
-	//
-//    CLI_Configure();
     
     memset(print_buf, 0x00, PRINT_BUF_LEN);
     sprintf((char*) print_buf, " \r\nSystemCoreClock = %dMHz\r\n ", SystemCoreClock /1000000);
@@ -267,7 +228,7 @@
                         HTTP_SERVER_APP_TASK_PRIORITY,
                         NULL );
 
-    Uart_Write((uint8_t*)"HttpServerApp Initialized \n\r");
+    Uart_Write((uint8_t*)"HttpServerApp Initializing \n\r");
 
     //
     // Start the task scheduler
@@ -395,10 +356,9 @@
   * @param  None
   * @retval None
   */
-/*  
+/*    
 void DMA2_Stream1_IRQHandler(void)
 {
-  DMA_HandleTypeDef hdma_dcmi;
   Uart_Write((uint8_t*)"DMA2_Stream1_IRQHandler \n\r");
   HAL_DMA_IRQHandler(&hdma_dcmi);  
 }
@@ -407,11 +367,10 @@
   * @brief  DCMI interrupt handler.
   * @param  None
   * @retval None
-  */
-/*  
+  */ 
+ /* 
 void DCMI_IRQHandler(void)
 {
-  DCMI_HandleTypeDef hdcmi;
   Uart_Write((uint8_t*)"DCMI_IRQHandler \n\r");
   HAL_DCMI_IRQHandler(&hdcmi);
 }
@@ -423,3 +382,6 @@
 //
 //*****************************************************************************
 
+
+
+
--- a/mbed.bld	Mon Jul 13 08:20:40 2015 +0000
+++ b/mbed.bld	Tue Aug 25 22:03:00 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file
--- a/simplelink/cc3100_spi.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/simplelink/cc3100_spi.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -61,7 +61,7 @@
 //    _sw2_irq.rise(this, &cc3100_spi::buttonHandler_2);
     _wlan_nHIB = 0;
     _wlan_cs = 1;
-    wait_ms(200);
+//    wait_ms(100);
     
     
 }
@@ -127,7 +127,7 @@
 {
 
     // 50 ms delay
-    wait_ms(50);
+ //   wait_ms(50);
 
     // Enable WLAN interrupt
     cc3100_InterruptEnable();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_it.c	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,92 @@
+/**
+  ******************************************************************************
+  * @file    stm32f4xx_it.c
+  * @brief   Interrupt Service Routines.
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+/* Includes ------------------------------------------------------------------*/
+#include "stm32f4xx_hal.h"
+#include "stm32f4xx.h"
+#include "stm32f4xx_it.h"
+#include "stm32f4xx_hal_dma.h"
+#include "stm32f4xx_hal_dcmi.h"
+
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+
+/* External variables --------------------------------------------------------*/
+extern DMA_HandleTypeDef phdma_dcmi;
+extern DCMI_HandleTypeDef phdcmi;
+
+/******************************************************************************/
+/*            Cortex-M4 Processor Interruption and Exception Handlers         */ 
+/******************************************************************************/
+
+
+/******************************************************************************/
+/* STM32F4xx Peripheral Interrupt Handlers                                    */
+/* Add here the Interrupt Handlers for the used peripherals.                  */
+/* For the available peripheral interrupt handler names,                      */
+/* please refer to the startup file (startup_stm32f4xx.s).                    */
+/******************************************************************************/
+
+/**
+* @brief This function handles DMA2 Stream1 global interrupt.
+*/
+void DMA2_Stream1_IRQHandler(void)
+{
+  /* USER CODE BEGIN DMA2_Stream1_IRQn 0 */
+
+  /* USER CODE END DMA2_Stream1_IRQn 0 */
+  HAL_DMA_IRQHandler(&phdma_dcmi);
+  /* USER CODE BEGIN DMA2_Stream1_IRQn 1 */
+
+  /* USER CODE END DMA2_Stream1_IRQn 1 */
+}
+
+/**
+* @brief This function handles DCMI global interrupt.
+*/
+void DCMI_IRQHandler(void)
+{
+  /* USER CODE BEGIN DCMI_IRQn 0 */
+
+  /* USER CODE END DCMI_IRQn 0 */
+  HAL_DCMI_IRQHandler(&phdcmi);
+  /* USER CODE BEGIN DCMI_IRQn 1 */
+
+  /* USER CODE END DCMI_IRQn 1 */
+}
+
+/* USER CODE BEGIN 1 */
+
+/* USER CODE END 1 */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_it.h	Tue Aug 25 22:03:00 2015 +0000
@@ -0,0 +1,57 @@
+/**
+  ******************************************************************************
+  * @file    stm32f4xx_it.h
+  * @brief   This file contains the headers of the interrupt handlers.
+  ******************************************************************************
+  *
+  * COPYRIGHT(c) 2015 STMicroelectronics
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_IT_H
+#define __STM32F4xx_IT_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif 
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+void DMA2_Stream1_IRQHandler(void);
+void DCMI_IRQHandler(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_IT_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/utils/app_config.h	Mon Jul 13 08:20:40 2015 +0000
+++ b/utils/app_config.h	Tue Aug 25 22:03:00 2015 +0000
@@ -2,13 +2,51 @@
 #ifndef app_config_H
 #define app_config_H
 
+//*****************************************************************************
+//
+// If building with a C++ compiler, make all of the definitions in this header
+// have a C binding.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define ENABLE_JPEG
+//#define MT9D111_CAM
+//#define OV5642_CAM
+#define OV2640_CAM
+
+//#define XGA_FRAME
+//#define VGA_FRAME
+#define QVGA_FRAME
+//#define QCIF_FRAME
+
+#ifdef MT9D111_CAM
+#define sensor_addr  0x0
+#endif
+#ifdef OV2640_CAM
+//#define sensor_addr  ((0x60 << 1))
+#define sensor_addr  0x60
+#endif
+#ifdef OV5642_CAM
+#define sensor_addr  0x78
+#endif
 
 #define SPAWN_TASK_PRIORITY            7//9
-#define HTTP_SERVER_APP_TASK_PRIORITY  1//1
-#define CAMERA_SERVICE_PRIORITY        1
+#define HTTP_SERVER_APP_TASK_PRIORITY  5//1
+#define CAMERA_SERVICE_PRIORITY        5
 #define OSI_STACK_SIZE                 8 * 1024
 
-
+//*****************************************************************************
+//
+// Mark the end of the C bindings section for C++ compilers.
+//
+//*****************************************************************************
+#ifdef __cplusplus
+}
+#endif
 
 #endif
 
--- a/utils/cli_uart.cpp	Mon Jul 13 08:20:40 2015 +0000
+++ b/utils/cli_uart.cpp	Tue Aug 25 22:03:00 2015 +0000
@@ -12,12 +12,11 @@
 
 #if (THIS_BOARD == Seeed_Arch_Max)
 Serial uart(PC_6, PC_7);//uart 6
+//Serial uart(USBTX, USBRX);
 #elif (THIS_BOARD == EA_MBED_LPC4088)
 Serial uart(p37, p31);
 #endif
 
-
-
 int Uart_Write(unsigned char *inBuff)
 {
     uint16_t ret, ecount, usLength = strlen((const char *)inBuff);