diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bb56f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.so +*.a \ No newline at end of file diff --git a/HowToCompile.txt b/HowToCompile.txt new file mode 100644 index 0000000..f80c107 --- /dev/null +++ b/HowToCompile.txt @@ -0,0 +1,41 @@ + + +#to compile for HiSilicon +export SDK_CODE=0x3516E200 +#export PATH=/home/home/src/openipc/output/host/bin:$PATH + +#this compiles but giver error on cam +#make CROSS_COMPILE=arm-openipc-linux-musleabi- CHIPARCH=hi3516ev200 + +# This will compile it correctly ! Set CHIPARCH and SDK_CODE accordingly !!! +``` +make \ +PATH="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin:/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/sbin:/home/home/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin" AR="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gcc-ar" AS="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-as" LD="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-ld" NM="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gcc-nm" CC="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gcc" GCC="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gcc" CPP="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-cpp" CXX="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-g++" FC="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gfortran" F77="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gfortran" RANLIB="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-gcc-ranlib" READELF="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-readelf" STRIP="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-strip" OBJCOPY="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-objcopy" OBJDUMP="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-objdump" AR_FOR_BUILD="/usr/bin/ar" AS_FOR_BUILD="/usr/bin/as" CC_FOR_BUILD="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/ccache /usr/bin/gcc" GCC_FOR_BUILD="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/ccache /usr/bin/gcc" CXX_FOR_BUILD="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/ccache /usr/bin/g++" LD_FOR_BUILD="/usr/bin/ld" CPPFLAGS_FOR_BUILD="-I/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/include" CFLAGS_FOR_BUILD="-O2 -I/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/include" CXXFLAGS_FOR_BUILD="-O2 -I/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/include" LDFLAGS_FOR_BUILD="-L/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/lib -Wl,-rpath,/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/lib" FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-as" DEFAULT_LINKER="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/arm-openipc-linux-musleabi-ld" CPPFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 " CXXFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 " LDFLAGS="" FCFLAGS=" -Os -g0" FFLAGS=" -Os -g0" PKG_CONFIG="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/bin/pkg-config" STAGING_DIR="/home/home/src/openipc/output/per-package/hisilicon-opensdk/host/arm-buildroot-linux-musleabi/sysroot" INTLTOOL_PERL=/usr/bin/perl \ +CHIPARCH=hi3516ev200 SDK_CODE=0x3516E200 -C /home/home/src/openhisilicon/openhisilicon/libraries all +``` + +copy driver to device: +scp /home/home/src/openhisilicon/openhisilicon/libraries/sensor/hi3516ev200/sony_imx335_fpv/libsns_imx335.so root@192.168.1.88:/usr/lib/sensors/libsns_imx335ex.so + +CHIPARCH=hi3516ev200 +export SDK_CODE=0x3516E200 +or +CHIPARCH=gk7205v200 +export SDK_CODE=0x7205200 + + +# To compile via copying over current drivers: +Compile OpenIPC for Hisilicon in ```/home/home/src/openipc/```. +Change code and copy over stock drivers: +cp imx335_sensor_ctl.c /home/home/src/openipc/output/build/hisilicon-opensdk/libraries/sensor/hi3516ev200/sony_imx335 +cp imx335_cmos.c /home/home/src/openipc/output/build/hisilicon-opensdk/libraries/sensor/hi3516ev200/sony_imx335 +cp Makefile /home/home/src/openipc/output/build/hisilicon-opensdk/libraries/sensor/hi3516ev200/sony_imx335 + +This will rebuild it: +make -C /home/home/src/openipc/output/ hisilicon-opensdk-rebuild + +copy driver to device: +scp /home/home/src/openipc/output/build/hisilicon-opensdk/libraries/sensor/hi3516ev200/sony_imx335/libsns_imx335.so root@192.168.1.88:/usr/lib/sensors/libsns_imx335ex.so + + + diff --git a/README.md b/README.md index 3db776a..0237573 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,25 @@ Opensource HiSilicon/Goke SoCs SDK Used by OpenIPC firmware and can be used by your software as well (libraries are MIT and kernel modules are GPL) + +## Changes for FPV sensor modes + +# Higher FPS imx335 sensor driver on Goke/Hisilicon SoCs. +Sensor modes added: +### 2592x1520 50fps , slightly cropped vertically to 16:9 +for on hi356ev300 : Isp_FrameRate=50 , majestic set to 1920x1080 50fps => 50fps +for gk7205v300 : Isp_FrameRate=48 , majestic set to 1920x1080 48fps => 47fps + +### 2592x1944 fullscale mode boosted to 40fps +for on hi356ev300 set Isp_FrameRate=45, majestic to 1920x1080 fps: 45 to get 39fps +for on gk7205v300 set Isp_FrameRate=36, majestic to 1920x1080 fps: 36 to get 33fps + +### 1920x1080 cropped, max 90fps , zoom 1.5x +Isp_FrameRate=90 # can work at 90fps only when majestic is set to 1280x720 !!! +Max Isp_FrameRate=55 for 1920x1080 + +### 1296x972 binning max 65fps, +Isp_FrameRate=68 # # max supported value on hi356ev300 at 1280x720 + +### 2592x1944 stock fullscale 30fps mode +set Isp_FrameRate=30 to enable this mode diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/Makefile b/libraries/sensor/hi3516ev200/sony_imx335_fpv/Makefile new file mode 100644 index 0000000..46feab2 --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/Makefile @@ -0,0 +1,17 @@ +LIB_NAME := libsns_imx335_fpv + +override CFLAGS += -DSDK_CODE=$(SDK_CODE) -fPIC -I$(CURDIR)/../../../../include -DCHIPARCH=$(CHIPARCH) + +SRCS := $(wildcard *.c) +OBJS := $(SRCS:%.c=%.o) $(ASM_SRCS:%.S=%.o) + +all: $(LIB_NAME).so $(LIB_NAME).a + +$(LIB_NAME).so: $(OBJS) + $(CC) -shared -o $@ $(OBJS) + +$(LIB_NAME).a: $(OBJS) + $(AR) -rcs $(LIB_NAME).a $(OBJS) + +clean: + -rm $(OBJS) $(LIB_NAME).so diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/Readme.md b/libraries/sensor/hi3516ev200/sony_imx335_fpv/Readme.md new file mode 100644 index 0000000..74a8abd --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/Readme.md @@ -0,0 +1,45 @@ +# Higher FPS imx335 sensor driver on Goke/Hisilicon SoCs. +Sensor modes added: +### 2592x1520 50fps , slightly cropped vertically to 16:9 +for on hi356ev300 : Isp_FrameRate=50 , majestic set to 1920x1080 50fps => 50fps +for gk7205v300 : Isp_FrameRate=48 , majestic set to 1920x1080 48fps => 47fps + +### 2592x1944 fullscale mode boosted to 40fps +for on hi356ev300 set Isp_FrameRate=45, majestic to 1920x1080 fps: 45 to get 39fps +for on gk7205v300 set Isp_FrameRate=36, majestic to 1920x1080 fps: 36 to get 33fps + +### 1920x1080 cropped, max 90fps , zoom 1.5x +Isp_FrameRate=90 # can work at 90fps only when majestic is set to 1280x720 !!! +Max Isp_FrameRate=55 for 1920x1080 + +### 1296x972 binning max 65fps, +Isp_FrameRate=68 # # max supported value on hi356ev300 at 1280x720 + +### 2592x1944 stock fullscale 30fps mode +set Isp_FrameRate=30 to enable this mode + + +# To configure. +Copy new driver to camera as ```usr/lib/sensors/libsns_imx335_fpv.so``` + +Copy imx335_fpv.ini to ```/etc/sensors/imx335_fpv.ini``` + +in /etc/majestic.yaml set: +``` +video0: + codec: h265 + rcMode: cbr + gopSize: 1.5 + size: 1920x1080 + fps: 45 +... +isp: + sensorConfig: /etc/sensors/imx335_fpv.ini +``` + +follow instructions in /etc/sensors/imx335_fpv.ini + + + +### Follow instructions in imx335_fps.ini to set the sensor mode +All modes will work at fps: 45, some of them can run at higher refresh rate. \ No newline at end of file diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos.c b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos.c new file mode 100644 index 0000000..0d98d27 --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos.c @@ -0,0 +1,2100 @@ +/* + * Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021. All rights reserved. + */ + +#include +#include +#include +#include "comm_sns.h" +#include "comm_video.h" +#include "sns_ctrl.h" +#include "gk_api_isp.h" +#include "gk_api_ae.h" +#include "gk_api_awb.h" +#include "hicompat.h" + + +#include "imx335_cmos_ex.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* End of #ifdef __cplusplus */ + +#define IMX335_ID 335 + +#define IMX335_HIG_4BITS(x) (((x)&0xF0000) >> 16) +#define IMX335_MID_8BITS(x) (((x)&0x0FF00) >> 8) +#define IMX335_LOW_8BITS(x) ((x)&0x000ff) + +#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_pastImx335[ISP_MAX_PIPE_NUM] = { GK_NULL }; + +#define IMX335_SENSOR_GET_CTX(dev, pstCtx) (pstCtx = g_pastImx335[dev]) +#define IMX335_SENSOR_SET_CTX(dev, pstCtx) (g_pastImx335[dev] = pstCtx) +#define IMX335_SENSOR_RESET_CTX(dev) (g_pastImx335[dev] = GK_NULL) + +static GK_U32 g_au32InitExposure[ISP_MAX_PIPE_NUM] = { 0 }; +static GK_U32 g_au32LinesPer500ms[ISP_MAX_PIPE_NUM] = { 0 }; +static GK_U16 g_au16InitWBGain[ISP_MAX_PIPE_NUM][3] = { { 0 } }; +static GK_U16 g_au16SampleRgain[ISP_MAX_PIPE_NUM] = { 0 }; +static GK_U16 g_au16SampleBgain[ISP_MAX_PIPE_NUM] = { 0 }; + +static GK_U32 g_u32Imx335AGain[ISP_MAX_PIPE_NUM] = { [0 ...(ISP_MAX_PIPE_NUM - + 1)] = 1024 }; +static GK_U32 g_u32Imx335DGain[ISP_MAX_PIPE_NUM] = { [0 ...(ISP_MAX_PIPE_NUM - + 1)] = 1024 }; + +ISP_SNS_COMMBUS_U g_aunImx335BusInfo[ISP_MAX_PIPE_NUM] = { + [0] = { .s8I2cDev = 0 }, + [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 +}; + +typedef struct IMX335_STATE_S { + GK_U32 u32BRL; + GK_U32 u32RHS1_MAX; + GK_U32 u32deltaRHS1; +} IMX335_STATE_S; + +IMX335_STATE_S g_astimx335State[ISP_MAX_PIPE_NUM] = { { 0 } }; + +static GK_U32 gu32MaxTimeGetCnt[ISP_MAX_PIPE_NUM] = { 0 }; + +static GK_U32 gu32STimeFps = 30; +static GK_U32 gu32LGain = 0; + +/**************************************************************************** + * extern * + ****************************************************************************/ +extern unsigned char imx335_i2c_addr; +extern unsigned int imx335_addr_byte; +extern unsigned int imx335_data_byte; + +extern void IMX335_init(VI_PIPE ViPipe); +extern void IMX335_exit(VI_PIPE ViPipe); +extern void IMX335_standby(VI_PIPE ViPipe); +extern void IMX335_restart(VI_PIPE ViPipe); +extern int IMX335_write_register(VI_PIPE ViPipe, int addr, int data); +extern int IMX335_read_register(VI_PIPE ViPipe, int addr); + +/**************************************************************************** + * local variables * + ****************************************************************************/ +#define IMX335_FULL_LINES_MAX (0xFFFF) + +#define IMX335_VMAX_ADDR_L (0x3030) +#define IMX335_VMAX_ADDR_M (0x3031) +#define IMX335_VMAX_ADDR_H (0x3032) +#define IMX335_Y_OUT_SIZE_LOW (0x3056) +#define IMX335_Y_OUT_SIZE_HIGH (0x3057) +#define IMX335_SHR0_LOW (0x3058) +#define IMX335_SHR0_MIDDLE (0x3059) +#define IMX335_SHR0_HIGH (0x305A) +#define IMX335_SHR1_LOW (0x305C) +#define IMX335_SHR1_MIDDLE (0x305D) +#define IMX335_SHR1_HIGH (0x305E) +#define IMX335_RHS1_LOW (0x3068) +#define IMX335_RHS1_MIDDLE (0x3069) +#define IMX335_RHS1_HIGH (0x306A) +#define IMX335_GAIN_LONG_LOW (0x30E8) +#define IMX335_GAIN_LONG_HIGH (0x30E9) +#define IMX335_GAIN_SHORT_LOW (0x30EA) +#define IMX335_GAIN_SHORT_HIGH (0x30EB) + +#define IMX335_INCREASE_LINES \ + (0) /* make real fps less than stand fps because NVR require */ + +#define IMX335_VMAX_5M_30FPS_12BIT_LINEAR (0x1194 + IMX335_INCREASE_LINES) +#define IMX335_VMAX_5M_30FPS_10BIT_WDR (0x1194 + IMX335_INCREASE_LINES) +#define IMX335_VMAX_4M_30FPS_10BIT_WDR (3300 + IMX335_INCREASE_LINES)//0xCE4 +#define IMX335_VMAX_4M_25FPS_10BIT_WDR (0xBB8 + IMX335_INCREASE_LINES) + +#define IMX335_VMAX_BINNING (0x1194 + IMX335_INCREASE_LINES) //!? +#define IMX335_VMAX_CROPPED_1080P (0x8F8 + IMX335_INCREASE_LINES) //!? 0x8F8 +#define IMX335_VMAX_CROPPED_1520P (0xC58 + IMX335_INCREASE_LINES) //!? + +// sensor fps mode + +#define IMX335_5M_30FPS_12BIT_LINEAR_MODE (0) //2592x1944 +#define IMX335_5M_30FPS_10BIT_WDR_MODE (1) //2592x1944 +//#define IMX335_4M_25FPS_10BIT_WDR_MODE (2) //2560x1440 +#define IMX335_1520P_10BIT_MODE (2) //2560x1440 + +#define IMX335_4M_30FPS_10BIT_WDR_MODE (3) //2592x1520 +#define IMX335_60FPS_BINNING_MODE (4) //1296x972 +#define IMX335_60FPS_CROPPED_1080P_MODE (5) //1920x1080 +#define IMX335_60FPS_FULL_1944P_MODE (6) //2592x1944 + + +#define IMX335_RES_IS_5M_12BIT_LINEAR(w, h) (((w) == 2592) && ((h) == 1944)) +#define IMX335_RES_IS_5M_10BIT_WDR(w, h) (((w) == 2592) && ((h) == 1944)) +//#define IMX335_RES_IS_4M_12BIT_LINEAR(w, h) (((w) == 2592) && ((h) == 1520)) +#define IMX335_RES_IS_1520P_10BIT(w, h) (((w) == 2592) && ((h) == 1520)) +#define IMX335_RES_IS_4M_10BIT_LINEAR(w, h) (((w) == 2560) && ((h) == 1440)) +#define IMX335_RES_IS_4M_10BIT_WDR(w, h) (((w) == 2592) && ((h) == 1520)) +#define IMX335_RES_IS_4M_10BIT_WDR_EX(w, h) (((w) == 2560) && ((h) == 1440)) + +#define IMX335_RES_IS_BINNING_12BIT(w, h) (((w) == 1296) && ((h) == 972)) + +#define IMX335_RES_IS_BINNING(w, h) (((w) == 1296) && ((h) == 972)) + +#define IMX335_RES_IS_1080P(w, h) (((w) == 1920) && ((h) == 1080)) + +// sensor gain +#define IMX335_AGAIN_MIN (1024) +#define IMX335_AGAIN_MAX (32381) // the max again is 32381 + +#define IMX335_DGAIN_MIN (1024) +#define IMX335_DGAIN_MAX (128914) + +#define IMX335_AD_GAIN_TBL_RANGE 241 +#define IMX335_AGAIN_TBL_RANGE 100 +#define IMX335_DGAIN_TBL_RANGE 140 + +#define IMX335_ERR_MODE_PRINT(pstSensorImageMode, pstSnsState) \ + do { \ + ISP_TRACE( \ + MODULE_DBG_ERR, \ + "Not support! Width:%d, Height:%d, Fps:%f, WDRMode:%d\n", \ + pstSensorImageMode->u16Width, \ + pstSensorImageMode->u16Height, \ + pstSensorImageMode->f32Fps, pstSnsState->enWDRMode); \ + } while (0) + + +#define XSTR(x) STR(x) +#define STR(x) #x + +// add -DCHIPARCH=$(CHIPARCH) to make file!!! +// override CFLAGS += -DSDK_CODE=$(SDK_CODE) -fPIC -I$(CURDIR)/../../../../include -DCHIPARCH=$(CHIPARCH) +#ifndef CHIPARCH + #error "CHIPARCH is not defined. Please specify CHIPARCH during compilation." +#endif + + +static GK_S32 cmos_get_ae_default(VI_PIPE ViPipe, + AE_SENSOR_DEFAULT_S *pstAeSnsDft) +{ + GK_U32 u32Fll = 0; + GK_U32 U32MaxFps = 0; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER(pstAeSnsDft); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + if (IMX335_5M_30FPS_12BIT_LINEAR_MODE == pstSnsState->u8ImgMode + || IMX335_60FPS_CROPPED_1080P_MODE == pstSnsState->u8ImgMode + || IMX335_1520P_10BIT_MODE == pstSnsState->u8ImgMode + || IMX335_60FPS_FULL_1944P_MODE == pstSnsState->u8ImgMode + ) { + u32Fll = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + U32MaxFps = 60;//needs 60 ?? + pstSnsState->u32FLStd = + u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + } else if (IMX335_5M_30FPS_10BIT_WDR_MODE == pstSnsState->u8ImgMode) { + u32Fll = IMX335_VMAX_5M_30FPS_10BIT_WDR; + U32MaxFps = 30; + + pstSnsState->u32FLStd = + u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + + if (0 != (pstSnsState->u32FLStd % 4)) { + pstSnsState->u32FLStd = + pstSnsState->u32FLStd - + (pstSnsState->u32FLStd % 4) + + 4; //Because FSC value an integer multiple of 8 + } + pstSnsState->u32FLStd = pstSnsState->u32FLStd * 2; + + } else if (IMX335_4M_30FPS_10BIT_WDR_MODE == pstSnsState->u8ImgMode) { + u32Fll = IMX335_VMAX_4M_30FPS_10BIT_WDR; + U32MaxFps = 30; + pstSnsState->u32FLStd = + u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + + if (0 != (pstSnsState->u32FLStd % 4)) { + pstSnsState->u32FLStd = + pstSnsState->u32FLStd - + (pstSnsState->u32FLStd % 4) + + 4; //Because FSC value an integer multiple of 8 + } + pstSnsState->u32FLStd = pstSnsState->u32FLStd * 2; + } + +/* else if (IMX335_4M_25FPS_10BIT_WDR_MODE == pstSnsState->u8ImgMode) { + u32Fll = IMX335_VMAX_4M_25FPS_10BIT_WDR; + U32MaxFps = 25; + pstSnsState->u32FLStd = + u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + if (0 != (pstSnsState->u32FLStd % 4)) { + pstSnsState->u32FLStd = + pstSnsState->u32FLStd - + (pstSnsState->u32FLStd % 4) + + 4; //Because FSC value an integer multiple of 8 + } + pstSnsState->u32FLStd = pstSnsState->u32FLStd * 2; + + }*/ + else if (IMX335_60FPS_BINNING_MODE == pstSnsState->u8ImgMode) { + u32Fll = IMX335_VMAX_BINNING; + U32MaxFps = 60; + pstSnsState->u32FLStd = u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + } else { + u32Fll = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + U32MaxFps = 30; + pstSnsState->u32FLStd = + u32Fll * U32MaxFps / DIV_0_TO_1_FLOAT(gu32STimeFps); + } + + //pstSnsState->u32FLStd = u32Fll; + + pstAeSnsDft->stIntTimeAccu.f32Offset = 0; + pstAeSnsDft->u32MaxIntTime = pstSnsState->u32FLStd - 8; + + pstAeSnsDft->u32FullLinesStd = pstSnsState->u32FLStd; + pstAeSnsDft->u32FlickerFreq = 0; + + pstAeSnsDft->stIntTimeAccu.enAccuType = AE_ACCURACY_LINEAR; + pstAeSnsDft->stIntTimeAccu.f32Accuracy = 1; + + 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 = 2 << 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 = GK_FALSE; + pstAeSnsDft->stAERouteAttr.u32TotalNum = 0; + pstAeSnsDft->stAERouteAttrEx.u32TotalNum = 0; + + if (g_au32InitExposure[ViPipe] == 0) { + pstAeSnsDft->u32InitExposure = 130000; + } else { + pstAeSnsDft->u32InitExposure = g_au32InitExposure[ViPipe]; + } + + if (g_au32LinesPer500ms[ViPipe] == 0) { + pstAeSnsDft->u32LinesPer500ms = (u32Fll * U32MaxFps) >> 1; + } 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->u32MinIntTime = 2; + pstAeSnsDft->u32MaxIntTimeTarget = 65535; + pstAeSnsDft->u32MinIntTimeTarget = pstAeSnsDft->u32MinIntTime; + pstAeSnsDft->stIntTimeAccu.f32Offset = -0.198; + + pstAeSnsDft->u32MaxAgain = IMX335_AGAIN_MAX; + pstAeSnsDft->u32MinAgain = IMX335_AGAIN_MIN; + pstAeSnsDft->u32MaxAgainTarget = pstAeSnsDft->u32MaxAgain; + pstAeSnsDft->u32MinAgainTarget = pstAeSnsDft->u32MinAgain; + + pstAeSnsDft->u32MaxDgain = + IMX335_DGAIN_MAX; /* if Dgain enable,please set ispdgain bigger than 1 */ + pstAeSnsDft->u32MinDgain = IMX335_DGAIN_MIN; + pstAeSnsDft->u32MaxDgainTarget = pstAeSnsDft->u32MaxDgain; + pstAeSnsDft->u32MinDgainTarget = pstAeSnsDft->u32MinDgain; + + break; + } + + case WDR_MODE_2To1_LINE: { + /* FS WDR mode */ + pstAeSnsDft->au8HistThresh[0] = 0xc; + pstAeSnsDft->au8HistThresh[1] = 0x18; + pstAeSnsDft->au8HistThresh[2] = 0x60; + pstAeSnsDft->au8HistThresh[3] = 0x80; + + pstAeSnsDft->u8AeCompensation = 0x38; + + pstAeSnsDft->stIntTimeAccu.f32Accuracy = 4; + pstAeSnsDft->u32MinIntTime = 4; // 2;//192; + pstAeSnsDft->u32MaxIntTimeTarget = 65535; + pstAeSnsDft->u32MinIntTimeTarget = pstAeSnsDft->u32MinIntTime; + ; + pstAeSnsDft->stIntTimeAccu.f32Offset = -0.396; + + pstAeSnsDft->u32MaxIntTimeStep = 1000; + pstAeSnsDft->u32LFMinExposure = 15000000; + pstAeSnsDft->enAeExpMode = AE_EXP_LOWLIGHT_PRIOR; + + pstAeSnsDft->u32MaxAgain = IMX335_AGAIN_MAX; + pstAeSnsDft->u32MinAgain = IMX335_AGAIN_MIN; + pstAeSnsDft->u32MaxAgainTarget = pstAeSnsDft->u32MaxAgain; + pstAeSnsDft->u32MinAgainTarget = pstAeSnsDft->u32MinAgain; + + pstAeSnsDft->u32MaxDgain = + IMX335_DGAIN_MAX; /* if Dgain enable,please set ispdgain bigger than 1 */ + pstAeSnsDft->u32MinDgain = IMX335_DGAIN_MIN; + pstAeSnsDft->u32MaxDgainTarget = 1024; + pstAeSnsDft->u32MinDgainTarget = 1024; + pstAeSnsDft->u32MaxISPDgainTarget = + 16 << pstAeSnsDft->u32ISPDgainShift; + pstAeSnsDft->bDiffGainSupport = GK_TRUE; + + pstAeSnsDft->u32ExpRatioMin = + 0x80; // The exposure ration from 2x to convergence + + if (ISP_FSWDR_LONG_FRAME_MODE != genFSWDRMode[ViPipe]) { + pstAeSnsDft->u16ManRatioEnable = GK_FALSE; + pstAeSnsDft->au32Ratio[0] = 0x400; + pstAeSnsDft->au32Ratio[1] = 0x40; + pstAeSnsDft->au32Ratio[2] = 0x40; + } + break; + } + } + + return GK_SUCCESS; +} + +/* the function of sensor set fps */ +static GK_VOID cmos_fps_set(VI_PIPE ViPipe, GK_FLOAT f32Fps, + AE_SENSOR_DEFAULT_S *pstAeSnsDft) +{ + + GK_U32 u32MaxFps; + GK_U32 u32Lines; + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER_VOID(pstAeSnsDft); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + switch (pstSnsState->u8ImgMode) { + case IMX335_60FPS_CROPPED_1080P_MODE: + if ((f32Fps <= 90.0) && (f32Fps >= 2.0)) { + u32MaxFps = 90;//was 30; + u32Lines = IMX335_VMAX_CROPPED_1080P* u32MaxFps/ DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_CROPPED_1080P * 30; //was 15 + pstSnsState->u32FLStd = u32Lines; + } else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps A: %f\n", + f32Fps); + return; + } + break; + case IMX335_1520P_10BIT_MODE: + if ((f32Fps <= 82.0) && (f32Fps >= 2.0)) { // this is the teorethical max as calculated by the sensor registers??? + + u32MaxFps = 60;// Found by trial and error for hi3516ev300 + +// Need to have different values for Goke and Hisilicon encoders! +#ifdef CHIPARCH + printf("CHIPARCH is defined and its value is: " XSTR(CHIPARCH)); +#endif + + +//#if CHIPARCH == gk7205v200 //Does not work as desired... read some C books +if (strcmp(XSTR(CHIPARCH), "gk7205v200") == 0){ + u32MaxFps = 49;//this is the max achievable frame rate with Goke + u32Lines = IMX335_VMAX_CROPPED_1520P /* IMX335_VMAX_5M_30FPS_12BIT_LINEAR*/ * u32MaxFps / DIV_0_TO_1_FLOAT(f32Fps); + ISP_TRACE(MODULE_DBG_ERR, "Goke u32Lines : %d\n",u32Lines); +} +//#endif + +//#if CHIPARCH == hi3516ev300 +if (strcmp(XSTR(CHIPARCH), "hi3516ev200") == 0){ + u32MaxFps = 60;// Found by trial and error for hi3516ev300 + u32Lines = /*IMX335_VMAX_CROPPED_1520P*/ IMX335_VMAX_5M_30FPS_12BIT_LINEAR * u32MaxFps / DIV_0_TO_1_FLOAT(f32Fps); + ISP_TRACE(MODULE_DBG_ERR, "HiSillicon u32Lines : %d\n",u32Lines); +} + + //u32Lines = 3200 form max fps + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_CROPPED_1520P * 30; //was 15 + pstSnsState->u32FLStd = u32Lines; + ISP_TRACE(MODULE_DBG_ERR, "Set 1520P_10BIT_MODE u32MaxFps:%f / fps:%f\n",u32MaxFps, f32Fps); + } else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps CROPPED_1520P : %f\n", + f32Fps); + return; + } + break; + + case IMX335_60FPS_FULL_1944P_MODE: + case IMX335_5M_30FPS_12BIT_LINEAR_MODE: + if ((f32Fps <= 30.0) && (f32Fps >= 2.0)) { + u32MaxFps = 30; + u32Lines = IMX335_VMAX_5M_30FPS_12BIT_LINEAR * u32MaxFps / DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_5M_30FPS_12BIT_LINEAR * 15; //was 15 + pstSnsState->u32FLStd = u32Lines; + ISP_TRACE(MODULE_DBG_ERR, "Set 30FPS_STOCK_1944P_MODE: %f\n",f32Fps); + } else + + // break; + //case IMX335_60FPS_FULL_1944P_MODE: + if ((f32Fps >30) ) { + pstSnsState->u8ImgMode=IMX335_60FPS_FULL_1944P_MODE;//Set new mode + u32MaxFps = 45;//was 30; + + if (strcmp(XSTR(CHIPARCH), "gk7205v200") == 0){ + ISP_TRACE(MODULE_DBG_ERR, "Goke SoC"); + u32MaxFps=33;//this is the max achievable frame rate with Goke + } + u32Lines = IMX335_VMAX_5M_30FPS_12BIT_LINEAR * u32MaxFps / DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_5M_30FPS_12BIT_LINEAR * 15; //was 15 + pstSnsState->u32FLStd = u32Lines; + + ISP_TRACE(MODULE_DBG_ERR, "Set 60FPS_FULL_1944P_MODE %f / fps: %f\n",u32MaxFps, f32Fps); + } else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps A: %f\n", + f32Fps); + return; + } + break; + + //IMX335_60FPS_FULL_1944P_MODE + + case IMX335_60FPS_BINNING_MODE: { + u32MaxFps = 90;//was 60 + u32Lines = 0xBE8 * u32MaxFps / DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = IMX335_VMAX_BINNING * 30; + pstSnsState->u32FLStd = u32Lines; + }; break; + + case IMX335_5M_30FPS_10BIT_WDR_MODE: + if ((f32Fps <= 30.0) && (f32Fps >= 15.0)) { + u32MaxFps = 30; + u32Lines = IMX335_VMAX_5M_30FPS_10BIT_WDR * u32MaxFps / + DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_5M_30FPS_10BIT_WDR * 30; + if (0 != (u32Lines % 4)) { + u32Lines = + u32Lines - (u32Lines % 4) + + 4; //Because FSC value an integer multiple of 8 + } + pstSnsState->u32FLStd = u32Lines; + } + + else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps B : %f\n", + f32Fps); + return; + } + break; + case IMX335_4M_30FPS_10BIT_WDR_MODE: + if ((f32Fps <= 30.0) && (f32Fps >= 15.0)) { + u32MaxFps = 30; + u32Lines = IMX335_VMAX_4M_30FPS_10BIT_WDR * u32MaxFps / + DIV_0_TO_1_FLOAT(f32Fps); + pstAeSnsDft->u32LinesPer500ms = + IMX335_VMAX_4M_30FPS_10BIT_WDR * 30; + if (0 != (u32Lines % 4)) { + u32Lines = + u32Lines - (u32Lines % 4) + + 4; //Because FSC value an integer multiple of 8 + } + pstSnsState->u32FLStd = u32Lines; + } + + else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps C: %f\n", + f32Fps); + return; + } + break; +/* + case IMX335_4M_25FPS_10BIT_WDR_MODE: + if ((f32Fps <= 30) && (f32Fps >= 15)) { + u32MaxFps = 25; + u32Lines = IMX335_VMAX_4M_25FPS_10BIT_WDR * u32MaxFps / + DIV_0_TO_1_FLOAT(f32Fps); + u32Lines = u32Lines + + (u32Lines % 2); //VMAX is 2n(n-0,1,2.....) + pstSnsState->u32FLStd = u32Lines; + } else { + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps D: %f\n", + f32Fps); + return; + } + break; +*/ + default: + ISP_TRACE(MODULE_DBG_ERR, "Not support this Mode : %d !!!\n",pstSnsState->u8ImgMode); + return; + break; + } + + /* SHR 16bit, So limit full_lines as 0xFFFF */ + if (/*f32Fps > u32MaxFps*/ 0) {//disable the check to easily tweak fpsfalse + ISP_TRACE(MODULE_DBG_ERR, "Not support Fps Z : %f\n", f32Fps); + return; + } + //ISP_TRACE(MODULE_DBG_ERR, "u32Lines : %d\n", u32Lines); + + if (u32Lines > IMX335_FULL_LINES_MAX) { + u32Lines = IMX335_FULL_LINES_MAX; + } + + pstAeSnsDft->f32Fps = f32Fps; + pstAeSnsDft->u32LinesPer500ms = pstSnsState->u32FLStd * f32Fps / 2; + pstAeSnsDft->u32FullLinesStd = pstSnsState->u32FLStd; + + pstSnsState->au32FL[0] = pstSnsState->u32FLStd; + pstAeSnsDft->u32FullLines = pstSnsState->au32FL[0]; + + if (WDR_MODE_NONE == pstSnsState->enWDRMode) { + pstSnsState->astRegsInfo[0].astI2cData[5].u32Data = + IMX335_LOW_8BITS(pstSnsState->au32FL[0]); + pstSnsState->astRegsInfo[0].astI2cData[6].u32Data = + IMX335_MID_8BITS(pstSnsState->au32FL[0]); + pstSnsState->astRegsInfo[0].astI2cData[7].u32Data = + IMX335_HIG_4BITS(pstSnsState->au32FL[0]); + + } else { + pstSnsState->astRegsInfo[0].astI2cData[8].u32Data = + IMX335_LOW_8BITS(pstSnsState->au32FL[0]); + pstSnsState->astRegsInfo[0].astI2cData[9].u32Data = + IMX335_MID_8BITS(pstSnsState->au32FL[0]); + pstSnsState->astRegsInfo[0].astI2cData[10].u32Data = + IMX335_HIG_4BITS(pstSnsState->au32FL[0]); + } + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + pstSnsState->u32FLStd = u32Lines * 2; + /* + RHS1 limitation: + 8n + 2 + RHS1= RHS1(N)+ 2*BRL - 2*VMAX + 2 ===> RHS1(N)-RHS1(N+1)<= 2*VMAX - 2*BRL -2) + */ + g_astimx335State[ViPipe].u32RHS1_MAX = + g_astimx335State[ViPipe].u32BRL * 2; + g_astimx335State[ViPipe].u32deltaRHS1 = + (u32Lines * 2) - (g_astimx335State[ViPipe].u32BRL * 2) - + 2; + } else { + pstSnsState->u32FLStd = u32Lines; + } + + pstAeSnsDft->f32Fps = f32Fps; + gu32STimeFps = (GK_U32)f32Fps; + pstAeSnsDft->u32LinesPer500ms = pstSnsState->u32FLStd * f32Fps / 2; + pstAeSnsDft->u32FullLinesStd = pstSnsState->u32FLStd; + + pstAeSnsDft->u32MaxIntTime = pstSnsState->u32FLStd - 8; + pstSnsState->au32FL[0] = pstSnsState->u32FLStd; + pstAeSnsDft->u32FullLines = pstSnsState->au32FL[0]; + pstAeSnsDft->u32HmaxTimes = + (1000000) / (pstSnsState->u32FLStd * DIV_0_TO_1_FLOAT(f32Fps)); + + return; +} + +static GK_VOID cmos_slow_framerate_set(VI_PIPE ViPipe, GK_U32 u32FullLines, + AE_SENSOR_DEFAULT_S *pstAeSnsDft) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + GK_U32 u32Fll; + CMOS_CHECK_POINTER_VOID(pstAeSnsDft); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + if (IMX335_4M_30FPS_10BIT_WDR_MODE == pstSnsState->u8ImgMode) { + u32Fll = IMX335_VMAX_4M_30FPS_10BIT_WDR; + } else { + u32Fll = IMX335_VMAX_5M_30FPS_10BIT_WDR; + } + + u32FullLines = (u32FullLines > (2 * 2 * u32Fll)) ? + (2 * 2 * u32Fll) : + u32FullLines; + + if (0 != (u32FullLines % 4)) { + u32FullLines = + u32FullLines + + (4 - + (u32FullLines % + 4)); // Because FSC value an integer multiple of 8 + } + pstSnsState->au32FL[0] = u32FullLines; + + g_astimx335State[ViPipe].u32RHS1_MAX = + g_astimx335State[ViPipe].u32BRL * 2; + g_astimx335State[ViPipe].u32deltaRHS1 = + u32FullLines - (g_astimx335State[ViPipe].u32BRL * 2) - + 2; + } else { + u32FullLines = (u32FullLines > IMX335_FULL_LINES_MAX) ? + IMX335_FULL_LINES_MAX : + u32FullLines; + pstSnsState->au32FL[0] = u32FullLines; + } + + if (WDR_MODE_NONE == pstSnsState->enWDRMode) { + pstSnsState->astRegsInfo[0].astI2cData[5].u32Data = + IMX335_LOW_8BITS(pstSnsState->au32FL[0]); // VMAX + pstSnsState->astRegsInfo[0].astI2cData[6].u32Data = + IMX335_MID_8BITS(pstSnsState->au32FL[0]); + pstSnsState->astRegsInfo[0].astI2cData[7].u32Data = + IMX335_HIG_4BITS(pstSnsState->au32FL[0]); + } else { + pstSnsState->astRegsInfo[0].astI2cData[8].u32Data = + IMX335_LOW_8BITS(pstSnsState->au32FL[0] >> 1); // VMAX + pstSnsState->astRegsInfo[0].astI2cData[9].u32Data = + IMX335_MID_8BITS(pstSnsState->au32FL[0] >> 1); + pstSnsState->astRegsInfo[0].astI2cData[10].u32Data = + IMX335_HIG_4BITS(pstSnsState->au32FL[0] >> 1); + } + + pstAeSnsDft->u32FullLines = pstSnsState->au32FL[0]; + pstAeSnsDft->u32MaxIntTime = pstSnsState->au32FL[0] - 8; + + return; +} + +/* Again and Dgain use the same table, Step is 0.3db */ +static GK_U32 ad_gain_table[IMX335_AD_GAIN_TBL_RANGE] = { + 1024, 1059, 1097, 1135, 1175, 1217, 1259, + 1304, 1349, 1397, 1446, 1497, 1549, 1604, // 3.9dB + 1660, 1719, 1779, 1842, 1906, 1973, 2043, + 2114, 2189, 2266, 2345, 2428, 2513, 2601, // 8.1dB + 2693, 2788, 2886, 2987, 3092, 3201, 3313, + 3430, 3550, 3675, 3804, 3938, 4076, 4219, // 12.3dB + 4368, 4521, 4680, 4845, 5015, 5191, 5374, + 5562, 5758, 5960, 6170, 6387, 6611, 6843, // 16.5dB + 7084, 7333, 7591, 7857, 8133, 8419, 8715, + 9021, 9338, 9667, 10006, 10358, 10722, 11099, // 20.7dB + 11489, 11893, 12311, 12743, 13191, 13655, 14135, + 14631, 15146, 15678, 16229, 16799, 17390, 18001, // 24.9dB + 18633, 19288, 19966, 20668, 21394, 22146, 22924, + 23730, 24564, 25427, 26320, 27245, 28203, 29194, // 29.1dB + 30220, 31282, 32381, 33519, 34697, 35917, 37179, + 38485, 39838, 41238, 42687, 44187, 45740, 47347, // 33.3dB + 49011, 50734, 52517, 54362, 56273, 58250, 60297, + 62416, 64610, 66880, 69230, 71663, 74182, 76789, // 37.5dB + 79487, 82281, 85172, 88165, 91264, 94471, 97791, + 101228, 104785, 108468, 112279, 116225, 120310, 124537, // 41.7dB + 128914, 133444, 138134, 142988, 148013, 153215, 158599, + 164172, 169942, 175914, 182096, 188495, 195119, 201976, // 45.9dB + 209074, 216421, 224027, 231900, 240049, 248485, 257217, + 266256, 275613, 285299, 295325, 305703, 316446, 327567, // 50.1dB + 339078, 350994, 363329, 376097, 389314, 402995, 417157, + 431817, 446992, 462700, 478961, 495793, 513216, 531251, // 54.3dB + 549921, 569246, 589250, 609958, 631393, 653582, 676550, + 700326, 724936, 750412, 776783, 804081, 832338, 861589, // 58.5dB + 891867, 923209, 955652, 989236, 1024000, 1059985, 1097236, + 1135795, 1175709, 1217026, 1259795, 1304067, 1349895, 1397333, // 62.7dB + 1446438, 1497269, 1549887, 1604353, 1660734, 1719095, 1779508, + 1842044, 1906777, 1973786, 2043149, 2114949, 2189273, 2266209, // 66.9dB + 2345848, 2428287, 2513622, 2601956, 2693394, 2788046, 2886024, + 2987445, 3092431, 3201105, 3313599, 3430046, 3550585, 3675361, // 71.1dB + 3804521, 3938220, 4076617 // 72.0dB +}; + +/* while isp notify ae to update sensor regs, ae call these funcs. */ +static GK_VOID cmos_inttime_update(VI_PIPE ViPipe, GK_U32 u32IntTime) +{ + static GK_BOOL bFirst[ISP_MAX_PIPE_NUM] = { [0 ...(ISP_MAX_PIPE_NUM - + 1)] = 1 }; + static GK_U32 u32LastShortIntTime = 0; + static GK_U32 u32ShortIntTime = 0; + static GK_U32 u32LongIntTime = 0; + + GK_U32 u32RHS1 = 0; + GK_U32 u32SHR0 = 8872; + GK_U32 u32SHR1 = 18; + + GK_U32 u32delta = 0; + GK_U32 u32Value = 0; + GK_U16 u16ShortExpMod4 = 0; + GK_U16 u16ShortExpMod8 = 0; + GK_U32 u32RHS1Limit = 0; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + if (bFirst[ViPipe]) { /* short exposure */ + pstSnsState->au32WDRIntTime[0] = u32IntTime; + u32ShortIntTime = u32IntTime; + + bFirst[ViPipe] = GK_FALSE; + } else { /* long exposure */ + pstSnsState->au32WDRIntTime[1] = u32IntTime; + u32LongIntTime = u32IntTime; + + u32SHR0 = pstSnsState->au32FL[1] - u32LongIntTime + + (u32LongIntTime % 4); + + if (u32LastShortIntTime > u32ShortIntTime) { + u32delta = + u32LastShortIntTime - u32ShortIntTime; + u32RHS1Limit = + (pstSnsState->au32FL[1] - + (g_astimx335State[ViPipe].u32BRL * 2) - + 2); + if (u32delta > u32RHS1Limit) { + if (u32ShortIntTime >= 30) { + u32ShortIntTime = + u32LastShortIntTime - + (u32RHS1Limit - + (u32RHS1Limit % 8) + + 8 + 8); + } else { + u32ShortIntTime = + u32LastShortIntTime - + (u32RHS1Limit - + (u32RHS1Limit % 8) + + 8); + } + } + } + + u16ShortExpMod4 = u32ShortIntTime % 4; + u16ShortExpMod8 = u32ShortIntTime % 8; + + if (0 == u16ShortExpMod8) { + u32SHR1 = 18; + u32RHS1 = 18 + u32ShortIntTime; + } else { + if (u16ShortExpMod4 == u16ShortExpMod8) { + u32SHR1 = 18; + u32RHS1 = 18 + u32ShortIntTime - + u16ShortExpMod8; + } else { + u32SHR1 = 22; + u32RHS1 = 22 + u32ShortIntTime - + u16ShortExpMod4; + } + } + if (u32SHR0 < (u32RHS1 + u32SHR1)) { + u32SHR0 = u32RHS1 + u32SHR1; + } else { + } + + pstSnsState->astRegsInfo[0].astI2cData[0].u32Data = + IMX335_LOW_8BITS(u32SHR0); // SHR0 + pstSnsState->astRegsInfo[0].astI2cData[1].u32Data = + IMX335_MID_8BITS(u32SHR0); + pstSnsState->astRegsInfo[0].astI2cData[2].u32Data = + IMX335_HIG_4BITS(u32SHR0); + + pstSnsState->astRegsInfo[0].astI2cData[5].u32Data = + IMX335_LOW_8BITS(u32SHR1); // SHR1 + pstSnsState->astRegsInfo[0].astI2cData[6].u32Data = + IMX335_MID_8BITS(u32SHR1); + pstSnsState->astRegsInfo[0].astI2cData[7].u32Data = + IMX335_HIG_4BITS(u32SHR1); + + pstSnsState->astRegsInfo[0].astI2cData[11].u32Data = + IMX335_LOW_8BITS(u32RHS1); // RHS1 + pstSnsState->astRegsInfo[0].astI2cData[12].u32Data = + IMX335_MID_8BITS(u32RHS1); + pstSnsState->astRegsInfo[0].astI2cData[13].u32Data = + IMX335_HIG_4BITS(u32RHS1); + bFirst[ViPipe] = GK_TRUE; + u32LastShortIntTime = u32ShortIntTime; + } + } else { // Linear + u32Value = pstSnsState->au32FL[0] - u32IntTime; + u32Value = MIN(u32Value, IMX335_FULL_LINES_MAX); + u32Value = MIN(MAX(u32Value, 9), (pstSnsState->au32FL[0] - 1)); + + pstSnsState->astRegsInfo[0].astI2cData[0].u32Data = + IMX335_LOW_8BITS(u32Value); // SHR0 + pstSnsState->astRegsInfo[0].astI2cData[1].u32Data = + IMX335_MID_8BITS(u32Value); + pstSnsState->astRegsInfo[0].astI2cData[2].u32Data = + IMX335_HIG_4BITS(u32Value); + } + + return; +} + +static GK_VOID cmos_again_calc_table(VI_PIPE ViPipe, GK_U32 *pu32AgainLin, + GK_U32 *pu32AgainDb) +{ + int i; + + CMOS_CHECK_POINTER_VOID(pu32AgainLin); + CMOS_CHECK_POINTER_VOID(pu32AgainDb); + + if (*pu32AgainLin >= ad_gain_table[IMX335_AGAIN_TBL_RANGE]) { + *pu32AgainLin = ad_gain_table[IMX335_AGAIN_TBL_RANGE]; + *pu32AgainDb = IMX335_AGAIN_TBL_RANGE; + } else { + for (i = 1; i < (IMX335_AGAIN_TBL_RANGE + 1); i++) { + if (*pu32AgainLin < ad_gain_table[i]) { + *pu32AgainLin = ad_gain_table[i - 1]; + *pu32AgainDb = i - 1; + break; + } + } + } + + g_u32Imx335AGain[ViPipe] = *pu32AgainLin; + return; +} + +static GK_VOID cmos_dgain_calc_table(VI_PIPE ViPipe, GK_U32 *pu32DgainLin, + GK_U32 *pu32DgainDb) +{ + int i; + + CMOS_CHECK_POINTER_VOID(pu32DgainLin); + CMOS_CHECK_POINTER_VOID(pu32DgainDb); + + if (*pu32DgainLin >= ad_gain_table[IMX335_DGAIN_TBL_RANGE]) { + *pu32DgainLin = ad_gain_table[IMX335_DGAIN_TBL_RANGE]; + *pu32DgainDb = IMX335_DGAIN_TBL_RANGE; + } else { + for (i = 1; i < (IMX335_DGAIN_TBL_RANGE + 1); i++) { + if (*pu32DgainLin < ad_gain_table[i]) { + *pu32DgainLin = ad_gain_table[i - 1]; + *pu32DgainDb = i - 1; + break; + } + } + } + + g_u32Imx335DGain[ViPipe] = *pu32DgainLin; + return; +} + +static GK_VOID cmos_gains_update(VI_PIPE ViPipe, GK_U32 u32Again, + GK_U32 u32Dgain) +{ + static GK_BOOL bFirstGain[ISP_MAX_PIPE_NUM] = { + [0 ...(ISP_MAX_PIPE_NUM - 1)] = 1 + }; + GK_U32 u32Tmp; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + if (pstSnsState->enWDRMode == WDR_MODE_2To1_LINE) { + if (bFirstGain[ViPipe]) { + u32Tmp = u32Again + u32Dgain; + gu32LGain = u32Tmp; + + pstSnsState->astRegsInfo[0].astI2cData[3].u32Data = + IMX335_LOW_8BITS(u32Tmp); + pstSnsState->astRegsInfo[0].astI2cData[4].u32Data = + IMX335_MID_8BITS(u32Tmp); + bFirstGain[ViPipe] = GK_FALSE; + } else { + u32Tmp = u32Again + u32Dgain; + + pstSnsState->astRegsInfo[0].astI2cData[14].u32Data = + IMX335_LOW_8BITS(u32Tmp); + pstSnsState->astRegsInfo[0].astI2cData[15].u32Data = + IMX335_MID_8BITS(u32Tmp); + bFirstGain[ViPipe] = GK_TRUE; + } + } else { + u32Tmp = u32Again + u32Dgain; + gu32LGain = u32Tmp; + + pstSnsState->astRegsInfo[0].astI2cData[3].u32Data = + IMX335_LOW_8BITS(u32Tmp); + pstSnsState->astRegsInfo[0].astI2cData[4].u32Data = + IMX335_MID_8BITS(u32Tmp); + + pstSnsState->astRegsInfo[0].astI2cData[14].u32Data = + IMX335_LOW_8BITS(u32Tmp); + pstSnsState->astRegsInfo[0].astI2cData[15].u32Data = + IMX335_MID_8BITS(u32Tmp); + } + + return; +} + +/* + Linear: SHR0 [9, VMAX-1]; Initime = VMAX - SHR0 Initime [1,VMAX -9] + WDR2t1: SHS1 4n+2 (n=0,1,2....) and 18 <= SHS1 <= RHS1-4 + RHS1 8n+2 (n=0,1,2....) and (SHR1+5)<= RHS1<=(SHR0-18) and RHS1<(BRL*2) + SHR0 4n(n=0,1,2.....) and (RHS1+18) <= SHR0<=(2*VMAX-4) VMAX :2n (n=0,1,2.....) +*/ +/* Only used in WDR_MODE_2To1_LINE and WDR_MODE_2To1_FRAME mode */ +static GK_VOID cmos_get_inttime_max(VI_PIPE ViPipe, GK_U16 u16ManRatioEnable, + GK_U32 *au32Ratio, GK_U32 *au32IntTimeMax, + GK_U32 *au32IntTimeMin, + GK_U32 *pu32LFMaxIntTime) +{ + GK_U32 u32IntTimeMaxTmp0 = 0; + GK_U32 u32IntTimeMaxTmp = 0; + GK_U32 u32RatioTmp = 0x40; + GK_U32 u32ShortTimeMinLimit = 4; + GK_U32 u32delta; + static GK_U32 u32LastIntTimeMaxTmp = 4; + GK_U16 u16LimitValue = 0; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER_VOID(au32Ratio); + CMOS_CHECK_POINTER_VOID(au32IntTimeMax); + CMOS_CHECK_POINTER_VOID(au32IntTimeMin); + CMOS_CHECK_POINTER_VOID(pu32LFMaxIntTime); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + if ((WDR_MODE_2To1_LINE == pstSnsState->enWDRMode)) { + /* + limitation for line base WDR + SHR1 limitation: + 18 or more + and (RHS1 - 4) or less + and 4n+2(n=0,1,2....) + + SHR0 limitation: + 4n(n=0,1,2....) + (RHS1 + 18) or more + and (FSC - 4) or less + + RHS1 Limitation: + 8n+2 (n=0,1,2....) + (SHR1+4)<=RHS1 <= (SHR0-18) + |RHS1(n+1) - RHS1(n)| < (VMAX-BRL)*2 - 2 + + RHS1 = 18 + st - (st % 8) + 8; + SHR0 = FSC - st * ratio + (lt % 4) - 4 + + RHS1 <= SHR0 -18 = FSC - st * ratio + (lt % 4) - 22 + st * (1 + ratio) <= FSC - 48 + (lt % 4) +(st % 8) + st * (1 + ratio) < = FSC - 48 + + short exposure time = RHS1 - SHR1 <= RHS1 - 18 + long exposure time = FSC - SHR0 <= FSC - (RHS1 + 18) + ExposureShort + ExposureLong <= FSC - 36 + short exposure time <= (FSC - 36) / (ratio + 1) + + when using withing FSC mode, please set to satisfy theste restrictions below + (VMAX*2 - BRL*2) / 4 -2 > (RHS1/2 - 3) / 2 + ==> RHS < ((((VMAX*2 - BRL*2) / 4 -2)* 2) + 3) * 2 + */ + //RHS1(N+1)>=RHS1(N)+BRL*2-VMAX*2+2 + + u16LimitValue = (IMX335_VMAX_4M_30FPS_10BIT_WDR * 2 - + g_astimx335State[ViPipe].u32BRL * 2 - 2) - + 8; + u16LimitValue = 300; + + if (ISP_FSWDR_LONG_FRAME_MODE == + genFSWDRMode[ViPipe]) { /* long frame mode enable */ + u32IntTimeMaxTmp0 = pstSnsState->au32FL[1] - 280 - + pstSnsState->au32WDRIntTime[0]; + u32IntTimeMaxTmp = pstSnsState->au32FL[0] - 280; + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp0 < u32IntTimeMaxTmp) ? + u32IntTimeMaxTmp0 : + u32IntTimeMaxTmp; + au32IntTimeMax[0] = u32IntTimeMaxTmp; + au32IntTimeMin[0] = u32ShortTimeMinLimit; + u32LastIntTimeMaxTmp = u32ShortTimeMinLimit; + return; + } else if (ISP_FSWDR_AUTO_LONG_FRAME_MODE == + genFSWDRMode[ViPipe]) { + if (pstSnsState->au32WDRIntTime[0] == + u32ShortTimeMinLimit && + au32Ratio[0] == 0x40) { + u32IntTimeMaxTmp0 = + pstSnsState->au32FL[1] - 280 - + pstSnsState->au32WDRIntTime[0]; + u32IntTimeMaxTmp = pstSnsState->au32FL[0] - 280; + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp0 < u32IntTimeMaxTmp) ? + u32IntTimeMaxTmp0 : + u32IntTimeMaxTmp; + au32IntTimeMax[0] = u32IntTimeMaxTmp; + au32IntTimeMin[0] = u32ShortTimeMinLimit; + u32LastIntTimeMaxTmp = u32ShortTimeMinLimit; + } else { + u32IntTimeMaxTmp0 = + ((pstSnsState->au32FL[1] - 280 - + pstSnsState->au32WDRIntTime[0]) * + 0x40) / + DIV_0_TO_1(au32Ratio[0]); + u32IntTimeMaxTmp = + ((pstSnsState->au32FL[0] - 280) * + 0x40) / + DIV_0_TO_1(au32Ratio[0] + 0x40); + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp0 < u32IntTimeMaxTmp) ? + u32IntTimeMaxTmp0 : + u32IntTimeMaxTmp; + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp > + (g_astimx335State[ViPipe].u32RHS1_MAX - + 18)) ? + (g_astimx335State[ViPipe] + .u32RHS1_MAX - + 18) : + u32IntTimeMaxTmp; + if (u32IntTimeMaxTmp > u32LastIntTimeMaxTmp) { + u32delta = u32IntTimeMaxTmp - + u32LastIntTimeMaxTmp; + if (u32delta > g_astimx335State[ViPipe] + .u32deltaRHS1) { + u32IntTimeMaxTmp = + u32LastIntTimeMaxTmp + + (g_astimx335State[ViPipe] + .u32deltaRHS1 - + (g_astimx335State[ViPipe] + .u32deltaRHS1 % + 8)); + } else { + } + } else if (u32LastIntTimeMaxTmp > + u32IntTimeMaxTmp) { + u32delta = u32LastIntTimeMaxTmp - + u32IntTimeMaxTmp; + if (u32delta > g_astimx335State[ViPipe] + .u32deltaRHS1) { + u32IntTimeMaxTmp = + u32LastIntTimeMaxTmp - + (g_astimx335State[ViPipe] + .u32deltaRHS1 - + (g_astimx335State[ViPipe] + .u32deltaRHS1 % + 8)); + } else { + } + } + u32IntTimeMaxTmp = (0 == u32IntTimeMaxTmp) ? + 1 : + u32IntTimeMaxTmp; + u32LastIntTimeMaxTmp = u32IntTimeMaxTmp; + } + } else { + u32IntTimeMaxTmp0 = ((pstSnsState->au32FL[1] - 280 - + pstSnsState->au32WDRIntTime[0]) * + 0x40) / + DIV_0_TO_1(au32Ratio[0]); + u32IntTimeMaxTmp = + ((pstSnsState->au32FL[0] - 280) * 0x40) / + DIV_0_TO_1(au32Ratio[0] + 0x40); + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp0 < u32IntTimeMaxTmp) ? + u32IntTimeMaxTmp0 : + u32IntTimeMaxTmp; + u32IntTimeMaxTmp = + (u32IntTimeMaxTmp > + (g_astimx335State[ViPipe].u32RHS1_MAX - 18)) ? + (g_astimx335State[ViPipe].u32RHS1_MAX - + 18) : + u32IntTimeMaxTmp; + + if (u32IntTimeMaxTmp >= u32LastIntTimeMaxTmp) { + u32delta = + u32IntTimeMaxTmp - u32LastIntTimeMaxTmp; + if (u32delta > u16LimitValue) { + u32IntTimeMaxTmp = + u32LastIntTimeMaxTmp + + u16LimitValue; + } + } else if (u32LastIntTimeMaxTmp > u32IntTimeMaxTmp) { + u32delta = + u32LastIntTimeMaxTmp - u32IntTimeMaxTmp; + if (u32delta > u16LimitValue) { + if (pstSnsState->au32WDRIntTime[0] > + (u16LimitValue + 4)) { + u32ShortTimeMinLimit = + pstSnsState + ->au32WDRIntTime + [0] - + u16LimitValue; + } + + u32IntTimeMaxTmp = + pstSnsState->au32WDRIntTime[0]; + + u32LastIntTimeMaxTmp = + u32ShortTimeMinLimit; + } + } + u32IntTimeMaxTmp = + (0 == u32IntTimeMaxTmp) ? 1 : u32IntTimeMaxTmp; + u32LastIntTimeMaxTmp = u32IntTimeMaxTmp; + *pu32LFMaxIntTime = + g_astimx335State[ViPipe].u32RHS1_MAX - 18; + } + } else { + } + + if (u32IntTimeMaxTmp >= u32ShortTimeMinLimit) { + if (IS_LINE_WDR_MODE(pstSnsState->enWDRMode)) { + au32IntTimeMax[0] = u32IntTimeMaxTmp; + au32IntTimeMax[1] = au32IntTimeMax[0] * au32Ratio[0] >> + 6; + au32IntTimeMax[2] = au32IntTimeMax[1] * au32Ratio[1] >> + 6; + au32IntTimeMax[3] = au32IntTimeMax[2] * au32Ratio[2] >> + 6; + au32IntTimeMin[0] = u32ShortTimeMinLimit; + au32IntTimeMin[1] = au32IntTimeMin[0] * au32Ratio[0] >> + 6; + au32IntTimeMin[2] = au32IntTimeMin[1] * au32Ratio[1] >> + 6; + au32IntTimeMin[3] = au32IntTimeMin[2] * au32Ratio[2] >> + 6; + } else { + } + } else { + if (1 == u16ManRatioEnable) { + printf("Manaul ExpRatio is too large!\n"); + return; + } else { + u32IntTimeMaxTmp = u32ShortTimeMinLimit; + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + u32RatioTmp = 0xFFF; + au32IntTimeMax[0] = u32IntTimeMaxTmp; + au32IntTimeMax[1] = + au32IntTimeMax[0] * u32RatioTmp >> 6; + } else { + } + au32IntTimeMin[0] = au32IntTimeMax[0]; + au32IntTimeMin[1] = au32IntTimeMax[1]; + au32IntTimeMin[2] = au32IntTimeMax[2]; + au32IntTimeMin[3] = au32IntTimeMax[3]; + } + } + return; +} + +/* Only used in FSWDR mode */ +static GK_VOID cmos_ae_fswdr_attr_set(VI_PIPE ViPipe, + AE_FSWDR_ATTR_S *pstAeFSWDRAttr) +{ + CMOS_CHECK_POINTER_VOID(pstAeFSWDRAttr); + + genFSWDRMode[ViPipe] = pstAeFSWDRAttr->enFSWDRMode; + gu32MaxTimeGetCnt[ViPipe] = 0; +} + +static GK_S32 cmos_init_ae_exp_function(AE_SENSOR_EXP_FUNC_S *pstExpFuncs) +{ + CMOS_CHECK_POINTER(pstExpFuncs); + + memset(pstExpFuncs, 0, sizeof(AE_SENSOR_EXP_FUNC_S)); + + pstExpFuncs->pfn_cmos_get_ae_default = cmos_get_ae_default; + pstExpFuncs->pfn_cmos_fps_set = cmos_fps_set; + pstExpFuncs->pfn_cmos_slow_framerate_set = cmos_slow_framerate_set; + pstExpFuncs->pfn_cmos_inttime_update = cmos_inttime_update; + pstExpFuncs->pfn_cmos_gains_update = cmos_gains_update; + pstExpFuncs->pfn_cmos_again_calc_table = cmos_again_calc_table; + pstExpFuncs->pfn_cmos_dgain_calc_table = cmos_dgain_calc_table; + pstExpFuncs->pfn_cmos_get_inttime_max = cmos_get_inttime_max; + pstExpFuncs->pfn_cmos_ae_fswdr_attr_set = cmos_ae_fswdr_attr_set; + + return GK_SUCCESS; +} + +/* AWB default parameter and function */ +#define CALIBRATE_STATIC_WB_R_GAIN 0x1E3 +#define CALIBRATE_STATIC_WB_GR_GAIN 0x100 +#define CALIBRATE_STATIC_WB_GB_GAIN 0x100 +#define CALIBRATE_STATIC_WB_B_GAIN 0x1d1 + +/* Calibration results for Auto WB Planck */ +#define CALIBRATE_AWB_P1 -0x0012 +#define CALIBRATE_AWB_P2 0x010b +#define CALIBRATE_AWB_Q1 -0x0007 +#define CALIBRATE_AWB_A1 0x2711F +#define CALIBRATE_AWB_B1 0x0080 +#define CALIBRATE_AWB_C1 -0x1A5C1 + +/* Rgain and Bgain of the golden sample */ +#define GOLDEN_RGAIN 0 +#define GOLDEN_BGAIN 0 + +static GK_S32 cmos_get_awb_default(VI_PIPE ViPipe, + AWB_SENSOR_DEFAULT_S *pstAwbSnsDft) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER(pstAwbSnsDft); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + memset(pstAwbSnsDft, 0, sizeof(AWB_SENSOR_DEFAULT_S)); + + pstAwbSnsDft->u16WbRefTemp = 4900; + + pstAwbSnsDft->au16GainOffset[0] = CALIBRATE_STATIC_WB_R_GAIN; + pstAwbSnsDft->au16GainOffset[1] = CALIBRATE_STATIC_WB_GR_GAIN; + pstAwbSnsDft->au16GainOffset[2] = CALIBRATE_STATIC_WB_GB_GAIN; + pstAwbSnsDft->au16GainOffset[3] = CALIBRATE_STATIC_WB_B_GAIN; + + pstAwbSnsDft->as32WbPara[0] = CALIBRATE_AWB_P1; + pstAwbSnsDft->as32WbPara[1] = CALIBRATE_AWB_P2; + pstAwbSnsDft->as32WbPara[2] = CALIBRATE_AWB_Q1; + pstAwbSnsDft->as32WbPara[3] = CALIBRATE_AWB_A1; + pstAwbSnsDft->as32WbPara[4] = CALIBRATE_AWB_B1; + pstAwbSnsDft->as32WbPara[5] = CALIBRATE_AWB_C1; + + pstAwbSnsDft->u16GoldenRgain = GOLDEN_RGAIN; + pstAwbSnsDft->u16GoldenBgain = GOLDEN_BGAIN; + + switch (pstSnsState->enWDRMode) { + default: + case WDR_MODE_NONE: + memcpy(&pstAwbSnsDft->stCcm, &g_stAwbCcm, sizeof(AWB_CCM_S)); + memcpy(&pstAwbSnsDft->stAgcTbl, &g_stAwbAgcTable, + sizeof(AWB_AGC_TABLE_S)); + break; + + case WDR_MODE_2To1_LINE: + memcpy(&pstAwbSnsDft->stCcm, &g_stAwbCcmFsWdr, + sizeof(AWB_CCM_S)); + memcpy(&pstAwbSnsDft->stAgcTbl, &g_stAwbAgcTableFSWDR, + sizeof(AWB_AGC_TABLE_S)); + break; + } + + pstAwbSnsDft->u16InitRgain = g_au16InitWBGain[ViPipe][0]; + pstAwbSnsDft->u16InitGgain = g_au16InitWBGain[ViPipe][1]; + pstAwbSnsDft->u16InitBgain = g_au16InitWBGain[ViPipe][2]; + pstAwbSnsDft->u16SampleRgain = g_au16SampleRgain[ViPipe]; + pstAwbSnsDft->u16SampleBgain = g_au16SampleBgain[ViPipe]; + + return GK_SUCCESS; +} + +static GK_S32 cmos_init_awb_exp_function(AWB_SENSOR_EXP_FUNC_S *pstExpFuncs) +{ + CMOS_CHECK_POINTER(pstExpFuncs); + + memset(pstExpFuncs, 0, sizeof(AWB_SENSOR_EXP_FUNC_S)); + + pstExpFuncs->pfn_cmos_get_awb_default = cmos_get_awb_default; + + return GK_SUCCESS; +} + +static ISP_CMOS_DNG_COLORPARAM_S g_stDngColorParam = { { 378, 256, 430 }, + { 439, 256, 439 } }; + +static GK_S32 cmos_get_isp_default(VI_PIPE ViPipe, ISP_CMOS_DEFAULT_S *pstDef) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER(pstDef); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + memset(pstDef, 0, sizeof(ISP_CMOS_DEFAULT_S)); +#ifdef CONFIG_ISP_CA_SUPPORT + pstDef->unKey.bit1Ca = 1; + pstDef->pstCa = &g_stIspCA; +#endif + + pstDef->unKey.bit1Dpc = 1; + pstDef->pstDpc = &g_stCmosDpc; + + pstDef->unKey.bit1Wdr = 1; + pstDef->pstWdr = &g_stIspWDR; + pstDef->unKey.bit1Lsc = 0; + pstDef->pstLsc = &g_stCmosLsc; + pstDef->unKey.bit1Ge = 1; + pstDef->pstGe = &g_stIspGe; + + switch (pstSnsState->enWDRMode) { + default: + case WDR_MODE_NONE: + pstDef->unKey.bit1Demosaic = 1; + pstDef->pstDemosaic = &g_stIspDemosaic; + pstDef->unKey.bit1Sharpen = 1; + pstDef->pstSharpen = &g_stIspYuvSharpen; + pstDef->unKey.bit1Drc = 1; + pstDef->pstDrc = &g_stIspDRC; + pstDef->unKey.bit1Gamma = 1; + pstDef->pstGamma = &g_stIspGamma; + pstDef->unKey.bit1BayerNr = 1; + pstDef->pstBayerNr = &g_stIspBayerNr; + pstDef->unKey.bit1AntiFalseColor = 1; + pstDef->pstAntiFalseColor = &g_stIspAntiFalseColor; + pstDef->unKey.bit1Ldci = 1; + pstDef->pstLdci = &g_stIspLdci; + pstDef->unKey.bit1Dehaze = 1; + pstDef->pstDehaze = &g_stIspDehaze; + pstDef->unKey.bit1Lcac = 0; + pstDef->pstLcac = &g_stIspLCac; + memcpy(&pstDef->stNoiseCalibration, &g_stIspNoiseCalibration, + sizeof(ISP_CMOS_NOISE_CALIBRATION_S)); + break; + + case WDR_MODE_2To1_LINE: + pstDef->unKey.bit1Demosaic = 1; + pstDef->pstDemosaic = &g_stIspDemosaicWdr; + pstDef->unKey.bit1Sharpen = 1; + pstDef->pstSharpen = &g_stIspYuvSharpenWdr; + pstDef->unKey.bit1Drc = 1; + pstDef->pstDrc = &g_stIspDRCWDR; + pstDef->unKey.bit1Gamma = 1; + pstDef->pstGamma = &g_stIspGammaFSWDR; + pstDef->unKey.bit1PreGamma = 0; + pstDef->pstPreGamma = &g_stPreGamma; + pstDef->unKey.bit1BayerNr = 1; + pstDef->pstBayerNr = &g_stIspBayerNrWdr2To1; + pstDef->unKey.bit1Ge = 1; + pstDef->pstGe = &g_stIspWdrGe; + pstDef->unKey.bit1AntiFalseColor = 1; + pstDef->pstAntiFalseColor = &g_stIspWdrAntiFalseColor; + pstDef->unKey.bit1Ldci = 1; + pstDef->pstLdci = &g_stIspWdrLdci; + pstDef->unKey.bit1Dehaze = 1; + pstDef->pstDehaze = &g_stIspDehazeWDR; + pstDef->unKey.bit1Lcac = 0; + pstDef->pstLcac = &g_stIspLCacWdr; + pstDef->unKey.bit1Rgbir = 0; + pstDef->stWdrSwitchAttr.au32ExpRatio[0] = 0x40; + + memcpy(&pstDef->stNoiseCalibration, &g_stIspNoiseCalibration, + sizeof(ISP_CMOS_NOISE_CALIBRATION_S)); + break; + } + + pstDef->stSensorMode.u32SensorID = IMX335_ID; + pstDef->stSensorMode.u8SensorMode = pstSnsState->u8ImgMode; + + memcpy(&pstDef->stDngColorParam, &g_stDngColorParam, + sizeof(ISP_CMOS_DNG_COLORPARAM_S)); + + switch (pstSnsState->u8ImgMode) { + default: + case IMX335_60FPS_FULL_1944P_MODE: + case IMX335_60FPS_CROPPED_1080P_MODE: + case IMX335_5M_30FPS_12BIT_LINEAR_MODE: + pstDef->stSensorMode.stDngRawFormat.u8BitsPerSample = 10;//was 12 + pstDef->stSensorMode.stDngRawFormat.u32WhiteLevel = 2592; + break; + + case IMX335_60FPS_BINNING_MODE: + pstDef->stSensorMode.stDngRawFormat.u8BitsPerSample = 12; + pstDef->stSensorMode.stDngRawFormat.u32WhiteLevel = 2592; + break; + + case IMX335_5M_30FPS_10BIT_WDR_MODE: + pstDef->stSensorMode.stDngRawFormat.u8BitsPerSample = 10; + pstDef->stSensorMode.stDngRawFormat.u32WhiteLevel = 2592; + break; + case IMX335_4M_30FPS_10BIT_WDR_MODE: + pstDef->stSensorMode.stDngRawFormat.u8BitsPerSample = 10; + pstDef->stSensorMode.stDngRawFormat.u32WhiteLevel = 2592; + break; + + case IMX335_1520P_10BIT_MODE: + pstDef->stSensorMode.stDngRawFormat.u8BitsPerSample = 10; + pstDef->stSensorMode.stDngRawFormat.u32WhiteLevel = 2592; + break; + } + + pstDef->stSensorMode.stDngRawFormat.stDefaultScale.stDefaultScaleH + .u32Denominator = 1; + pstDef->stSensorMode.stDngRawFormat.stDefaultScale.stDefaultScaleH + .u32Numerator = 1; + pstDef->stSensorMode.stDngRawFormat.stDefaultScale.stDefaultScaleV + .u32Denominator = 1; + pstDef->stSensorMode.stDngRawFormat.stDefaultScale.stDefaultScaleV + .u32Numerator = 1; + pstDef->stSensorMode.stDngRawFormat.stCfaRepeatPatternDim + .u16RepeatPatternDimRows = 2; + pstDef->stSensorMode.stDngRawFormat.stCfaRepeatPatternDim + .u16RepeatPatternDimCols = 2; + pstDef->stSensorMode.stDngRawFormat.stBlcRepeatDim.u16BlcRepeatRows = 2; + pstDef->stSensorMode.stDngRawFormat.stBlcRepeatDim.u16BlcRepeatCols = 2; + pstDef->stSensorMode.stDngRawFormat.enCfaLayout = + CFALAYOUT_TYPE_RECTANGULAR; + pstDef->stSensorMode.stDngRawFormat.au8CfaPlaneColor[0] = 0; + pstDef->stSensorMode.stDngRawFormat.au8CfaPlaneColor[1] = 1; + pstDef->stSensorMode.stDngRawFormat.au8CfaPlaneColor[2] = 2; + pstDef->stSensorMode.stDngRawFormat.au8CfaPattern[0] = 0; + pstDef->stSensorMode.stDngRawFormat.au8CfaPattern[1] = 1; + pstDef->stSensorMode.stDngRawFormat.au8CfaPattern[2] = 1; + pstDef->stSensorMode.stDngRawFormat.au8CfaPattern[3] = 2; + pstDef->stSensorMode.bValidDngRawFormat = GK_TRUE; + + return GK_SUCCESS; +} + +static GK_S32 cmos_get_isp_black_level(VI_PIPE ViPipe, + ISP_CMOS_BLACK_LEVEL_S *pstBlackLevel) +{ + GK_S32 i; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + if (GK_NULL == pstBlackLevel) { + printf("null pointer when get isp black level value!\n"); + return -1; + } + + /* Don't need to update black level when iso change */ + pstBlackLevel->bUpdate = GK_TRUE; + + if (GK_TRUE == pstBlackLevel->bUpdate) { + if (g_u32Imx335AGain[ViPipe] >= 32381) { + if (g_u32Imx335DGain[ViPipe] < 12288) { + for (i = 0; i < 4; i++) { + pstBlackLevel->au16BlackLevel[i] = + 200; /* 12bit,0xC8 */ + } + } else if ((g_u32Imx335DGain[ViPipe] >= 12288) && + (g_u32Imx335DGain[ViPipe] < 16384)) { + pstBlackLevel->au16BlackLevel[0] = 217; + pstBlackLevel->au16BlackLevel[1] = 211; + pstBlackLevel->au16BlackLevel[2] = 208; + pstBlackLevel->au16BlackLevel[3] = 216; + } else if ((g_u32Imx335DGain[ViPipe] >= 16384) && + (g_u32Imx335DGain[ViPipe] < 20480)) { + pstBlackLevel->au16BlackLevel[0] = 223; + pstBlackLevel->au16BlackLevel[1] = 228; + pstBlackLevel->au16BlackLevel[2] = 229; + pstBlackLevel->au16BlackLevel[3] = 219; + } else if ((g_u32Imx335DGain[ViPipe] >= 20480) && + (g_u32Imx335DGain[ViPipe] < 24576)) { + pstBlackLevel->au16BlackLevel[0] = 248; + pstBlackLevel->au16BlackLevel[1] = 255; + pstBlackLevel->au16BlackLevel[2] = 256; + pstBlackLevel->au16BlackLevel[3] = 244; + } else if ((g_u32Imx335DGain[ViPipe] >= 24576) && + (g_u32Imx335DGain[ViPipe] < 28672)) { + pstBlackLevel->au16BlackLevel[0] = 277; + pstBlackLevel->au16BlackLevel[1] = 283; + pstBlackLevel->au16BlackLevel[2] = 285; + pstBlackLevel->au16BlackLevel[3] = 272; + } else if ((g_u32Imx335DGain[ViPipe] >= 28672) && + (g_u32Imx335DGain[ViPipe] < 31768)) { + pstBlackLevel->au16BlackLevel[0] = 303; + pstBlackLevel->au16BlackLevel[1] = 308; + pstBlackLevel->au16BlackLevel[2] = 310; + pstBlackLevel->au16BlackLevel[3] = 295; + } else { + pstBlackLevel->au16BlackLevel[0] = 330; + pstBlackLevel->au16BlackLevel[1] = 338; + pstBlackLevel->au16BlackLevel[2] = 339; + pstBlackLevel->au16BlackLevel[3] = 323; + } + } else { + for (i = 0; i < 4; i++) { + pstBlackLevel->au16BlackLevel[i] = + 200; /* 12bit,0xC8 */ + } + } + } else { + if (WDR_MODE_NONE == pstSnsState->enWDRMode) { + for (i = 0; i < 4; i++) { + pstBlackLevel->au16BlackLevel[i] = + 200; /* 12bit,0xC8 */ + } + } else if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + for (i = 0; i < 4; i++) { + pstBlackLevel->au16BlackLevel[i] = + 200; /* 10bit 50, 12bit 200 */ + } + } else { + for (i = 0; i < 4; i++) { + pstBlackLevel->au16BlackLevel[i] = + 200; /* 10bit 50, 12bit 200 */ + } + } + } + + return 0; +} + +static GK_VOID cmos_set_pixel_detect(VI_PIPE ViPipe, GK_BOOL bEnable) +{ + GK_U32 u32FullLines_5Fps = 0; + GK_U32 u32MaxIntTime_5Fps = 0; + + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + return; + } else { + if (IMX335_5M_30FPS_12BIT_LINEAR_MODE == pstSnsState->u8ImgMode || + IMX335_60FPS_CROPPED_1080P_MODE == pstSnsState->u8ImgMode || + IMX335_60FPS_FULL_1944P_MODE == pstSnsState->u8ImgMode + ) { + u32FullLines_5Fps = + (IMX335_VMAX_5M_30FPS_12BIT_LINEAR * 60 /*30*/) / 5; + } else if (IMX335_60FPS_BINNING_MODE == pstSnsState->u8ImgMode) { + u32FullLines_5Fps = (IMX335_VMAX_BINNING * 60) / 5; + }else{ + + return; + } + } + + u32MaxIntTime_5Fps = u32FullLines_5Fps - 8; + + if (bEnable) { /* setup for ISP pixel calibration mode */ + IMX335_write_register(ViPipe, IMX335_GAIN_LONG_LOW, + 0x00); // gain + IMX335_write_register(ViPipe, IMX335_GAIN_LONG_HIGH, 0x00); + + IMX335_write_register( + ViPipe, IMX335_VMAX_ADDR_L, + IMX335_LOW_8BITS(u32FullLines_5Fps)); // VMAX + IMX335_write_register(ViPipe, IMX335_VMAX_ADDR_M, + IMX335_MID_8BITS(u32FullLines_5Fps)); + IMX335_write_register(ViPipe, IMX335_VMAX_ADDR_H, + IMX335_HIG_4BITS(u32FullLines_5Fps)); + + IMX335_write_register(ViPipe, IMX335_SHR0_LOW, + IMX335_LOW_8BITS(u32MaxIntTime_5Fps)); + IMX335_write_register(ViPipe, IMX335_SHR0_MIDDLE, + IMX335_MID_8BITS(u32MaxIntTime_5Fps)); + IMX335_write_register(ViPipe, IMX335_SHR0_MIDDLE, + IMX335_HIG_4BITS(u32MaxIntTime_5Fps)); + } else { /* setup for ISP 'normal mode' */ + pstSnsState->u32FLStd = + (pstSnsState->u32FLStd > IMX335_FULL_LINES_MAX) ? + IMX335_FULL_LINES_MAX : + pstSnsState->u32FLStd; + IMX335_write_register(ViPipe, IMX335_VMAX_ADDR_L, + IMX335_LOW_8BITS(pstSnsState->u32FLStd)); + IMX335_write_register(ViPipe, IMX335_VMAX_ADDR_M, + IMX335_MID_8BITS(pstSnsState->u32FLStd)); + IMX335_write_register(ViPipe, IMX335_VMAX_ADDR_H, + IMX335_HIG_4BITS(pstSnsState->u32FLStd)); + pstSnsState->bSyncInit = GK_FALSE; + } + + return; +} + +static GK_S32 cmos_set_wdr_mode(VI_PIPE ViPipe, GK_U8 u8Mode) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + pstSnsState->bSyncInit = GK_FALSE; + + switch (u8Mode & 0x3F) { + case WDR_MODE_NONE: + pstSnsState->enWDRMode = WDR_MODE_NONE; + printf("linear mode\n"); + break; + + case WDR_MODE_2To1_LINE: + pstSnsState->enWDRMode = WDR_MODE_2To1_LINE; + printf("2to1 line WDR mode\n"); + break; + + default: + ISP_TRACE(MODULE_DBG_ERR, "NOT support this mode!\n"); + return GK_FAILURE; + } + + memset(pstSnsState->au32WDRIntTime, 0, + sizeof(pstSnsState->au32WDRIntTime)); + + return GK_SUCCESS; +} + +static GK_S32 cmos_get_sns_regs_info(VI_PIPE ViPipe, + ISP_SNS_REGS_INFO_S *pstSnsRegsInfo) +{ + GK_S32 i; + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + CMOS_CHECK_POINTER(pstSnsRegsInfo); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + if ((GK_FALSE == pstSnsState->bSyncInit) || + (GK_FALSE == pstSnsRegsInfo->bConfig)) { + pstSnsState->astRegsInfo[0].enSnsType = ISP_SNS_I2C_TYPE; + pstSnsState->astRegsInfo[0].unComBus.s8I2cDev = + g_aunImx335BusInfo[ViPipe].s8I2cDev; + pstSnsState->astRegsInfo[0].u8Cfg2ValidDelayMax = 2; + pstSnsState->astRegsInfo[0].u32RegNum = 8; + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + pstSnsState->astRegsInfo[0].u32RegNum += 8; + } + + for (i = 0; i < pstSnsState->astRegsInfo[0].u32RegNum; i++) { + pstSnsState->astRegsInfo[0].astI2cData[i].bUpdate = + GK_TRUE; + pstSnsState->astRegsInfo[0].astI2cData[i].u8DevAddr = + imx335_i2c_addr; + pstSnsState->astRegsInfo[0] + .astI2cData[i] + .u32AddrByteNum = imx335_addr_byte; + pstSnsState->astRegsInfo[0] + .astI2cData[i] + .u32DataByteNum = imx335_data_byte; + } + + // shutter related + pstSnsState->astRegsInfo[0].astI2cData[0].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[0].u32RegAddr = + IMX335_SHR0_LOW; // SHR0 + pstSnsState->astRegsInfo[0].astI2cData[1].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[1].u32RegAddr = + IMX335_SHR0_MIDDLE; + pstSnsState->astRegsInfo[0].astI2cData[2].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[2].u32RegAddr = + IMX335_SHR0_HIGH; + + pstSnsState->astRegsInfo[0].astI2cData[3].u8DelayFrmNum = + 0; // Long Gain + pstSnsState->astRegsInfo[0].astI2cData[3].u32RegAddr = + IMX335_GAIN_LONG_LOW; + pstSnsState->astRegsInfo[0].astI2cData[4].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[4].u32RegAddr = + IMX335_GAIN_LONG_HIGH; + + // Vmax + pstSnsState->astRegsInfo[0].astI2cData[5].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[5].u32RegAddr = + IMX335_VMAX_ADDR_L; + pstSnsState->astRegsInfo[0].astI2cData[6].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[6].u32RegAddr = + IMX335_VMAX_ADDR_M; + pstSnsState->astRegsInfo[0].astI2cData[7].u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[7].u32RegAddr = + IMX335_VMAX_ADDR_H; + + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + pstSnsState->astRegsInfo[0].astI2cData[3].u8DelayFrmNum = + 0; + pstSnsState->astRegsInfo[0].astI2cData[4].u8DelayFrmNum = + 1; + + pstSnsState->astRegsInfo[0].astI2cData[5].u8DelayFrmNum = + 0; + pstSnsState->astRegsInfo[0].astI2cData[5].u32RegAddr = + IMX335_SHR1_LOW; // SHR1 + pstSnsState->astRegsInfo[0].astI2cData[6].u8DelayFrmNum = + 0; + pstSnsState->astRegsInfo[0].astI2cData[6].u32RegAddr = + IMX335_SHR1_MIDDLE; + pstSnsState->astRegsInfo[0].astI2cData[7].u8DelayFrmNum = + 0; + pstSnsState->astRegsInfo[0].astI2cData[7].u32RegAddr = + IMX335_SHR1_HIGH; + + pstSnsState->astRegsInfo[0].astI2cData[8].u8DelayFrmNum = + 1; + pstSnsState->astRegsInfo[0].astI2cData[8].u32RegAddr = + IMX335_VMAX_ADDR_L; // VMAX wdr + pstSnsState->astRegsInfo[0].astI2cData[9].u8DelayFrmNum = + 1; + pstSnsState->astRegsInfo[0].astI2cData[9].u32RegAddr = + IMX335_VMAX_ADDR_M; + pstSnsState->astRegsInfo[0] + .astI2cData[10] + .u8DelayFrmNum = 1; + pstSnsState->astRegsInfo[0].astI2cData[10].u32RegAddr = + IMX335_VMAX_ADDR_H; + + pstSnsState->astRegsInfo[0] + .astI2cData[11] + .u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[11].u32RegAddr = + IMX335_RHS1_LOW; // RHS1 + pstSnsState->astRegsInfo[0] + .astI2cData[12] + .u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[12].u32RegAddr = + IMX335_RHS1_MIDDLE; + pstSnsState->astRegsInfo[0] + .astI2cData[13] + .u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[13].u32RegAddr = + IMX335_RHS1_HIGH; + + pstSnsState->astRegsInfo[0] + .astI2cData[14] + .u8DelayFrmNum = 0; + pstSnsState->astRegsInfo[0].astI2cData[14].u32RegAddr = + IMX335_GAIN_SHORT_LOW; // Short Gain + pstSnsState->astRegsInfo[0] + .astI2cData[15] + .u8DelayFrmNum = 1; + pstSnsState->astRegsInfo[0].astI2cData[15].u32RegAddr = + IMX335_GAIN_SHORT_HIGH; + } + + pstSnsState->bSyncInit = GK_TRUE; + } else { + for (i = 0; i < pstSnsState->astRegsInfo[0].u32RegNum; i++) { + if (pstSnsState->astRegsInfo[0].astI2cData[i].u32Data == + pstSnsState->astRegsInfo[1].astI2cData[i].u32Data) { + pstSnsState->astRegsInfo[0] + .astI2cData[i] + .bUpdate = GK_FALSE; + } + + else { + pstSnsState->astRegsInfo[0] + .astI2cData[i] + .bUpdate = GK_TRUE; + } + } + } + pstSnsRegsInfo->bConfig = GK_FALSE; + + memcpy(pstSnsRegsInfo, &pstSnsState->astRegsInfo[0], + sizeof(ISP_SNS_REGS_INFO_S)); + memcpy(&pstSnsState->astRegsInfo[1], &pstSnsState->astRegsInfo[0], + sizeof(ISP_SNS_REGS_INFO_S)); + + pstSnsState->au32FL[1] = pstSnsState->au32FL[0]; + + return GK_SUCCESS; +} + +static GK_S32 +cmos_set_image_mode(VI_PIPE ViPipe, + ISP_CMOS_SENSOR_IMAGE_MODE_S *pstSensorImageMode) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + GK_U8 u8SensorImageMode = 0; + + CMOS_CHECK_POINTER(pstSensorImageMode); + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER(pstSnsState); + + pstSnsState->bSyncInit = GK_FALSE; + + //printf("Lation@ cmos_set_image_mode width: %d, height: %d\n", pstSensorImageMode->u16Width, pstSensorImageMode->u16Height); + if (WDR_MODE_2To1_LINE == pstSnsState->enWDRMode) { + // if (IMX335_RES_IS_4M_10BIT_WDR_EX( + // pstSensorImageMode->u16Width, + // pstSensorImageMode->u16Height)) { + // u8SensorImageMode = IMX335_4M_25FPS_10BIT_WDR_MODE; + // g_astimx335State[ViPipe].u32BRL = 1480 * 2; + // pstSnsState->u32FLStd = IMX335_VMAX_5M_30FPS_10BIT_WDR; + // } else + if (IMX335_RES_IS_5M_10BIT_WDR( + pstSensorImageMode->u16Width, + pstSensorImageMode->u16Height)) { + u8SensorImageMode = IMX335_5M_30FPS_10BIT_WDR_MODE; + g_astimx335State[ViPipe].u32BRL = 1984 * 2; + pstSnsState->u32FLStd = IMX335_VMAX_5M_30FPS_10BIT_WDR; + } else if (IMX335_RES_IS_4M_10BIT_WDR( + pstSensorImageMode->u16Width, + pstSensorImageMode->u16Height)) { + u8SensorImageMode = IMX335_4M_30FPS_10BIT_WDR_MODE; + g_astimx335State[ViPipe].u32BRL = 1548 * 2; + pstSnsState->u32FLStd = IMX335_VMAX_4M_30FPS_10BIT_WDR; + } else { + IMX335_ERR_MODE_PRINT(pstSensorImageMode, pstSnsState); + return GK_FAILURE; + } + } else if (WDR_MODE_NONE == pstSnsState->enWDRMode) { + if (IMX335_RES_IS_5M_12BIT_LINEAR( + pstSensorImageMode->u16Width, + pstSensorImageMode->u16Height) || +// IMX335_RES_IS_1520P_10BIT( +// pstSensorImageMode->u16Width, +// pstSensorImageMode->u16Height) || +// IMX335_RES_IS_BINNING_12BIT( //new this will run 30fps binning +// pstSensorImageMode->u16Width, +// pstSensorImageMode->u16Height) || + +// IMX335_RES_IS_1080P( //new this will run 30fps binning +// pstSensorImageMode->u16Width, +// pstSensorImageMode->u16Height) || + IMX335_RES_IS_4M_10BIT_LINEAR( + pstSensorImageMode->u16Width, + pstSensorImageMode->u16Height)) { + + u8SensorImageMode = IMX335_5M_30FPS_12BIT_LINEAR_MODE; + g_astimx335State[ViPipe].u32BRL = 1984 * 2; + pstSnsState->u32FLStd = + IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + } else if (IMX335_RES_IS_BINNING(pstSensorImageMode->u16Width, pstSensorImageMode->u16Height)) { + u8SensorImageMode = IMX335_60FPS_BINNING_MODE; + g_astimx335State[ViPipe].u32BRL = 1984 * 2; + pstSnsState->u32FLStd = + IMX335_VMAX_BINNING; + } else if (IMX335_RES_IS_1080P(pstSensorImageMode->u16Width, pstSensorImageMode->u16Height)) { + u8SensorImageMode = IMX335_60FPS_CROPPED_1080P_MODE; + g_astimx335State[ViPipe].u32BRL = 1984 * 2; + pstSnsState->u32FLStd = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + } else if (IMX335_RES_IS_1520P_10BIT(pstSensorImageMode->u16Width, pstSensorImageMode->u16Height)) { + u8SensorImageMode = IMX335_1520P_10BIT_MODE; + g_astimx335State[ViPipe].u32BRL = 1984 * 2; + pstSnsState->u32FLStd = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + } else { + IMX335_ERR_MODE_PRINT(pstSensorImageMode, pstSnsState); + return GK_FAILURE; + } + } else { + IMX335_ERR_MODE_PRINT(pstSensorImageMode, pstSnsState); + return GK_FAILURE; + } + + if ((GK_TRUE == pstSnsState->bInit) && + (u8SensorImageMode == pstSnsState->u8ImgMode)) { + /* Don't need to switch SensorImageMode */ + return ISP_DO_NOT_NEED_SWITCH_IMAGEMODE; + } + + pstSnsState->u8ImgMode = u8SensorImageMode; + pstSnsState->au32FL[0] = pstSnsState->u32FLStd; + pstSnsState->au32FL[1] = pstSnsState->au32FL[0]; + + return GK_SUCCESS; +} + +static GK_VOID sensor_global_init(VI_PIPE ViPipe) +{ + ISP_SNS_STATE_S *pstSnsState = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pstSnsState); + CMOS_CHECK_POINTER_VOID(pstSnsState); + + pstSnsState->bInit = GK_FALSE; + pstSnsState->bSyncInit = GK_FALSE; + pstSnsState->u8ImgMode = IMX335_5M_30FPS_12BIT_LINEAR_MODE; + pstSnsState->enWDRMode = WDR_MODE_NONE; + pstSnsState->u32FLStd = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + pstSnsState->au32FL[0] = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + pstSnsState->au32FL[1] = IMX335_VMAX_5M_30FPS_12BIT_LINEAR; + + memset(&pstSnsState->astRegsInfo[0], 0, sizeof(ISP_SNS_REGS_INFO_S)); + memset(&pstSnsState->astRegsInfo[1], 0, sizeof(ISP_SNS_REGS_INFO_S)); +} + +static GK_S32 +cmos_init_sensor_exp_function(ISP_SENSOR_EXP_FUNC_S *pstSensorExpFunc) +{ + CMOS_CHECK_POINTER(pstSensorExpFunc); + + memset(pstSensorExpFunc, 0, sizeof(ISP_SENSOR_EXP_FUNC_S)); + + pstSensorExpFunc->pfn_cmos_sensor_init = IMX335_init; + pstSensorExpFunc->pfn_cmos_sensor_exit = IMX335_exit; + pstSensorExpFunc->pfn_cmos_sensor_global_init = sensor_global_init; + pstSensorExpFunc->pfn_cmos_set_image_mode = cmos_set_image_mode; + pstSensorExpFunc->pfn_cmos_set_wdr_mode = cmos_set_wdr_mode; + pstSensorExpFunc->pfn_cmos_get_isp_default = cmos_get_isp_default; + pstSensorExpFunc->pfn_cmos_get_isp_black_level = + cmos_get_isp_black_level; + pstSensorExpFunc->pfn_cmos_set_pixel_detect = cmos_set_pixel_detect; + pstSensorExpFunc->pfn_cmos_get_sns_reg_info = cmos_get_sns_regs_info; + + return GK_SUCCESS; +} + +/**************************************************************************** + * callback structure * + ****************************************************************************/ + +static GK_S32 IMX335_set_bus_info(VI_PIPE ViPipe, + ISP_SNS_COMMBUS_U unSNSBusInfo) +{ + g_aunImx335BusInfo[ViPipe].s8I2cDev = unSNSBusInfo.s8I2cDev; + + return GK_SUCCESS; +} + +static GK_S32 sensor_ctx_init(VI_PIPE ViPipe) +{ + ISP_SNS_STATE_S *pastSnsStateCtx = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pastSnsStateCtx); + + if (GK_NULL == pastSnsStateCtx) { + pastSnsStateCtx = + (ISP_SNS_STATE_S *)malloc(sizeof(ISP_SNS_STATE_S)); + if (GK_NULL == pastSnsStateCtx) { + ISP_TRACE(MODULE_DBG_ERR, + "Isp[%d] SnsCtx malloc memory failed!\n", + ViPipe); + return ERR_CODE_ISP_NOMEM; + } + } + + memset(pastSnsStateCtx, 0, sizeof(ISP_SNS_STATE_S)); + + IMX335_SENSOR_SET_CTX(ViPipe, pastSnsStateCtx); + + return GK_SUCCESS; +} + +static GK_VOID sensor_ctx_exit(VI_PIPE ViPipe) +{ + ISP_SNS_STATE_S *pastSnsStateCtx = GK_NULL; + + IMX335_SENSOR_GET_CTX(ViPipe, pastSnsStateCtx); + SENSOR_FREE(pastSnsStateCtx); + IMX335_SENSOR_RESET_CTX(ViPipe); +} + +static GK_S32 sensor_register_callback(VI_PIPE ViPipe, ALG_LIB_S *pstAeLib, + ALG_LIB_S *pstAwbLib) +{ + GK_S32 s32Ret; + + ISP_SENSOR_REGISTER_S stIspRegister; + AE_SENSOR_REGISTER_S stAeRegister; + AWB_SENSOR_REGISTER_S stAwbRegister; + ISP_SNS_ATTR_INFO_S stSnsAttrInfo; + + CMOS_CHECK_POINTER(pstAeLib); + CMOS_CHECK_POINTER(pstAwbLib); + + s32Ret = sensor_ctx_init(ViPipe); + + if (GK_SUCCESS != s32Ret) { + return GK_FAILURE; + } + + stSnsAttrInfo.eSensorId = IMX335_ID; + + s32Ret = cmos_init_sensor_exp_function(&stIspRegister.stSnsExp); + s32Ret |= GK_API_ISP_SensorRegCallBack(ViPipe, &stSnsAttrInfo, + &stIspRegister); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE(MODULE_DBG_ERR, + "sensor register callback function failed!\n"); + return s32Ret; + } + + s32Ret = cmos_init_ae_exp_function(&stAeRegister.stSnsExp); + s32Ret |= GK_API_AE_SensorRegCallBack(ViPipe, pstAeLib, &stSnsAttrInfo, + &stAeRegister); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE( + MODULE_DBG_ERR, + "sensor register callback function to ae lib failed!\n"); + return s32Ret; + } + + s32Ret = cmos_init_awb_exp_function(&stAwbRegister.stSnsExp); + s32Ret |= GK_API_AWB_SensorRegCallBack(ViPipe, pstAwbLib, + &stSnsAttrInfo, &stAwbRegister); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE( + MODULE_DBG_ERR, + "sensor register callback function to awb lib failed!\n"); + return s32Ret; + } + + return GK_SUCCESS; +} + +static GK_S32 sensor_unregister_callback(VI_PIPE ViPipe, ALG_LIB_S *pstAeLib, + ALG_LIB_S *pstAwbLib) +{ + GK_S32 s32Ret; + + CMOS_CHECK_POINTER(pstAeLib); + CMOS_CHECK_POINTER(pstAwbLib); + + s32Ret = GK_API_ISP_SensorUnRegCallBack(ViPipe, IMX335_ID); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE(MODULE_DBG_ERR, + "sensor unregister callback function failed!\n"); + return s32Ret; + } + + s32Ret = GK_API_AE_SensorUnRegCallBack(ViPipe, pstAeLib, IMX335_ID); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE( + MODULE_DBG_ERR, + "sensor unregister callback function to ae lib failed!\n"); + return s32Ret; + } + + s32Ret = GK_API_AWB_SensorUnRegCallBack(ViPipe, pstAwbLib, IMX335_ID); + + if (GK_SUCCESS != s32Ret) { + ISP_TRACE( + MODULE_DBG_ERR, + "sensor unregister callback function to awb lib failed!\n"); + return s32Ret; + } + + sensor_ctx_exit(ViPipe); + + return GK_SUCCESS; +} + +static GK_S32 sensor_set_init(VI_PIPE ViPipe, ISP_INIT_ATTR_S *pstInitAttr) +{ + CMOS_CHECK_POINTER(pstInitAttr); + + g_au32InitExposure[ViPipe] = pstInitAttr->u32Exposure; + g_au32LinesPer500ms[ViPipe] = pstInitAttr->u32LinesPer500ms; + g_au16InitWBGain[ViPipe][0] = pstInitAttr->u16WBRgain; + g_au16InitWBGain[ViPipe][1] = pstInitAttr->u16WBGgain; + g_au16InitWBGain[ViPipe][2] = pstInitAttr->u16WBBgain; + g_au16SampleRgain[ViPipe] = pstInitAttr->u16SampleRgain; + g_au16SampleBgain[ViPipe] = pstInitAttr->u16SampleBgain; + + return GK_SUCCESS; +} + +ISP_SNS_OBJ_S stSnsImx335Obj = { + .pfnRegisterCallback = sensor_register_callback, + .pfnUnRegisterCallback = sensor_unregister_callback, + .pfnStandby = IMX335_standby, + .pfnRestart = IMX335_restart, + .pfnMirrorFlip = GK_NULL, + .pfnWriteReg = IMX335_write_register, + .pfnReadReg = IMX335_read_register, + .pfnSetBusInfo = IMX335_set_bus_info, + .pfnSetInit = sensor_set_init +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* End of #ifdef __cplusplus */ diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos_ex.h b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos_ex.h new file mode 100644 index 0000000..04101ce --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_cmos_ex.h @@ -0,0 +1,2910 @@ +/* + * Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021. All rights reserved. + */ +#ifndef __IMX335_CMOS_EX_H_ +#define __IMX335_CMOS_EX_H_ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +static const ISP_CMOS_LCAC_S g_stIspLCac = { + + /*bEnable*/ + 1, + /*u16PurpleDetRange*/ + 30, + /*VarThr*/ + 0, + /*au16RLumaThd*/ + { 1500, 1500, 0 }, + /*au16GLumaThd*/ + { 1500, 1500, 0 }, + /*au16BLumaThd*/ + { 4095, 1500, 0 }, + /*au16YLumaThd*/ + { 3200, 1500, 0 }, + /*as16CbCrRatio*/ + { -50, -50, -50 }, + /*enOpMode*/ + 0, + /*stManual*/ + { //u8DePurpleCrStr + 0, + //u8DePurpleCbStr + 3 }, + /*stAuto*/ + { //u8DePurpleCrStr + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + //u8DePurpleCbStr + { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } } +}; + +static const ISP_CMOS_LCAC_S g_stIspLCacWdr = { + + /*bEnable*/ + 1, + /*u16PurpleDetRange*/ + 30, + /*VarThr*/ + 130, + /*au16RLumaThd*/ + { 1500, 1500, 0 }, + /*au16GLumaThd*/ + { 1500, 1500, 0 }, + /*au16BLumaThd*/ + { 4095, 1500, 0 }, + /*au16YLumaThd*/ + { 3200, 1500, 0 }, + /*as16CbCrRatio*/ + { -50, -50, -50 }, + /*enOpMode*/ + 0, + /*stManual*/ + { //u8DePurpleCrStr + 0, + //u8DePurpleCbStr + 3 }, + /*stAuto*/ + { //u8DePurpleCrStr + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + //u8DePurpleCbStr + { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } } +}; + +/* Piris attr */ +static ISP_PIRIS_ATTR_S gstPirisAttr = { + 0, // bStepFNOTableChange + 1, // bZeroIsMax + 94, // u16TotalStep + 62, // u16StepCount + /* Step-F number mapping table. Must be from small to large. F1.0 is 1024 and F32.0 is 1 */ + { 30, 35, 40, 45, 50, 56, 61, 67, 73, 79, 85, 92, 98, + 105, 112, 120, 127, 135, 143, 150, 158, 166, 174, 183, 191, 200, + 208, 217, 225, 234, 243, 252, 261, 270, 279, 289, 298, 307, 316, + 325, 335, 344, 353, 362, 372, 381, 390, 399, 408, 417, 426, 435, + 444, 453, 462, 470, 478, 486, 493, 500, 506, 512 }, + ISP_IRIS_F_NO_1_4, // enMaxIrisFNOTarget + ISP_IRIS_F_NO_5_6 // enMinIrisFNOTarget +}; + +static const ISP_CMOS_DPC_S g_stCmosDpc = { + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { 0, 0, 0, 152, 220, 220, 220, 220, 220, 220, 152, 152, 152, 152, 152, + 152 }, /* au16Strength[16] */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 50, 50, 50, 50, + 50 }, /* au16BlendRatio[16] */ + 0, /* 0 for after drc, 1 for before wdr */ +}; + +static const ISP_CMOS_GE_S g_stIspGe = { + /* For GE */ + 1, /* bEnable */ + 13, /* u8Slope */ + 13, /* u8SensiSlope */ + 4800, /* u16SensiThr */ + /* ISO */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 4800, 4800, 4800, 4800, 4960, 4960, 4960, 4960, 5120, 5120, 5120, + 5120, 5280, 5280, 5280, + 5280 }, /* au16Threshold[ISP_AUTO_ISO_STRENGTH_NUM] */ + { 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, + 131, 131 }, /* au16Strength[ISP_AUTO_ISO_STRENGTH_NUM] */ + { 16384, 16384, 16384, 16384, 16384, 32768, 32768, 32768, 32768, 32768, + 32768, 32768, 32768, 32768, 32768, + 32768 } /* au16NpOffset[ISP_AUTO_ISO_STRENGTH_NUM] */ +}; + +static const ISP_CMOS_GE_S g_stIspWdrGe = { + /* For GE */ + 1, /* bEnable */ + 13, /* u8Slope */ + 13, /* u8SensiSlope */ + 4800, /* u16SensiThr */ + + /* ISO */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192,16384, 32768 */ + { 4800, 4800, 4800, 4800, 4960, 4960, 4960, 4960, 5120, 5120, 5120, + 5120, 5280, 5280, 5280, + 5280 }, /* au16Threshold[ISP_AUTO_ISO_STRENGTH_NUM] */ + { 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, + 131, 131 }, /* au16Strength[ISP_AUTO_ISO_STRENGTH_NUM] */ + { 16384, 16384, 16384, 16384, 16384, 32768, 32768, 32768, 32768, 32768, + 32768, 32768, 32768, 32768, 32768, + 32768 } /* au16NpOffset[ISP_AUTO_ISO_STRENGTH_NUM] */ +}; + +static const ISP_CMOS_DEMOSAIC_S g_stIspDemosaic = { + 1, // bEnable + /* au8NonDirStr */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }, + /* au8NonDirLFDetailEhc */ + { 32, 24, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }, + /* au8NonDirHFDetailEhc */ + { 3, 3, 3, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, + /* au8DetailSmoothRange */ + { 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 7, 7, 7, 7, 7, 7 }, +}; + +static const ISP_CMOS_DEMOSAIC_S g_stIspDemosaicWdr = { + 1, // bEnable + /* au8NonDirStr */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 64, 64, 64, 48, 48, 48, 32, 32, 32, 32, 16, 16, 16, 16, 16, 16 }, + /* au8NonDirLFDetailEhc */ + { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }, + /* au8NonDirHFDetailEhc */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* au8DetailSmoothRange */ + { 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7 }, +}; + +static const ISP_CMOS_ANTIFALSECOLOR_S g_stIspAntiFalseColor = { + 1, /* bEnable */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 10, 10, 8, 8, 7, 7, 7, 6, 6, 6, 5, 4, 3, 2, 1, + 0 }, /* au8AntiFalseColorThreshold */ + { 8, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 4, 3, 2, 1, + 0 }, /* au8AntiFalseColorStrength */ +}; + +static const ISP_CMOS_ANTIFALSECOLOR_S g_stIspWdrAntiFalseColor = { + 1, /* bEnable */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, + 0 }, /* au8AntiFalseColorThreshold */ + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, + 0 }, /* au8AntiFalseColorStrength */ +}; + +/***BAYER NR**/ +static ISP_CMOS_NOISE_CALIBRATION_S g_stIspNoiseCalibration = { + 12, // Calibration Lut Num + /*************Calibration LUT Table*************/ + { { 106.0f, 0.017536f, 0.024127f }, + { 117.0f, 0.01939f, 0.025791f }, + { 227.0f, 0.037736f, 0.040171f }, + { 470.0f, 0.07777f, 0.084227f }, + { 1747.0f, 0.287293f, 0.379383f }, + { 4002.0f, 0.655649f, 1.155996f }, + { 6491.0f, 1.065072f, 2.335924f }, + { 15969.0f, 2.720477f, 10.456544f }, + { 29738.0f, 5.172001f, 30.797239f }, + { 59343.0f, 10.782349f, 100.457473f }, + { 103124.0f, 21.000038f, 210.387179f }, + { 238817.0f, 28.774144f, 257.811098f } } + /*********************************************/ +}; +static const ISP_CMOS_BAYERNR_S g_stIspBayerNr = { + 1, // bEnable + 0, // bBnrMonoSensorEn + 0, // bNrLscEnable + 96, // u8BnrLscMaxGain + 256, // u16BnrLscCmpStrength + { 86, 80, 80, 70, 70, 65, 65, 60, 50, 50, 50, 50, 50, 50, 40, + 40 }, // FineStr + { + { 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 3 }, // ChromaStrR + { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2 }, // ChromaStrGr + { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2 }, // ChromaStrGb + { 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3 } // ChromaStrB + }, + { 0, 0, 0, 0 }, // WDRFrameStr + { 0, 0, 0, 0 }, // FusionFrameStr + { + { 80, 100, 110, 110, 110, 120, 130, 150, 160, 170, 170, 170, + 170, 170, 170, 170 }, // CoarseStrR + { 80, 100, 110, 110, 110, 120, 130, 150, 160, 170, 170, 170, + 170, 170, 170, 170 }, // CoarseStrGR + { 80, 100, 110, 110, 110, 120, 130, 150, 160, 170, 170, 170, + 170, 170, 170, 170 }, // CoarseStrGB + { 80, 100, 110, 110, 110, 120, 130, 150, 160, 170, 170, 170, + 170, 170, 170, 170 } // CoarseStrB + }, + { 30, 45, 50, 50, 50, 50, 50, 50, 55, 55, 55, 60, 65, 70, 78, + 85 }, // lutCoringWeight + { 10, 15, 19, 25, 32, 39, 45, 50, 55, 60, 65, + 70, 75, 80, 85, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 100, 100, 100, 100, 100, 100, 100 }, // CoringRatio +}; + +static const ISP_CMOS_BAYERNR_S g_stIspBayerNrWdr2To1 = { + 1, // bEnable + 0, // bBnrMonoSensorEn + 0, // bNrLscEnable + 96, // u8BnrLscMaxGain + 256, // u16BnrLscCmpStrength + { 128, 128, 128, 128, 95, 75, 70, 65, 60, 55, 50, 40, 40, 30, 30, + 30 }, // FineStr + { + { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 3 }, // ChromaStrR + { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2 }, // ChromaStrGr + { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2 }, // ChromaStrGb + { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3 } // ChromaStrB + }, + { 16, 7, 16, 0 }, // WDRFrameStr + { 26, 10, 0, 0 }, // FusionCoarseStr + { + { 100, 110, 110, 110, 110, 110, 110, 140, 160, 160, 180, 200, + 200, 200, 200, 200 }, // CoarseStrR + { 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, + 110, 110, 110, 110 }, // CoarseStrGR + { 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, + 110, 110, 110, 110 }, // CoarseStrGB + { 100, 110, 110, 110, 110, 120, 120, 140, 160, 160, 180, 200, + 200, 200, 200, 200 } // CoarseStrB + }, + { 20, 20, 30, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 100, 100, + 100 }, // lutCoringWeight + { 150, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }, // coring ratio +}; + +static const ISP_CMOS_LDCI_S g_stIspLdci = { + /* bEnable */ + 1, + /* u8GaussLPFSigma */ + 36, + + /* au8HePosWgt */ + { 50, 45, 42, 40, 35, 32, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0 }, + /* au8HePosSigma */ + { 80, 80, 72, 72, 72, 64, 24, 20, 12, 8, 6, 2, 1, 1, 1, 1 }, + /* au8HePosMean */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8HeNegWgt */ + { 50, 45, 45, 45, 45, 24, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0 }, + /* au8HeNegSigma */ + { 80, 80, 80, 80, 80, 72, 64, 54, 36, 8, 6, 2, 1, 1, 1, 1 }, + /* au8HeNegMean */ + { 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au16BlcCtrl */ + { 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 } +}; + +static const ISP_CMOS_LDCI_S g_stIspWdrLdci = { + /* bEnable */ + 0, + /* u8GaussLPFSigma */ + 36, + + /* au8HePosWgt */ + { 50, 45, 42, 40, 35, 32, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0 }, + /* au8HePosSigma */ + { 80, 80, 72, 72, 72, 64, 24, 20, 12, 8, 6, 2, 1, 1, 1, 1 }, + /* au8HePosMean */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8HeNegWgt */ + { 50, 45, 45, 45, 45, 24, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0 }, + /* au8HeNegSigma */ + { 80, 80, 80, 80, 80, 72, 64, 54, 36, 8, 6, 2, 1, 1, 1, 1 }, + /* au8HeNegMean */ + { 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au16BlcCtrl */ + { 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 } +}; + +static const ISP_CMOS_GAMMA_S g_stIspGamma = { + /* au16Gamma[GAMMA_EXT_NODE_NUMBER] */ + { 0, 33, 63, 92, 120, 146, 172, 196, 220, 243, 266, + 289, 310, 331, 350, 370, 390, 410, 431, 451, 470, 488, + 506, 523, 540, 558, 576, 593, 610, 626, 641, 655, 670, + 685, 700, 715, 730, 744, 758, 772, 786, 800, 814, 828, + 842, 855, 868, 881, 894, 907, 919, 932, 944, 956, 968, + 981, 994, 1008, 1022, 1036, 1050, 1063, 1074, 1085, 1096, 1107, + 1117, 1128, 1138, 1148, 1158, 1168, 1178, 1188, 1198, 1208, 1218, + 1228, 1237, 1246, 1254, 1261, 1267, 1273, 1280, 1288, 1296, 1305, + 1314, 1322, 1330, 1338, 1346, 1354, 1362, 1370, 1378, 1386, 1393, + 1401, 1408, 1415, 1423, 1430, 1438, 1445, 1453, 1460, 1467, 1474, + 1480, 1487, 1493, 1500, 1506, 1513, 1519, 1525, 1531, 1537, 1543, + 1549, 1555, 1562, 1568, 1574, 1580, 1586, 1592, 1598, 1604, 1609, + 1615, 1621, 1626, 1632, 1638, 1644, 1650, 1655, 1661, 1667, 1672, + 1678, 1683, 1689, 1694, 1700, 1705, 1710, 1715, 1721, 1726, 1731, + 1737, 1742, 1748, 1753, 1759, 1764, 1769, 1774, 1779, 1784, 1789, + 1794, 1799, 1805, 1810, 1815, 1820, 1825, 1830, 1835, 1839, 1844, + 1849, 1854, 1859, 1864, 1869, 1874, 1879, 1883, 1888, 1893, 1897, + 1902, 1907, 1912, 1916, 1921, 1926, 1931, 1936, 1940, 1945, 1950, + 1954, 1959, 1963, 1967, 1972, 1976, 1981, 1985, 1990, 1994, 1999, + 2004, 2008, 2013, 2017, 2021, 2025, 2030, 2034, 2038, 2043, 2048, + 2052, 2056, 2061, 2065, 2069, 2073, 2078, 2082, 2086, 2090, 2094, + 2098, 2102, 2106, 2110, 2115, 2119, 2123, 2128, 2132, 2136, 2140, + 2144, 2148, 2152, 2156, 2160, 2164, 2168, 2172, 2176, 2180, 2184, + 2188, 2192, 2196, 2200, 2204, 2208, 2212, 2216, 2220, 2223, 2227, + 2231, 2235, 2239, 2243, 2247, 2251, 2255, 2258, 2262, 2266, 2269, + 2273, 2277, 2281, 2285, 2288, 2292, 2296, 2300, 2303, 2307, 2311, + 2314, 2318, 2322, 2326, 2330, 2333, 2337, 2341, 2344, 2347, 2351, + 2355, 2358, 2362, 2366, 2370, 2373, 2377, 2380, 2383, 2387, 2390, + 2394, 2398, 2401, 2405, 2408, 2411, 2415, 2418, 2422, 2426, 2429, + 2433, 2436, 2439, 2443, 2446, 2450, 2454, 2457, 2461, 2464, 2467, + 2470, 2474, 2477, 2480, 2484, 2488, 2491, 2494, 2498, 2501, 2504, + 2507, 2511, 2515, 2518, 2521, 2525, 2528, 2531, 2534, 2537, 2541, + 2544, 2547, 2551, 2554, 2557, 2560, 2563, 2567, 2570, 2573, 2577, + 2580, 2583, 2586, 2589, 2593, 2596, 2599, 2603, 2606, 2609, 2612, + 2615, 2618, 2621, 2624, 2628, 2631, 2634, 2637, 2640, 2643, 2646, + 2649, 2652, 2656, 2659, 2662, 2665, 2668, 2671, 2674, 2677, 2680, + 2683, 2686, 2690, 2693, 2696, 2699, 2702, 2705, 2708, 2711, 2714, + 2717, 2720, 2723, 2726, 2729, 2732, 2735, 2738, 2741, 2744, 2747, + 2750, 2753, 2756, 2759, 2762, 2764, 2767, 2770, 2773, 2776, 2779, + 2782, 2785, 2788, 2791, 2794, 2796, 2799, 2802, 2805, 2808, 2811, + 2814, 2817, 2820, 2822, 2825, 2828, 2831, 2834, 2837, 2840, 2843, + 2845, 2848, 2851, 2853, 2856, 2859, 2862, 2865, 2868, 2871, 2874, + 2877, 2879, 2882, 2885, 2887, 2890, 2893, 2896, 2899, 2901, 2904, + 2907, 2909, 2912, 2915, 2918, 2920, 2923, 2926, 2929, 2932, 2934, + 2937, 2940, 2942, 2945, 2948, 2951, 2954, 2956, 2959, 2962, 2964, + 2966, 2969, 2972, 2974, 2977, 2980, 2983, 2986, 2988, 2991, 2994, + 2996, 2998, 3001, 3004, 3006, 3009, 3012, 3015, 3018, 3020, 3023, + 3026, 3028, 3031, 3033, 3035, 3038, 3040, 3043, 3046, 3048, 3051, + 3054, 3057, 3059, 3062, 3064, 3066, 3069, 3071, 3074, 3077, 3080, + 3082, 3085, 3088, 3090, 3093, 3095, 3097, 3100, 3102, 3105, 3108, + 3110, 3113, 3115, 3117, 3120, 3122, 3125, 3128, 3130, 3133, 3135, + 3138, 3140, 3143, 3145, 3147, 3150, 3152, 3155, 3158, 3160, 3163, + 3165, 3167, 3170, 3172, 3175, 3178, 3180, 3183, 3185, 3187, 3189, + 3192, 3194, 3196, 3199, 3201, 3204, 3207, 3209, 3211, 3214, 3217, + 3219, 3222, 3224, 3226, 3228, 3231, 3233, 3235, 3238, 3241, 3243, + 3245, 3247, 3250, 3252, 3254, 3257, 3260, 3262, 3264, 3267, 3269, + 3271, 3273, 3276, 3279, 3281, 3283, 3286, 3288, 3290, 3292, 3295, + 3298, 3300, 3302, 3305, 3307, 3309, 3311, 3313, 3316, 3318, 3320, + 3322, 3325, 3327, 3329, 3332, 3335, 3337, 3339, 3342, 3344, 3346, + 3348, 3350, 3353, 3355, 3357, 3360, 3362, 3364, 3366, 3368, 3371, + 3373, 3375, 3378, 3380, 3382, 3384, 3386, 3389, 3391, 3393, 3396, + 3398, 3400, 3402, 3405, 3407, 3409, 3411, 3413, 3416, 3418, 3420, + 3423, 3425, 3427, 3429, 3431, 3434, 3436, 3438, 3441, 3443, 3445, + 3447, 3449, 3452, 3454, 3456, 3459, 3461, 3463, 3465, 3467, 3469, + 3471, 3473, 3475, 3478, 3480, 3482, 3484, 3487, 3489, 3491, 3494, + 3496, 3498, 3500, 3502, 3504, 3506, 3508, 3511, 3513, 3515, 3517, + 3519, 3521, 3523, 3525, 3528, 3530, 3532, 3534, 3536, 3538, 3540, + 3542, 3545, 3547, 3549, 3551, 3553, 3555, 3557, 3559, 3561, 3564, + 3566, 3568, 3570, 3572, 3574, 3576, 3578, 3581, 3583, 3585, 3587, + 3589, 3591, 3593, 3595, 3598, 3600, 3602, 3604, 3606, 3608, 3610, + 3612, 3614, 3616, 3618, 3620, 3622, 3624, 3626, 3628, 3631, 3633, + 3635, 3637, 3639, 3641, 3643, 3645, 3647, 3649, 3651, 3653, 3655, + 3657, 3659, 3661, 3663, 3665, 3667, 3670, 3672, 3674, 3676, 3678, + 3680, 3682, 3684, 3686, 3688, 3690, 3692, 3694, 3696, 3698, 3700, + 3702, 3704, 3706, 3708, 3710, 3712, 3714, 3716, 3718, 3720, 3722, + 3724, 3726, 3728, 3730, 3732, 3734, 3736, 3738, 3740, 3742, 3744, + 3746, 3748, 3750, 3752, 3754, 3756, 3758, 3760, 3762, 3764, 3766, + 3767, 3769, 3771, 3773, 3775, 3777, 3779, 3781, 3783, 3785, 3787, + 3789, 3791, 3793, 3795, 3797, 3799, 3801, 3803, 3804, 3806, 3808, + 3810, 3812, 3814, 3816, 3818, 3820, 3822, 3824, 3826, 3828, 3830, + 3832, 3834, 3836, 3837, 3839, 3841, 3843, 3845, 3847, 3849, 3851, + 3853, 3855, 3857, 3858, 3860, 3862, 3864, 3866, 3868, 3870, 3872, + 3873, 3875, 3877, 3879, 3881, 3883, 3885, 3887, 3888, 3890, 3892, + 3894, 3896, 3898, 3900, 3902, 3904, 3905, 3907, 3909, 3911, 3913, + 3915, 3917, 3919, 3920, 3922, 3924, 3926, 3928, 3930, 3932, 3934, + 3935, 3937, 3939, 3941, 3943, 3945, 3947, 3949, 3950, 3952, 3954, + 3955, 3957, 3959, 3961, 3963, 3965, 3967, 3969, 3971, 3972, 3974, + 3976, 3977, 3979, 3981, 3983, 3985, 3987, 3989, 3991, 3993, 3994, + 3996, 3998, 4000, 4001, 4003, 4005, 4006, 4008, 4010, 4012, 4014, + 4016, 4018, 4020, 4022, 4023, 4025, 4027, 4028, 4030, 4032, 4034, + 4036, 4037, 4039, 4041, 4042, 4044, 4046, 4048, 4050, 4052, 4054, + 4056, 4058, 4059, 4061, 4063, 4064, 4066, 4068, 4070, 4072, 4073, + 4075, 4077, 4078, 4080, 4082, 4084, 4086, 4087, 4089, 4091, 4092, + 4094, 4095 } +}; + +static const ISP_CMOS_GAMMA_S g_stIspGammaFSWDR = { + /* 0.8gamma */ + { + + 0, 23, 38, 52, 64, 76, 87, 97, 108, 118, + 127, 137, 146, 155, 164, 172, 181, 189, 198, 206, + 214, 222, 230, 238, 245, 253, 260, 268, 275, 283, + 290, 297, 304, 311, 319, 326, 332, 339, 346, 353, + 360, 367, 373, 380, 386, 393, 400, 406, 413, 419, + 425, 432, 438, 444, 451, 457, 463, 469, 475, 482, + 488, 494, 500, 506, 512, 518, 524, 530, 536, 542, + 547, 553, 559, 565, 571, 577, 582, 588, 594, 599, + 605, 611, 616, 622, 628, 633, 639, 644, 650, 655, + 661, 667, 672, 677, 683, 688, 694, 699, 705, 710, + 715, 721, 726, 731, 737, 742, 747, 753, 758, 763, + 768, 774, 779, 784, 789, 794, 800, 805, 810, 815, + 820, 825, 830, 836, 841, 846, 851, 856, 861, 866, + 871, 876, 881, 886, 891, 896, 901, 906, 911, 916, + 921, 926, 931, 935, 940, 945, 950, 955, 960, 965, + 970, 974, 979, 984, 989, 994, 999, 1003, 1008, 1013, + 1018, 1022, 1027, 1032, 1037, 1041, 1046, 1051, 1056, 1060, + 1065, 1070, 1074, 1079, 1084, 1088, 1093, 1098, 1102, 1107, + 1112, 1116, 1121, 1126, 1130, 1135, 1139, 1144, 1149, 1153, + 1158, 1162, 1167, 1171, 1176, 1180, 1185, 1190, 1194, 1199, + 1203, 1208, 1212, 1217, 1221, 1226, 1230, 1235, 1239, 1243, + 1248, 1252, 1257, 1261, 1266, 1270, 1275, 1279, 1283, 1288, + 1292, 1297, 1301, 1305, 1310, 1314, 1319, 1323, 1327, 1332, + 1336, 1340, 1345, 1349, 1353, 1358, 1362, 1366, 1371, 1375, + 1379, 1384, 1388, 1392, 1397, 1401, 1405, 1409, 1414, 1418, + 1422, 1427, 1431, 1435, 1439, 1444, 1448, 1452, 1456, 1461, + 1465, 1469, 1473, 1477, 1482, 1486, 1490, 1494, 1498, 1503, + 1507, 1511, 1515, 1519, 1523, 1528, 1532, 1536, 1540, 1544, + 1548, 1553, 1557, 1561, 1565, 1569, 1573, 1577, 1582, 1586, + 1590, 1594, 1598, 1602, 1606, 1610, 1614, 1618, 1623, 1627, + 1631, 1635, 1639, 1643, 1647, 1651, 1655, 1659, 1663, 1667, + 1671, 1675, 1679, 1683, 1687, 1691, 1695, 1700, 1704, 1708, + 1712, 1716, 1720, 1724, 1728, 1732, 1736, 1740, 1744, 1748, + 1752, 1755, 1759, 1763, 1767, 1771, 1775, 1779, 1783, 1787, + 1791, 1795, 1799, 1803, 1807, 1811, 1815, 1819, 1823, 1827, + 1831, 1834, 1838, 1842, 1846, 1850, 1854, 1858, 1862, 1866, + 1870, 1874, 1877, 1881, 1885, 1889, 1893, 1897, 1901, 1905, + 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1935, 1939, 1943, + 1947, 1951, 1955, 1959, 1962, 1966, 1970, 1974, 1978, 1981, + 1985, 1989, 1993, 1997, 2001, 2004, 2008, 2012, 2016, 2020, + 2023, 2027, 2031, 2035, 2039, 2042, 2046, 2050, 2054, 2057, + 2061, 2065, 2069, 2072, 2076, 2080, 2084, 2088, 2091, 2095, + 2099, 2103, 2106, 2110, 2114, 2117, 2121, 2125, 2129, 2132, + 2136, 2140, 2144, 2147, 2151, 2155, 2158, 2162, 2166, 2170, + 2173, 2177, 2181, 2184, 2188, 2192, 2195, 2199, 2203, 2207, + 2210, 2214, 2218, 2221, 2225, 2229, 2232, 2236, 2240, 2243, + 2247, 2251, 2254, 2258, 2262, 2265, 2269, 2273, 2276, 2280, + 2284, 2287, 2291, 2294, 2298, 2302, 2305, 2309, 2313, 2316, + 2320, 2323, 2327, 2331, 2334, 2338, 2342, 2345, 2349, 2352, + 2356, 2360, 2363, 2367, 2370, 2374, 2378, 2381, 2385, 2388, + 2392, 2396, 2399, 2403, 2406, 2410, 2413, 2417, 2421, 2424, + 2428, 2431, 2435, 2438, 2442, 2446, 2449, 2453, 2456, 2460, + 2463, 2467, 2470, 2474, 2478, 2481, 2485, 2488, 2492, 2495, + 2499, 2502, 2506, 2509, 2513, 2516, 2520, 2524, 2527, 2531, + 2534, 2538, 2541, 2545, 2548, 2552, 2555, 2559, 2562, 2566, + 2569, 2573, 2576, 2580, 2583, 2587, 2590, 2594, 2597, 2601, + 2604, 2608, 2611, 2615, 2618, 2622, 2625, 2629, 2632, 2636, + 2639, 2642, 2646, 2649, 2653, 2656, 2660, 2663, 2667, 2670, + 2674, 2677, 2681, 2684, 2687, 2691, 2694, 2698, 2701, 2705, + 2708, 2712, 2715, 2718, 2722, 2725, 2729, 2732, 2736, 2739, + 2742, 2746, 2749, 2753, 2756, 2760, 2763, 2766, 2770, 2773, + 2777, 2780, 2784, 2787, 2790, 2794, 2797, 2801, 2804, 2807, + 2811, 2814, 2818, 2821, 2824, 2828, 2831, 2835, 2838, 2841, + 2845, 2848, 2851, 2855, 2858, 2862, 2865, 2868, 2872, 2875, + 2878, 2882, 2885, 2889, 2892, 2895, 2899, 2902, 2905, 2909, + 2912, 2916, 2919, 2922, 2926, 2929, 2932, 2936, 2939, 2942, + 2946, 2949, 2952, 2956, 2959, 2962, 2966, 2969, 2972, 2976, + 2979, 2982, 2986, 2989, 2992, 2996, 2999, 3002, 3006, 3009, + 3012, 3016, 3019, 3022, 3026, 3029, 3032, 3036, 3039, 3042, + 3046, 3049, 3052, 3055, 3059, 3062, 3065, 3069, 3072, 3075, + 3079, 3082, 3085, 3088, 3092, 3095, 3098, 3102, 3105, 3108, + 3112, 3115, 3118, 3121, 3125, 3128, 3131, 3135, 3138, 3141, + 3144, 3148, 3151, 3154, 3157, 3161, 3164, 3167, 3170, 3174, + 3177, 3180, 3184, 3187, 3190, 3193, 3197, 3200, 3203, 3206, + 3210, 3213, 3216, 3219, 3223, 3226, 3229, 3232, 3236, 3239, + 3242, 3245, 3249, 3252, 3255, 3258, 3262, 3265, 3268, 3271, + 3274, 3278, 3281, 3284, 3287, 3291, 3294, 3297, 3300, 3303, + 3307, 3310, 3313, 3316, 3320, 3323, 3326, 3329, 3332, 3336, + 3339, 3342, 3345, 3348, 3352, 3355, 3358, 3361, 3365, 3368, + 3371, 3374, 3377, 3381, 3384, 3387, 3390, 3393, 3396, 3400, + 3403, 3406, 3409, 3412, 3416, 3419, 3422, 3425, 3428, 3432, + 3435, 3438, 3441, 3444, 3447, 3451, 3454, 3457, 3460, 3463, + 3466, 3470, 3473, 3476, 3479, 3482, 3485, 3489, 3492, 3495, + 3498, 3501, 3504, 3508, 3511, 3514, 3517, 3520, 3523, 3527, + 3530, 3533, 3536, 3539, 3542, 3545, 3549, 3552, 3555, 3558, + 3561, 3564, 3567, 3571, 3574, 3577, 3580, 3583, 3586, 3589, + 3593, 3596, 3599, 3602, 3605, 3608, 3611, 3614, 3618, 3621, + 3624, 3627, 3630, 3633, 3636, 3639, 3643, 3646, 3649, 3652, + 3655, 3658, 3661, 3664, 3667, 3671, 3674, 3677, 3680, 3683, + 3686, 3689, 3692, 3695, 3699, 3702, 3705, 3708, 3711, 3714, + 3717, 3720, 3723, 3726, 3730, 3733, 3736, 3739, 3742, 3745, + 3748, 3751, 3754, 3757, 3760, 3764, 3767, 3770, 3773, 3776, + 3779, 3782, 3785, 3788, 3791, 3794, 3797, 3800, 3804, 3807, + 3810, 3813, 3816, 3819, 3822, 3825, 3828, 3831, 3834, 3837, + 3840, 3843, 3847, 3850, 3853, 3856, 3859, 3862, 3865, 3868, + 3871, 3874, 3877, 3880, 3883, 3886, 3889, 3892, 3895, 3898, + 3902, 3905, 3908, 3911, 3914, 3917, 3920, 3923, 3926, 3929, + 3932, 3935, 3938, 3941, 3944, 3947, 3950, 3953, 3956, 3959, + 3962, 3965, 3968, 3971, 3974, 3977, 3980, 3984, 3987, 3990, + 3993, 3996, 3999, 4002, 4005, 4008, 4011, 4014, 4017, 4020, + 4023, 4026, 4029, 4032, 4035, 4038, 4041, 4044, 4047, 4050, + 4053, 4056, 4059, 4062, 4065, 4068, 4071, 4074, 4077, 4080, + 4083, 4086, 4089, 4092, 4095 + + } +}; + +static const ISP_CMOS_PREGAMMA_S g_stPreGamma = { + 0, + { 3821, 7131, 9741, 11691, 13307, 14713, 15971, 17118, + 18179, 20099, 21818, 23385, 24833, 26185, 27456, 28659, + 29804, 30897, 31945, 32952, 33923, 35770, 37506, 39150, + 40713, 42207, 43638, 45014, 46340, 47622, 48863, 50066, + 51235, 52373, 53481, 54561, 55616, 57656, 59611, 61491, + 63303, 65054, 66749, 68393, 69990, 71543, 73057, 74533, + 75974, 77383, 78761, 80110, 81432, 83999, 86475, 88866, + 91182, 93428, 95609, 97731, 99799, 101815, 103784, 105708, + 107590, 109433, 111239, 113010, 114747, 118128, 121395, 124558, + 127626, 130606, 133505, 136330, 139084, 141773, 144402, 146973, + 149491, 151957, 154376, 156749, 159079, 161368, 163618, 165831, + 168008, 170152, 172263, 174342, 176392, 178413, 180407, 182374, + 184315, 186232, 188125, 189995, 191842, 193668, 197259, 200771, + 204210, 207580, 210884, 214126, 217308, 220435, 223509, 226532, + 229506, 232434, 235318, 238159, 240959, 243720, 246443, 249130, + 251782, 254400, 256986, 259540, 262064, 264559, 267025, 269464, + 271876, 274262, 276623, 278960, 281273, 283562, 288076, 292504, + 296852, 301124, 305323, 309452, 313515, 317515, 321454, 325335, + 329160, 332931, 336651, 340322, 343945, 347521, 351054, 354543, + 357991, 361399, 364767, 368099, 371394, 374653, 377878, 381070, + 384230, 387358, 390456, 393523, 396562, 399573, 405512, 411348, + 417083, 422724, 428274, 433738, 439119, 444420, 449646, 454798, + 459880, 464894, 469842, 474728, 479554, 484320, 489030, 493685, + 498287, 502838, 507339, 511791, 516197, 520557, 524874, 529147, + 533378, 537569, 541720, 545833, 549908, 553946, 557949, 561917, + 565852, 569753, 577458, 585040, 592504, 599854, 607096, 614234, + 621272, 628214, 635064, 641824, 648498, 655090, 661601, 668035, + 674394, 680681, 686897, 693045, 699128, 705146, 711103, 716999, + 722836, 728616, 734341, 740012, 745630, 751197, 756713, 762181, + 767602, 778305, 788831, 799189, 809384, 819425, 829318, 839069, + 848683, 858166, 867523, 876757, 885875, 894879, 903774, 912563, + 921249, 938329, 955037, 971395, 987423, 1003139, 1018560, 1033701, + 1048575 } +}; + +static const ISP_CMOS_SHARPEN_S g_stIspYuvSharpen = { + /* u8SkinUmin */ + 110, + /* u8SkinVmin */ + 128, + /* u8SkinUmax */ + 128, + /* u8SkinVmax */ + 149, + + /* Manual Para */ + { /* au8LumaWgt */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + /* u16TextureStr */ + { 250, 420, 390, 390, 390, 390, 390, 370, 350, 330, 310, + 290, 270, 270, 270, 270, 270, 270, 266, 260, 244, 230, + 230, 230, 230, 230, 230, 210, 190, 190, 170, 150 }, + /* u16EdgeStr */ + { 120, 123, 125, 128, 130, 135, 140, 148, 160, 168, 180, + 190, 200, 210, 210, 210, 210, 210, 200, 190, 185, 175, + 165, 160, 146, 136, 130, 128, 125, 123, 120, 120 }, + /* u16TextureFreq; */ + 160, + /* u16EdgeFreq; */ + 100, + /* u8OverShoot; */ + 55, + /* u8UnderShoot; */ + 70, + /* u8shootSupStr; */ + 10, + /* u8shootSupAdj; */ + 9, + /* u8DetailCtrl; */ + 128, + /* u8DetailCtrlThr; */ + 180, + /* u8EdgeFiltStr; */ + 60, + /*u8EdgeFiltMaxCap; */ + 18, + /*u8RGain; */ + 28, + /* u8GGain; */ + 32, + /* u8BGain; */ + 31, + /* u8SkinGain; */ + 23, + /* u8MaxSharpGain; */ + 67, + /* u8WeakDetailGain */ + 6 }, + /* Auto Para */ + { /* au16LumaWgt */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { { 31, 31, 20, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 17, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, + { 31, 31, 20, 20, 20, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }, + { 31, 31, 23, 23, 23, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21 }, + { 31, 31, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25 }, + { 31, 31, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 28, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 23, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 } }, + /* au16TextureStr */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { { + 133, + 239, + 205, + 201, + 264, + 188, + 243, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + }, + { + 209, + 273, + 251, + 245, + 307, + 225, + 241, + 155, + 126, + 127, + 124, + 124, + 124, + 124, + 124, + 124, + }, + { + 273, + 308, + 300, + 292, + 351, + 264, + 257, + 213, + 153, + 156, + 149, + 149, + 149, + 149, + 149, + 149, + }, + { + 360, + 341, + 362, + 334, + 393, + 301, + 323, + 261, + 180, + 183, + 173, + 173, + 173, + 173, + 173, + 173, + }, + { + 390, + 368, + 419, + 368, + 429, + 336, + 402, + 311, + 207, + 210, + 195, + 195, + 195, + 195, + 195, + 195, + }, + { + 390, + 386, + 447, + 389, + 457, + 368, + 460, + 371, + 233, + 234, + 212, + 212, + 212, + 212, + 212, + 212, + }, + { + 390, + 398, + 463, + 401, + 481, + 400, + 512, + 429, + 259, + 257, + 226, + 226, + 226, + 226, + 226, + 226, + }, + { + 380, + 407, + 475, + 409, + 498, + 427, + 561, + 468, + 285, + 279, + 240, + 240, + 240, + 240, + 240, + 240, + }, + { + 375, + 413, + 482, + 415, + 510, + 449, + 599, + 501, + 311, + 300, + 256, + 256, + 256, + 256, + 256, + 256, + }, + { + 384, + 415, + 479, + 419, + 512, + 462, + 611, + 533, + 338, + 320, + 273, + 273, + 273, + 273, + 273, + 273, + }, + { + 393, + 413, + 474, + 421, + 507, + 470, + 614, + 558, + 366, + 339, + 291, + 291, + 291, + 291, + 291, + 291, + }, + { + 398, + 410, + 475, + 420, + 498, + 474, + 620, + 562, + 392, + 357, + 309, + 309, + 309, + 309, + 309, + 309, + }, + { + 400, + 408, + 476, + 419, + 489, + 476, + 626, + 561, + 411, + 375, + 328, + 328, + 328, + 328, + 328, + 328, + }, + { + 397, + 406, + 471, + 415, + 479, + 476, + 636, + 568, + 420, + 392, + 346, + 346, + 346, + 346, + 346, + 346, + }, + { + 393, + 404, + 463, + 410, + 469, + 473, + 641, + 573, + 424, + 409, + 366, + 366, + 366, + 366, + 366, + 366, + }, + { + 389, + 402, + 448, + 404, + 457, + 469, + 627, + 563, + 424, + 424, + 385, + 385, + 385, + 385, + 385, + 385, + }, + { + 385, + 398, + 434, + 400, + 448, + 463, + 611, + 554, + 425, + 436, + 402, + 402, + 402, + 402, + 402, + 402, + }, + { + 375, + 390, + 429, + 397, + 438, + 451, + 610, + 570, + 427, + 443, + 420, + 420, + 420, + 420, + 420, + 420, + }, + { + 364, + 379, + 422, + 394, + 429, + 437, + 607, + 583, + 427, + 445, + 436, + 436, + 436, + 436, + 436, + 436, + }, + { + 353, + 368, + 413, + 389, + 419, + 419, + 599, + 595, + 427, + 446, + 453, + 453, + 453, + 453, + 453, + 453, + }, + { + 345, + 359, + 398, + 377, + 408, + 401, + 588, + 602, + 425, + 446, + 466, + 466, + 466, + 466, + 466, + 466, + }, + { + 338, + 351, + 383, + 364, + 395, + 380, + 574, + 608, + 422, + 446, + 481, + 481, + 481, + 481, + 481, + 481, + }, + { + 329, + 336, + 372, + 352, + 383, + 358, + 557, + 613, + 418, + 446, + 493, + 493, + 493, + 493, + 493, + 493, + }, + { + 320, + 322, + 364, + 343, + 372, + 339, + 539, + 618, + 415, + 446, + 503, + 503, + 503, + 503, + 503, + 503, + }, + { + 309, + 316, + 353, + 335, + 362, + 322, + 517, + 622, + 411, + 445, + 507, + 507, + 507, + 507, + 507, + 507, + }, + { + 300, + 313, + 343, + 328, + 352, + 307, + 493, + 627, + 406, + 445, + 509, + 509, + 509, + 509, + 509, + 509, + }, + { + 290, + 304, + 334, + 321, + 344, + 292, + 467, + 630, + 402, + 445, + 507, + 507, + 507, + 507, + 507, + 507, + }, + { + 283, + 294, + 324, + 315, + 338, + 277, + 440, + 630, + 400, + 446, + 504, + 504, + 504, + 504, + 504, + 504, + }, + { + 275, + 285, + 310, + 306, + 333, + 260, + 410, + 625, + 398, + 446, + 497, + 497, + 497, + 497, + 497, + 497, + }, + { + 269, + 277, + 294, + 296, + 330, + 242, + 378, + 617, + 399, + 447, + 487, + 487, + 487, + 487, + 487, + 487, + }, + { + 263, + 265, + 271, + 283, + 328, + 224, + 345, + 608, + 399, + 448, + 476, + 476, + 476, + 476, + 476, + 476, + }, + { + 258, + 254, + 247, + 269, + 326, + 207, + 313, + 600, + 400, + 449, + 466, + 466, + 466, + 466, + 466, + 466, + } }, + /* au16EdgeStr */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { { + 250, + 256, + 262, + 279, + 320, + 417, + 320, + 320, + 400, + 400, + 400, + 400, + 400, + 400, + 400, + 400, + }, + { + 250, + 260, + 270, + 296, + 331, + 421, + 337, + 337, + 412, + 412, + 412, + 412, + 412, + 412, + 412, + 412, + }, + { + 250, + 264, + 279, + 314, + 343, + 425, + 354, + 355, + 424, + 424, + 424, + 424, + 424, + 424, + 424, + 424, + }, + { + 250, + 268, + 288, + 332, + 356, + 429, + 371, + 373, + 436, + 436, + 436, + 436, + 436, + 436, + 436, + 436, + }, + { + 250, + 272, + 296, + 350, + 368, + 433, + 386, + 390, + 452, + 452, + 452, + 452, + 452, + 452, + 452, + 452, + }, + { + 250, + 276, + 305, + 368, + 380, + 437, + 398, + 406, + 470, + 470, + 470, + 470, + 470, + 470, + 470, + 470, + }, + { + 250, + 280, + 313, + 384, + 391, + 441, + 410, + 421, + 490, + 490, + 490, + 490, + 490, + 490, + 490, + 490, + }, + { + 250, + 286, + 321, + 398, + 401, + 445, + 420, + 436, + 512, + 512, + 512, + 512, + 512, + 512, + 512, + 512, + }, + { + 250, + 292, + 328, + 411, + 410, + 448, + 430, + 451, + 534, + 534, + 534, + 534, + 534, + 534, + 534, + 534, + }, + { + 249, + 299, + 334, + 420, + 416, + 450, + 438, + 463, + 556, + 556, + 556, + 556, + 556, + 556, + 556, + 556, + }, + { + 249, + 307, + 339, + 428, + 422, + 452, + 446, + 475, + 580, + 580, + 580, + 580, + 580, + 580, + 580, + 580, + }, + { + 249, + 316, + 344, + 434, + 427, + 453, + 453, + 486, + 603, + 603, + 603, + 603, + 603, + 603, + 603, + 603, + }, + { + 248, + 326, + 349, + 439, + 431, + 454, + 460, + 498, + 623, + 623, + 623, + 623, + 623, + 623, + 623, + 623, + }, + { + 248, + 335, + 353, + 442, + 434, + 455, + 466, + 511, + 639, + 639, + 639, + 639, + 639, + 639, + 639, + 639, + }, + { + 248, + 344, + 357, + 445, + 437, + 456, + 473, + 524, + 652, + 652, + 652, + 652, + 652, + 652, + 652, + 652, + }, + { + 247, + 351, + 360, + 447, + 439, + 456, + 479, + 538, + 664, + 664, + 664, + 664, + 664, + 664, + 664, + 664, + }, + { + 247, + 357, + 364, + 449, + 442, + 457, + 485, + 550, + 674, + 674, + 674, + 674, + 674, + 674, + 674, + 674, + }, + { + 246, + 361, + 367, + 450, + 444, + 456, + 489, + 563, + 683, + 683, + 683, + 683, + 683, + 683, + 683, + 683, + }, + { + 245, + 364, + 369, + 450, + 445, + 455, + 492, + 575, + 690, + 690, + 690, + 690, + 690, + 690, + 690, + 690, + }, + { + 244, + 366, + 371, + 450, + 446, + 454, + 496, + 585, + 695, + 695, + 695, + 695, + 695, + 695, + 695, + 695, + }, + { + 243, + 366, + 373, + 448, + 446, + 453, + 500, + 590, + 696, + 696, + 696, + 696, + 696, + 696, + 696, + 696, + }, + { + 242, + 366, + 375, + 445, + 445, + 451, + 504, + 594, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + }, + { + 241, + 366, + 376, + 441, + 445, + 450, + 508, + 597, + 696, + 696, + 696, + 696, + 696, + 696, + 696, + 696, + }, + { + 241, + 366, + 377, + 436, + 444, + 449, + 511, + 600, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + }, + { + 240, + 365, + 377, + 429, + 442, + 448, + 509, + 601, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + 697, + }, + { + 239, + 363, + 377, + 422, + 440, + 447, + 506, + 600, + 698, + 698, + 698, + 698, + 698, + 698, + 698, + 698, + }, + { + 238, + 361, + 377, + 413, + 437, + 446, + 502, + 600, + 699, + 699, + 699, + 699, + 699, + 699, + 699, + 699, + }, + { + 238, + 359, + 376, + 403, + 434, + 446, + 500, + 600, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + }, + { + 237, + 356, + 376, + 393, + 431, + 445, + 498, + 600, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + }, + { + 236, + 353, + 375, + 383, + 428, + 445, + 498, + 600, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + }, + { + 235, + 351, + 375, + 373, + 425, + 444, + 498, + 600, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + }, + { + 235, + 349, + 375, + 364, + 423, + 444, + 498, + 600, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + 700, + } }, + /* au16TextureFreq */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { 160, 170, 180, 180, 160, 160, 128, 128, 128, 128, 128, 100, 100, + 100, 100, 100 }, + + /* au16EdgeFreq */ + { 130, 115, 100, 100, 100, 100, 100, 100, 100, 100, 96, 96, 96, 96, + 96, 96 }, + + /* au8OverShoot */ + { 58, 70, 75, 75, 75, 55, 40, 30, 30, 30, 30, 10, 10, 10, 10, 10 }, + + /* au8UnderShoot */ + { 69, 87, 90, 82, 80, 70, 50, 50, 45, 45, 40, 20, 15, 15, 15, 15 }, + + /* au16shootSupStr */ + { 8, 8, 7, 7, 7, 6, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8ShootSupAdj */ + { 9, 9, 8, 8, 7, 7, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8DetailCtrl */ + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 120, 120, 120, + 120, 120, 120 }, + + /* au8DetailCtrlThr */ + { 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, + 160, 160, 160 }, + + /* au8EdgeFiltStr */ + { 56, 57, 58, 58, 59, 60, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62 }, + + /*au8EdgeFiltMaxCap[ISP_AUTO_ISO_STRENGTH_NUM];*/ + { 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }, + + /*au8RGain[ISP_AUTO_ISO_STRENGTH_NUM];*/ + { 28, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* au8GGain */ + { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 }, + + /* au8BGain */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* au8SkinGain */ + { 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* u8MaxSharpGain */ + { 67, 70, 72, 74, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80 }, + /* au8WeakDetailGain */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + +}; + +static const ISP_CMOS_SHARPEN_S g_stIspYuvSharpenWdr = { + /* u8SkinUmin */ + 100, + /* u8SkinVmin */ + 135, + /* u8SkinUmax */ + 128, + /* u8SkinVmax */ + 150, + /* Manual Para */ + { /* au8LumaWgt */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + /* u16TextureStr */ + { 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 140, 140, 140, 140, 140 }, + /* u16EdgeStr */ + { 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 }, + /* u16TextureFreq; */ + 256, + /* u16EdgeFreq; */ + 100, + /* u8OverShoot; */ + 65, + /* u8UnderShoot; */ + 70, + /* u8shootSupStr; */ + 10, + /* u8shootSupAdj; */ + 9, + /* u8DetailCtrl; */ + 128, + /* u8DetailCtrlThr; */ + 180, + /* u8EdgeFiltStr; */ + 62, + /*u8EdgeFiltMaxCap; */ + 18, + /* u8RGain; */ + 31, + /* u8GGain; */ + 32, + /* u8BGain; */ + 31, + /* u8SkinGain; */ + 31, + /* u8MaxSharpGain; */ + 70, + /* u8WeakDetailGain */ + 6 }, + /* Auto Para */ + { /* au16LumaWgt */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200,1638400,3276800 */ + { { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 } }, + /* au16TextureStr */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200,1638400,3276800 */ + { { 140, 140, 80, 30, 20, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 140, 140, 81, 31, 21, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 150, 150, 82, 32, 22, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 150, 150, 93, 33, 24, 18, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 160, 160, 95, 35, 26, 20, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 170, 170, 96, 36, 28, 22, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 190, 190, 97, 37, 30, 24, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 197, 197, 98, 38, 31, 25, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 205, 205, 100, 40, 33, 27, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 212, 212, 102, 42, 34, 29, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 220, 220, 104, 44, 36, 32, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 227, 227, 107, 47, 39, 34, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 235, 235, 110, 50, 42, 36, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 242, 242, 113, 53, 45, 37, 19, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 250, 250, 116, 56, 48, 38, 20, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 255, 255, 118, 58, 50, 40, 21, 4, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 260, 260, 122, 62, 54, 44, 22, 7, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 260, 260, 135, 71, 62, 51, 26, 10, 3, 3, 3, 3, 3, 3, 3, 3 }, + { 260, 260, 153, 77, 70, 57, 31, 13, 7, 7, 7, 7, 7, 7, 7, 7 }, + { 260, 260, 168, 81, 73, 62, 35, 17, 11, 11, 11, 11, 11, 11, 11, + 11 }, + { 260, 260, 182, 84, 79, 72, 38, 22, 14, 14, 14, 14, 14, 14, 14, + 14 }, + { 260, 260, 191, 87, 83, 80, 41, 26, 17, 17, 17, 17, 17, 17, 17, + 17 }, + { 260, 260, 196, 90, 88, 87, 45, 30, 20, 20, 20, 20, 20, 20, 20, + 20 }, + { 260, 260, 200, 90, 90, 90, 50, 30, 20, 20, 20, 20, 20, 20, 20, + 20 }, + { 260, 260, 200, 90, 90, 90, 50, 30, 20, 20, 20, 20, 20, 20, 20, + 20 }, + { 260, 260, 200, 89, 88, 87, 49, 29, 19, 19, 19, 19, 19, 19, 19, + 19 }, + { 260, 260, 200, 85, 83, 79, 45, 25, 15, 15, 15, 15, 15, 15, 15, + 15 }, + { 260, 260, 200, 77, 75, 71, 38, 18, 10, 10, 10, 10, 10, 10, 10, + 10 }, + { 260, 260, 200, 71, 64, 57, 30, 12, 6, 6, 6, 6, 6, 6, 6, 6 }, + { 260, 260, 200, 64, 52, 39, 22, 6, 2, 2, 2, 2, 2, 2, 2, 2 }, + { 260, 260, 200, 50, 38, 30, 15, 5, 2, 2, 2, 2, 2, 2, 2, 2 }, + { 260, 260, 200, 33, 28, 21, 10, 5, 2, 2, 2, 2, 2, 2, 2, 2 } }, + /* au16EdgeStr */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200,1638400,3276800 */ + { { 250, 300, 250, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 250, 300, 248, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 250, 300, 245, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 260, 300, 242, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 270, 300, 240, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 280, 300, 236, 150, 160, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 290, 300, 230, 148, 163, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 300, 300, 224, 144, 168, 180, 180, 180, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 310, 300, 218, 142, 170, 186, 186, 186, 106, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 210, 140, 172, 190, 190, 190, 110, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 206, 136, 176, 194, 194, 194, 124, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 150, 180, 200, 200, 200, 130, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 160, 184, 202, 202, 202, 132, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 170, 190, 206, 206, 206, 136, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 190, 198, 212, 212, 212, 142, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 200, 212, 220, 220, 220, 140, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 200, 215, 226, 226, 226, 146, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 200, 218, 230, 230, 230, 150, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 196, 220, 230, 230, 230, 150, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 180, 220, 230, 230, 230, 150, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 170, 220, 228, 228, 228, 138, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 165, 210, 220, 220, 220, 130, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 160, 202, 210, 210, 210, 120, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 150, 180, 190, 190, 190, 100, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 130, 145, 160, 160, 160, 90, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 105, 130, 145, 145, 145, 75, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 100, 120, 130, 130, 130, 60, 60, 50, 50, 50, 50, + 50, 50 }, + { 320, 300, 200, 90, 96, 100, 100, 100, 50, 50, 50, 50, 50, 50, 50, + 50 }, + { 320, 300, 200, 70, 76, 80, 80, 80, 40, 40, 40, 40, 40, 40, 40, + 40 }, + { 320, 300, 200, 56, 53, 50, 50, 50, 30, 30, 30, 30, 30, 30, 30, + 30 }, + { 320, 300, 200, 36, 32, 30, 30, 30, 25, 25, 25, 25, 25, 25, 25, + 25 }, + { 320, 300, 200, 30, 26, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20 } }, + /* au16TextureFreq */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { 256, 256, 256, 160, 160, 160, 200, 160, 150, 130, 128, 128, 128, + 128, 128, 128 }, + + /* au16EdgeFreq */ + { 100, 100, 148, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96 }, + + /* au8OverShoot */ + { 65, 65, 67, 70, 70, 70, 55, 55, 35, 30, 20, 10, 10, 10, 10, 10 }, + + /* au8UnderShoot */ + { 71, 75, 80, 80, 80, 80, 60, 60, 45, 40, 30, 20, 15, 15, 15, 15 }, + + /* au16shootSupStr */ + { 8, 8, 7, 7, 7, 6, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8ShootSupAdj */ + { 9, 9, 8, 8, 7, 7, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0 }, + + /* au8DetailCtrl */ + { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128 }, + + /* au8DetailCtrlThr */ + { 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, + 160, 160, 160 }, + + /* au8EdgeFiltStr */ + { 45, 45, 45, 50, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62 }, + /*au8EdgeFiltMaxCap*/ + { 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }, + /* au8RGain */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* au8GGain */ + { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 }, + + /* au8BGain */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* au8SkinGain */ + { 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 }, + + /* u8MaxSharpGain */ + { 70, 70, 72, 74, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80 }, + /* au8WeakDetailGain */ + /* ISO */ + /* 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200, 102400, 204800, 409600, 819200, 1638400, 3276800 */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, +}; + +static AWB_CCM_S g_stAwbCcm = { + 3, + { + { + 4900, + { 0x01C4, 0x80B8, 0x800C, 0x804D, 0x0164, 0x8017, + 0x8001, 0x80C5, 0x01C6 }, + }, + + { + 3850, + { 0x01C0, 0x80AB, 0x8015, 0x8041, 0x0164, 0x8023, + 0x8001, 0x80DA, 0x01DB }, + }, + + { + 2650, + { 0x0198, 0x807A, 0x801E, 0x8056, 0x017D, 0x8027, + 0x8001, 0x8158, 0x0258 }, + }, + { + 2100, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + { + 1600, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + { + 1400, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + { + 1000, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + }, +}; + +static AWB_CCM_S g_stAwbCcmFsWdr = { + 3, + { + { + 4900, + { 0x0112, 0x8001, 0x8011, 0x804C, 0x0166, 0x801A, + 0x8001, 0x8022, 0x0123 }, + }, + { + 3850, + { 0x0112, 0x8001, 0x8011, 0x805C, 0x0176, 0x801A, + 0x8001, 0x8032, 0x0133 }, + }, + { + 2650, + { 0x0112, 0x8001, 0x8011, 0x806C, 0x0186, 0x801A, + 0x8001, 0x8042, 0x0143 }, + }, + { + 2100, + { 0x0112, 0x8011, 0x8001, 0x806C, 0x0186, 0x801A, + 0x8001, 0x8042, 0x0143 }, + }, + { + 1600, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + { + 1400, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + { + 1000, + { 0x0100, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000, + 0x0000, 0x0000, 0x0100 }, + }, + }, +}; + +static AWB_AGC_TABLE_S g_stAwbAgcTable = { + /* bvalid */ + 1, + + /* saturation */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 0x80, 0x7a, 0x78, 0x74, 0x68, 0x60, 0x58, 0x50, 0x48, 0x40, 0x38, + 0x38, 0x38, 0x38, 0x38, 0x38 } +}; + +static AWB_AGC_TABLE_S g_stAwbAgcTableFSWDR = { + /* bvalid */ + 1, + + /* saturation */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 0x78, 0x78, 0x6e, 0x64, 0x5E, 0x58, 0x50, 0x48, 0x40, 0x38, 0x38, + 0x38, 0x38, 0x38, 0x38, 0x38 } +}; + +static const ISP_CMOS_WDR_S g_stIspWDR = { + /* bFusionMode */ + 0, + + /* bMotionComp */ + 1, + + /* u16ShortThr */ + 4032, + + /* u16LongThr */ + 3008, + + /* bForceLong */ + + 1, + + /* u16ForceLongLowThr */ + + 500, + + /* u16ForceLongHigThr */ + + 700, + + /* bShortExpoChk */ + 0, + + /* u16ShortCheckThd */ + + 0x8, + + /* au8MdThrLowGain[16] */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 16, 16, 16, 16, 16, 16, 16, 64, 128, 255, 255, 255, 255, 255, 255, + 255 }, + + /* au8MdThrHigGain[16] */ + { 24, 24, 24, 24, 24, 24, 24, 128, 128, 255, 255, 255, 255, 255, 255, + 255 }, + + /* au16FusionThr[2] */ + { 3855, 3000 }, + + /* u8MdtStillThd */ + 0x14, + + /* u8MdtLongBlend */ + 0x0 +}; + +static const ISP_CMOS_DEHAZE_S g_stIspDehaze = { + /* bEnable */ + 0, + /* bUserLutEnable */ + 0, + /* enOpType */ + 0, + /* u8AutoStrength */ + 128, + /* u8ManualStrength */ + 128 + +}; + +static const ISP_CMOS_DEHAZE_S g_stIspDehazeWDR = { + /* bEnable */ + 1, + /* bUserLutEnable */ + 1, + /* enOpType */ + 0, + /* u8AutoStrength */ + 100, + /* u8ManualStrength */ + 128 +}; + +static const ISP_CMOS_DRC_S g_stIspDRC = { + /* bEnable */ + 0, + /* enOpType */ + 0, + /* u16ManualStrength */ + 512, + /* u16AutoStrength */ + 512, + /* u8SpatialFltCoef */ + 1, + /* u8RangeFltCoef */ + 2, + /* u8ContrastControl */ + 8, + /* s8DetailAdjustFactor */ + 0, + /* u8RangeAdaMax */ + 8, + /* u8FltScaleFine */ + 6, + /* u8FltScaleCoarse */ + 6, + /* u8GradRevMax */ + 64, + /* u8GradRevThr */ + 50, + /* u8BrightGainLmt */ + 12, + /* u8BrightGainLmtStep */ + 8, + /* u8DarkGainLmtY */ + 0, + /* u8DarkGainLmtC */ + 0, + /* u8PDStrength */ + 35, + /* u8LocalMixingBrightMax */ + 64, + /* u8LocalMixingBrightMin */ + 32, + /* u8LocalMixingBrightThr */ + 96, + /* s8LocalMixingBrightSlo */ + -3, + /* u8LocalMixingDarkMax */ + 64, + /* u8LocalMixingDarkMin */ + 32, + /* u8LocalMixingDarkThr */ + 200, + /* s8LocalMixingDarkSlo */ + 5, + /* ColorCorrectionLut[33] */ + { 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024 }, + /* ToneMappingValue[200] */ + { 8, 8, 16, 24, 31, 39, 48, 56, 65, 75, + 85, 95, 106, 118, 130, 143, 156, 170, 185, 201, + 218, 235, 254, 274, 294, 316, 339, 364, 390, 417, + 446, 477, 509, 543, 579, 617, 658, 701, 746, 794, + 844, 898, 955, 1015, 1078, 1145, 1216, 1291, 1370, 1454, + 1543, 1637, 1736, 1841, 1952, 2069, 2194, 2325, 2465, 2612, + 2767, 2932, 3106, 3290, 3485, 3691, 3909, 4140, 4384, 4641, + 4914, 5202, 5507, 5830, 6171, 6531, 6913, 7316, 7742, 8193, + 8669, 9173, 9705, 10268, 10863, 11492, 12145, 12808, 13483, 14171, + 14872, 15587, 16319, 17069, 17840, 18635, 19458, 19881, 20313, 20754, + 21204, 21661, 22122, 22586, 23053, 23525, 24000, 24480, 24965, 25455, + 25950, 26451, 26959, 27473, 27995, 28524, 29062, 29609, 30165, 30732, + 31309, 31899, 32501, 33116, 33746, 34391, 35043, 35706, 36381, 37066, + 37763, 38472, 39192, 39925, 40671, 41429, 42201, 42591, 42986, 43383, + 43784, 44189, 44597, 45008, 45424, 45842, 46265, 46691, 47121, 47555, + 47993, 48434, 48880, 49329, 49783, 50241, 50703, 51169, 51639, 52113, + 52592, 53075, 53564, 54056, 54552, 55054, 55560, 56071, 56586, 56846, + 57107, 57369, 57632, 57896, 58162, 58429, 58697, 58967, 59238, 59510, + 59783, 60057, 60333, 60611, 60889, 61169, 61451, 61733, 62017, 62303, + 62589, 62877, 63167, 63458, 63750, 64044, 64340, 64636, 64934, 65234 }, + /* u8Asymmetry */ + 2, + /* u8SecondPole */ + 180, + /* u8Stretch */ + 54, + /* u8Compress */ + 180, + /* u8CurveSel */ + 0, + /* au16Xpoint */ + { 0, 200, 400, 600, 1000 }, + /* au16Ypoint */ + { 0, 200, 400, 600, 1000 }, + /* au16Slope */ + { 1000, 1000, 1000, 1000, 1000 } +}; + +static const ISP_CMOS_DRC_S g_stIspDRCWDR = { + /* bEnable */ + 1, + /* enOpType */ + 0, + /* u16ManualStrength */ + 1023, + /* u16AutoStrength */ + 512, + /* u8SpatialFltCoef */ + 1, + /* u8RangeFltCoef */ + 2, + /* u8ContrastControl */ + 9, + /* s8DetailAdjustFactor */ + 8, + /* u8RangeAdaMax */ + 4, + /* u8FltScaleFine */ + 3, + /* u8FltScaleCoarse */ + 3, + /* u8GradRevMax */ + 64, + /* u8GradRevThr */ + 40, + /* u8BrightGainLmt */ + 15, + /* u8BrightGainLmtStep */ + 10, + /* u8DarkGainLmtY */ + 0, + /* u8DarkGainLmtC */ + 0, + /* u8PDStrength */ + 35, + /* u8LocalMixingBrightMax */ + 32, + /* u8LocalMixingBrightMin */ + 32, + /* u8LocalMixingBrightThr */ + 96, + /* s8LocalMixingBrightSlo */ + -3, + /* u8LocalMixingDarkMax */ + 64, + /* u8LocalMixingDarkMin */ + 40, + /* u8LocalMixingDarkThr */ + 200, + /* s8LocalMixingDarkSlo */ + 5, + /* ColorCorrectionLut[33] */ + { 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, + 1024, 1024, 1024, 772, 768, 764, 760, 756, 752, 748, 744, + 740, 736, 732, 728, 724, 720, 716, 712, 708, 704, 700 }, + /* ToneMappingValue[200] */ + { 8, 8, 16, 24, 31, 39, 48, 56, 65, 75, + 85, 95, 106, 118, 130, 143, 156, 170, 185, 201, + 218, 235, 254, 274, 294, 316, 339, 364, 390, 417, + 446, 477, 509, 543, 579, 617, 658, 701, 746, 794, + 844, 898, 955, 1015, 1078, 1145, 1216, 1291, 1370, 1454, + 1543, 1637, 1736, 1841, 1952, 2069, 2194, 2325, 2465, 2612, + 2767, 2932, 3106, 3290, 3485, 3691, 3909, 4140, 4384, 4641, + 4914, 5202, 5507, 5830, 6171, 6531, 6913, 7316, 7742, 8193, + 8669, 9173, 9705, 10268, 10863, 11492, 12145, 12808, 13483, 14171, + 14872, 15587, 16319, 17069, 17840, 18635, 19458, 19881, 20313, 20754, + 21204, 21661, 22122, 22586, 23053, 23525, 24000, 24480, 24965, 25455, + 25950, 26451, 26959, 27473, 27995, 28524, 29062, 29609, 30165, 30732, + 31309, 31899, 32501, 33116, 33746, 34391, 35043, 35706, 36381, 37066, + 37763, 38472, 39192, 39925, 40671, 41429, 42201, 42591, 42986, 43383, + 43784, 44189, 44597, 45008, 45424, 45842, 46265, 46691, 47121, 47555, + 47993, 48434, 48880, 49329, 49783, 50241, 50703, 51169, 51639, 52113, + 52592, 53075, 53564, 54056, 54552, 55054, 55560, 56071, 56586, 56846, + 57107, 57369, 57632, 57896, 58162, 58429, 58697, 58967, 59238, 59510, + 59783, 60057, 60333, 60611, 60889, 61169, 61451, 61733, 62017, 62303, + 62589, 62877, 63167, 63458, 63750, 64044, 64340, 64636, 64934, 65234 }, + /* u8Asymmetry */ + 2, + /* u8SecondPole */ + 200, + /* u8Stretch */ + 45, + /* u8Compress */ + 150, + /* u8CurveSel */ + 0, + /* au16Xpoint */ + { 0, 200, 400, 600, 1000 }, + /* au16Ypoint */ + { 0, 200, 400, 600, 1000 }, + /* au16Slope */ + { 1000, 1000, 1000, 1000, 1000 } +}; + +static const ISP_CMOS_CA_S g_stIspCA = { + /* CA */ + 1, + /* Y */ + { 516, 525, 534, 544, 554, 563, 573, 583, 594, 604, 614, + 624, 634, 644, 654, 664, 674, 684, 694, 704, 713, 723, + 732, 741, 750, 758, 766, 775, 782, 790, 797, 804, 811, + 817, 823, 828, 834, 839, 844, 848, 853, 857, 861, 865, + 868, 872, 875, 878, 881, 884, 887, 890, 892, 895, 898, + 900, 903, 905, 908, 910, 913, 915, 918, 921, 924, 926, + 929, 932, 935, 937, 940, 943, 945, 948, 950, 952, 955, + 957, 959, 961, 964, 966, 968, 970, 972, 974, 976, 978, + 979, 981, 983, 985, 987, 988, 990, 992, 993, 994, 995, + 996, 997, 998, 998, 999, 1000, 1001, 1002, 1002, 1003, 1004, + 1005, 1006, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, + 1015, 1016, 1018, 1019, 1020, 1022, 1024 }, + /* ISO */ + /* 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 */ + { 1300, 1300, 1250, 1200, 1150, 1100, 1050, 1000, 950, 900, 900, 800, + 800, 800, 800, 800 } +}; + +static const ISP_CMOS_LSC_S g_stCmosLsc = { + /* MeshStrength */ + 256, + /* MeshScale */ + 4, + /* ISP_LSC_CABLI_TABLE_S */ + { + { + // Rgain: + { + 0x26b, 0x1de, 0x179, 0x12a, 0xee, 0xc4, 0xa2, + 0x94, 0x94, 0x97, 0xad, 0xc8, 0x10d, 0x133, + 0x184, 0x1fd, 0x284, 0x235, 0x1ba, 0x158, 0x10d, + 0xd3, 0xad, 0x8c, 0x7b, 0x74, 0x7b, 0x90, + 0xaf, 0xd8, 0x114, 0x164, 0x1d1, 0x253, 0x210, + 0x194, 0x136, 0xec, 0xbc, 0x91, 0x6f, 0x5d, + 0x59, 0x5f, 0x75, 0x94, 0xbf, 0xf7, 0x149, + 0x1ac, 0x229, 0x1e1, 0x177, 0x11a, 0xd7, 0xa6, + 0x7c, 0x5b, 0x44, 0x3e, 0x4a, 0x5c, 0x7d, + 0xab, 0xe2, 0x127, 0x18f, 0x200, 0x1c8, 0x15f, + 0x10d, 0xc9, 0x98, 0x69, 0x4a, 0x32, 0x2a, + 0x33, 0x4a, 0x6b, 0x9e, 0xd0, 0x113, 0x175, + 0x1e5, 0x1b6, 0x14f, 0xf9, 0xbf, 0x84, 0x57, + 0x34, 0x21, 0x18, 0x21, 0x3a, 0x5e, 0x8e, + 0xc2, 0x105, 0x162, 0x1d8, 0x1a9, 0x140, 0xef, + 0xb4, 0x7d, 0x50, 0x2d, 0x11, 0xa, 0x15, + 0x2f, 0x57, 0x83, 0xb9, 0xfb, 0x156, 0x1c3, + 0x1a5, 0x134, 0xe9, 0xae, 0x7a, 0x4b, 0x26, + 0x8, 0x4, 0xc, 0x28, 0x4f, 0x7f, 0xb8, + 0xf7, 0x151, 0x1bf, 0x19d, 0x134, 0xe8, 0xac, + 0x75, 0x48, 0x34, 0x4, 0x0, 0xa, 0x25, + 0x50, 0x7e, 0xb5, 0xf8, 0x150, 0x1bd, 0x199, + 0x134, 0xea, 0xae, 0x73, 0x4b, 0x32, 0x5, + 0x2, 0xd, 0x2a, 0x4e, 0x83, 0xbc, 0xf9, + 0x151, 0x1c0, 0x1a5, 0x139, 0xee, 0xb1, 0x7e, + 0x51, 0x2f, 0x14, 0xd, 0x16, 0x31, 0x56, + 0x86, 0xbb, 0x100, 0x158, 0x1c3, 0x1b2, 0x147, + 0xfe, 0xbd, 0x87, 0x5f, 0x3b, 0x24, 0x1b, + 0x24, 0x43, 0x64, 0x90, 0xc8, 0x107, 0x164, + 0x1d2, 0x1c1, 0x159, 0x107, 0xca, 0x94, 0x6e, + 0x4d, 0x36, 0x30, 0x36, 0x4e, 0x74, 0x9b, + 0xd1, 0x11a, 0x173, 0x1e2, 0x1de, 0x16f, 0x119, + 0xda, 0xa7, 0x7f, 0x64, 0x4e, 0x45, 0x4f, + 0x62, 0x86, 0xb1, 0xe6, 0x128, 0x188, 0x1fd, + 0x1f9, 0x18a, 0x131, 0xf2, 0xbf, 0x99, 0x79, + 0x65, 0x60, 0x6a, 0x7b, 0x9e, 0xc9, 0xfb, + 0x13d, 0x19f, 0x21e, 0x21c, 0x1a9, 0x14b, 0x109, + 0xd6, 0xb4, 0x96, 0x83, 0x7f, 0x83, 0x94, + 0xb7, 0xe0, 0x115, 0x15d, 0x1c1, 0x23f, 0x244, + 0x1c8, 0x167, 0x127, 0xf5, 0xcc, 0xb1, 0x9f, + 0x99, 0x98, 0xb3, 0xce, 0xf7, 0x12e, 0x17a, + 0x1e9, 0x262, + }, + + // Grgain: + { + 0x27c, 0x1fd, 0x18b, 0x138, 0xfb, 0xd2, 0xb1, + 0xa3, 0x9d, 0xa0, 0xb7, 0xd8, 0x11d, 0x141, + 0x1a4, 0x21c, 0x2ab, 0x24a, 0x1d0, 0x164, 0x113, + 0xde, 0xb4, 0x96, 0x83, 0x7e, 0x84, 0x9a, + 0xbb, 0xe8, 0x128, 0x17a, 0x1ec, 0x274, 0x21c, + 0x1a8, 0x140, 0xf8, 0xc5, 0x9b, 0x77, 0x64, + 0x5d, 0x67, 0x80, 0x9f, 0xca, 0x105, 0x15a, + 0x1c1, 0x24e, 0x1f6, 0x18b, 0x127, 0xe6, 0xaf, + 0x82, 0x62, 0x4b, 0x46, 0x4e, 0x64, 0x85, + 0xb6, 0xee, 0x13c, 0x1a6, 0x22d, 0x1de, 0x170, + 0x118, 0xd3, 0x9d, 0x6f, 0x4c, 0x35, 0x2a, + 0x37, 0x4f, 0x76, 0xa3, 0xdb, 0x123, 0x187, + 0x20b, 0x1ca, 0x15c, 0x107, 0xc6, 0x8e, 0x5d, + 0x3c, 0x21, 0x19, 0x27, 0x41, 0x68, 0x94, + 0xce, 0x116, 0x17a, 0x1fa, 0x1b4, 0x151, 0xfc, + 0xbd, 0x85, 0x54, 0x31, 0x12, 0x9, 0x16, + 0x34, 0x5c, 0x89, 0xc6, 0x10a, 0x16b, 0x1e5, + 0x1ae, 0x147, 0xf7, 0xb7, 0x80, 0x53, 0x29, + 0xa, 0x4, 0x12, 0x2c, 0x56, 0x86, 0xc1, + 0x103, 0x166, 0x1dc, 0x1ac, 0x144, 0xf5, 0xb5, + 0x7d, 0x4c, 0x37, 0x7, 0x1, 0xc, 0x2a, + 0x55, 0x83, 0xbe, 0x101, 0x166, 0x1d7, 0x1aa, + 0x145, 0xf9, 0xb6, 0x82, 0x52, 0x3a, 0xb, + 0x5, 0xd, 0x2d, 0x57, 0x88, 0xc0, 0x102, + 0x162, 0x1dc, 0x1b4, 0x14d, 0xfe, 0xbc, 0x87, + 0x5c, 0x36, 0x16, 0xf, 0x19, 0x36, 0x5f, + 0x8f, 0xca, 0x10d, 0x16b, 0x1e2, 0x1be, 0x15a, + 0x10b, 0xca, 0x90, 0x63, 0x3e, 0x26, 0x1f, + 0x2b, 0x44, 0x69, 0x9c, 0xd2, 0x119, 0x175, + 0x1f3, 0x1c9, 0x16a, 0x114, 0xd5, 0x9e, 0x77, + 0x54, 0x3a, 0x33, 0x3a, 0x54, 0x79, 0xa8, + 0xe1, 0x127, 0x184, 0x203, 0x1ed, 0x186, 0x12a, + 0xe7, 0xb1, 0x87, 0x6a, 0x55, 0x4c, 0x54, + 0x6d, 0x8f, 0xbb, 0xf4, 0x137, 0x1a0, 0x21a, + 0x20d, 0x1a0, 0x140, 0xfc, 0xc7, 0xa3, 0x81, + 0x6d, 0x66, 0x71, 0x85, 0xa5, 0xd3, 0x108, + 0x152, 0x1b9, 0x23c, 0x231, 0x1bf, 0x160, 0x119, + 0xe6, 0xbd, 0x9e, 0x8a, 0x84, 0x8c, 0xa2, + 0xc5, 0xf0, 0x123, 0x16d, 0x1da, 0x260, 0x25c, + 0x1e1, 0x17f, 0x136, 0xfd, 0xda, 0xbe, 0xaa, + 0x9f, 0xa9, 0xbb, 0xda, 0x104, 0x13e, 0x18e, + 0x1ff, 0x285, + }, + + // Gbgain: + { + 0x28b, 0x1fd, 0x18e, 0x139, 0xfd, 0xd7, 0xb6, + 0xa3, 0xa4, 0xa9, 0xbc, 0xde, 0x126, 0x14d, + 0x1a5, 0x21f, 0x2b1, 0x256, 0x1d6, 0x16a, 0x11d, + 0xe4, 0xb9, 0x9b, 0x87, 0x83, 0x8b, 0xa0, + 0xc1, 0xec, 0x12e, 0x183, 0x1f5, 0x284, 0x229, + 0x1ad, 0x142, 0xfb, 0xc9, 0x9f, 0x7c, 0x6a, + 0x62, 0x6c, 0x84, 0xa4, 0xd2, 0x10f, 0x15f, + 0x1ce, 0x252, 0x201, 0x18a, 0x129, 0xe8, 0xb1, + 0x86, 0x67, 0x4d, 0x4b, 0x51, 0x6a, 0x8b, + 0xbc, 0xf9, 0x140, 0x1ac, 0x229, 0x1ea, 0x176, + 0x116, 0xd2, 0x9e, 0x73, 0x4e, 0x38, 0x2f, + 0x3c, 0x54, 0x7a, 0xaa, 0xe0, 0x127, 0x18f, + 0x211, 0x1ce, 0x160, 0x107, 0xc8, 0x94, 0x5f, + 0x3d, 0x22, 0x1e, 0x28, 0x43, 0x6b, 0x9a, + 0xd1, 0x11c, 0x17d, 0x1fa, 0x1bf, 0x153, 0x101, + 0xbe, 0x86, 0x54, 0x2f, 0x14, 0xc, 0x1b, + 0x36, 0x60, 0x91, 0xc9, 0x110, 0x16f, 0x1eb, + 0x1bf, 0x14a, 0xfa, 0xb8, 0x81, 0x4f, 0x28, + 0xb, 0x3, 0x11, 0x2e, 0x56, 0x8a, 0xc6, + 0x10a, 0x16a, 0x1e2, 0x1b1, 0x149, 0xfa, 0xb8, + 0x7f, 0x50, 0x37, 0x8, 0x0, 0xf, 0x2e, + 0x57, 0x89, 0xc2, 0x107, 0x16a, 0x1df, 0x1b9, + 0x148, 0xf9, 0xba, 0x82, 0x54, 0x36, 0xd, + 0x5, 0x10, 0x2f, 0x5a, 0x8b, 0xc5, 0x10a, + 0x167, 0x1dd, 0x1c0, 0x150, 0x100, 0xbf, 0x86, + 0x5a, 0x34, 0x16, 0x10, 0x18, 0x39, 0x61, + 0x91, 0xcb, 0x115, 0x171, 0x1e9, 0x1d0, 0x15d, + 0x10b, 0xc9, 0x93, 0x66, 0x43, 0x26, 0x1f, + 0x29, 0x46, 0x6d, 0x9f, 0xd4, 0x11a, 0x17d, + 0x1f3, 0x1e1, 0x16e, 0x11a, 0xd6, 0x9d, 0x76, + 0x54, 0x3c, 0x35, 0x40, 0x59, 0x7b, 0xad, + 0xe4, 0x128, 0x187, 0x20a, 0x200, 0x184, 0x12c, + 0xe8, 0xb3, 0x87, 0x66, 0x51, 0x4d, 0x55, + 0x6d, 0x93, 0xbd, 0xf9, 0x13f, 0x1a2, 0x21d, + 0x214, 0x1a4, 0x145, 0xfd, 0xc7, 0x9f, 0x82, + 0x6d, 0x66, 0x6d, 0x86, 0xa8, 0xd7, 0x10c, + 0x155, 0x1bd, 0x246, 0x242, 0x1c2, 0x161, 0x119, + 0xe4, 0xb9, 0x9d, 0x8f, 0x83, 0x8d, 0xa3, + 0xc4, 0xf1, 0x12a, 0x174, 0x1e1, 0x26b, 0x261, + 0x1de, 0x17f, 0x131, 0xfd, 0xd8, 0xbc, 0xac, + 0x9d, 0xa9, 0xbe, 0xe0, 0x109, 0x142, 0x193, + 0x208, 0x28f, + }, + + // Bgain: + { + 0x28e, 0x202, 0x186, 0x12f, 0xfb, 0xcc, 0xb4, + 0xa4, 0xa4, 0xa9, 0xba, 0xe2, 0x120, 0x14b, + 0x1a5, 0x220, 0x2b6, 0x251, 0x1d8, 0x16e, 0x114, + 0xde, 0xb3, 0x92, 0x83, 0x81, 0x88, 0xa1, + 0xbe, 0xec, 0x128, 0x17d, 0x1f1, 0x274, 0x228, + 0x1ac, 0x144, 0xfc, 0xc2, 0x97, 0x7c, 0x67, + 0x61, 0x67, 0x7e, 0x9e, 0xcf, 0x107, 0x155, + 0x1c9, 0x252, 0x1fa, 0x183, 0x12a, 0xe4, 0xb0, + 0x83, 0x61, 0x4d, 0x48, 0x50, 0x67, 0x86, + 0xb4, 0xec, 0x133, 0x1a4, 0x22c, 0x1da, 0x16d, + 0x113, 0xcd, 0x9f, 0x70, 0x4e, 0x3a, 0x2f, + 0x3c, 0x51, 0x75, 0xa0, 0xdb, 0x11e, 0x185, + 0x201, 0x1c5, 0x15d, 0x101, 0xc5, 0x8b, 0x5b, + 0x41, 0x24, 0x1e, 0x27, 0x3d, 0x65, 0x93, + 0xce, 0x114, 0x179, 0x1fc, 0x1bc, 0x150, 0xfb, + 0xbe, 0x87, 0x57, 0x30, 0x17, 0xd, 0x18, + 0x37, 0x5f, 0x8b, 0xbf, 0x105, 0x16b, 0x1e9, + 0x1ac, 0x147, 0xf1, 0xb8, 0x80, 0x4f, 0x29, + 0xf, 0x5, 0x10, 0x32, 0x5c, 0x88, 0xc2, + 0x107, 0x160, 0x1d4, 0x1af, 0x143, 0xf7, 0xb4, + 0x7d, 0x4f, 0x3a, 0x7, 0x1, 0xc, 0x2f, + 0x57, 0x8b, 0xc0, 0x102, 0x15f, 0x1d8, 0x1a8, + 0x147, 0xf5, 0xb6, 0x80, 0x51, 0x37, 0xc, + 0x5, 0x10, 0x2f, 0x5a, 0x8b, 0xc8, 0x108, + 0x163, 0x1da, 0x1bc, 0x151, 0xfb, 0xba, 0x8a, + 0x59, 0x36, 0x15, 0xf, 0x1b, 0x38, 0x62, + 0x92, 0xc9, 0x10e, 0x171, 0x1ec, 0x1cd, 0x156, + 0x105, 0xc6, 0x8c, 0x66, 0x45, 0x27, 0x23, + 0x27, 0x47, 0x6f, 0x9a, 0xd8, 0x115, 0x17e, + 0x1ee, 0x1da, 0x16c, 0x110, 0xd2, 0x9e, 0x78, + 0x54, 0x3d, 0x38, 0x3e, 0x58, 0x78, 0xad, + 0xe3, 0x126, 0x186, 0x20d, 0x201, 0x18e, 0x12b, + 0xe2, 0xb1, 0x87, 0x67, 0x54, 0x51, 0x58, + 0x6c, 0x93, 0xb8, 0xf4, 0x13b, 0x1a3, 0x229, + 0x217, 0x1aa, 0x147, 0x100, 0xc8, 0xa0, 0x82, + 0x6c, 0x66, 0x6c, 0x86, 0xa9, 0xd0, 0x107, + 0x156, 0x1bb, 0x23b, 0x232, 0x1c2, 0x165, 0x117, + 0xe4, 0xbf, 0xa2, 0x8c, 0x85, 0x8a, 0x9f, + 0xc1, 0xeb, 0x126, 0x16b, 0x1dd, 0x26c, 0x262, + 0x1ea, 0x17c, 0x132, 0xf7, 0xd2, 0xc0, 0xa9, + 0x9f, 0xa5, 0xb9, 0xd3, 0x102, 0x137, 0x184, + 0x206, 0x289, + }, + }, + + { + // Rgain: + { + 0x399, 0x2df, 0x23e, 0x1cd, 0x170, 0x135, 0xfc, + 0xdb, 0xda, 0xe4, 0xfd, 0x12f, 0x16e, 0x1d4, + 0x24e, 0x2ee, 0x3e2, 0x372, 0x2b0, 0x20f, 0x19a, + 0x140, 0x109, 0xdc, 0xb7, 0xaf, 0xbe, 0xd5, + 0x105, 0x14c, 0x1a4, 0x225, 0x2b8, 0x384, 0x32a, + 0x276, 0x1e3, 0x174, 0x11c, 0xda, 0xaf, 0x92, + 0x88, 0x97, 0xac, 0xec, 0x125, 0x180, 0x200, + 0x289, 0x34f, 0x2f6, 0x24f, 0x1bd, 0x14b, 0xfd, + 0xba, 0x89, 0x6c, 0x61, 0x71, 0x89, 0xc6, + 0x107, 0x15a, 0x1c7, 0x262, 0x319, 0x2c9, 0x229, + 0x1a5, 0x135, 0xdb, 0x9b, 0x6a, 0x4a, 0x3f, + 0x4e, 0x6c, 0xa5, 0xeb, 0x13e, 0x1b1, 0x23d, + 0x2e3, 0x2b9, 0x211, 0x187, 0x11b, 0xc9, 0x81, + 0x4d, 0x2b, 0x21, 0x2f, 0x58, 0x8f, 0xda, + 0x12a, 0x196, 0x229, 0x2c8, 0x29c, 0x1fb, 0x16e, + 0x10d, 0xb5, 0x6e, 0x37, 0x11, 0x7, 0x1a, + 0x46, 0x7b, 0xc3, 0x118, 0x187, 0x210, 0x2b7, + 0x2bc, 0x1f5, 0x16b, 0x106, 0xb1, 0x61, 0x2e, + 0x4, 0x0, 0xe, 0x3a, 0x71, 0xba, 0x113, + 0x17f, 0x206, 0x2a4, 0x33a, 0x1f3, 0x165, 0xfd, + 0xab, 0x62, 0x2d, 0x2, 0x3, 0x8, 0x35, + 0x6e, 0xb6, 0x10f, 0x179, 0x202, 0x29f, 0x2f0, + 0x1e6, 0x165, 0x103, 0xac, 0x63, 0x30, 0x7, + 0x1, 0xb, 0x36, 0x70, 0xb8, 0x112, 0x176, + 0x208, 0x2a4, 0x2d2, 0x1f4, 0x171, 0x106, 0xb6, + 0x70, 0x38, 0x15, 0xa, 0x18, 0x40, 0x78, + 0xbf, 0x11c, 0x181, 0x20c, 0x2ac, 0x2d0, 0x202, + 0x17e, 0x118, 0xc0, 0x7c, 0x4a, 0x2e, 0x1d, + 0x2e, 0x4f, 0x87, 0xcd, 0x122, 0x190, 0x21a, + 0x2bb, 0x2be, 0x216, 0x194, 0x12d, 0xd9, 0x99, + 0x64, 0x49, 0x3d, 0x48, 0x68, 0x9d, 0xdd, + 0x13f, 0x1a3, 0x229, 0x2cf, 0x2e4, 0x236, 0x1bb, + 0x144, 0xf0, 0xb5, 0x81, 0x63, 0x62, 0x66, + 0x86, 0xb7, 0xfb, 0x14e, 0x1be, 0x249, 0x2ed, + 0x30c, 0x26c, 0x1ce, 0x164, 0x110, 0xd4, 0xa4, + 0x86, 0x7f, 0x86, 0xa6, 0xd7, 0x115, 0x171, + 0x1da, 0x270, 0x31c, 0x339, 0x28d, 0x1fb, 0x18d, + 0x133, 0xf6, 0xc5, 0xaa, 0xa1, 0xae, 0xca, + 0xf8, 0x138, 0x195, 0x210, 0x2a1, 0x355, 0x37f, + 0x2be, 0x229, 0x1b1, 0x159, 0x118, 0xeb, 0xd3, + 0xc6, 0xd4, 0xed, 0x11f, 0x15d, 0x1cd, 0x23d, + 0x2cc, 0x388, + }, + + // Grgain: + { + 0x324, 0x279, 0x1f5, 0x191, 0x148, 0x113, 0xe4, + 0xcd, 0xc9, 0xd4, 0xf2, 0x11f, 0x164, 0x1b6, + 0x22c, 0x2ba, 0x392, 0x2f1, 0x250, 0x1cb, 0x16c, + 0x11f, 0xe9, 0xc2, 0xa8, 0xa5, 0xb1, 0xcf, + 0xfa, 0x13d, 0x193, 0x208, 0x28d, 0x349, 0x2b8, + 0x225, 0x1a9, 0x148, 0xfa, 0xc5, 0x9c, 0x80, + 0x7e, 0x8e, 0xa5, 0xe3, 0x11b, 0x16e, 0x1e6, + 0x266, 0x316, 0x28b, 0x201, 0x18e, 0x12a, 0xe4, + 0xa5, 0x79, 0x60, 0x59, 0x6a, 0x85, 0xbf, + 0xfe, 0x151, 0x1b7, 0x243, 0x2e3, 0x26b, 0x1e5, + 0x174, 0x111, 0xc4, 0x88, 0x5d, 0x40, 0x39, + 0x4a, 0x69, 0xa2, 0xea, 0x137, 0x19e, 0x223, + 0x2b8, 0x253, 0x1cd, 0x159, 0xfc, 0xb2, 0x73, + 0x43, 0x26, 0x1e, 0x30, 0x57, 0x90, 0xd8, + 0x124, 0x188, 0x211, 0x2a4, 0x247, 0x1bd, 0x14c, + 0xf2, 0xa4, 0x65, 0x31, 0x10, 0x6, 0x1a, + 0x49, 0x7c, 0xc3, 0x116, 0x17a, 0x201, 0x292, + 0x263, 0x1b6, 0x141, 0xec, 0xa1, 0x5a, 0x26, + 0x3, 0x1, 0xf, 0x3f, 0x74, 0xb9, 0x111, + 0x172, 0x1f3, 0x285, 0x2dc, 0x1b4, 0x13e, 0xe6, + 0x98, 0x56, 0x25, 0x1, 0x5, 0xb, 0x38, + 0x71, 0xb8, 0x10e, 0x16f, 0x1ed, 0x281, 0x291, + 0x1af, 0x142, 0xe5, 0x9d, 0x5a, 0x2b, 0x7, + 0x2, 0xe, 0x3c, 0x74, 0xbb, 0x10f, 0x170, + 0x1f0, 0x27f, 0x28d, 0x1b7, 0x14b, 0xee, 0xa5, + 0x64, 0x35, 0x13, 0xa, 0x1c, 0x42, 0x7d, + 0xbe, 0x116, 0x17b, 0x1f8, 0x28c, 0x27e, 0x1c3, + 0x156, 0xfc, 0xb1, 0x76, 0x46, 0x2e, 0x1f, + 0x2f, 0x55, 0x8c, 0xd1, 0x127, 0x185, 0x207, + 0x2a5, 0x265, 0x1d8, 0x169, 0x111, 0xc5, 0x8a, + 0x5c, 0x49, 0x3f, 0x4c, 0x6e, 0xa0, 0xe2, + 0x13b, 0x199, 0x215, 0x2ac, 0x282, 0x1f2, 0x188, + 0x125, 0xde, 0xa5, 0x79, 0x5e, 0x63, 0x67, + 0x89, 0xb8, 0xf8, 0x14c, 0x1ae, 0x231, 0x2cb, + 0x2a6, 0x221, 0x19c, 0x141, 0xfb, 0xc2, 0x9a, + 0x82, 0x7d, 0x88, 0xa6, 0xd6, 0x114, 0x168, + 0x1cd, 0x257, 0x2f4, 0x2cd, 0x240, 0x1c2, 0x166, + 0x11e, 0xe7, 0xbc, 0xa8, 0xa0, 0xac, 0xca, + 0xf7, 0x138, 0x18a, 0x1f8, 0x27d, 0x31d, 0x317, + 0x268, 0x1ef, 0x189, 0x13b, 0x106, 0xde, 0xc9, + 0xc3, 0xd3, 0xed, 0x119, 0x15a, 0x1c1, 0x221, + 0x2a9, 0x357, + }, + + // Gbgain: + { + 0x32b, 0x277, 0x1f2, 0x18f, 0x148, 0x116, 0xe3, + 0xc9, 0xc9, 0xd5, 0xf1, 0x11c, 0x15a, 0x1b4, + 0x22d, 0x2bd, 0x38d, 0x2f4, 0x24d, 0x1ca, 0x16d, + 0x11b, 0xea, 0xc4, 0xa8, 0xa3, 0xb3, 0xc9, + 0xfb, 0x13d, 0x190, 0x204, 0x28e, 0x348, 0x2b8, + 0x221, 0x1a8, 0x149, 0xfe, 0xc5, 0x9b, 0x80, + 0x7a, 0x8e, 0xa6, 0xe2, 0x119, 0x16f, 0x1e4, + 0x269, 0x315, 0x28e, 0x201, 0x18a, 0x12d, 0xe3, + 0xa2, 0x78, 0x60, 0x58, 0x6c, 0x86, 0xc0, + 0xfc, 0x14e, 0x1b9, 0x242, 0x2e7, 0x270, 0x1e1, + 0x178, 0x115, 0xc5, 0x8a, 0x5e, 0x41, 0x3a, + 0x4b, 0x6a, 0xa2, 0xe7, 0x136, 0x19e, 0x225, + 0x2bd, 0x258, 0x1ce, 0x15c, 0xff, 0xb1, 0x75, + 0x44, 0x26, 0x1e, 0x30, 0x57, 0x8d, 0xd7, + 0x125, 0x18c, 0x212, 0x2a7, 0x241, 0x1bd, 0x14f, + 0xf2, 0xa5, 0x65, 0x30, 0x11, 0x7, 0x1b, + 0x48, 0x7d, 0xc3, 0x118, 0x17b, 0x1ff, 0x297, + 0x26b, 0x1ba, 0x147, 0xef, 0xa1, 0x5b, 0x28, + 0x4, 0x1, 0x10, 0x3e, 0x75, 0xba, 0x112, + 0x171, 0x1f4, 0x28b, 0x2de, 0x1b6, 0x140, 0xe5, + 0x98, 0x5a, 0x27, 0x1, 0x5, 0xb, 0x37, + 0x71, 0xb8, 0x10f, 0x171, 0x1f2, 0x27f, 0x293, + 0x1b0, 0x144, 0xe6, 0x9c, 0x5a, 0x2c, 0x7, + 0x4, 0xe, 0x39, 0x74, 0xbc, 0x10f, 0x16e, + 0x1f4, 0x282, 0x285, 0x1ba, 0x14b, 0xef, 0xa5, + 0x66, 0x36, 0x15, 0xb, 0x1d, 0x46, 0x7c, + 0xc1, 0x117, 0x17c, 0x1f8, 0x293, 0x27c, 0x1c5, + 0x159, 0xfd, 0xb1, 0x79, 0x47, 0x2e, 0x1f, + 0x33, 0x56, 0x8e, 0xce, 0x129, 0x187, 0x206, + 0x295, 0x266, 0x1db, 0x16d, 0x111, 0xc6, 0x8d, + 0x5f, 0x49, 0x3f, 0x4a, 0x6f, 0xa3, 0xe1, + 0x13a, 0x19c, 0x219, 0x2ac, 0x280, 0x1f4, 0x18a, + 0x126, 0xde, 0xa5, 0x7e, 0x61, 0x61, 0x67, + 0x87, 0xbd, 0xf6, 0x14e, 0x1ae, 0x232, 0x2cb, + 0x2ae, 0x21f, 0x1a0, 0x141, 0xf8, 0xc4, 0x99, + 0x84, 0x7f, 0x89, 0xa6, 0xd4, 0x115, 0x169, + 0x1d1, 0x255, 0x2f2, 0x2d4, 0x243, 0x1c6, 0x165, + 0x11a, 0xe6, 0xc0, 0xa8, 0xa0, 0xaa, 0xca, + 0xfc, 0x137, 0x18a, 0x1f9, 0x282, 0x324, 0x310, + 0x26a, 0x1f0, 0x18a, 0x13d, 0x108, 0xde, 0xca, + 0xc3, 0xcf, 0xf0, 0x11d, 0x15b, 0x1c1, 0x227, + 0x2aa, 0x360, + }, + + // Bgain: + { + 0x2f0, 0x24a, 0x1d2, 0x175, 0x137, 0x105, 0xd7, + 0xbd, 0xc0, 0xca, 0xec, 0x10f, 0x14b, 0x1a7, + 0x21b, 0x29c, 0x35e, 0x2b8, 0x228, 0x1ad, 0x155, + 0x114, 0xe1, 0xbe, 0xa0, 0x9d, 0xad, 0xc1, + 0xf3, 0x138, 0x183, 0x1f5, 0x278, 0x325, 0x28f, + 0x1fe, 0x18b, 0x138, 0xf1, 0xbc, 0x96, 0x7e, + 0x78, 0x8a, 0xa2, 0xda, 0x114, 0x162, 0x1d6, + 0x253, 0x2f5, 0x25e, 0x1df, 0x171, 0x11b, 0xd7, + 0x9f, 0x76, 0x5d, 0x5b, 0x69, 0x84, 0xbd, + 0xf9, 0x14a, 0x1ae, 0x232, 0x2c8, 0x249, 0x1c4, + 0x15d, 0x105, 0xba, 0x83, 0x5a, 0x3c, 0x37, + 0x4c, 0x67, 0x9f, 0xe7, 0x12f, 0x195, 0x214, + 0x2a1, 0x234, 0x1af, 0x141, 0xf0, 0xa8, 0x71, + 0x3e, 0x23, 0x1d, 0x30, 0x58, 0x91, 0xd3, + 0x122, 0x180, 0x202, 0x287, 0x21e, 0x19d, 0x138, + 0xe3, 0x9d, 0x61, 0x2e, 0xf, 0x6, 0x1a, + 0x47, 0x7c, 0xbf, 0x119, 0x171, 0x1f5, 0x279, + 0x244, 0x19f, 0x133, 0xdd, 0x97, 0x56, 0x28, + 0x4, 0x1, 0x11, 0x3d, 0x77, 0xbc, 0x10f, + 0x16f, 0x1e9, 0x276, 0x2a9, 0x19e, 0x12e, 0xda, + 0x92, 0x54, 0x24, 0x4, 0x7, 0xd, 0x3c, + 0x75, 0xb4, 0x10b, 0x168, 0x1e9, 0x271, 0x267, + 0x192, 0x128, 0xd9, 0x96, 0x56, 0x2a, 0x6, + 0x7, 0x10, 0x3d, 0x74, 0xb6, 0x10c, 0x168, + 0x1e4, 0x271, 0x263, 0x19a, 0x134, 0xdd, 0x9d, + 0x65, 0x37, 0x16, 0xe, 0x1f, 0x46, 0x79, + 0xbd, 0x112, 0x170, 0x1ef, 0x286, 0x254, 0x1a5, + 0x143, 0xf0, 0xa7, 0x70, 0x46, 0x2e, 0x21, + 0x33, 0x55, 0x90, 0xcb, 0x11d, 0x17d, 0x1f9, + 0x287, 0x236, 0x1bd, 0x153, 0x100, 0xba, 0x84, + 0x57, 0x45, 0x42, 0x50, 0x6d, 0xa2, 0xde, + 0x137, 0x194, 0x20a, 0x297, 0x25b, 0x1db, 0x175, + 0x115, 0xd2, 0x9b, 0x76, 0x5b, 0x5f, 0x69, + 0x8a, 0xba, 0xf4, 0x149, 0x1a4, 0x226, 0x2bb, + 0x27d, 0x1fb, 0x186, 0x132, 0xef, 0xbc, 0x97, + 0x81, 0x7d, 0x86, 0xa4, 0xd5, 0x112, 0x15e, + 0x1bc, 0x242, 0x2da, 0x2a9, 0x21f, 0x1aa, 0x151, + 0x10e, 0xdc, 0xb7, 0xa3, 0x99, 0xaa, 0xc6, + 0xee, 0x130, 0x183, 0x1f3, 0x264, 0x304, 0x2d0, + 0x245, 0x1da, 0x175, 0x12c, 0xf9, 0xdb, 0xc3, + 0xbb, 0xc8, 0xe7, 0x114, 0x14d, 0x1b2, 0x218, + 0x29b, 0x338, + }, + }, + }, + +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* End of #ifdef __cplusplus */ + +#endif /* __IMX335_CMOS_EX_H_ */ diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_fpv.ini b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_fpv.ini new file mode 100644 index 0000000..ea3072e --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_fpv.ini @@ -0,0 +1,52 @@ +[sensor] +Sensor_type=stSnsImx335Obj +Mode=WDR_MODE_NONE +DllFile=libsns_imx335_fpv.so + +[mode] +input_mode=INPUT_MODE_MIPI +raw_bitness=10 + +[mipi] +lane_id = 0|1|2|3|-1|-1|-1|-1| ;lane_id: -1 - disable + +[isp_image] +Isp_FrameRate=30 +Isp_Bayer=BAYER_RGGB + +[vi_dev] +Input_mod=VI_MODE_MIPI + +# +# uncomment either DevRect pair to select sensor mode +# + +#2592x1520 50fps , slightly cropped vertically to 16:9 +#DevRect_w = 2592 +#DevRect_h = 1520 +#Isp_FrameRate=52 #max supported on hi3516ev300 when majestic is set to 1920x1080 52fps + +#stock fullscale mode boosted to 40fps +#DevRect_w = 2592 +#DevRect_h = 1944 + +#1080p cropped, +#DevRect_w = 1920 +#DevRect_h = 1080 +#Isp_FrameRate=90 #can work at 90fps only when majestic is set to 1280x720 90fps !!! +#Max Isp_FrameRate=55 for 1920x1080 + +#binning max 65fps, in majestic.yaml set 1296x972 or 1280x720 +#DevRect_w = 1296 +#DevRect_h = 972 +#Isp_FrameRate=68 # max supported value on hi356ev300 at 1280x720 + +#Current, set by channels.sh +DevRect_w=2592 +DevRect_h=1944 + + +DevRect_x=200 +DevRect_y=20 + +FullLinesStd=1375 diff --git a/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_sensor_ctl.c b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_sensor_ctl.c new file mode 100644 index 0000000..539cee2 --- /dev/null +++ b/libraries/sensor/hi3516ev200/sony_imx335_fpv/imx335_sensor_ctl.c @@ -0,0 +1,1798 @@ +/* + * Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021. All rights reserved. + */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "comm_video.h" +#include "sns_ctrl.h" + +#ifdef GPIO_I2C +#include "gpioi2c_ex.h" +#else +#include "i2c.h" +#endif + +const unsigned char imx335_i2c_addr = 0x34; /* I2C Address of imx335 */ +const unsigned int imx335_addr_byte = 2; +const unsigned int imx335_data_byte = 1; +static int g_fd[ISP_MAX_PIPE_NUM] = { [0 ...(ISP_MAX_PIPE_NUM - 1)] = -1 }; + +extern WDR_MODE_E genSensorMode; +extern GK_U8 gu8SensorImageMode; +extern GK_BOOL bSensorInit; + +extern ISP_SNS_STATE_S *g_pastImx335[ISP_MAX_PIPE_NUM]; +extern ISP_SNS_COMMBUS_U g_aunImx335BusInfo[]; + +#define IMX335_5M_30FPS_12BIT_LINEAR_MODE (0) //2592x1944 +#define IMX335_5M_30FPS_10BIT_WDR_MODE (1) //2592x1944 +//#define IMX335_4M_25FPS_10BIT_WDR_MODE (2) //2592x1520 +#define IMX335_1520P_10BIT_MODE (2) //2592x1520 +#define IMX335_4M_30FPS_10BIT_WDR_MODE (3) //2592x1520 +#define IMX335_60FPS_BINNING_MODE (4) //1296x972 +#define IMX335_60FPS_CROPPED_1080P_MODE (5) //1920x1080 +#define IMX335_60FPS_FULL_1944P_MODE (6) //2592x1944 + + +int IMX335_i2c_init(VI_PIPE ViPipe) +{ + char acDevFile[16] = { 0 }; + GK_U8 u8DevNum; + + if (g_fd[ViPipe] >= 0) { + return GK_SUCCESS; + } +#ifdef GPIO_I2C + int ret; + + g_fd[ViPipe] = open("/dev/gpioi2c_ex", O_RDONLY, S_IRUSR); + if (g_fd[ViPipe] < 0) { + ISP_TRACE(MODULE_DBG_ERR, "Open gpioi2c_ex error!\n"); + return GK_FAILURE; + } +#else + int ret; + + u8DevNum = g_aunImx335BusInfo[ViPipe].s8I2cDev; + snprintf(acDevFile, sizeof(acDevFile), "/dev/i2c-%u", u8DevNum); + + g_fd[ViPipe] = open(acDevFile, O_RDWR, S_IRUSR | S_IWUSR); + + if (g_fd[ViPipe] < 0) { + ISP_TRACE(MODULE_DBG_ERR, "Open /dev/i2c_drv-%u error!\n", + u8DevNum); + return GK_FAILURE; + } + + ret = ioctl(g_fd[ViPipe], I2C_SLAVE_FORCE, (imx335_i2c_addr >> 1)); + if (ret < 0) { + ISP_TRACE(MODULE_DBG_ERR, "I2C_SLAVE_FORCE error!\n"); + close(g_fd[ViPipe]); + g_fd[ViPipe] = -1; + return ret; + } +#endif + + return GK_SUCCESS; +} + +int IMX335_i2c_exit(VI_PIPE ViPipe) +{ + if (g_fd[ViPipe] >= 0) { + close(g_fd[ViPipe]); + g_fd[ViPipe] = -1; + return GK_SUCCESS; + } + return GK_FAILURE; +} + +int IMX335_read_register(VI_PIPE ViPipe, int addr) +{ + return GK_SUCCESS; +} +int IMX335_write_register(VI_PIPE ViPipe, GK_U32 addr, GK_U32 data) +{ + if (g_fd[ViPipe] < 0) { + return GK_SUCCESS; + } + +#ifdef GPIO_I2C + i2c_data.dev_addr = imx335_i2c_addr; + i2c_data.reg_addr = addr; + i2c_data.addr_byte_num = imx335_addr_byte; + i2c_data.data = data; + i2c_data.data_byte_num = imx335_data_byte; + + ret = ioctl(g_fd[ViPipe], GPIO_I2C_WRITE, &i2c_data); + + if (ret) { + ISP_TRACE(MODULE_DBG_ERR, "GPIO-I2C write faild!\n"); + return ret; + } +#else + int idx = 0; + int ret; + char buf[8]; + + if (imx335_addr_byte == 2) { + buf[idx] = (addr >> 8) & 0xff; + idx++; + buf[idx] = addr & 0xff; + idx++; + } else { + } + + if (imx335_data_byte == 2) { + } else { + buf[idx] = data & 0xff; + idx++; + } + + ret = write(g_fd[ViPipe], buf, imx335_addr_byte + imx335_data_byte); + if (ret < 0) { + ISP_TRACE(MODULE_DBG_ERR, "I2C_WRITE error!\n"); + return GK_FAILURE; + } + +#endif + return GK_SUCCESS; +} + +void IMX335_standby(VI_PIPE ViPipe) +{ + return; +} + +void IMX335_restart(VI_PIPE ViPipe) +{ + return; +} + +static void delay_ms(int ms) +{ + usleep(ms * 1000); +} + +void IMX335_linear_5M30_12bit_init(VI_PIPE ViPipe); +void IMX335_linear_5M30_12bit_40fps_init(VI_PIPE ViPipe); +void IMX335_wdr_5M30_10bit_init(VI_PIPE ViPipe); +void IMX335_wdr_4M25_10bit_init(VI_PIPE ViPipe); +void IMX335_wdr_4M30_10bit_init(VI_PIPE ViPipe); +void IMX335_binning_60pfs_init(VI_PIPE ViPipe); + +void imx335_default_reg_init(VI_PIPE ViPipe) +{ + GK_U32 i; + for (i = 0; i < g_pastImx335[ViPipe]->astRegsInfo[0].u32RegNum; i++) { + IMX335_write_register(ViPipe, + g_pastImx335[ViPipe] + ->astRegsInfo[0] + .astI2cData[i] + .u32RegAddr, + g_pastImx335[ViPipe] + ->astRegsInfo[0] + .astI2cData[i] + .u32Data); + } +} + +void IMX335_init(VI_PIPE ViPipe) +{ + WDR_MODE_E enWDRMode; + GK_BOOL bInit; + GK_U8 u8ImgMode; + + bInit = g_pastImx335[ViPipe]->bInit; + enWDRMode = g_pastImx335[ViPipe]->enWDRMode; + u8ImgMode = g_pastImx335[ViPipe]->u8ImgMode; + + if (bInit == GK_FALSE) { + /* sensor i2c init */ + printf("binit false IMX335 i2c init\n"); + IMX335_i2c_init(ViPipe); + } + + /* When sensor first init, config all registers */ + + if (WDR_MODE_2To1_LINE == enWDRMode) { + if (u8ImgMode == IMX335_5M_30FPS_10BIT_WDR_MODE) { + IMX335_wdr_5M30_10bit_init(ViPipe); + //} else if (u8ImgMode == IMX335_4M_25FPS_10BIT_WDR_MODE) { + // IMX335_wdr_4M25_10bit_init(ViPipe); + } else if (u8ImgMode == IMX335_4M_30FPS_10BIT_WDR_MODE) { + IMX335_wdr_4M30_10bit_init(ViPipe); + } + + else { + printf("IMX335_init Not support this mode\n"); + return; + } + } else if (enWDRMode == WDR_MODE_NONE) { + switch (u8ImgMode) { + // - 2x2 binning @ 60fps + case IMX335_60FPS_BINNING_MODE: { + IMX335_binning_60pfs_init(ViPipe); + }; break; + case IMX335_60FPS_CROPPED_1080P_MODE: { + IMX335_cropped_60fps_1080p_init(ViPipe); + }; break; + case IMX335_1520P_10BIT_MODE: { + IMX335_cropped_41fps_2592_1520_init(ViPipe); + }; break; + case IMX335_60FPS_FULL_1944P_MODE: { + IMX335_linear_5M30_12bit_40fps_init(ViPipe); + }; break; + case IMX335_5M_30FPS_12BIT_LINEAR_MODE: { + IMX335_linear_5M30_12bit_init(ViPipe); + }; break; + default:{ + IMX335_linear_5M30_12bit_init(ViPipe); + printf("IMX335_init unknown mode\n"); + break; + } + } + } else { + printf("IMX335_init Not support this mode\n"); + return; + } + + imx335_default_reg_init(ViPipe); + g_pastImx335[ViPipe]->bInit = GK_TRUE; + + return; +} + +void IMX335_exit(VI_PIPE ViPipe) +{ + IMX335_i2c_exit(ViPipe); + + return; +} + +//classic stock mode tweaked to 40fps +void IMX335_linear_5M30_12bit_40fps_init(VI_PIPE ViPipe) +{ + + //return IMX335_cropped_41fps_2592_1520_init(ViPipe); + //return IMX335_wdr_4M30_10bit_init(ViPipe); + //Restart the sensor and take default registry values + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + IMX335_write_register(ViPipe, 0x3000, 0x01);//pause + IMX335_write_register(ViPipe, 0x3002, 0x01);//continue + IMX335_write_register(ViPipe, 0x3004, 0x04);//restart + IMX335_write_register(ViPipe, 0x3004, 0x00); + delay_ms(18);//Not needed maybe + + IMX335_write_register(ViPipe, 0x3000, 0x01); // standby + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + + IMX335_write_register(ViPipe, 0x3034, 0xA0); //HMAX default 0226h/0294h is for 25fps, 14A works 38fos + IMX335_write_register(ViPipe, 0x3035, 0x01);// 200 works at 32fps , 1B0 at 38fps, 190 at 41fps with problems!, + + + if (1==1){ + + IMX335_write_register(ViPipe, 0x3018, 0x00);//window mode, 0-default | 3-binning | 4- cropping + + IMX335_write_register(ViPipe, 0x302C, 0x30);// HTRIMMING Horiz Start in cropping START + IMX335_write_register(ViPipe, 0x302D, 0x00); + + IMX335_write_register(ViPipe, 0x302E, 0x38);//HNUM Horiz size 0A20 - 2592 cropping size designation + IMX335_write_register(ViPipe, 0x302F, 0x0A);//0798 for 1920 + + IMX335_write_register(ViPipe, 0x3030, 0x94);// VMAX default 1194h , + IMX335_write_register(ViPipe, 0x3031, 0x11);// + IMX335_write_register(ViPipe, 0x3032, 0x00); + + //IMX335_write_register(ViPipe, 0x3034, 0x26);//HMAX default 0226h/0294h is for 25fps, 14A works 38fos + //IMX335_write_register(ViPipe, 0x3035, 0x02);// 12C for 41fps + + //This increases the FPS !!! + IMX335_write_register(ViPipe, 0x3034, 0xA0); //HMAX default 0226h/0294h is for 25fps, 14A works 38fos + IMX335_write_register(ViPipe, 0x3035, 0x01);// 200 works at 32fps , 1B0 at 38fps, 190 at 41fps with problems!, + + + + IMX335_write_register(ViPipe, 0x3056, 0xAC); //Y_OUT_SIZE effective pixel lines 07ACh + IMX335_write_register(ViPipe, 0x3057, 0x07); //5B4h = 1440 + + IMX335_write_register(ViPipe, 0x3072, 0x28);// Vert Crop start 0x28 + IMX335_write_register(ViPipe, 0x3073, 0x00); + + + IMX335_write_register(ViPipe, 0x3076, 0x58);//// AREA3_WIDTH_1 Vert Cropping Size designation * 2 , = Y_OUT_SIZE*2 + IMX335_write_register(ViPipe, 0x3077, 0x0F); + } + + + + IMX335_write_register(ViPipe, 0x3050, 0x00); + + if (1==1){//return to defaults not working?! + IMX335_write_register(ViPipe, 0x3074, 0xB0);// AREA3_ST_Addr Upper left cropping postion + IMX335_write_register(ViPipe, 0x3075, 0x00); + IMX335_write_register(ViPipe, 0x30C6, 0x00);//Black Offset Addr 12h + IMX335_write_register(ViPipe, 0x30CE, 0x00);//UNRD_Line_Max in cropping + IMX335_write_register(ViPipe, 0x30D8, 0x4C);//UNREAD_ED_ADR in cropping + IMX335_write_register(ViPipe, 0x30D9, 0x10); + } + + IMX335_write_register(ViPipe, 0x314C, 0xC0); + + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x02); //// SYS_MODE = 891Mbps + IMX335_write_register(ViPipe, 0x31A1, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + + + + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + + IMX335_write_register(ViPipe, 0x3740, 0x02); + + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("----->> Sony IMX335_init_5M_2592x1944_12bit_linear 40fps Initial OK! <<-----\n"); +} + + +//No chance 2592_1944_60fps meant to TEST configs +void IMX335__2592_1944_60fps10bit_init(VI_PIPE ViPipe) +{ + //https://github.com/khadas/common_drivers/blob/68f0856b5fb80cb9c17b53ec367ff8d3c1ff142a/drivers/armisp/subdev/sensor/src/driver/sensor/IMX335_seq.h#L686 + //Turned out wrong, changed a lot + //Restart the sensor and take default registry values + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + IMX335_write_register(ViPipe, 0x3000, 0x01);//pause + IMX335_write_register(ViPipe, 0x3002, 0x01);//continue + IMX335_write_register(ViPipe, 0x3004, 0x04);//restart + IMX335_write_register(ViPipe, 0x3004, 0x00); + delay_ms(18);//Not needed maybe + + +/* + {0x300C,0x5B,0xff,1}, + {0x300D,0x40,0xff,1}, + {0x3034,0x13,0xff,1}, + {0x3035,0x01,0xff,1}, + {0x3050,0x00,0xff,1}, + {0x315A,0x02,0xff,1}, + {0x316A,0x7E,0xff,1}, +*/ + //37Mhz + IMX335_write_register(ViPipe, 0x300C, 0xB6 ); // 0xB6- BCWAIT_TIME = 74.25 + IMX335_write_register(ViPipe, 0x300D, 0x7F); // 0x7F - CPWAIT_TIME = 74.25 + IMX335_write_register(ViPipe, 0x3018,0x00); //winmode normal mode + IMX335_write_register(ViPipe, 0x3034,0x26); //113h HMAX + IMX335_write_register(ViPipe, 0x3035,0x02); //HMAX + IMX335_write_register(ViPipe, 0x3050,0x00); + + IMX335_write_register(ViPipe, 0x314C, 0x80); // INCKSEL1 = + IMX335_write_register(ViPipe, 0x314D, 0x00); + IMX335_write_register(ViPipe, 0x315A, 0x06); // x06 INCKSEL2 = 37.125 / 24 | 891 + IMX335_write_register(ViPipe, 0x3168, 0x68); // INCKSEL3 = 37.125 / 74.25 + IMX335_write_register(ViPipe, 0x316A, 0x7E); // INCKSEL4 = 37.125 + + IMX335_write_register(ViPipe,0x319D,0x00); //AD bits + + IMX335_write_register(ViPipe, 0x319E, 0x01);//// SYS_MODE 1 = 1188Mbps, 2=891 + + IMX335_write_register(ViPipe,0x31A1,0x00);//Master mode + IMX335_write_register(ViPipe,0x3288,0x21); + IMX335_write_register(ViPipe,0x328A,0x02); + IMX335_write_register(ViPipe,0x3414,0x05); + IMX335_write_register(ViPipe,0x3416,0x18); + IMX335_write_register(ViPipe,0x341C,0xFF);//AD bits 01FFh=10 + IMX335_write_register(ViPipe,0x341D,0x01); + IMX335_write_register(ViPipe,0x3648,0x01); + IMX335_write_register(ViPipe,0x364A,0x04); + IMX335_write_register(ViPipe,0x364C,0x04); + IMX335_write_register(ViPipe,0x3678,0x01); + IMX335_write_register(ViPipe,0x367C,0x31); + IMX335_write_register(ViPipe,0x367E,0x31); + IMX335_write_register(ViPipe,0x3706,0x10); + IMX335_write_register(ViPipe,0x3708,0x03); + IMX335_write_register(ViPipe,0x3714,0x02); + IMX335_write_register(ViPipe,0x3715,0x02); + IMX335_write_register(ViPipe,0x3716,0x01); + IMX335_write_register(ViPipe,0x3717,0x03); + IMX335_write_register(ViPipe,0x371C,0x3D); + IMX335_write_register(ViPipe,0x371D,0x3F); + IMX335_write_register(ViPipe,0x372C,0x00); + IMX335_write_register(ViPipe,0x372D,0x00); + IMX335_write_register(ViPipe,0x372E,0x46); + IMX335_write_register(ViPipe,0x372F,0x00); + IMX335_write_register(ViPipe,0x3730,0x89); + IMX335_write_register(ViPipe,0x3731,0x00); + IMX335_write_register(ViPipe,0x3732,0x08); + IMX335_write_register(ViPipe,0x3733,0x01); + IMX335_write_register(ViPipe,0x3734,0xFE); + IMX335_write_register(ViPipe,0x3735,0x05); + IMX335_write_register(ViPipe,0x3740,0x02); + IMX335_write_register(ViPipe,0x375D,0x00); + IMX335_write_register(ViPipe,0x375E,0x00); + IMX335_write_register(ViPipe,0x375F,0x11); + IMX335_write_register(ViPipe,0x3760,0x01); + IMX335_write_register(ViPipe,0x3768,0x1B); + IMX335_write_register(ViPipe,0x3769,0x1B); + IMX335_write_register(ViPipe,0x376A,0x1B); + IMX335_write_register(ViPipe,0x376B,0x1B); + IMX335_write_register(ViPipe,0x376C,0x1A); + IMX335_write_register(ViPipe,0x376D,0x17); + IMX335_write_register(ViPipe,0x376E,0x0F); + IMX335_write_register(ViPipe,0x3776,0x00); + IMX335_write_register(ViPipe,0x3777,0x00); + IMX335_write_register(ViPipe,0x3778,0x46); + IMX335_write_register(ViPipe,0x3779,0x00); + IMX335_write_register(ViPipe,0x377A,0x89); + IMX335_write_register(ViPipe,0x377B,0x00); + IMX335_write_register(ViPipe,0x377C,0x08); + IMX335_write_register(ViPipe,0x377D,0x01); + IMX335_write_register(ViPipe,0x377E,0x23); + IMX335_write_register(ViPipe,0x377F,0x02); + IMX335_write_register(ViPipe,0x3780,0xD9); + IMX335_write_register(ViPipe,0x3781,0x03); + IMX335_write_register(ViPipe,0x3782,0xF5); + IMX335_write_register(ViPipe,0x3783,0x06); + IMX335_write_register(ViPipe,0x3784,0xA5); + IMX335_write_register(ViPipe,0x3788,0x0F); + IMX335_write_register(ViPipe,0x378A,0xD9); + IMX335_write_register(ViPipe,0x378B,0x03); + IMX335_write_register(ViPipe,0x378C,0xEB); + IMX335_write_register(ViPipe,0x378D,0x05); + IMX335_write_register(ViPipe,0x378E,0x87); + IMX335_write_register(ViPipe,0x378F,0x06); + IMX335_write_register(ViPipe,0x3790,0xF5); + IMX335_write_register(ViPipe,0x3792,0x43); + IMX335_write_register(ViPipe,0x3794,0x7A); + IMX335_write_register(ViPipe,0x3796,0xA1); + + + +// taken from manual for 1186 60fps/30fps + // --- Timings +/* + IMX335_write_register(ViPipe, 0x3A18, 0x8F); + IMX335_write_register(ViPipe, 0x3A1A, 0x4F); + IMX335_write_register(ViPipe, 0x3A1C, 0x47); + IMX335_write_register(ViPipe, 0x3A1E, 0x37); + IMX335_write_register(ViPipe, 0x3A1F, 0x01); + + IMX335_write_register(ViPipe, 0x3A20, 0x4F); + IMX335_write_register(ViPipe, 0x3A22, 0x87); + IMX335_write_register(ViPipe, 0x3A24, 0x4F); + IMX335_write_register(ViPipe, 0x3A26, 0x7F); + IMX335_write_register(ViPipe, 0x3A28, 0x3F); +*/ + +// imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("----->> Sony IMX335_init_5M_2592x1944_10bit_60fps Initial OK!!! <<-----\n"); + + +} + + +//Cropped vertically, 16:9, on hi3516ec300 24fps at h265 are possible +void IMX335_cropped_41fps_2592_1520_init(VI_PIPE ViPipe)//added by trial and error by Tipoman. +{ + + SensorReset(ViPipe); + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + + //IMX335_write_register(ViPipe, 0x3018, 0x00);//window mode, 0-default | 3-binning | 4- cropping + IMX335_write_register(ViPipe, 0x3018, 0x04);//window mode, 0-default | 3-binning | 4- cropping + + IMX335_write_register(ViPipe, 0x302C, 0x30);// HTRIMMING Horiz Start in cropping START + IMX335_write_register(ViPipe, 0x302D, 0x00); + IMX335_write_register(ViPipe, 0x302E, 0x20);//HNUM Horiz size 0A20 - 2592 cropping size designation + IMX335_write_register(ViPipe, 0x302F, 0x0A);//0798 for 1920 + + //2592x1944 2592x1520 + //DevRect_w=2560 DevRect_h=1440 + IMX335_write_register(ViPipe, 0x3030, 0x58);// VMAX default 1194h , 0CE4 for 2560x1440 + IMX335_write_register(ViPipe, 0x3031, 0x0C);// Cropping 08F8h - 1024 0CE4 works at 41fps + IMX335_write_register(ViPipe, 0x3032, 0x00); + IMX335_write_register(ViPipe, 0x3034, 0x20);//HMAX default 0226h/0294h is for 25fps, 14A works 38fos + IMX335_write_register(ViPipe, 0x3035, 0x01);// 12C for 41fps + + + IMX335_write_register(ViPipe, 0x3056, 0x04); //Y_OUT_SIZE effective pixel lines 07ACh + IMX335_write_register(ViPipe, 0x3057, 0x06); //5B4h = 1440 + + IMX335_write_register(ViPipe, 0x3072, 0x28);// Vert Crop start 0x28 + IMX335_write_register(ViPipe, 0x3073, 0x00); + IMX335_write_register(ViPipe, 0x3074, 0xB0);// AREA3_ST_Addr Upper left cropping postion + IMX335_write_register(ViPipe, 0x3075, 0x00); + + IMX335_write_register(ViPipe, 0x3076, 0x08);//// AREA3_WIDTH_1 Vert Cropping Size designation * 2 , = Y_OUT_SIZE*2 + IMX335_write_register(ViPipe, 0x3077, 0x0C); + + + IMX335_write_register(ViPipe, 0x3050, 0x00); + + IMX335_write_register(ViPipe, 0x30C6, 0x12);//Black Offset Addr 12h + + IMX335_write_register(ViPipe, 0x30CE, 0x64);//UNRD_Line_Max in cropping + IMX335_write_register(ViPipe, 0x30D8, 0x78);//UNREAD_ED_ADR in cropping + IMX335_write_register(ViPipe, 0x30D9, 0x0D); + + IMX335_write_register(ViPipe, 0x314C, 0xC0); + + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + + IMX335_write_register(ViPipe, 0x319D, 0x00);//00-10bit | 01 - 12bit + + + IMX335_write_register(ViPipe, 0x319E, 0x02);//// SYS_MODE = 891Mbps + IMX335_write_register(ViPipe, 0x31A1, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + + IMX335_write_register(ViPipe, 0x341C, 0xFF); // Input AD bit, changing this affects output + IMX335_write_register(ViPipe, 0x341D, 0x01); //Input AD bit 0047-12bit | 01FF-10bit + + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + + IMX335_write_register(ViPipe, 0x3740, 0x02); + + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony IMX335__2592_1520_10bit_52fps Initial OK!-------\n"); +} + + +void SensorReset(VI_PIPE ViPipe){ + IMX335_write_register(ViPipe, 0x3000, 0x01); /* standby */ + IMX335_write_register(ViPipe, 0x3001, 0x00); + delay_ms(18);//Not needed maybe + IMX335_write_register(ViPipe, 0x3002, 0x01);//continue + IMX335_write_register(ViPipe, 0x3003, 0x00); + delay_ms(18);//Not needed maybe + IMX335_write_register(ViPipe, 0x3004, 0x04);//restart + delay_ms(18);//Not needed maybe + IMX335_write_register(ViPipe, 0x3004, 0x00); +} +void IMX335_cropped_60fps_1080p_init(VI_PIPE ViPipe)//added by trial and error by Tipoman. +{ + //Restart the sensor and take default registry values +/* + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + IMX335_write_register(ViPipe, 0x3000, 0x01);//pause + IMX335_write_register(ViPipe, 0x3002, 0x01);//continue + IMX335_write_register(ViPipe, 0x3004, 0x04);//restart + IMX335_write_register(ViPipe, 0x3004, 0x00); + delay_ms(18);//Not needed maybe + + IMX335_write_register(ViPipe, 0x3000, 0x01); // standby +*/ + SensorReset(ViPipe); + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + + //IMX335_write_register(ViPipe, 0x3018, 0x00);//window mode, 0-default | 3-binning | 4- cropping + IMX335_write_register(ViPipe, 0x3018, 0x04);//window mode, 0-default | 3-binning | 4- cropping + IMX335_write_register(ViPipe, 0x302C, 0x80);//HTRIMMING Horiz Start in cropping START + IMX335_write_register(ViPipe, 0x302D, 0x01); + IMX335_write_register(ViPipe, 0x302E, 0x98);//HNUM Horiz size 0A20 - 2592 cropping size designation + IMX335_write_register(ViPipe, 0x302F, 0x07); + + //2592x1944 2592x1520 + //DevRect_w=2560 DevRect_h=1440 + IMX335_write_register(ViPipe, 0x3030, 0xF8);//VMAX default 1194h , 0CE4 for 2560x1440 + IMX335_write_register(ViPipe, 0x3031, 0x08);// Cropping 08F8h - 1024 //Input AD + IMX335_write_register(ViPipe, 0x3032, 0x00); + IMX335_write_register(ViPipe, 0x3034, 0x6E);//HMAX default 0226h gives 59fps at 1080p, encoder can't handle more than 55! + IMX335_write_register(ViPipe, 0x3035, 0x01);//16Eh for 90fps + //Can do 90fps when encoder set at 1280x720 and 16Eh + + IMX335_write_register(ViPipe, 0x3056, 0x4C); //Y_OUT_SIZE effective pixel lines 07ACh + IMX335_write_register(ViPipe, 0x3057, 0x04); //5B4h = 1440 + + IMX335_write_register(ViPipe, 0x3072, 0x28);// Vert Crop start + IMX335_write_register(ViPipe, 0x3073, 0x00); + IMX335_write_register(ViPipe, 0x3074, 0x10);// AREA3_ST_Addr Upper left cropping postion + IMX335_write_register(ViPipe, 0x3075, 0x04); + + IMX335_write_register(ViPipe, 0x3076, 0x98);//// AREA3_WIDTH_1 Vert Cropping Size designation * 2 , = Y_OUT_SIZE*2 + IMX335_write_register(ViPipe, 0x3077, 0x08); + + + IMX335_write_register(ViPipe, 0x3050, 0x00); + + IMX335_write_register(ViPipe, 0x30C6, 0x12);//Black Offset Addr 12h + + IMX335_write_register(ViPipe, 0x30CE, 0x64);//UNRD_Line_Max in cropping + IMX335_write_register(ViPipe, 0x30D8, 0x78);//UNREAD_ED_ADR in cropping + IMX335_write_register(ViPipe, 0x30D9, 0x0D); + + IMX335_write_register(ViPipe, 0x314C, 0xC0); + + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + + IMX335_write_register(ViPipe, 0x319D, 0x00);//00-10bit | 01 - 12bit + + + IMX335_write_register(ViPipe, 0x319E, 0x02);//// SYS_MODE = 891Mbps + IMX335_write_register(ViPipe, 0x31A1, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + + IMX335_write_register(ViPipe, 0x341C, 0xFF); // Input AD bit, changing this affects output + IMX335_write_register(ViPipe, 0x341D, 0x01); //Input AD bit 0047-12bit | 01FF-10bit + + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + + IMX335_write_register(ViPipe, 0x3740, 0x02); + + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("------=>Sony IMX335_Cropped_1920x1080_10bit_90fps Initial OK!-------\n"); +} + +void IMX335_wdr_5M30_10bit_init(VI_PIPE ViPipe) +{ + IMX335_write_register(ViPipe, 0x3000, 0x01); + IMX335_write_register(ViPipe, 0x3002, 0x01); + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + IMX335_write_register(ViPipe, 0x3018, 0x00); + IMX335_write_register(ViPipe, 0x302C, 0x30); + IMX335_write_register(ViPipe, 0x302D, 0x00); + IMX335_write_register(ViPipe, 0x302E, 0x38); + IMX335_write_register(ViPipe, 0x302F, 0x0A); + IMX335_write_register(ViPipe, 0x3030, 0xB5); + IMX335_write_register(ViPipe, 0x3031, 0x0F); + IMX335_write_register(ViPipe, 0x3032, 0x00); + IMX335_write_register(ViPipe, 0x3034, 0x2C); + IMX335_write_register(ViPipe, 0x3035, 0x01); + IMX335_write_register(ViPipe, 0x304E, 0x00); + IMX335_write_register(ViPipe, 0x304F, 0x00); + IMX335_write_register(ViPipe, 0x3050, 0x00); + IMX335_write_register(ViPipe, 0x3072, 0x28); + IMX335_write_register(ViPipe, 0x3073, 0x00); + IMX335_write_register(ViPipe, 0x3074, 0xB0); + IMX335_write_register(ViPipe, 0x3075, 0x00); + IMX335_write_register(ViPipe, 0x3076, 0x58); + IMX335_write_register(ViPipe, 0x3077, 0x0F); + IMX335_write_register(ViPipe, 0x3078, 0x01); + IMX335_write_register(ViPipe, 0x3079, 0x02); + IMX335_write_register(ViPipe, 0x307A, 0xFF); + IMX335_write_register(ViPipe, 0x307B, 0x02); + IMX335_write_register(ViPipe, 0x307C, 0x00); + IMX335_write_register(ViPipe, 0x307D, 0x00); + IMX335_write_register(ViPipe, 0x307E, 0x00); + IMX335_write_register(ViPipe, 0x307F, 0x00); + IMX335_write_register(ViPipe, 0x3080, 0x01); + IMX335_write_register(ViPipe, 0x3081, 0x02); + IMX335_write_register(ViPipe, 0x3082, 0xFF); + IMX335_write_register(ViPipe, 0x3083, 0x02); + IMX335_write_register(ViPipe, 0x3084, 0x00); + IMX335_write_register(ViPipe, 0x3085, 0x00); + IMX335_write_register(ViPipe, 0x3086, 0x00); + IMX335_write_register(ViPipe, 0x3087, 0x00); + IMX335_write_register(ViPipe, 0x30A4, 0x33); + IMX335_write_register(ViPipe, 0x30A8, 0x10); + IMX335_write_register(ViPipe, 0x30A9, 0x04); + IMX335_write_register(ViPipe, 0x30AC, 0x00); + IMX335_write_register(ViPipe, 0x30AD, 0x00); + IMX335_write_register(ViPipe, 0x30B0, 0x10); + IMX335_write_register(ViPipe, 0x30B1, 0x08); + IMX335_write_register(ViPipe, 0x30B4, 0x00); + IMX335_write_register(ViPipe, 0x30B5, 0x00); + IMX335_write_register(ViPipe, 0x30B6, 0x00); + IMX335_write_register(ViPipe, 0x30B7, 0x00); + IMX335_write_register(ViPipe, 0x3112, 0x08); + IMX335_write_register(ViPipe, 0x3113, 0x00); + IMX335_write_register(ViPipe, 0x3116, 0x08); + IMX335_write_register(ViPipe, 0x3117, 0x00); + IMX335_write_register(ViPipe, 0x314C, 0x38); + IMX335_write_register(ViPipe, 0x314D, 0x01); + IMX335_write_register(ViPipe, 0x315A, 0x07); + IMX335_write_register(ViPipe, 0x3167, 0x02); + IMX335_write_register(ViPipe, 0x3168, 0xA9); + IMX335_write_register(ViPipe, 0x316A, 0x7F); + IMX335_write_register(ViPipe, 0x3199, 0x00); + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x02); + IMX335_write_register(ViPipe, 0x31A0, 0x2A); + IMX335_write_register(ViPipe, 0x3300, 0x00); + IMX335_write_register(ViPipe, 0x3302, 0x32); + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + IMX335_write_register(ViPipe, 0x3A00, 0x01); + IMX335_write_register(ViPipe, 0x3A01, 0x03); + IMX335_write_register(ViPipe, 0x3A04, 0x48); + IMX335_write_register(ViPipe, 0x3A05, 0x09); + IMX335_write_register(ViPipe, 0x3A18, 0x6F); + IMX335_write_register(ViPipe, 0x3A19, 0x00); + IMX335_write_register(ViPipe, 0x3A1A, 0x2F); + IMX335_write_register(ViPipe, 0x3A1B, 0x00); + IMX335_write_register(ViPipe, 0x3A1C, 0x2F); + IMX335_write_register(ViPipe, 0x3A1D, 0x00); + IMX335_write_register(ViPipe, 0x3A1E, 0xD7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x37); + IMX335_write_register(ViPipe, 0x3A21, 0x00); + IMX335_write_register(ViPipe, 0x3A22, 0x5F); + IMX335_write_register(ViPipe, 0x3A23, 0x00); + IMX335_write_register(ViPipe, 0x3A24, 0x37); + IMX335_write_register(ViPipe, 0x3A25, 0x00); + IMX335_write_register(ViPipe, 0x3A26, 0x57); + IMX335_write_register(ViPipe, 0x3A27, 0x00); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + IMX335_write_register(ViPipe, 0x3A29, 0x00); + + IMX335_write_register(ViPipe, 0x3048, 0x01); + IMX335_write_register(ViPipe, 0x3049, 0x01); + IMX335_write_register(ViPipe, 0x304A, 0x04); + IMX335_write_register(ViPipe, 0x304B, 0x03); + IMX335_write_register(ViPipe, 0x304C, 0x13); + IMX335_write_register(ViPipe, 0x3056, 0xAC); + IMX335_write_register(ViPipe, 0x3057, 0x07); + + IMX335_write_register(ViPipe, 0x319F, 0x01); + IMX335_write_register(ViPipe, 0x31D7, 0x01); + + IMX335_write_register(ViPipe, 0x3058, 0x68); + IMX335_write_register(ViPipe, 0x3059, 0x01); + IMX335_write_register(ViPipe, 0x305A, 0x00); + + IMX335_write_register(ViPipe, 0x305C, 0x1A); + IMX335_write_register(ViPipe, 0x305D, 0x00); + IMX335_write_register(ViPipe, 0x305E, 0x00); + + IMX335_write_register(ViPipe, 0x3068, 0x2A); + IMX335_write_register(ViPipe, 0x3069, 0x00); + IMX335_write_register(ViPipe, 0x306A, 0x00); + + IMX335_write_register(ViPipe, 0x31A0, 0x2A); + IMX335_write_register(ViPipe, 0x31A1, 0x00); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(20); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony IMX335_init_5M_2592x1944_10bit_wdr30 Initial OK!-------\n"); +} + +void IMX335_wdr_4M25_10bit_init(VI_PIPE ViPipe) // use weighted binning mode +{ + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + + IMX335_write_register(ViPipe, 0x3000, 0x01); + IMX335_write_register(ViPipe, 0x3002, 0x01); + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + IMX335_write_register(ViPipe, 0x3018, 0x04); + IMX335_write_register(ViPipe, 0x302C, 0x3c); + IMX335_write_register(ViPipe, 0x302D, 0x00); + IMX335_write_register(ViPipe, 0x302E, 0x20); + IMX335_write_register(ViPipe, 0x302F, 0x0A); + + IMX335_write_register(ViPipe, 0x304E, 0x00); + IMX335_write_register(ViPipe, 0x304F, 0x00); + IMX335_write_register(ViPipe, 0x3050, 0x00); + IMX335_write_register(ViPipe, 0x3056, 0xb4); + IMX335_write_register(ViPipe, 0x3057, 0x05); + + IMX335_write_register(ViPipe, 0x3072, 0x28); + IMX335_write_register(ViPipe, 0x3073, 0x00); + IMX335_write_register(ViPipe, 0x3074, 0xA8); + IMX335_write_register(ViPipe, 0x3075, 0x02); + IMX335_write_register(ViPipe, 0x3076, 0x68); + IMX335_write_register(ViPipe, 0x3077, 0x0b); + IMX335_write_register(ViPipe, 0x30c6, 0x12); + IMX335_write_register(ViPipe, 0x30ce, 0x64); + IMX335_write_register(ViPipe, 0x30d8, 0x6c); + IMX335_write_register(ViPipe, 0x30d9, 0x0e); + IMX335_write_register(ViPipe, 0x314C, 0x80); + IMX335_write_register(ViPipe, 0x314D, 0x00); + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x3168, 0x68); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + IMX335_write_register(ViPipe, 0x3199, 0x00); + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x03); + IMX335_write_register(ViPipe, 0x319f, 0x01); + + IMX335_write_register(ViPipe, 0x31A0, 0x2A); + IMX335_write_register(ViPipe, 0x31d7, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + IMX335_write_register(ViPipe, 0x3300, 0x00); + IMX335_write_register(ViPipe, 0x3302, 0x32); + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + IMX335_write_register(ViPipe, 0x3740, 0x02); + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x37B0, 0x36); + IMX335_write_register(ViPipe, 0x3A00, 0x01); + IMX335_write_register(ViPipe, 0x3A01, 0x03); + IMX335_write_register(ViPipe, 0x3A04, 0x48); + IMX335_write_register(ViPipe, 0x3A05, 0x09); + + IMX335_write_register(ViPipe, 0x3A18, 0x67); + IMX335_write_register(ViPipe, 0x3A19, 0x00); + IMX335_write_register(ViPipe, 0x3A1A, 0x27); + IMX335_write_register(ViPipe, 0x3A1B, 0x00); + IMX335_write_register(ViPipe, 0x3A1C, 0x27); + IMX335_write_register(ViPipe, 0x3A1D, 0x00); + IMX335_write_register(ViPipe, 0x3A1E, 0xb7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x2F); + IMX335_write_register(ViPipe, 0x3A21, 0x00); + IMX335_write_register(ViPipe, 0x3A22, 0x4f); + IMX335_write_register(ViPipe, 0x3A23, 0x00); + IMX335_write_register(ViPipe, 0x3A24, 0x2F); + IMX335_write_register(ViPipe, 0x3A25, 0x00); + IMX335_write_register(ViPipe, 0x3A26, 0x47); + IMX335_write_register(ViPipe, 0x3A27, 0x00); + IMX335_write_register(ViPipe, 0x3A28, 0x27); + IMX335_write_register(ViPipe, 0x3A29, 0x00); + + IMX335_write_register(ViPipe, 0x3048, 0x01); + IMX335_write_register(ViPipe, 0x3049, 0x01); + IMX335_write_register(ViPipe, 0x304A, 0x04); + IMX335_write_register(ViPipe, 0x304B, 0x03); + IMX335_write_register(ViPipe, 0x304C, 0x13); + IMX335_write_register(ViPipe, 0x3050, 0x00); + IMX335_write_register(ViPipe, 0x3056, 0xb4); // Y_OUT_SIZE_LOW + IMX335_write_register(ViPipe, 0x3057, 0x05); + IMX335_write_register(ViPipe, 0x319f, 0x01); + IMX335_write_register(ViPipe, 0x31d7, 0x01); + IMX335_write_register(ViPipe, 0x3200, 0x00); + IMX335_write_register(ViPipe, 0x305C, 0x12); // SHR1_LOW + IMX335_write_register(ViPipe, 0x305D, 0x00); + IMX335_write_register(ViPipe, 0x305E, 0x00); + IMX335_write_register(ViPipe, 0x3068, 0x1a); // RHS1_LOW + IMX335_write_register(ViPipe, 0x3069, 0x00); + IMX335_write_register(ViPipe, 0x306A, 0x00); + IMX335_write_register(ViPipe, 0x3058, 0x70); // SHR0_LOW + IMX335_write_register(ViPipe, 0x3059, 0x13); + IMX335_write_register(ViPipe, 0x305a, 0x00); + IMX335_write_register(ViPipe, 0x3060, 0x00); + IMX335_write_register(ViPipe, 0x3061, 0x00); + IMX335_write_register(ViPipe, 0x3062, 0x00); + IMX335_write_register(ViPipe, 0x306C, 0x00); + IMX335_write_register(ViPipe, 0x306D, 0x00); + IMX335_write_register(ViPipe, 0x306E, 0x00); + IMX335_write_register(ViPipe, 0x30E8, 0x00); // GAIN_LONG_LOW + IMX335_write_register(ViPipe, 0x30E9, 0x00); + IMX335_write_register(ViPipe, 0x3030, 0xb8); // VMAX + IMX335_write_register(ViPipe, 0x3031, 0x0b); + IMX335_write_register(ViPipe, 0x3032, 0x00); + IMX335_write_register(ViPipe, 0x3034, 0xef); + IMX335_write_register(ViPipe, 0x3035, 0x01); + IMX335_write_register(ViPipe, 0x304E, 0x00); + IMX335_write_register(ViPipe, 0x304F, 0x00); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony IMX335_init_4M_2560x1440_10bit_wdr25 Initial OK!-------\n"); +} + +void IMX335_wdr_4M30_10bit_init(VI_PIPE ViPipe) +{ + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + IMX335_write_register(ViPipe, 0x3018, 0x04); + IMX335_write_register(ViPipe, 0x3030, 0xE4); + IMX335_write_register(ViPipe, 0x3031, 0x0C); + IMX335_write_register(ViPipe, 0x3034, 0x77); + IMX335_write_register(ViPipe, 0x3035, 0x01); + IMX335_write_register(ViPipe, 0x3048, 0x01); + IMX335_write_register(ViPipe, 0x3049, 0x01); + IMX335_write_register(ViPipe, 0x304A, 0x04); + IMX335_write_register(ViPipe, 0x304B, 0x03); + IMX335_write_register(ViPipe, 0x304C, 0x13); + IMX335_write_register(ViPipe, 0x3050, 0x00); + IMX335_write_register(ViPipe, 0x3056, 0x0C); + IMX335_write_register(ViPipe, 0x3057, 0x06); + IMX335_write_register(ViPipe, 0x3074, 0x50); + IMX335_write_register(ViPipe, 0x3075, 0x02); + IMX335_write_register(ViPipe, 0x3076, 0x18); + IMX335_write_register(ViPipe, 0x3077, 0x0C); + IMX335_write_register(ViPipe, 0x30C6, 0x12); + IMX335_write_register(ViPipe, 0x30CE, 0x64); + IMX335_write_register(ViPipe, 0x30D8, 0x38); + IMX335_write_register(ViPipe, 0x30D9, 0x0F); + IMX335_write_register(ViPipe, 0x314C, 0xC0); + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x02); + IMX335_write_register(ViPipe, 0x3200, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + IMX335_write_register(ViPipe, 0x3740, 0x02); + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + IMX335_write_register(ViPipe, 0x31D7, 0x01); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); //Standby Cancel + + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony IMX335_init_4M_2592x1520_10bit_wdr30 Initial OK!-------\n"); +} + +//DevRect_w=1296 DevRect_h=972 +void IMX335_linear_binning_30fps_12bit_init(VI_PIPE ViPipe) +{ + IMX335_write_register(ViPipe, 0x3000, 0x01); // standby + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + IMX335_write_register(ViPipe, 0x3050, 0x00); + + /* Horizontal/Vertical 2/2-line binning */ + IMX335_write_register(ViPipe, 0x3018, 0x01); + IMX335_write_register(ViPipe, 0x3199, 3 << 4); + IMX335_write_register(ViPipe, 0x3300, 0x01); + IMX335_write_register(ViPipe, 0x304C, 0x14); + IMX335_write_register(ViPipe, 0x3056, 0xd8); + IMX335_write_register(ViPipe, 0x3057, 0x3); + IMX335_write_register(ViPipe, 0x3072, 0x30); + IMX335_write_register(ViPipe, 0x3073, 0); + IMX335_write_register(ViPipe, 0x3076, 0x60); + IMX335_write_register(ViPipe, 0x3077, 0xf); + IMX335_write_register(ViPipe, 0x3078, 4); + + IMX335_write_register(ViPipe, 0x314C, 0xC0); + + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + + IMX335_write_register(ViPipe, 0x319D, 0x01); + IMX335_write_register(ViPipe, 0x319E, 0x02);//// SYS_MODE = 891Mbps + IMX335_write_register(ViPipe, 0x31A1, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + + IMX335_write_register(ViPipe, 0x3740, 0x02); + + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + imx335_default_reg_init(ViPipe); + + // only required for 2x2 binning + IMX335_write_register(ViPipe, 0x3079, 0xfd); + IMX335_write_register(ViPipe, 0x307A, 4); + IMX335_write_register(ViPipe, 0x307B, 0xfe); + IMX335_write_register(ViPipe, 0x307C, 4); + IMX335_write_register(ViPipe, 0x307D, 0xfb); + IMX335_write_register(ViPipe, 0x307E, 4); + IMX335_write_register(ViPipe, 0x307F, 2); + IMX335_write_register(ViPipe, 0x3080, 4); + IMX335_write_register(ViPipe, 0x3081, 0xfd); + IMX335_write_register(ViPipe, 0x3082, 4); + IMX335_write_register(ViPipe, 0x3083, 0xfe); + IMX335_write_register(ViPipe, 0x3084, 4); + IMX335_write_register(ViPipe, 0x3085, 0xfb); + IMX335_write_register(ViPipe, 0x3086, 4); + IMX335_write_register(ViPipe, 0x3087, 2); + IMX335_write_register(ViPipe, 0x30A4, 0x77); + IMX335_write_register(ViPipe, 0x30A8, 0x20); + IMX335_write_register(ViPipe, 0x30A9, 0); + IMX335_write_register(ViPipe, 0x30AC, 8); + IMX335_write_register(ViPipe, 0x30AD, 8); + IMX335_write_register(ViPipe, 0x30B0, 20); + IMX335_write_register(ViPipe, 0x30B1, 0); + IMX335_write_register(ViPipe, 0x30B4, 0x10); + IMX335_write_register(ViPipe, 0x30B5, 0x10); + IMX335_write_register(ViPipe, 0x30B6, 0); + IMX335_write_register(ViPipe, 0x30B7, 0); + IMX335_write_register(ViPipe, 0x3112, 0x10); + IMX335_write_register(ViPipe, 0x3113, 0); + IMX335_write_register(ViPipe, 0x3116, 0x10); + IMX335_write_register(ViPipe, 0x3117, 0); + + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony IMX335_init_binning DevRect_w=1296 DevRect_h=972 Initial OK!-------\n"); +} + +void IMX335_binning_60pfs_init(VI_PIPE ViPipe) { + + //30fps instead + //IMX335_linear_binning_30fps_12bit_init(ViPipe); + //return; + + + //Restart the sensor and take default registry values + IMX335_write_register(ViPipe, 0x3004, 0x04); + IMX335_write_register(ViPipe, 0x3004, 0x00); + IMX335_write_register(ViPipe, 0x3000, 0x01);//pause + IMX335_write_register(ViPipe, 0x3002, 0x01);//continue + IMX335_write_register(ViPipe, 0x3004, 0x04);//restart + IMX335_write_register(ViPipe, 0x3004, 0x00); + delay_ms(18);//Not needed maybe + + IMX335_write_register(ViPipe, 0x3000, 0x01); // standby + + IMX335_write_register(ViPipe, 0x300C, 0xB6); // - BCWAIT_TIME = 74.25 + IMX335_write_register(ViPipe, 0x300D, 0x7F); // - CPWAIT_TIME = 74.25 + + + IMX335_write_register(ViPipe, 0x3018, 0x01); // - WINMODE = 2x2 binning + IMX335_write_register(ViPipe, 0x3300, 0x01); // - TCYCLE = 2x2 binning (0 - all pixels) + +// this is a test, works without it with default reg 1194h + IMX335_write_register(ViPipe, 0x3030, 0xE8);// VMAX default 1194h , 0CE4 works, 65fps + IMX335_write_register(ViPipe, 0x3031, 0x0D);// does not work 08F8h - 1024 + IMX335_write_register(ViPipe, 0x3032, 0x00);// can reach 68fps when configured + //^^^above^^^^^^^^^^^^^^^^^^^^TEST^^^^^^^^^^^^^^above^^^^ + + IMX335_write_register(ViPipe, 0x3034, 0x13); // - HMAX 113 works for 60 fps + IMX335_write_register(ViPipe, 0x3035, 0x01); + + IMX335_write_register(ViPipe, 0x3050, 0x00); // - ADBIT = 10bit + + IMX335_write_register(ViPipe, 0x3056, 0xD8); + IMX335_write_register(ViPipe, 0x3057, 0x03); + + IMX335_write_register(ViPipe, 0x3072, 0x30); + IMX335_write_register(ViPipe, 0x3073, 0x00); + + IMX335_write_register(ViPipe, 0x3074, 0xA8); + IMX335_write_register(ViPipe, 0x3075, 0x00); + + IMX335_write_register(ViPipe, 0x3076, 0x60); + IMX335_write_register(ViPipe, 0x3077, 0x0F); + + + // --- INCSEL + IMX335_write_register(ViPipe, 0x314C, 0x80); // INCKSEL1 = + IMX335_write_register(ViPipe, 0x314D, 0x00); + IMX335_write_register(ViPipe, 0x315A, 0x06); // INCKSEL2 = 37.125 / 24 | 891 + IMX335_write_register(ViPipe, 0x3168, 0x68); // INCKSEL3 = 37.125 / 74.25 + IMX335_write_register(ViPipe, 0x316A, 0x7E); // INCKSEL4 = 37.125 + + IMX335_write_register(ViPipe, 0x3199, 0x10); // HADD / VADD = 2x2 binning + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x01); // SYS_MODE = 1188Mbps + + + IMX335_write_register(ViPipe, 0x341C, 0xFF); // ADBIT1 = 10-bit + IMX335_write_register(ViPipe, 0x341D, 0x01); + IMX335_write_register(ViPipe, 0x3A01, 0x03); // LANEMODE = CSI-2 x4 + + // --- Timings + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + + // - Shutter configuration + uint32_t lines = 4500 - 1; + IMX335_write_register(ViPipe, 0x3058, lines & 0xFF); + IMX335_write_register(ViPipe, 0x3059, (lines >> 8) & 0xFF); + IMX335_write_register(ViPipe, 0x305A, (lines >> 16) & 0x0F); + + // - Static registers + IMX335_write_register(ViPipe, 0x3078, 0x04); + IMX335_write_register(ViPipe, 0x3079, 0xFD); + IMX335_write_register(ViPipe, 0x307A, 0x04); + IMX335_write_register(ViPipe, 0x307B, 0xFE); + IMX335_write_register(ViPipe, 0x307C, 0x04); + IMX335_write_register(ViPipe, 0x307D, 0xFB); + IMX335_write_register(ViPipe, 0x307E, 0x04); + IMX335_write_register(ViPipe, 0x307F, 0x02); + + IMX335_write_register(ViPipe, 0x3080, 0x04); + IMX335_write_register(ViPipe, 0x3081, 0xFD); + IMX335_write_register(ViPipe, 0x3082, 0x04); + IMX335_write_register(ViPipe, 0x3083, 0xFE); + IMX335_write_register(ViPipe, 0x3084, 0x04); + IMX335_write_register(ViPipe, 0x3085, 0xFB); + IMX335_write_register(ViPipe, 0x3086, 0x04); + IMX335_write_register(ViPipe, 0x3087, 0x02); + + IMX335_write_register(ViPipe, 0x30A4, 0x77); + IMX335_write_register(ViPipe, 0x30A8, 0x20); + IMX335_write_register(ViPipe, 0x30A9, 0x00); + + IMX335_write_register(ViPipe, 0x30AC, 0x08); + IMX335_write_register(ViPipe, 0x30AD, 0x08); + + IMX335_write_register(ViPipe, 0x30B0, 0x10); // - All pixels + IMX335_write_register(ViPipe, 0x30B1, 0x08); // - All pixels + + IMX335_write_register(ViPipe, 0x30B4, 0x10); + IMX335_write_register(ViPipe, 0x30B5, 0x10); + + IMX335_write_register(ViPipe, 0x30B6, 0x00); + IMX335_write_register(ViPipe, 0x30B7, 0x00); + + IMX335_write_register(ViPipe, 0x3112, 0x10); + IMX335_write_register(ViPipe, 0x3113, 0x00); + + IMX335_write_register(ViPipe, 0x3116, 0x10); + IMX335_write_register(ViPipe, 0x3117, 0x00); + + + // - OK + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("------- Sony IMX335 2x2 binning mode 1296x972 @ 60fps -------\n"); +} + + +/// @brief Stock 30fps full sensor mode +/// @param ViPipe +void IMX335_linear_5M30_12bit_init(VI_PIPE ViPipe) +{ + + SensorReset(ViPipe); + + IMX335_write_register(ViPipe, 0x300C, 0x5B); + IMX335_write_register(ViPipe, 0x300D, 0x40); + + if (1==1){ + + IMX335_write_register(ViPipe, 0x3018, 0x00);//window mode, 0-default | 3-binning | 4- cropping + + IMX335_write_register(ViPipe, 0x302C, 0x30);// HTRIMMING Horiz Start in cropping START + IMX335_write_register(ViPipe, 0x302D, 0x00); + + IMX335_write_register(ViPipe, 0x302E, 0x38);//HNUM Horiz size 0A20 - 2592 cropping size designation + IMX335_write_register(ViPipe, 0x302F, 0x0A);//0798 for 1920 + + IMX335_write_register(ViPipe, 0x3030, 0x94);// VMAX default 1194h , + IMX335_write_register(ViPipe, 0x3031, 0x11);// + IMX335_write_register(ViPipe, 0x3032, 0x00); + IMX335_write_register(ViPipe, 0x3034, 0x26);//HMAX default 0226h/0294h is for 25fps, 14A works 38fos + IMX335_write_register(ViPipe, 0x3035, 0x02);// 12C for 41fps + + + IMX335_write_register(ViPipe, 0x3056, 0xAC); //Y_OUT_SIZE effective pixel lines 07ACh + IMX335_write_register(ViPipe, 0x3057, 0x07); //5B4h = 1440 + + IMX335_write_register(ViPipe, 0x3072, 0x28);// Vert Crop start 0x28 + IMX335_write_register(ViPipe, 0x3073, 0x00); + + + IMX335_write_register(ViPipe, 0x3076, 0x58);//// AREA3_WIDTH_1 Vert Cropping Size designation * 2 , = Y_OUT_SIZE*2 + IMX335_write_register(ViPipe, 0x3077, 0x0F); + } + + + IMX335_write_register(ViPipe, 0x3050, 0x00); + + // + if (1==1){//return to defaults not working?! + IMX335_write_register(ViPipe, 0x3074, 0xB0);// AREA3_ST_Addr Upper left cropping postion + IMX335_write_register(ViPipe, 0x3075, 0x00); + IMX335_write_register(ViPipe, 0x30C6, 0x00);//Black Offset Addr 12h + IMX335_write_register(ViPipe, 0x30CE, 0x00);//UNRD_Line_Max in cropping + IMX335_write_register(ViPipe, 0x30D8, 0x4C);//UNREAD_ED_ADR in cropping + IMX335_write_register(ViPipe, 0x30D9, 0x10); + } + // + + IMX335_write_register(ViPipe, 0x314C, 0xC0); + + IMX335_write_register(ViPipe, 0x315A, 0x06); + IMX335_write_register(ViPipe, 0x316A, 0x7E); + + IMX335_write_register(ViPipe, 0x319D, 0x00); + IMX335_write_register(ViPipe, 0x319E, 0x02); + IMX335_write_register(ViPipe, 0x31A1, 0x00); + IMX335_write_register(ViPipe, 0x3288, 0x21); + IMX335_write_register(ViPipe, 0x328A, 0x02); + + IMX335_write_register(ViPipe, 0x3414, 0x05); + IMX335_write_register(ViPipe, 0x3416, 0x18); + + IMX335_write_register(ViPipe, 0x341C, 0xFF); + IMX335_write_register(ViPipe, 0x341D, 0x01); + + IMX335_write_register(ViPipe, 0x3648, 0x01); + IMX335_write_register(ViPipe, 0x364A, 0x04); + IMX335_write_register(ViPipe, 0x364C, 0x04); + + IMX335_write_register(ViPipe, 0x3678, 0x01); + IMX335_write_register(ViPipe, 0x367C, 0x31); + IMX335_write_register(ViPipe, 0x367E, 0x31); + + IMX335_write_register(ViPipe, 0x3706, 0x10); + IMX335_write_register(ViPipe, 0x3708, 0x03); + + IMX335_write_register(ViPipe, 0x3714, 0x02); + IMX335_write_register(ViPipe, 0x3715, 0x02); + IMX335_write_register(ViPipe, 0x3716, 0x01); + IMX335_write_register(ViPipe, 0x3717, 0x03); + IMX335_write_register(ViPipe, 0x371C, 0x3D); + IMX335_write_register(ViPipe, 0x371D, 0x3F); + + IMX335_write_register(ViPipe, 0x372C, 0x00); + IMX335_write_register(ViPipe, 0x372D, 0x00); + IMX335_write_register(ViPipe, 0x372E, 0x46); + IMX335_write_register(ViPipe, 0x372F, 0x00); + IMX335_write_register(ViPipe, 0x3730, 0x89); + IMX335_write_register(ViPipe, 0x3731, 0x00); + IMX335_write_register(ViPipe, 0x3732, 0x08); + IMX335_write_register(ViPipe, 0x3733, 0x01); + IMX335_write_register(ViPipe, 0x3734, 0xFE); + IMX335_write_register(ViPipe, 0x3735, 0x05); + + IMX335_write_register(ViPipe, 0x3740, 0x02); + + IMX335_write_register(ViPipe, 0x375D, 0x00); + IMX335_write_register(ViPipe, 0x375E, 0x00); + IMX335_write_register(ViPipe, 0x375F, 0x11); + IMX335_write_register(ViPipe, 0x3760, 0x01); + + IMX335_write_register(ViPipe, 0x3768, 0x1B); + IMX335_write_register(ViPipe, 0x3769, 0x1B); + IMX335_write_register(ViPipe, 0x376A, 0x1B); + IMX335_write_register(ViPipe, 0x376B, 0x1B); + IMX335_write_register(ViPipe, 0x376C, 0x1A); + IMX335_write_register(ViPipe, 0x376D, 0x17); + IMX335_write_register(ViPipe, 0x376E, 0x0F); + + IMX335_write_register(ViPipe, 0x3776, 0x00); + IMX335_write_register(ViPipe, 0x3777, 0x00); + IMX335_write_register(ViPipe, 0x3778, 0x46); + IMX335_write_register(ViPipe, 0x3779, 0x00); + IMX335_write_register(ViPipe, 0x377A, 0x89); + IMX335_write_register(ViPipe, 0x377B, 0x00); + IMX335_write_register(ViPipe, 0x377C, 0x08); + IMX335_write_register(ViPipe, 0x377D, 0x01); + IMX335_write_register(ViPipe, 0x377E, 0x23); + IMX335_write_register(ViPipe, 0x377F, 0x02); + IMX335_write_register(ViPipe, 0x3780, 0xD9); + IMX335_write_register(ViPipe, 0x3781, 0x03); + IMX335_write_register(ViPipe, 0x3782, 0xF5); + IMX335_write_register(ViPipe, 0x3783, 0x06); + IMX335_write_register(ViPipe, 0x3784, 0xA5); + IMX335_write_register(ViPipe, 0x3788, 0x0F); + IMX335_write_register(ViPipe, 0x378A, 0xD9); + IMX335_write_register(ViPipe, 0x378B, 0x03); + IMX335_write_register(ViPipe, 0x378C, 0xEB); + IMX335_write_register(ViPipe, 0x378D, 0x05); + IMX335_write_register(ViPipe, 0x378E, 0x87); + IMX335_write_register(ViPipe, 0x378F, 0x06); + IMX335_write_register(ViPipe, 0x3790, 0xF5); + IMX335_write_register(ViPipe, 0x3792, 0x43); + IMX335_write_register(ViPipe, 0x3794, 0x7A); + IMX335_write_register(ViPipe, 0x3796, 0xA1); + IMX335_write_register(ViPipe, 0x3A18, 0x7F); + IMX335_write_register(ViPipe, 0x3A1A, 0x37); + IMX335_write_register(ViPipe, 0x3A1C, 0x37); + IMX335_write_register(ViPipe, 0x3A1E, 0xF7); + IMX335_write_register(ViPipe, 0x3A1F, 0x00); + IMX335_write_register(ViPipe, 0x3A20, 0x3F); + IMX335_write_register(ViPipe, 0x3A22, 0x6F); + IMX335_write_register(ViPipe, 0x3A24, 0x3F); + IMX335_write_register(ViPipe, 0x3A26, 0x5F); + IMX335_write_register(ViPipe, 0x3A28, 0x2F); + + imx335_default_reg_init(ViPipe); + IMX335_write_register(ViPipe, 0x3000, 0x00); // Standby Cancel + delay_ms(18); + IMX335_write_register(ViPipe, 0x3002, 0x00); + + printf("-------Sony stock IMX335_init_5M_2592x1944_12bit_linear30 Initial OK!-------\n"); +} \ No newline at end of file