www.pudn.com > MT6226(YUV)_SIV100A.zip > image_sensor.c


/***************************************************************************** 
*  Copyright Statement: 
*  -------------------- 
*  This software is protected by Copyright and the information contained 
*  herein is confidential. The software may not be copied and the information 
*  contained herein may not be used or disclosed except with the written 
*  permission of MediaTek Inc. (C) 2005 
* 
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES 
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") 
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON 
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, 
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. 
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE 
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR 
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH 
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO 
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S 
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. 
* 
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE 
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, 
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, 
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO 
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.  
* 
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE 
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF 
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND 
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER 
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). 
* 
*****************************************************************************/ 
 
/***************************************************************************** 
 * 
 * Filename: 
 * --------- 
 *   image_sensor.c 
 * 
 * Project: 
 * -------- 
 *   Maui_sw 
 * 
 * Description: 
 * ------------ 
 *   Image sensor driver function 
 * 
 *============================================================================ 
 *             HISTORY 
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *------------------------------------------------------------------------------ 
 * 
 *------------------------------------------------------------------------------ 
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *============================================================================ 
 ****************************************************************************/ 
#include "drv_comm.h" 
#include "IntrCtrl.h" 
#include "reg_base.h" 
#include "gpio_sw.h" 
#include "sccb.h" 
#include "isp_if.h" 
#include "image_sensor.h" 
#include "camera_para.h" 
#include "upll_ctrl.h" 
#include "med_api.h" 
 
/* Global Valuable */ 
SensorInfo g_CCT_MainSensor = OV7660_OMNIVISION;    // must be defined but not referenced by YUV driver 
kal_uint8 g_CCT_FirstGrabColor = INPUT_ORDER_CbYCrY1;   // must be defined but not referenced by YUV driver 
 
static kal_bool g_bVideoMode = KAL_FALSE;    // KAL_TRUE for video recorder mode 
static kal_bool g_bNightMode = KAL_FALSE; 
static kal_bool g_bCaptureMode = KAL_FALSE; 
static kal_uint8 g_iBanding = CAM_BANDING_60HZ; 
static kal_uint8 g_iAE_Meter = CAM_AE_METER_AUTO; 
 
/* MAX/MIN Explosure Lines Used By AE Algorithm */ 
kal_uint16 MAX_EXPOSURE_LINES = 1000;   // must be defined but not referenced by YUV driver 
kal_uint8  MIN_EXPOSURE_LINES = 1;  // must be defined but not referenced by YUV driver 
 
#ifndef HW_SCCB 
 
#define SENSOR_I2C_DELAY    (0x01) 
 
#define I2C_START_TRANSMISSION \ 
{ \ 
    volatile kal_uint8 j; \ 
    SET_SCCB_CLK_OUTPUT; \ 
    SET_SCCB_DATA_OUTPUT; \ 
    SET_SCCB_CLK_HIGH; \ 
    SET_SCCB_DATA_HIGH; \ 
    for (j = 0; j < SENSOR_I2C_DELAY; j++);\ 
    SET_SCCB_DATA_LOW; \ 
    for (j = 0; j < SENSOR_I2C_DELAY; j++);\ 
    SET_SCCB_CLK_LOW; \ 
} 
     
#define I2C_STOP_TRANSMISSION \ 
{ \ 
    volatile kal_uint8 j; \ 
    SET_SCCB_CLK_OUTPUT; \ 
    SET_SCCB_DATA_OUTPUT; \ 
    SET_SCCB_CLK_LOW; \ 
    SET_SCCB_DATA_LOW; \ 
    for (j = 0; j < SENSOR_I2C_DELAY; j++);\ 
    SET_SCCB_CLK_HIGH; \ 
    for (j = 0; j < SENSOR_I2C_DELAY; j++);\ 
    SET_SCCB_DATA_HIGH; \ 
} 
 
static void SCCB_send_byte(kal_uint8 send_byte) 
{ 
    volatile signed char i; 
    volatile kal_uint8 j; 
 
    for (i = 7; i >= 0; i--) { /* data bit 7~0 */ 
        if (send_byte & (1 << i)) { 
            SET_SCCB_DATA_HIGH; 
        }else { 
            SET_SCCB_DATA_LOW; 
        } 
 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SET_SCCB_CLK_HIGH; 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SET_SCCB_CLK_LOW; 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
    } 
    /* don't care bit, 9th bit */ 
    SET_SCCB_DATA_LOW; 
    SET_SCCB_DATA_INPUT; 
    SET_SCCB_CLK_HIGH; 
    for (j = 0; j < SENSOR_I2C_DELAY; j++); 
    SET_SCCB_CLK_LOW; 
    SET_SCCB_DATA_OUTPUT; 
}   /* SCCB_send_byte() */ 
 
static kal_uint8 SCCB_get_byte(void) 
{ 
    volatile signed char i; 
    volatile kal_uint8 j; 
    kal_uint8 get_byte = 0; 
 
    SET_SCCB_DATA_INPUT; 
 
    for (i = 7; i >= 0; i--) { /* data bit 7~0 */ 
        SET_SCCB_CLK_HIGH; 
		for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        if (GET_SCCB_DATA_BIT) 
            get_byte |= (1 << i); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SET_SCCB_CLK_LOW; 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
    } 
    /* don't care bit, 9th bit */ 
    SET_SCCB_DATA_HIGH; 
    SET_SCCB_DATA_OUTPUT; 
    for (j = 0; j < SENSOR_I2C_DELAY; j++); 
    SET_SCCB_CLK_HIGH; 
    for (j = 0; j < SENSOR_I2C_DELAY; j++); 
    SET_SCCB_CLK_LOW; 
 
    return get_byte; 
}   /* SCCB_get_byte() */ 
 
#endif 
 
static void write_cmos_sensor(kal_uint32 addr, kal_uint32 para) 
{ 
    volatile kal_uint8 j; 
 
    #ifdef HW_SCCB 
        SET_SCCB_DATA_LENGTH(3); 
        ENABLE_SCCB; 
        REG_SCCB_DATA = SIV100A_I2C_WRITE_ID | SCCB_DATA_REG_ID_ADDRESS; 
        REG_SCCB_DATA = addr; 
        REG_SCCB_DATA = para; 
        while (SCCB_IS_WRITTING); 
    #else 
        I2C_START_TRANSMISSION; 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SCCB_send_byte(SIV100A_I2C_WRITE_ID); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SCCB_send_byte(addr); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SCCB_send_byte(para); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        I2C_STOP_TRANSMISSION; 
    #endif /* HW_SCCB */ 
}	/* write_cmos_sensor() */ 
 
static kal_uint32 read_cmos_sensor(kal_uint32 addr) 
{ 
    volatile kal_uint8 j; 
    kal_uint8 get_byte = 0; 
 
    #ifdef HW_SCCB 
        SET_SCCB_DATA_LENGTH(2); 
        ENABLE_SCCB; 
        REG_SCCB_DATA = SIV100A_I2C_WRITE_ID | SCCB_DATA_REG_ID_ADDRESS; 
        REG_SCCB_DATA = addr; 
        while (SCCB_IS_WRITTING); 
        ENABLE_SCCB; 
        REG_SCCB_DATA = SIV100A_I2C_READ_ID | SCCB_DATA_REG_ID_ADDRESS; 
        REG_SCCB_DATA = 0; 
        while (SCCB_IS_READING); 
        get_byte = REG_SCCB_READ_DATA & 0xFF; 
    #else 
        I2C_START_TRANSMISSION; 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SCCB_send_byte(SIV100A_I2C_WRITE_ID); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
        SCCB_send_byte(addr); 
        for (j = 0; j < SENSOR_I2C_DELAY; j++); 
//      I2C_STOP_TRANSMISSION; 
//      for(j=0;j> 8)); 
        write_cmos_sensor(0x22, iVal2Write & 0x00FF); 
        break; 
 
//    case CAM_BANDING_50HZ: 
        // SIV100A cannot use all blank size registers of 50Hz 
//        write_cmos_sensor(0x23, (read_cmos_sensor(0x23) & 0xFC) | ((iVal2Write & 0x0300) >> 8)); 
//        write_cmos_sensor(0x25, iVal2Write & 0x00FF); 
    } 
}   /* ConfigVBlank */ 
 
/************************************************************************* 
* FUNCTION 
*   ConfigHBlank 
* 
* DESCRIPTION 
*   This function is to set HBlank size. 
* 
* PARAMETERS 
*   iBlank: target HBlank size 
*      iHz: banding frequency 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void ConfigHBlank(const kal_uint16 iBlank, const kal_uint8 iHz) 
{ 
    /******************************************** 
    *   50Hz-relative registers can not be used * 
    ********************************************/ 
    const kal_uint16 iVal2Write = iBlank - 1; 
 
    ASSERT(iBlank < (1 << 10)); 
 
    switch (iHz) { 
    case CAM_BANDING_50HZ: 
    case CAM_BANDING_60HZ: 
        write_cmos_sensor(0x20, (read_cmos_sensor(0x20) & 0xCF) | ((iVal2Write & 0x0300) >> 4)); 
        write_cmos_sensor(0x21, iVal2Write & 0x00FF); 
        break; 
 
//    case CAM_BANDING_50HZ: 
        // SIV100A cannot use all blank size registers of 50Hz 
//        write_cmos_sensor(0x23, (read_cmos_sensor(0x23) & 0xCF) | ((iVal2Write & 0x0300) >> 4)); 
//        write_cmos_sensor(0x24, iVal2Write & 0x00FF); 
    } 
}   /* ConfigHBlank */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_PowerOff 
* 
* DESCRIPTION 
*   This function is to turn off sensor module power. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_PowerOff(void) 
{ 
    cis_module_power_on(KAL_FALSE); // power off sensor 
 
    SET_SCCB_CLK_LOW; 
    SET_SCCB_DATA_LOW; 
 
    UPLL_Disable(UPLL_OWNER_ISP); 
}   /* SIV100A_PowerOff */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Get_I2C_ID 
* 
* DESCRIPTION 
*   This function return the sensor read/write IDs of I2C I/F. 
* 
* PARAMETERS 
*   *pI2C_WriteID : address pointer of sensor's I2C write id 
*   *pI2C_ReadID  : address pointer of sensor's I2C read id 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_Get_I2C_ID(kal_uint8 *pI2C_WriteID, kal_uint8 *pI2C_ReadID) 
{ 
    *pI2C_WriteID = SIV100A_I2C_WRITE_ID; 
    *pI2C_ReadID = SIV100A_I2C_READ_ID; 
}   /* SIV100A_Get_I2C_ID */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_GetSize 
* 
* DESCRIPTION 
*   This function return the image width and height of image sensor. 
* 
* PARAMETERS 
*   *pWidth : address pointer of horizontal effective pixels of image sensor 
*  *pHeight : address pointer of vertical effective lines of image sensor 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_GetSize(kal_uint16 *pWidth, kal_uint16 *pHeight) 
{ 
    *pWidth = IMAGE_SENSOR_VGA_WIDTH;   // valid pixel # in one frame 
    *pHeight = IMAGE_SENSOR_VGA_HEIGHT; // valid line # in one frame 
}   /* SIV100A_GetSize */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_GetPeriod 
* 
* DESCRIPTION 
*   This function return the image width and height of image sensor. 
* 
* PARAMETERS 
*   *pPixelNumber : address pointer of pixel numbers in one period of HSYNC 
*   *pLineNumber : address pointer of line numbers in one period of VSYNC 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_GetPeriod(kal_uint16 *pPixelNumber, kal_uint16 *pLineNumber) 
{ 
    /************************************ 
    *   No need for YUV sensor driver   * 
    ************************************/ 
//    *pPixelNumber = VGA_PERIOD_PIXEL_NUMS;  // pixel numbers in one period of HSYNC 
//    *pLineNumber = VGA_PERIOD_LINE_NUMS;    // line numbers in one period of VSYNC 
}   /* SIV100A_GetPeriod */ 
 
/************************************************************************* 
* FUNCTION 
*	SIV100A_Preview 
* 
* DESCRIPTION 
*	This function configure the sensor to preview mode. 
* 
* PARAMETERS 
* 
* RETURNS 
*	None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_Preview(image_sensor_exposure_window_struct *pImage_Window, image_sensor_config_struct *pSensor_Config_Data) 
{ 
    kal_uint8 iHV_Mirror = 0; 
    kal_uint8 iStartX = 0, iStartY = 1; 
    kal_uint8 iTemp = 0; 
    volatile kal_uint16 iRetry; 
    static kal_uint16 iBound = 0x00FF; 
 
    write_cmos_sensor(0x40, 0x80);  // enable *NORMAL* AE 
    write_cmos_sensor(0x60, 0x90);  // enable AWB 
    write_cmos_sensor(0x4E, 0x00); 
    if (pSensor_Config_Data->frame_rate == 0x0F) {  // MPEG4 Encode Mode 
        g_bVideoMode = KAL_TRUE; 
 
        // config TG for video recorder mode 
        SET_TG_OUTPUT_CLK_DIVIDER(3);   // MCLK = 12MHz 
        SET_CMOS_RISING_EDGE(0); 
        SET_CMOS_FALLING_EDGE(2); 
        SET_TG_PIXEL_CLK_DIVIDER(3); 
        SET_CMOS_DATA_LATCH(2); 
    }else { 
        g_bVideoMode = KAL_FALSE; 
        g_bCaptureMode = KAL_FALSE; 
 
        iTemp = read_cmos_sensor(0x04) & 0xF3; 
        write_cmos_sensor(0x04, iTemp | 0x00);  // set CLK divider to 1/2 
        // config TG for camera preview mode 
        SET_TG_OUTPUT_CLK_DIVIDER(1); 
        SET_CMOS_RISING_EDGE(0); 
        SET_CMOS_FALLING_EDGE(1); 
        SET_TG_PIXEL_CLK_DIVIDER(1); 
        SET_CMOS_DATA_LATCH(1); 
    } 
 
    iHV_Mirror = read_cmos_sensor(0x04) & 0xFC; 
    switch (pSensor_Config_Data->image_mirror) { 
    case IMAGE_NORMAL: 
        iHV_Mirror |= 0x00; 
        if (g_bVideoMode == KAL_TRUE) { 
            SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1); 
            iStartX = 0; 
            iStartY = 1; 
        }else { 
            SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1); 
            iStartX = 0; 
            iStartY = 1; 
        } 
        break; 
 
    case IMAGE_HV_MIRROR: 
        iHV_Mirror |= 0x03; 
        if (g_bVideoMode == KAL_TRUE) { 
            SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1); 
            iStartX = 0; 
            iStartY = 1; 
        }else { 
            SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1); 
            iStartX = 0; 
            iStartY = 1; 
        } 
        break; 
 
    default: 
        ASSERT(0); 
    } 
    write_cmos_sensor(0x04, iHV_Mirror); 
 
    pImage_Window->grab_start_x = iStartX; 
    pImage_Window->grab_start_y = iStartY; 
    pImage_Window->exposure_window_width = IMAGE_SENSOR_VGA_WIDTH - iStartX; 
    pImage_Window->exposure_window_height = IMAGE_SENSOR_VGA_HEIGHT - iStartY; 
 
    for (iRetry = 0; iRetry < iBound; iRetry++) { 
        /******************************** 
        *   0x7F[0] = 1 when AE stable  * 
        ********************************/ 
        if ((read_cmos_sensor(0x7F) & 0x01) != 0) { 
            break; 
        } 
    } 
}   /* SIV100A_Preview */ 
 
/************************************************************************* 
* FUNCTION 
*   SID201A_Capture 
* 
* DESCRIPTION 
*   This function configures the sensor to capture mode. 
* 
* PARAMETERS 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_Capture(image_sensor_exposure_window_struct *pImage_Window, image_sensor_config_struct *pSensor_Config_Data) 
{ 
    kal_uint8 iStartX = 0, iStartY = 1, iTemp; 
    kal_uint32 iExp; 
 
    g_bCaptureMode = KAL_TRUE; 
 
    if (pSensor_Config_Data->frame_rate == 0xF0) { 
        /************************************ 
        *   Webcam mode, AE/AWB still on    * 
        ************************************/ 
        ConfigVBlank(WEBCAM_MODE_VBLANK, CAM_BANDING_50HZ); 
        ConfigHBlank(WEBCAM_MODE_HBLANK, CAM_BANDING_50HZ); 
    }else { 
        /******************************** 
        *   Normal camera capture mode  * 
        ********************************/ 
        write_cmos_sensor(0x40, 0x00);  // disable AE 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        if (pImage_Window->image_target_width <= IMAGE_SENSOR_VGA_WIDTH && 
            pImage_Window->image_target_height <= IMAGE_SENSOR_VGA_HEIGHT) { 
            /******************************************************** 
            *   This part captures image size equal to or under VGA * 
            ********************************************************/ 
            if (pImage_Window->digital_zoom_factor >= (ISP_DIGITAL_ZOOM_INTERVAL << 1)) { 
                iTemp = read_cmos_sensor(0x04) & 0xF3; 
                write_cmos_sensor(0x04, iTemp | 0x04);  // set CLK divider = 1/4 
                SET_TG_PIXEL_CLK_DIVIDER(3); 
                SET_CMOS_DATA_LATCH(2); 
 
                iExp = (read_cmos_sensor(0x30) << 8) | read_cmos_sensor(0x31); 
                iTemp = (read_cmos_sensor(0x14) & 0x07) + 1; 
                if (iExp == 1) { 
                    iTemp >>= 1; 
                    write_cmos_sensor(0x14, (read_cmos_sensor(0x14) & 0xF8) | iTemp); 
                    write_cmos_sensor(0x30, 0x00); 
                    write_cmos_sensor(0x31, 0x01); 
                }else { 
                    iExp = (((iExp << 3) + iTemp) >> 1); 
                    write_cmos_sensor(0x30, (iExp >> 11) & 0x00FF); 
                    write_cmos_sensor(0x31, (iExp >> 3) & 0x00FF); 
                    write_cmos_sensor(0x14, (read_cmos_sensor(0x14) & 0xF8) | (iExp & 0x0007)); 
                } 
            } 
        }else if (pImage_Window->image_target_width > IMAGE_SENSOR_VGA_WIDTH && 
                  pImage_Window->image_target_height > IMAGE_SENSOR_VGA_HEIGHT) { 
            /******************************************** 
            *   This part captures image size over VGA  * 
            ********************************************/ 
            iTemp = read_cmos_sensor(0x04) & 0xF3; 
            write_cmos_sensor(0x04, iTemp | 0x0C);  // set CLK divider = 1/16  
 
            SET_TG_PIXEL_CLK_DIVIDER(15); 
            SET_CMOS_DATA_LATCH(8); 
  
            iExp = (read_cmos_sensor(0x30) << 8) | read_cmos_sensor(0x31); 
            iExp += 4;  // round 
             
            if (pImage_Window->digital_zoom_factor >= (ISP_DIGITAL_ZOOM_INTERVAL << 1)) { 
                /******************************************************** 
                *   Capture SXGA resolution with zoom factor over 2x    * 
                ********************************************************/ 
                ConfigHBlank(CP_1M_MODE_ZOOM_HBLANK, CAM_BANDING_50HZ); 
                if (g_bNightMode == KAL_TRUE) { 
                    if (g_iBanding == CAM_BANDING_50HZ) { 
                        iExp = iExp * (PV_MODE_HVP_PERIOD + PV_MODE_HBLANK_50HZ_NIGHT) / (PV_MODE_HVP_PERIOD + CP_1M_MODE_ZOOM_HBLANK); 
                    }else { 
                        iExp = iExp * (PV_MODE_HVP_PERIOD + PV_MODE_HBLANK_60HZ_NIGHT) / (PV_MODE_HVP_PERIOD + CP_1M_MODE_ZOOM_HBLANK); 
                    } 
                }else { 
                    if (g_iBanding == CAM_BANDING_50HZ) { 
                        iExp = iExp * (PV_MODE_HVP_PERIOD + PV_MODE_HBLANK_50HZ_NORMAL) / (PV_MODE_HVP_PERIOD + CP_1M_MODE_ZOOM_HBLANK); 
                    }else { 
                        iExp = iExp * (PV_MODE_HVP_PERIOD + PV_MODE_HBLANK_60HZ_NORMAL) / (PV_MODE_HVP_PERIOD + CP_1M_MODE_ZOOM_HBLANK); 
                    } 
                } 
            } 
 
            //iTemp = (read_cmos_sensor(0x14) & 0x07) + 1; // remove this line. This register does not use. 
            if (iExp <= 8) {                
                //iTemp >>= 1;  
                //write_cmos_sensor(0x14, 0x00);  
                write_cmos_sensor(0x30, 0x00);  
                write_cmos_sensor(0x31, 0x01);  
            }else { 
                iExp >>= 3;    // iExp / 8  
                if (iExp < 1) { // make sure nonzero exposure 
                    iExp = 1; 
                } 
 
                write_cmos_sensor(0x30, (iExp >> 8) & 0x00FF);  
                write_cmos_sensor(0x31,  iExp & 0x00FF);  
                //write_cmos_sensor(0x14, 0x00);  
            }  
        } 
    } 
 
    pImage_Window->grab_start_x = iStartX; 
    pImage_Window->grab_start_y = iStartY; 
    pImage_Window->exposure_window_width = IMAGE_SENSOR_VGA_WIDTH - iStartX; 
    pImage_Window->exposure_window_height = IMAGE_SENSOR_VGA_HEIGHT - iStartY; 
}   /* SIV100A_Capture() */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_WriteReg 
* 
* DESCRIPTION 
*   This function set the register of SIV100A. 
* 
* PARAMETERS 
*   iAddr : the register index of SIV100A 
*   iPara : setting parameter of the specified register of SIV100A 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_WriteReg(kal_uint32 iAddr, kal_uint32 iPara) 
{ 
    write_cmos_sensor(iAddr, iPara); 
}   /* SIV100A_WriteReg() */ 
 
/************************************************************************* 
* FUNCTION 
*   read_cmos_sensor 
* 
* DESCRIPTION 
*   This function read parameter of specified register from SIV100A. 
* 
* PARAMETERS 
*   iAddr: the register index of SIV100A 
* 
* RETURNS 
*   the data that read from SIV100A 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_ReadReg(kal_uint32 iAddr) 
{ 
    return read_cmos_sensor(iAddr); 
}   /* SIV100A_ReadReg() */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_SetShutter 
* 
* DESCRIPTION 
*   This function set e-shutter of SIV100A to change exposure time. 
* 
* PARAMETERS 
*   shutter : exposured lines 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_SetShutter(kal_uint16 shutter) 
{ 
}   /* SIV100A_SetShutter */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_SetGain 
* 
* DESCRIPTION 
*   This function is to set global gain to sensor. 
* 
* PARAMETERS 
*   iGain : sensor global gain(base: 0x40) 
* 
* RETURNS 
*   the actually gain set to sensor. 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint16 SIV100A_SetGain(kal_uint16 iGain) 
{ 
    return iGain; 
}   /* SIV100A_SetGain */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_NightMode 
* 
* DESCRIPTION 
*   This function switch on/off night mode of SIV100A. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_NightMode(kal_bool bEnable) 
{ 
    static kal_uint32 iDelay = 0x000FFFFF; 
    volatile kal_uint32 iI = 0; 
 
    g_bNightMode = bEnable; 
 
    if (g_bCaptureMode == KAL_TRUE) { 
        return; 
    } 
 
    /************************************************************ 
    *   AE must be off to do the following mode change setting. * 
    *   If not off, the covered EV range will be the same for   * 
    *   normal/night modes.                                     * 
    ************************************************************/ 
    write_cmos_sensor(0x40, 0x00); 
 
    /******************************************************** 
    *   MUST delay after turn off AE.                       * 
    *   If no such delay, AE will not work after re-enable  * 
    ********************************************************/ 
    for (iI = 0; iI < iDelay; iI++); 
 
    if (bEnable == KAL_TRUE) { 
        if (g_bVideoMode == KAL_TRUE) { // video preview mode 
            if (g_iBanding == CAM_BANDING_50HZ) { 
                ConfigVBlank(VIDEO_MODE_VBLANK_50HZ_NIGHT, CAM_BANDING_50HZ); 
                ConfigHBlank(VIDEO_MODE_HBLANK_50HZ_NIGHT, CAM_BANDING_50HZ); 
                write_cmos_sensor(0x33, VIDEO_MODE_FRCNT_50HZ_NIGHT); 
                write_cmos_sensor(0x34, VIDEO_MODE_STSTN_50HZ_NIGHT); 
            }else { 
                ConfigVBlank(VIDEO_MODE_VBLANK_60HZ_NIGHT, CAM_BANDING_60HZ); 
                ConfigHBlank(VIDEO_MODE_HBLANK_60HZ_NIGHT, CAM_BANDING_60HZ); 
                write_cmos_sensor(0x33, VIDEO_MODE_FRCNT_60HZ_NIGHT); 
                write_cmos_sensor(0x34, VIDEO_MODE_STSTN_60HZ_NIGHT); 
            } 
        }else { // camera preview mode 
            if (g_iBanding == CAM_BANDING_50HZ) { 
                ConfigVBlank(PV_MODE_VBLANK_50HZ_NIGHT, CAM_BANDING_50HZ); 
                ConfigHBlank(PV_MODE_HBLANK_50HZ_NIGHT, CAM_BANDING_50HZ); 
                write_cmos_sensor(0x33, PV_MODE_FRCNT_50HZ_NIGHT); 
                write_cmos_sensor(0x34, PV_MODE_STSTN_50HZ_NIGHT); 
            }else { 
                ConfigVBlank(PV_MODE_VBLANK_60HZ_NIGHT, CAM_BANDING_60HZ); 
                ConfigHBlank(PV_MODE_HBLANK_60HZ_NIGHT, CAM_BANDING_60HZ); 
                write_cmos_sensor(0x33, PV_MODE_FRCNT_60HZ_NIGHT); 
                write_cmos_sensor(0x34, PV_MODE_STSTN_60HZ_NIGHT); 
            } 
        } 
    }else { 
        if (g_bVideoMode == KAL_TRUE) { // video preview mode 
            if (g_iBanding == CAM_BANDING_50HZ) { 
                ConfigVBlank(VIDEO_MODE_VBLANK_50HZ_NORMAL, CAM_BANDING_50HZ); 
                ConfigHBlank(VIDEO_MODE_HBLANK_50HZ_NORMAL, CAM_BANDING_50HZ); 
                write_cmos_sensor(0x33, VIDEO_MODE_FRCNT_50HZ_NORMAL); 
                write_cmos_sensor(0x34, VIDEO_MODE_STSTN_50HZ_NORMAL); 
            }else { 
                ConfigVBlank(VIDEO_MODE_VBLANK_60HZ_NORMAL, CAM_BANDING_60HZ); 
                ConfigHBlank(VIDEO_MODE_HBLANK_60HZ_NORMAL, CAM_BANDING_60HZ); 
                write_cmos_sensor(0x33, VIDEO_MODE_FRCNT_60HZ_NORMAL); 
                write_cmos_sensor(0x34, VIDEO_MODE_STSTN_60HZ_NORMAL); 
            } 
        }else { // camera preview mode 
            if (g_iBanding == CAM_BANDING_50HZ) { 
                ConfigVBlank(PV_MODE_VBLANK_50HZ_NORMAL, CAM_BANDING_50HZ); 
                ConfigHBlank(PV_MODE_HBLANK_50HZ_NORMAL, CAM_BANDING_50HZ); 
                write_cmos_sensor(0x33, PV_MODE_FRCNT_50HZ_NORMAL); 
                write_cmos_sensor(0x34, PV_MODE_STSTN_50HZ_NORMAL); 
            }else { 
                ConfigVBlank(PV_MODE_VBLANK_60HZ_NORMAL, CAM_BANDING_60HZ); 
                ConfigHBlank(PV_MODE_HBLANK_60HZ_NORMAL, CAM_BANDING_60HZ); 
                write_cmos_sensor(0x33, PV_MODE_FRCNT_60HZ_NORMAL); 
                write_cmos_sensor(0x34, PV_MODE_STSTN_60HZ_NORMAL); 
            } 
        } 
    } 
 
    /************************************************************ 
    *   After the above mode change setting, turn on AE again   * 
    ************************************************************/ 
    write_cmos_sensor(0x40, g_iAE_Meter == CAM_AE_METER_AUTO ? 0x80 : 0xA0); 
}   /* SIV100A_NightMode */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_SetFlash 
* 
* DESCRIPTION 
*   turn on/off SIV100A flashlight . 
* 
* PARAMETERS 
*   bEnable: 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void SIV100A_SetFlash(kal_bool bEnable) 
{ 
}   /* SIV100A_SetFlash */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Param_Zoom 
* 
* DESCRIPTION 
*   SIV100A zoom setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Zoom(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_ZOOM_1X: 
    case CAM_ZOOM_2X: 
    case CAM_ZOOM_4X: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Param_Zoom */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Contrast 
* 
* DESCRIPTION 
*   SIV100A contrast setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Contrast(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Contrast */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Brightness 
* 
* DESCRIPTION 
*   SIV100A brightness setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Brightness(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Brightness */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Hue 
* 
* DESCRIPTION 
*   SIV100A hue setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Hue(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Hue */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Gamma 
* 
* DESCRIPTION 
*   SIV100A gamma setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Gamma(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Gamma */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_WB 
* 
* DESCRIPTION 
*   SIV100A WB setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_WB(kal_uint32 iPara) 
{ 
    /**************************************************************************** 
    *   camera_para.AWB.LightSource[m][n] is in 0x80 base, i.e. 0x80 = 1x gain  * 
    ****************************************************************************/ 
    kal_uint16 iRGain = 0x80, iGGain = 0x80, iBGain = 0x80; // all set to 1x gain 
 
		// Fix AWB problem by Fordarm 060828 
    if (g_bCaptureMode == KAL_TRUE) { 
        return; 
    } 
 
    switch (iPara) { 
    case CAM_WB_AUTO:   // enable AWB 
        // CAM_WB_AUTO mode should not update R/G/B gains 
        write_cmos_sensor(0x60, 0x90); 
        return KAL_TRUE; 
 
    case CAM_WB_CLOUD: 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        iRGain = camera_para.AWB.LightSource[0][1]; 
        iGGain = camera_para.AWB.LightSource[0][2]; 
        iBGain = camera_para.AWB.LightSource[0][3]; 
        break; 
 
    case CAM_WB_DAYLIGHT: 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        iRGain = camera_para.AWB.LightSource[1][1]; 
        iGGain = camera_para.AWB.LightSource[1][2]; 
        iBGain = camera_para.AWB.LightSource[1][3]; 
        break; 
 
    case CAM_WB_INCANDESCENCE: 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        iRGain = camera_para.AWB.LightSource[2][1]; 
        iGGain = camera_para.AWB.LightSource[2][2]; 
        iBGain = camera_para.AWB.LightSource[2][3]; 
        break; 
 
    case CAM_WB_FLUORESCENT: 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        iRGain = camera_para.AWB.LightSource[3][1]; 
        iGGain = camera_para.AWB.LightSource[3][2]; 
        iBGain = camera_para.AWB.LightSource[3][3]; 
        break; 
 
    case CAM_WB_TUNGSTEN: 
        write_cmos_sensor(0x60, 0x00);  // disable AWB 
        iRGain = camera_para.AWB.LightSource[4][1]; 
        iGGain = camera_para.AWB.LightSource[4][2]; 
        iBGain = camera_para.AWB.LightSource[4][3]; 
        break; 
 
    case CAM_WB_MANUAL: 
    default: 
        return KAL_FALSE; 
    } 
 
    write_cmos_sensor(0x7A, iRGain);    // set R gain 
    write_cmos_sensor(0x7B, iBGain);    // set B gain 
    write_cmos_sensor(0x7C, iGGain);    // set G gain 
 
    return KAL_TRUE; 
}   /* SIV100A_Set_Para_WB */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_EV 
* 
* DESCRIPTION 
*   SIV100A exposure setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_EV(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_EV_NEG_4_3:    // -4 EV 
        write_cmos_sensor(0x41, 0x4A); 
        break; 
 
    case CAM_EV_NEG_3_3:    // -3 EV 
        write_cmos_sensor(0x41, 0x5A); 
        break; 
 
    case CAM_EV_NEG_2_3:    // -2 EV 
        write_cmos_sensor(0x41, 0x6A); 
        break; 
 
    case CAM_EV_NEG_1_3:    // -1 EV 
        write_cmos_sensor(0x41, 0x7A); 
        break; 
 
    case CAM_EV_ZERO:   // +0 EV 
        write_cmos_sensor(0x41, 0x8A); 
        break; 
 
    case CAM_EV_POS_1_3:    // +1 EV 
        write_cmos_sensor(0x41, 0x9A); 
        break; 
 
    case CAM_EV_POS_2_3:    // +2 EV 
        write_cmos_sensor(0x41, 0xAA); 
        break; 
 
    case CAM_EV_POS_3_3:    // +3 EV 
        write_cmos_sensor(0x41, 0xBA); 
        break; 
 
    case CAM_EV_POS_4_3:    // +4 EV 
        write_cmos_sensor(0x41, 0xCA); 
        break; 
 
    default: 
        return KAL_FALSE;     
    } 
 
    return KAL_TRUE;	 
}   /* SIV100A_Set_Para_EV */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Banding 
* 
* DESCRIPTION 
*   SIV100A banding setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Banding(kal_uint32 iPara) 
{ 
    g_iBanding = iPara; 
  
    switch (iPara) { 
    case CAM_BANDING_50HZ: 
        // all 50HZ blank register cannot be used 
        if (g_bVideoMode == KAL_TRUE) { 
//            ConfigVBlank(VIDEO_MODE_VBLANK_50HZ, CAM_BANDING_60HZ); 
//            ConfigHBlank(VIDEO_MODE_HBLANK_50HZ, CAM_BANDING_60HZ); 
//            write_cmos_sensor(0x34, 0x42); 
//            ConfigVBlank(VIDEO_MODE_VBLANK, CAM_BANDING_50HZ); 
//            ConfigHBlank(VIDEO_MODE_HBLANK, CAM_BANDING_50HZ); 
        }else { 
        } 
        break; 
 
    case CAM_BANDING_60HZ: 
        if (g_bVideoMode == KAL_TRUE) { 
//            ConfigVBlank(VIDEO_MODE_VBLANK_60HZ, CAM_BANDING_60HZ); 
//            ConfigHBlank(VIDEO_MODE_HBLANK_60HZ, CAM_BANDING_60HZ); 
//            write_cmos_sensor(0x34, 0x3A); 
        }else { 
        } 
        break; 
 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_TRUE; 
}   /* SIV100A_Set_Para_Banding */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Saturation 
* 
* DESCRIPTION 
*   SIV100A SATURATION setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Saturation(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Saturation */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_NightMode 
* 
* DESCRIPTION 
*   SIV100A night mode setting. 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_NightMode(kal_uint32 iPara) 
{ 
    SIV100A_NightMode((kal_bool) iPara); 
 
    return KAL_TRUE; 
}   /* SIV100A_Set_Para_NightMode */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_AE_Meter 
* 
* DESCRIPTION 
*   SIV100A AE metering mode 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_AE_Meter(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_AE_METER_AUTO: // NORMAL mode AE metering 
        write_cmos_sensor(0x40, 0x80); 
        g_iAE_Meter = CAM_AE_METER_AUTO; 
        break; 
 
    case CAM_AE_METER_SPOT: // SPOT mode AE metering 
        write_cmos_sensor(0x40, 0xA0); 
        g_iAE_Meter = CAM_AE_METER_SPOT; 
        break; 
 
    case CAM_AE_METER_CENTRAL: 
    case CAM_AE_METER_AVERAGE: 
    default: 
        return KAL_FALSE; 
	} 
 
    return KAL_TRUE; 
}   /* SIV100A_Set_Para_AE_Meter */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Shutter_Priority 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Shutter_Priority(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Shutter_Priority */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Aperture_Priority 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Aperture_Priority(kal_uint32 iPara) 
{ 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Aperture_Priority */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_ISO 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_ISO(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_ISO_AUTO: 
    case CAM_ISO_100: 
    case CAM_ISO_200: 
    case CAM_ISO_400: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_ISO */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_DSC_Mode 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_DSC_Mode(kal_uint32 iPara) 
{ 
    switch(iPara) { 
    case CAM_AUTO_DSC: 
    case CAM_PORTRAIT: 
    case CAM_LANDSCAPE: 
    case CAM_SPORT: 
    case CAM_FLOWER: 
    case CAM_NIGHTSCENE: 
    case CAM_TV_MODE: 
    case CAM_AV_MODE: 
    case CAM_ISO_MODE: 
    default: 
	    return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_DSC_Mode */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Effect 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Effect(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_EFFECT_DEC_NORMAL: 
        write_cmos_sensor(0xE6, 0xFF); 
        write_cmos_sensor(0xE7, 0x00); 
        write_cmos_sensor(0xE8, 0xFF); 
        write_cmos_sensor(0xE9, 0x00); 
        break; 
 
    case CAM_EFFECT_DEC_GRAYSCALE: 
        write_cmos_sensor(0xE6, 0x80); 
        write_cmos_sensor(0xE8, 0x80); 
        write_cmos_sensor(0xE7, 0x80); 
        write_cmos_sensor(0xE9, 0x80); 
        break; 
 
    case CAM_EFFECT_DEC_SEPIA: 
        write_cmos_sensor(0xE6, 0xA0); 
        write_cmos_sensor(0xE7, 0xA0); 
        write_cmos_sensor(0xE8, 0x60); 
        write_cmos_sensor(0xE9, 0x60); 
        break; 
 
    case CAM_EFFECT_DEC_SEPIAGREEN: 
        write_cmos_sensor(0xE6, 0x50); 
        write_cmos_sensor(0xE7, 0x50); 
        write_cmos_sensor(0xE8, 0x50); 
        write_cmos_sensor(0xE9, 0x50); 
        break; 
 
    case CAM_EFFECT_DEC_SEPIABLUE: 
        write_cmos_sensor(0xE6, 0x60); 
        write_cmos_sensor(0xE7, 0x60); 
        write_cmos_sensor(0xE8, 0xC0); 
        write_cmos_sensor(0xE9, 0xC0); 
        break; 
 
    case CAM_EFFECT_DEC_COLORINV: 
    case CAM_EFFECT_DEC_GRAYINV: 
    case CAM_EFFECT_DEC_WATERCOLOR: 
    case CAM_EFFECT_DEC_LIGHTBLUR: 
    case CAM_EFFECT_DEC_BLUR: 
    case CAM_EFFECT_DEC_STRONGBLUR: 
    case CAM_EFFECT_DEC_UNSHARP: 
    case CAM_EFFECT_DEC_SHARPEN: 
    case CAM_EFFECT_DEC_MORESHARPEN: 
    case CAM_EFFECT_DEC_MEDIAN: 
    case CAM_EFFECT_DEC_DILATION: 
    case CAM_EFFECT_DEC_EROSION: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_TRUE; 
}   /* SIV100A_Set_Para_Effect */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_AF_Key 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_AF_Key(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_AF_RELEASE: 
    case CAM_AF_ONE_TIME: 
    case CAM_AF_CONTINUE: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_AF_Key */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Manual_Focus_Dir 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Manual_Focus_Dir(kal_uint32 iPara) 
{ 
	switch (iPara) { 
    case CAM_FOCUS_STOP: 
    case CAM_FOCUS_FORWARD: 
    case CAM_FOCUS_BACKWARD: 
    case CAM_FOCUS_FORWARD_CONTINUE: 
    case CAM_FOCUS_BACKWARD_CONTINUE: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Manual_Focus_Dir */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_AF_Mode 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_AF_Mode(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_AF_AUTO_MODE: 
    case CAM_AF_MACRO_MODE: 
    case CAM_AF_INFINITE_MODE: 
    case CAM_AF_MANUAL_MODE: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_AF_Mode */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_AF_Meter 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_AF_Meter(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_AF_SINGLE_ZONE: 
    case CAM_AF_MULTI3_ZONE: 
    case CAM_AF_MULTI5_ZONE: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_AF_Meter */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_Set_Para_Flash 
* 
* DESCRIPTION 
*   SIV100A 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_Set_Para_Flash(kal_uint32 iPara) 
{ 
    switch (iPara) { 
    case CAM_FLASH_OFF: 
    case CAM_FLASH_ON: 
    case CAM_FLASH_AUTO: 
    case CAM_FLASH_REDEYE: 
    default: 
        return KAL_FALSE; 
    } 
 
    return KAL_FALSE; 
}   /* SIV100A_Set_Para_Flash */ 
 
/************************************************************************* 
* FUNCTION 
*   SIV100A_YUV_SensorSetting 
* 
* DESCRIPTION 
*   This function sends command and parameter to YUV-mode SIV100A to configure it 
* 
* PARAMETERS 
*   None 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
kal_uint32 SIV100A_YUV_SensorSetting(kal_uint32 iCmd, kal_uint32 iPara) 
{ 
    kal_uint32 iRet = KAL_FALSE; 
 
    switch (iCmd) { 
    case CAM_PARAM_ZOOM_FACTOR: 
        iRet = SIV100A_Set_Para_Zoom(iPara); 
        break; 
 
    case CAM_PARAM_CONTRAST: 
        iRet = SIV100A_Set_Para_Contrast(iPara); 
        break; 
 
    case CAM_PARAM_BRIGHTNESS: 
        iRet = SIV100A_Set_Para_Brightness(iPara); 
        break; 
 
    case CAM_PARAM_HUE: 
        iRet = SIV100A_Set_Para_Hue(iPara); 
        break; 
 
    case CAM_PARAM_GAMMA: 
        iRet = SIV100A_Set_Para_Gamma(iPara); 
        break; 
 
    case CAM_PARAM_WB: 
        iRet = SIV100A_Set_Para_WB(iPara); 
        break; 
 
    case CAM_PARAM_EXPOSURE: 
        iRet = SIV100A_Set_Para_EV(iPara); 
        break; 
 
    case CAM_PARAM_EFFECT: 
        iRet = SIV100A_Set_Para_Effect(iPara); 
        break; 
 
    case CAM_PARAM_BANDING: 
        iRet = SIV100A_Set_Para_Banding(iPara); 
        break; 
 
    case CAM_PARAM_SATURATION: 
        iRet = SIV100A_Set_Para_Saturation(iPara); 
        break; 
 
    case CAM_PARAM_NIGHT_MODE: 
        iRet = SIV100A_Set_Para_NightMode(iPara); 
        break; 
 
    case CAM_PARAM_EV_VALUE: 
        iRet = SIV100A_Set_Para_EV(iPara); 
        break; 
 
    case CAM_PARAM_FLASH: 
        iRet = SIV100A_Set_Para_Flash(iPara); 
        break; 
 
    case CAM_PARAM_AE_METERING: 
        iRet = SIV100A_Set_Para_AE_Meter(iPara); 
        break; 
 
    case CAM_PARAM_AF_KEY: 
        iRet = SIV100A_Set_Para_AF_Key(iPara); 
        break; 
 
    case CAM_PARAM_AF_METERING: 
        iRet = SIV100A_Set_Para_AF_Meter(iPara); 
        break; 
 
    case CAM_PARAM_AF_MODE: 
        iRet = SIV100A_Set_Para_AF_Mode(iPara); 
        break; 
 
    case CAM_PARAM_MANUAL_FOCUS_DIR: 
        iRet = SIV100A_Set_Para_Manual_Focus_Dir(iPara); 
        break; 
 
    case CAM_PARAM_SHUTTER_PRIORITY: 
        iRet = SIV100A_Set_Para_Shutter_Priority(iPara); 
        break; 
 
    case CAM_PARAM_APERTURE_PRIORITY: 
        iRet = SIV100A_Set_Para_Aperture_Priority(iPara); 
        break; 
 
    case CAM_PARAM_ISO: 
        iRet = SIV100A_Set_Para_ISO(iPara); 
        break; 
 
    case CAM_PARAM_DSC_MODE: 
        iRet = SIV100A_Set_Para_DSC_Mode(iPara); 
        break; 
 
    default: 
        ASSERT(0); 
    } 
 
    return iRet; 
}   /* SIV100A_YUV_SensorSetting */ 
 
/************************************************************************* 
* FUNCTION 
*	image_sensor_func_OV76X0 
* 
* DESCRIPTION 
*	OV76X0 Image Sensor functions struct. 
* 
* PARAMETERS 
*	none 
* 
* RETURNS 
*	None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
image_sensor_func_struct image_sensor_func_SIV100A = 
{ 
    SIV100A_Init, 
    SIV100A_Get_I2C_ID, 
    SIV100A_GetSize, 
    SIV100A_GetPeriod, 
    SIV100A_Preview, 
    SIV100A_Capture, 
    SIV100A_WriteReg, 
    SIV100A_ReadReg, 
    SIV100A_SetShutter, 
    SIV100A_NightMode, 
    SIV100A_PowerOff, 
    SIV100A_SetGain, 
    SIV100A_SetFlash, 
    SIV100A_YUV_SensorSetting 
};  /* image_sensor_func_SIV100A */ 
 
/************************************************************************* 
* FUNCTION 
*   image_sensor_func_config 
* 
* DESCRIPTION 
*   This function maps the external camera module function API structure. 
* 
* PARAMETERS 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void image_sensor_func_config(void) 
{ 
    image_sensor_func = &image_sensor_func_SIV100A; 
}   /* image_sensor_func_config() */ 
 
/************************************************************************* 
* FUNCTION 
*   camera_para_to_sensor 
* 
* DESCRIPTION 
*   This function write initial setting sequence into sensor's registers 
* 
* PARAMETERS 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void camera_para_to_sensor(void) 
{ 
    kal_uint16 iI; 
 
    for (iI = 0; camera_para.SENSOR.reg[iI].addr != 0xFFFFFFFF; iI++) { 
        write_cmos_sensor(camera_para.SENSOR.reg[iI].addr, camera_para.SENSOR.reg[iI].para); 
    } 
 
    for (iI = FACTORY_START_ADDR; camera_para.SENSOR.reg[iI].addr != 0xFFFFFFFF; iI++) { 
        write_cmos_sensor(camera_para.SENSOR.reg[iI].addr, camera_para.SENSOR.reg[iI].para); 
    } 
 
    for (iI = 0; iI < CCT_END_ADDR; iI++) { 
        write_cmos_sensor(camera_para.SENSOR.cct[iI].addr, camera_para.SENSOR.cct[iI].para); 
    } 
}   /* camera_para_to_sensor */ 
 
/************************************************************************* 
* FUNCTION 
*   sensor_to_camera_para 
* 
* DESCRIPTION 
*   This function read back sensor's register values to camera_para structure 
* 
* PARAMETERS 
* 
* RETURNS 
*   None 
* 
* GLOBALS AFFECTED 
* 
*************************************************************************/ 
void sensor_to_camera_para(void) 
{ 
}   /* sensor_to_camera_para */ 
 
//------------------------Engineer mode--------------------------------- 
/******************************************************** 
*   Engineer mode is unnecessary for YUV sensor driver  * 
********************************************************/ 
void get_sensor_group_count(kal_int32 *pGroupCount) 
{ 
} 
 
void get_sensor_group_info(kal_uint16 group_idx, kal_int8* group_name_ptr, kal_int32* item_count_ptr) 
{ 
} 
 
void get_sensor_item_info(kal_uint16 group_idx,kal_uint16 item_idx, ENG_sensor_info* info_ptr) 
{ 
} 
 
kal_bool set_sensor_item_info(kal_uint16 group_idx, kal_uint16 item_idx, kal_int32 item_value) 
{ 
    return KAL_TRUE; 
}