/******************************************************************************
Copyright (C), 2016, Hisilicon Tech. Co., Ltd.
******************************************************************************
File Name : imx347_cmos.c
Version : Initial Draft
Author : Hisilicon multimedia software group
Created : 2013/11/07
Description :
History :
1.Date : 2013/11/07
Author :
Modification: Created file
******************************************************************************/
#if !defined(__imx347_CMOS_H_)
#define __imx347_CMOS_H_
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "hi_comm_sns.h"
#include "hi_comm_video.h"
#include "hi_sns_ctrl.h"
#include "mpi_isp.h"
#include "mpi_ae.h"
#include "mpi_awb.h"
#include "imx347_cmos_ex.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */
#define imx347_ID 347
#define HIGHER_4BITS(x) (((x) & 0xf0000) >> 16)
#define HIGH_8BITS(x) (((x) & 0xff00) >> 8)
#define LOW_8BITS(x) ((x) & 0x00ff)
#ifndef MAX
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#endif
#ifndef MIN
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#endif
ISP_SNS_STATE_S *g_pastimx347[ISP_MAX_PIPE_NUM] = {HI_NULL};
#define imx347_SENSOR_GET_CTX(dev, pstCtx) (pstCtx = g_pastimx347[dev])
#define imx347_SENSOR_SET_CTX(dev, pstCtx) (g_pastimx347[dev] = pstCtx)
#define imx347_SENSOR_RESET_CTX(dev) (g_pastimx347[dev] = HI_NULL)
static HI_U32 g_au32InitExposure[ISP_MAX_PIPE_NUM] = {0};
static HI_U32 g_au32LinesPer500ms[ISP_MAX_PIPE_NUM] = {0};
static HI_U16 g_au16InitWBGain[ISP_MAX_PIPE_NUM][3] = {{0}};
static HI_U16 g_au16SampleRgain[ISP_MAX_PIPE_NUM] = {0};
static HI_U16 g_au16SampleBgain[ISP_MAX_PIPE_NUM] = {0};
ISP_SNS_COMMBUS_U g_aunimx347BusInfo[ISP_MAX_PIPE_NUM] =
{
[0] = { .s8I2cDev = 1},
[1 ... ISP_MAX_PIPE_NUM - 1] = { .s8I2cDev = -1}
};
static ISP_FSWDR_MODE_E genFSWDRMode[ISP_MAX_PIPE_NUM] =
{
[0 ... ISP_MAX_PIPE_NUM - 1] = ISP_FSWDR_NORMAL_MODE
};
static HI_U32 gu32MaxTimeGetCnt[ISP_MAX_PIPE_NUM] = {0};
typedef struct hiimx347_STATE_S
{
HI_U32 u32BRL;
HI_U32 u32RHS1_MAX;
HI_U32 u32deltaRHS1;
} imx347_STATE_S;
imx347_STATE_S g_astimx347State[ISP_MAX_PIPE_NUM] = {{0}};
/****************************************************************************
* extern *
****************************************************************************/
extern unsigned char imx347_i2c_addr;
extern unsigned int imx347_addr_byte;
extern unsigned int imx347_data_byte;
extern void imx347_init(VI_PIPE ViPipe);
extern void imx347_exit(VI_PIPE ViPipe);
extern void imx347_standby(VI_PIPE ViPipe);
extern void imx347_restart(VI_PIPE ViPipe);
extern int imx347_write_register(VI_PIPE ViPipe, int addr, int data);
extern int imx347_read_register(VI_PIPE ViPipe, int addr);
/****************************************************************************
* local variables *
****************************************************************************/
#define imx347_FULL_LINES_MAX (0xFFFFF) /* VMAX is 20bit */
#define imx347_FULL_LINES_MAX_2TO1_WDR (0x1194) //considering the YOUT_SIZE and bad frame
#define imx347_SHR0_L (0x3058) /* SHR0[7:0] */
#define imx347_SHR0_M (0x3059) /* SHR0[15:8] */
#define imx347_SHR0_H (0x305a) /* SHR0[19:16] */
#define imx347_SHR1_L (0x305c) /* SHR1[7:0] */
#define imx347_SHR1_M (0x305d) /* SHR1[15:8] */
#define imx347_SHR1_H (0x305e) /* SHR1[19:16] */
#define imx347_RHS1_L (0x3068) /* RHS1[7:0] */
#define imx347_RHS1_M (0x3069) /* RHS1[15:8] */
#define imx347_RHS1_H (0x306a) /* RHS1[19:16] */
#define imx347_PGC_L (0x30e8) /* GAIN[7:0] */
#define imx347_PGC_H (0x30e9) /* GAIN[10:8] */
#define imx347_VMAX_L (0x3030) /* VMAX[7:0] */
#define imx347_VMAX_M (0x3031) /* VMAX[15:8] */
#define imx347_VMAX_H (0x3032) /* VMAX[19:16] */
#define imx347_Y_OUTSIZE_L (0x3308) /* Y_OUT_SIZE [7:0]*/
#define imx347_Y_OUTSIZE_H (0x3309) /* Y_OUT_SIZE [12:8]*/
#define imx347_INCREASE_LINES (0) /* make real fps less than stand fps because NVR require*/
#define imx347_VMAX_4M_30FPS_12BIT_LINEAR (0x8CA+imx347_INCREASE_LINES)
#define imx347_VMAX_4M_30FPS_12BIT_2TO1_WDR (0x8CA+imx347_INCREASE_LINES)
//sensor fps mode
#define imx347_4M_30FPS_12BIT_LINEAR_MODE (1) /* 4M@30fps Linear 12bit*/
#define imx347_4M_30FPS_12BIT_2t1_DOL_MODE (2)
#define imx347_RES_IS_4M30_12BIT(w, h) ((2688 == (w)) && (1520 == (h)))
//sensor gain
#define imx347_AGAIN_MAX (31356) //the max again is 31356
#define imx347_DGAIN_MAX (124833) //the max dgain is 124833
static HI_S32 cmos_get_ae_default(VI_PIPE ViPipe, AE_SENSOR_DEFAULT_S *pstAeSnsDft)
{
ISP_SNS_STATE_S *pstSnsState = HI_NULL;
CMOS_CHECK_POINTER(pstAeSnsDft);
imx347_SENSOR_GET_CTX(ViPipe, pstSnsState);
CMOS_CHECK_POINTER(pstSnsState);
memset(&pstAeSnsDft->stAERouteAttr, 0, sizeof(ISP_AE_ROUTE_S));
pstAeSnsDft->u32FullLinesStd = pstSnsState->u32FLStd;
pstAeSnsDft->u32FlickerFreq = 0;
pstAeSnsDft->u32FullLinesMax = imx347_FULL_LINES_MAX;
pstAeSnsDft->stIntTimeAccu.enAccuType = AE_ACCURACY_LINEAR;
pstAeSnsDft->stIntTimeAccu.f32Accuracy = 1;
pstAeSnsDft->stIntTimeAccu.f32Offset = 0;
pstAeSnsDft->stAgainAccu.enAccuType = AE_ACCURACY_TABLE;
pstAeSnsDft->stAgainAccu.f32Accuracy = 1;
pstAeSnsDft->stDgainAccu.enAccuType = AE_ACCURACY_TABLE;
pstAeSnsDft->stDgainAccu.f32Accuracy = 1;
pstAeSnsDft->u32ISPDgainShift = 8;
pstAeSnsDft->u32MinISPDgainTarget = 1 << pstAeSnsDft->u32ISPDgainShift;
pstAeSnsDft->u32MaxISPDgainTarget = 4 << pstAeSnsDft->u32ISPDgainShift;
memcpy(&pstAeSnsDft->stPirisAttr, &gstPirisAttr, sizeof(ISP_PIRIS_ATTR_S));
pstAeSnsDft->enMaxIrisFNO = ISP_IRIS_F_NO_1_4;
pstAeSnsDft->enMinIrisFNO = ISP_IRIS_F_NO_5_6;
pstAeSnsDft->bAERouteExValid = HI_FALSE;
pstAeSnsDft->stAERouteAttr.u32TotalNum = 0;
pstAeSnsDft->stAERouteAttrEx.u32TotalNum = 0;
if (g_au32InitExposure[ViPipe] == 0)
{
pstAeSnsDft->u32InitExposure = 1000000;
}
//else
//{
//pstAeSnsDft->u32InitExposure = pstAeSnsDft->u32InitExposure;
//}
if (g_au32LinesPer500ms[ViPipe] == 0)
{
pstAeSnsDft->u32LinesPer500ms = pstSnsState->u32FLStd * 30 / 2;
}
else
{
pstAeSnsDft->u32LinesPer500ms = g_au32LinesPer500ms[ViPipe];
}
switch (pstSnsState->enWDRMode)
{
default:
case WDR_MODE_NONE:
pstAeSnsDft->au8HistThresh[0] = 0xd;
pstAeSnsDft->au8HistThresh[1] = 0x28;
pstAeSnsDft->au8HistThresh[2] = 0x60;
pstAeSnsDft->au8HistThresh[3] = 0x80;
pstAeSnsDft->u8AeCompensation = 0x38;
pstAeSnsDft->enAeExpMode = AE_EXP_HIGHLIGHT_PRIOR;
pstAeSnsDft->u32MaxIntTime = pstSnsState->u32FLStd - 5;
pstAeSnsDft->u32MinIntTime = 1;
pstAeSnsDft->u32MaxIntTimeTarget = 65535;
pstAeSnsDft->u32MinIntTimeTarget = pstAeSnsDft->u32MinIntTime;
pstAeSnsDft->u32MaxAgain = 31356;
pstAeSnsDft->u32MinAgain = 1024;
pstAeSnsDft->u32MaxAgainTarget = pstAeSnsDft->u32MaxAgain;
pstAeSnsDft->u32MinAgainTarget = pstAeSnsDft->u32MinAgain;
pstAeSnsDft->u32MaxDgain = 128913; /* if Dgain enable,please set ispdgain bigger than 1*/
pstAeSnsDft->u32MinDgain = 1024;
pstAeSnsDft->u32MaxDgainTarget = pstAeSnsDft->u32MaxDgain;
pstAeSnsDft->u32MinD
评论0