📄 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 "isp_yuv_if.h"
#include "image_sensor.h"
#include "camera_para.h"
#include "upll_ctrl.h"
#include "med_api.h"
#define SLOW_DOWN_SENSOR_FOR_240X320_LCD //Add dummy pixel to slow down frame rate from 30 to 20 fps
/* Global Valuable */
SensorInfo g_CCT_MainSensor = OV7660_OMNIVISION; // must be defined but not referenced by YUV driver
kal_uint8 g_CCT_FirstGrabColor = INPUT_ORDER_YCbY1Cr; // 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_bMJPEGMode = KAL_FALSE; // KAL_TRUE for motion jpeg recorder mode
static kal_bool g_bCaptureMode = KAL_FALSE;
kal_uint32 g_iPreviewExp = 0;
kal_uint32 g_iFlicker = 0;
/* 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 = MC501CB_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(MC501CB_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 = MC501CB_I2C_WRITE_ID | SCCB_DATA_REG_ID_ADDRESS;
REG_SCCB_DATA = addr;
while (SCCB_IS_WRITTING);
ENABLE_SCCB;
REG_SCCB_DATA = MC501CB_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(MC501CB_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<SENSOR_I2C_DELAY;j++);
I2C_START_TRANSMISSION;
for (j = 0; j < SENSOR_I2C_DELAY; j++);
SCCB_send_byte(MC501CB_I2C_READ_ID);
for (j = 0; j < SENSOR_I2C_DELAY; j++);
get_byte = SCCB_get_byte();
for (j = 0; j < SENSOR_I2C_DELAY; j++);
I2C_STOP_TRANSMISSION;
#endif
return get_byte;
} /* read_cmos_sensor() */
/*************************************************************************
* FUNCTION
* MC501CB_WriteReg
*
* DESCRIPTION
* This function set the register of MC501CB.
*
* PARAMETERS
* iAddr : the register index of MC501CB
* iPara : setting parameter of the specified register of MC501CB
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void MC501CB_WriteReg(kal_uint32 iAddr, kal_uint32 iPara)
{
const kal_uint8 iPage = (iAddr & 0x0000FF00) >> 8;
ASSERT(iPage < 5);
write_cmos_sensor(0x03, (kal_uint8) iPage); // change page
write_cmos_sensor((kal_uint8) (iAddr & 0x000000FF), iPara);
} /* MC501CB_WriteReg() */
/*************************************************************************
* FUNCTION
* MC501CB_ReadReg
*
* DESCRIPTION
* This function read parameter of specified register from MC501CB.
*
* PARAMETERS
* iAddr: the register index of MC501CB
*
* RETURNS
* the data that read from MC501CB
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 MC501CB_ReadReg(kal_uint32 iAddr)
{
const kal_uint8 iPage = (iAddr & 0x0000FF00) >> 8;
ASSERT(iPage < 5);
write_cmos_sensor(0x03, (kal_uint8) iPage); // change page
return read_cmos_sensor((kal_uint8) (iAddr & 0x000000FF));
} /* MC501CB_ReadReg() */
/*************************************************************************
* FUNCTION
* MC501CB_Write_Sensor_Initial_Setting
*
* DESCRIPTION
* This function initialize the registers of CMOS sensor.
*
* PARAMETERS
* None
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void MC501CB_Write_Sensor_Initial_Setting(void)
{
CHANGE_TO_PAGE(0);
write_cmos_sensor(0x01, 0x01); // power sleep mode on
write_cmos_sensor(0x01, 0x03); // power sleep mode on + ???
write_cmos_sensor(0x01, 0x01); // power sleep mode on
write_cmos_sensor(0x00, 0x00); // ???
write_cmos_sensor(0x02, 0x00); // ???
write_cmos_sensor(0x01, 0x01); // power sleep mode on
write_cmos_sensor(0x10, 0x00); // set to VGA output mode
write_cmos_sensor(0x11, 0x80); // enable windowing
write_cmos_sensor(0x12, 0x0C); // setup sync signal polarity
// window region setup
write_cmos_sensor(0x13, 0x00); // WINROWH
write_cmos_sensor(0x14, 0x01); // WINROWL
write_cmos_sensor(0x15, 0x00); // WINCOLH
write_cmos_sensor(0x16, 0x05); // WINCOLL
write_cmos_sensor(0x17, 0x01); // WINHGTH
write_cmos_sensor(0x18, 0xE0); // WINHGTL
write_cmos_sensor(0x19, 0x02); // WINWIDH
write_cmos_sensor(0x1A, 0x80); // WINWIDL
// HBLANK and VBLANK setting
write_cmos_sensor(0x1B, 0x00); // HBLANKH
write_cmos_sensor(0x1C, 0x6C); // HBLANKL
/************************************
* VSCLIP < VBLANK, otherwise *
* there will be no sensor output. *
************************************/
write_cmos_sensor(0x1D, 0x00); // VSYNCH
write_cmos_sensor(0x1E, 0x14); // VSYNCL
write_cmos_sensor(0x1F, 0x09); // VSCLIP
write_cmos_sensor(0x20, 0xA8); // ABLC
write_cmos_sensor(0x21, 0x00); // ???
write_cmos_sensor(0x40, 0x33); // ???
write_cmos_sensor(0x41, 0x77); // ???
write_cmos_sensor(0x42, 0x53); // ???
write_cmos_sensor(0x43, 0xB0); // ???
write_cmos_sensor(0x44, 0x10); // ???
write_cmos_sensor(0x45, 0x00); // ???
write_cmos_sensor(0x46, 0x00); // ???
write_cmos_sensor(0x47, 0x8F); // ???
write_cmos_sensor(0x48, 0x4A); // ???
write_cmos_sensor(0x49, 0x00); // ???
write_cmos_sensor(0x4A, 0x03); // ???
write_cmos_sensor(0x85, 0x50); // ???
write_cmos_sensor(0x91, 0x70); // ???
write_cmos_sensor(0x92, 0x72); // ???
CHANGE_TO_PAGE(1);
write_cmos_sensor(0x10, 0x03); // ISPCTL1, YUV output control
write_cmos_sensor(0x11, 0x03); // ISPCTL2, color space, interpolation
write_cmos_sensor(0x12, 0x10); // ISPCTL3
write_cmos_sensor(0x13, 0x00); // ISPCTL4
write_cmos_sensor(0x14, 0x80); // ???
write_cmos_sensor(0x20, 0x0F); // SATCTL
// color correction setting
write_cmos_sensor(0x30, 0x0F); // CMCCTL
write_cmos_sensor(0x36, 0x3F); // CMCSIGN
write_cmos_sensor(0x38, 0x6F); // CMC11
write_cmos_sensor(0x39, 0x2F); // CMC12
write_cmos_sensor(0x3A, 0x00); // CMC13
write_cmos_sensor(0x3B, 0x1A); // CMC21
write_cmos_sensor(0x3C, 0x75); // CMC22
write_cmos_sensor(0x3D, 0x1A); // CMC23
write_cmos_sensor(0x3E, 0x0E); // CMC31
write_cmos_sensor(0x3F, 0x38); // CMC32
write_cmos_sensor(0x40, 0x86); // CMC33
write_cmos_sensor(0x41, 0x00); // ???
write_cmos_sensor(0x42, 0x0F); // ???
write_cmos_sensor(0x43, 0x8F); // ???
write_cmos_sensor(0x44, 0x03); // ???
write_cmos_sensor(0x45, 0x00); // ???
write_cmos_sensor(0x46, 0x84); // ???
write_cmos_sensor(0x47, 0x97); // ???
write_cmos_sensor(0x48, 0xA2); // ???
write_cmos_sensor(0x49, 0x3A); // ???
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -