nt9856x/rtos/code/application/source/cardv/SrcCode/FastFlow/flow_preview.c

1213 lines
35 KiB
C
Executable File

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hdal.h>
#include <kwrap/perf.h>
#include <kwrap/debug.h>
#include <kwrap/util.h>
#include <FreeRTOS_POSIX.h>
#include <FreeRTOS_POSIX/pthread.h>
#include "PrjCfg.h"
#include "sys_fastboot.h"
#include "flow_preview.h"
#include "vendor_videocapture.h"
#include "vendor_common.h"
#include "vendor_isp.h"
#include "PhotoFast.h"
#include "UIAppPhoto.h"
#include "UIAppPhoto_Param.h"
#include "UIWnd/UIFlow.h"
#include "ImageApp/ImageApp_Photo.h"
#include "SysSensor.h"
#include "PhotoFastSliceEncode.h"
#include <kwrap/cmdsys.h>
#if HUNTING_CAMERA_MCU == ENABLE
#include <sf_mcu.h>
#endif
///////////////////////////////////////////////////////////////////////////////
//header
#define DBGINFO_BUFSIZE() (0x200)
//RAW
#define VDO_RAW_BUFSIZE(w, h, pxlfmt) (ALIGN_CEIL_4((w) * HD_VIDEO_PXLFMT_BPP(pxlfmt) / 8) * (h))
//NRX: RAW compress: Only support 12bit mode
#define RAW_COMPRESS_RATIO 59
#define VDO_NRX_BUFSIZE(w, h) (ALIGN_CEIL_4(ALIGN_CEIL_64(w) * 12 / 8 * RAW_COMPRESS_RATIO / 100 * (h)))
//CA for AWB
#define VDO_CA_BUF_SIZE(win_num_w, win_num_h) ALIGN_CEIL_4((win_num_w * win_num_h << 3) << 1)
//LA for AE
#define VDO_LA_BUF_SIZE(win_num_w, win_num_h) ALIGN_CEIL_4((win_num_w * win_num_h << 1) << 1)
//YUV
#define VDO_YUV_BUFSIZE(w, h, pxlfmt) (ALIGN_CEIL_4((w) * HD_VIDEO_PXLFMT_BPP(pxlfmt) / 8) * (h))
//NVX: YUV compress
#define YUV_COMPRESS_RATIO 75
#define VDO_NVX_BUFSIZE(w, h, pxlfmt) (VDO_YUV_BUFSIZE(w, h, pxlfmt) * YUV_COMPRESS_RATIO / 100)
///////////////////////////////////////////////////////////////////////////////
#define SEN_OUT_FMT HD_VIDEO_PXLFMT_RAW12
#define CAP_OUT_FMT HD_VIDEO_PXLFMT_RAW12
#define SHDR_CAP_OUT_FMT HD_VIDEO_PXLFMT_RAW12_SHDR2
#define CA_WIN_NUM_W 32
#define CA_WIN_NUM_H 32
#define LA_WIN_NUM_W 32
#define LA_WIN_NUM_H 32
#define VA_WIN_NUM_W 16
#define VA_WIN_NUM_H 16
#define YOUT_WIN_NUM_W 128
#define YOUT_WIN_NUM_H 128
#define ETH_8BIT_SEL 0 //0: 2bit out, 1:8 bit out
#define ETH_OUT_SEL 1 //0: full, 1: subsample 1/2
#define LCD_SIZE_W 960
#define LCD_SIZE_H 240
#define DEFAULT_TASK_STACK_SIZE 4096
#define FLOW_PREVIEW_TASK_STACK_SIZE 8192
#define FLAG_SENSOR_TASK_EXIT 0x00000001
#define FLAG_CAP_PROC_TASK_EXIT 0x00000002
#define FLAG_VOUT_TASK_EXIT 0x00000004
#define FLAG_FLOW_PREVIEW_TASK_EXIT 0x00000008
#define AE_PRESET_FUNC DISABLE
#if (AE_PRESET_FUNC == ENABLE)
#include "adc.h"
#define ADC_CH_PHOTORESISTOR ADC_CHANNEL_0
#define ADC_READY_RETRY_CNT (1000000/10) //1 sec
#endif
static ID flag_task = 0;
#if defined(_sen_sc4238_)
static UINT32 g_shdr_mode = 1;
#else
static UINT32 g_shdr_mode = 0;
#endif
extern UINT16 IRSHTTER;
extern void get_preset_param(void);
static ISP_SENSOR_INIT_INFO preset_param;
ISP_SENSOR_INIT_INFO *sen_preset_param(void)
{
return &preset_param;
}
HD_RESULT fastflow_common_init(void)
{
static BOOL need_init = TRUE;
HD_RESULT ret = HD_OK;
HD_COMMON_MEM_INIT_CONFIG mem_cfg = {0};
// init hdal
if (need_init) {
ret = hd_common_init(0);
if (ret != HD_OK) {
printf("common fail=%d\n", ret);
return -1;
}
// init memory
// default
mem_cfg.pool_info[0].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[0].blk_size = DBGINFO_BUFSIZE() + 160*120*3/2;
mem_cfg.pool_info[0].blk_cnt = 1;
mem_cfg.pool_info[0].ddr_id = DDR_ID0;
ret = hd_common_mem_init(&mem_cfg);
if (ret != HD_OK) {
printf("mem_init fail=%d\n", ret);
return -1;
}
need_init = FALSE;
}
return ret;
}
static HD_RESULT flowpreview_mem_relayout(void)
{
HD_RESULT ret;
HD_COMMON_MEM_INIT_CONFIG mem_cfg = {0};
UIAPP_PHOTO_SENSOR_INFO *pSensorInfo = UIAppPhoto_get_SensorInfo(0);
// config common pool (cap)
mem_cfg.pool_info[0].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[0].blk_size = DBGINFO_BUFSIZE()+VDO_RAW_BUFSIZE(pSensorInfo->sSize.w, pSensorInfo->sSize.h, CAP_OUT_FMT)
+VDO_CA_BUF_SIZE(CA_WIN_NUM_W, CA_WIN_NUM_H)
+VDO_LA_BUF_SIZE(LA_WIN_NUM_W, LA_WIN_NUM_H);
if (g_shdr_mode == 1) {
mem_cfg.pool_info[0].blk_cnt = 4;
} else {
mem_cfg.pool_info[0].blk_cnt = 4;
}
mem_cfg.pool_info[0].ddr_id = DDR_ID0;
// config common pool (main)
mem_cfg.pool_info[1].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[1].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(pSensorInfo->sSize.w, pSensorInfo->sSize.h, HD_VIDEO_PXLFMT_YUV420);
mem_cfg.pool_info[1].blk_cnt = 2;
mem_cfg.pool_info[1].ddr_id = DDR_ID0;
#if POWERON_FAST_SLICE_ENC == ENABLE
{
PhotoFast_SliceSize_Info dst_slice_info;
PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info);
mem_cfg.pool_info[2].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[2].blk_size = DBGINFO_BUFSIZE() + PhotoFast_SliceEncode_Get_Max_Dst_Slice_Buffer_Size(HD_VIDEO_PXLFMT_YUV420);
mem_cfg.pool_info[2].blk_cnt = 1;
mem_cfg.pool_info[2].ddr_id = DDR_ID0;
}
#else
// config common pool (primary image)
{
UINT32 u32W, u32H;
u32W = GetPhotoSizeWidth(SysGetFlag(FL_PHOTO_SIZE));
u32H = GetPhotoSizeHeight(SysGetFlag(FL_PHOTO_SIZE));
mem_cfg.pool_info[2].type = HD_COMMON_MEM_COMMON_POOL;
u32W = ALIGN_CEIL_16(u32W);
u32H = ALIGN_CEIL_16(u32H);
mem_cfg.pool_info[2].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(u32W, u32H, HD_VIDEO_PXLFMT_YUV420);
mem_cfg.pool_info[2].blk_cnt = 1;
mem_cfg.pool_info[2].ddr_id = DDR_ID0;
}
#endif
// config common pool (screennail image)
mem_cfg.pool_info[3].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[3].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(CFG_SCREENNAIL_W, CFG_SCREENNAIL_H, HD_VIDEO_PXLFMT_YUV420);
mem_cfg.pool_info[3].blk_cnt = 1;
mem_cfg.pool_info[3].ddr_id = DDR_ID0;
// config common pool (thumbnail image)
mem_cfg.pool_info[4].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[4].blk_size = DBGINFO_BUFSIZE()+VDO_YUV_BUFSIZE(CFG_THUMBNAIL_W, CFG_THUMBNAIL_H, HD_VIDEO_PXLFMT_YUV420);
mem_cfg.pool_info[4].blk_cnt = 1;
mem_cfg.pool_info[4].ddr_id = DDR_ID0;
// config common pool (EXIF)
mem_cfg.pool_info[5].type = HD_COMMON_MEM_COMMON_POOL;
mem_cfg.pool_info[5].blk_size = DBGINFO_BUFSIZE()+CFG_JPG_HEADER_SIZE;
mem_cfg.pool_info[5].blk_cnt = 1;
mem_cfg.pool_info[5].ddr_id = DDR_ID0;
ret = vendor_common_mem_relayout(&mem_cfg);
return ret;
}
///////////////////////////////////////////////////////////////////////////////
static HD_RESULT set_cap_cfg(HD_PATH_ID *p_video_cap_ctrl)
{
HD_RESULT ret = HD_OK;
HD_VIDEOCAP_DRV_CONFIG cap_cfg = {0};
HD_PATH_ID video_cap_ctrl = 0;
HD_VIDEOCAP_CTRL iq_ctl = {0};
System_GetSensorInfo(0, SENSOR_DRV_CFG, &cap_cfg);
#if (SENSOR_SIEPATGEN == ENABLE)
snprintf(cap_cfg.sen_cfg.sen_dev.driver_name, HD_VIDEOCAP_SEN_NAME_LEN-1, "PATTERN_GEN");
#endif
printf("Using %s\n", cap_cfg.sen_cfg.sen_dev.driver_name);
if (g_shdr_mode == 1) {
printf("Using g_shdr_mode\n");
}
ret = hd_videocap_open(0, HD_VIDEOCAP_0_CTRL, &video_cap_ctrl); //open this for device control
if (ret != HD_OK) {
return ret;
}
if (g_shdr_mode == 1) {
cap_cfg.sen_cfg.shdr_map = HD_VIDEOCAP_SHDR_MAP(HD_VIDEOCAP_HDR_SENSOR1, (HD_VIDEOCAP_0|HD_VIDEOCAP_1));
}
ret |= hd_videocap_set(video_cap_ctrl, HD_VIDEOCAP_PARAM_DRV_CONFIG, &cap_cfg);
if (g_shdr_mode == 1) {
iq_ctl.func = HD_VIDEOCAP_FUNC_AE | HD_VIDEOCAP_FUNC_AWB | HD_VIDEOCAP_FUNC_SHDR;
} else {
iq_ctl.func = HD_VIDEOCAP_FUNC_AE | HD_VIDEOCAP_FUNC_AWB;
}
ret |= hd_videocap_set(video_cap_ctrl, HD_VIDEOCAP_PARAM_CTRL, &iq_ctl);
*p_video_cap_ctrl = video_cap_ctrl;
return ret;
}
static HD_RESULT set_cap_param(HD_PATH_ID video_cap_path, HD_DIM *p_dim)
{
HD_RESULT ret = HD_OK;
{//select sensor mode, manually or automatically
HD_VIDEOCAP_IN video_in_param = {0};
#if (SENSOR_SIEPATGEN == DISABLE)
video_in_param.sen_mode = HD_VIDEOCAP_SEN_MODE_AUTO; //auto select sensor mode by the parameter of HD_VIDEOCAP_PARAM_OUT
#else
UIAPP_PHOTO_SENSOR_INFO *pSensorInfo = UIAppPhoto_get_SensorInfo(0);
video_in_param.sen_mode = HD_VIDEOCAP_PATGEN_MODE(1, ALIGN_CEIL((pSensorInfo->sSize.w *10/65), 2));
#endif
video_in_param.frc = HD_VIDEO_FRC_RATIO(30,1);
video_in_param.dim.w = p_dim->w;
video_in_param.dim.h = p_dim->h;
video_in_param.pxlfmt = SEN_OUT_FMT;
if (g_shdr_mode == 1) {
video_in_param.out_frame_num = HD_VIDEOCAP_SEN_FRAME_NUM_2;
} else {
video_in_param.out_frame_num = HD_VIDEOCAP_SEN_FRAME_NUM_1;
}
ret = hd_videocap_set(video_cap_path, HD_VIDEOCAP_PARAM_IN, &video_in_param);
//printf("set_cap_param MODE=%d\r\n", ret);
if (ret != HD_OK) {
return ret;
}
}
#if 0 //no crop, full frame
{
HD_VIDEOCAP_CROP video_crop_param = {0};
video_crop_param.mode = HD_CROP_OFF;
ret = hd_videocap_set(video_cap_path, HD_VIDEOCAP_PARAM_IN_CROP, &video_crop_param);
if (ret != HD_OK) {
return ret;
}
//printf("set_cap_param CROP NONE=%d\r\n", ret);
}
#else //HD_CROP_ON
{
HD_VIDEOCAP_CROP video_crop_param = {0};
video_crop_param.mode = HD_CROP_ON;
video_crop_param.win.rect.x = -1;
video_crop_param.win.rect.y = -1;
video_crop_param.win.rect.w = p_dim->w;
video_crop_param.win.rect.h = p_dim->h;
video_crop_param.align.w = 4;
video_crop_param.align.h = 4;
ret = hd_videocap_set(video_cap_path, HD_VIDEOCAP_PARAM_IN_CROP, &video_crop_param);
//printf("set_cap_param CROP ON=%d\r\n", ret);
}
#endif
{
HD_VIDEOCAP_OUT video_out_param = {0};
//without setting dim for no scaling, using original sensor out size
if (g_shdr_mode == 1) {
video_out_param.pxlfmt = SHDR_CAP_OUT_FMT;
} else {
video_out_param.pxlfmt = CAP_OUT_FMT;
}
video_out_param.dir = HD_VIDEO_DIR_NONE;
ret = hd_videocap_set(video_cap_path, HD_VIDEOCAP_PARAM_OUT, &video_out_param);
//printf("set_cap_param OUT=%d\r\n", ret);
}
{
UINT32 data_lane = 0;
System_GetSensorInfo(0, SENSOR_DATA_LANE, &data_lane);
if (data_lane) {
if ((ret = vendor_videocap_set(video_cap_path, VENDOR_VIDEOCAP_PARAM_DATA_LANE, &data_lane)) != HD_OK) {
DBG_ERR("set VENDOR_VIDEOCAP_PARAM_DATA_LANE fail(%d)\r\n", ret);
}
}
}
return ret;
}
///////////////////////////////////////////////////////////////////////////////
static HD_RESULT set_proc_cfg(HD_PATH_ID *p_video_proc_ctrl, HD_DIM* p_max_dim)
{
HD_RESULT ret = HD_OK;
HD_VIDEOPROC_DEV_CONFIG video_cfg_param = {0};
HD_PATH_ID video_proc_ctrl = 0;
HD_VIDEOPROC_CTRL video_ctrl_param = {0};
ret = hd_videoproc_open(0, HD_VIDEOPROC_0_CTRL, &video_proc_ctrl); //open this for device control
if (ret != HD_OK)
return ret;
if (p_max_dim != NULL ) {
video_cfg_param.pipe = HD_VIDEOPROC_PIPE_RAWALL;
video_cfg_param.isp_id = 0;
video_cfg_param.ctrl_max.func |=(HD_VIDEOPROC_FUNC_3DNR|HD_VIDEOPROC_FUNC_WDR|HD_VIDEOPROC_FUNC_COLORNR);
video_cfg_param.ctrl_max.func |=(HD_VIDEOPROC_FUNC_WDR|HD_VIDEOPROC_FUNC_COLORNR);
if (g_shdr_mode == 1) {
video_cfg_param.ctrl_max.func |= HD_VIDEOPROC_FUNC_SHDR;
}
video_cfg_param.in_max.func = 0;
video_cfg_param.in_max.dim.w = p_max_dim->w;
video_cfg_param.in_max.dim.h = p_max_dim->h;
if (g_shdr_mode == 1) {
video_cfg_param.in_max.pxlfmt = SHDR_CAP_OUT_FMT;
} else {
video_cfg_param.in_max.pxlfmt = CAP_OUT_FMT;
}
video_cfg_param.in_max.frc = HD_VIDEO_FRC_RATIO(1,1);
ret = hd_videoproc_set(video_proc_ctrl, HD_VIDEOPROC_PARAM_DEV_CONFIG, &video_cfg_param);
if (ret != HD_OK) {
return HD_ERR_NG;
}
}
#if 1
video_ctrl_param.func = HD_VIDEOPROC_FUNC_3DNR;
video_ctrl_param.ref_path_3dnr = HD_VIDEOPROC_OUT(0, 0);
ret = hd_videoproc_set(video_proc_ctrl, HD_VIDEOPROC_PARAM_CTRL, &video_ctrl_param);
#endif
video_ctrl_param.func |= (HD_VIDEOPROC_FUNC_WDR|HD_VIDEOPROC_FUNC_COLORNR);
ret = hd_videoproc_set(video_proc_ctrl, HD_VIDEOPROC_PARAM_CTRL, &video_ctrl_param);
if (g_shdr_mode == 1) {
video_ctrl_param.func |= HD_VIDEOPROC_FUNC_SHDR;
ret = hd_videoproc_set(video_proc_ctrl, HD_VIDEOPROC_PARAM_CTRL, &video_ctrl_param);
if (ret != HD_OK) {
return HD_ERR_NG;
}
}
*p_video_proc_ctrl = video_proc_ctrl;
return ret;
}
static HD_RESULT set_proc_param(HD_PATH_ID video_proc_path, HD_DIM* p_dim)
{
HD_RESULT ret = HD_OK;
if (p_dim != NULL) { //if videoproc is already binding to dest module, not require to setting this!
HD_VIDEOPROC_OUT video_out_param = {0};
video_out_param.func = 0;
video_out_param.dim.w = p_dim->w;
video_out_param.dim.h = p_dim->h;
video_out_param.pxlfmt = HD_VIDEO_PXLFMT_YUV420;
video_out_param.dir = HD_VIDEO_DIR_NONE;
video_out_param.frc = HD_VIDEO_FRC_RATIO(1,1);
video_out_param.depth = 1; //set 1 to allow pull
ret = hd_videoproc_set(video_proc_path, HD_VIDEOPROC_PARAM_OUT, &video_out_param);
}
return ret;
}
///////////////////////////////////////////////////////////////////////////////
#if (_PACKAGE_DISPLAY_)
static HD_RESULT set_out_cfg(HD_PATH_ID *p_video_out_ctrl, UINT32 out_type,HD_VIDEOOUT_HDMI_ID hdmi_id)
{
HD_RESULT ret = HD_OK;
HD_VIDEOOUT_MODE videoout_mode = {0};
HD_PATH_ID video_out_ctrl = 0;
ret = hd_videoout_open(0, HD_VIDEOOUT_0_CTRL, &video_out_ctrl); //open this for device control
if (ret != HD_OK) {
return ret;
}
printf("out_type=%d\r\n", (int)out_type);
#if 1
videoout_mode.output_type = HD_COMMON_VIDEO_OUT_LCD;
videoout_mode.input_dim = HD_VIDEOOUT_IN_AUTO;
videoout_mode.output_mode.lcd = HD_VIDEOOUT_LCD_0;
if (out_type != 1) {
printf("520 only support LCD\r\n");
}
#else
switch(out_type){
case 0:
videoout_mode.output_type = HD_COMMON_VIDEO_OUT_CVBS;
videoout_mode.input_dim = HD_VIDEOOUT_IN_AUTO;
videoout_mode.output_mode.cvbs= HD_VIDEOOUT_CVBS_NTSC;
break;
case 1:
videoout_mode.output_type = HD_COMMON_VIDEO_OUT_LCD;
videoout_mode.input_dim = HD_VIDEOOUT_IN_AUTO;
videoout_mode.output_mode.lcd = HD_VIDEOOUT_LCD_0;
break;
case 2:
videoout_mode.output_type = HD_COMMON_VIDEO_OUT_HDMI;
videoout_mode.input_dim = HD_VIDEOOUT_IN_AUTO;
videoout_mode.output_mode.hdmi= hdmi_id;
break;
default:
printf("not support out_type\r\n");
break;
}
#endif
ret = hd_videoout_set(video_out_ctrl, HD_VIDEOOUT_PARAM_MODE, &videoout_mode);
*p_video_out_ctrl=video_out_ctrl ;
return ret;
}
static HD_RESULT get_out_caps(HD_PATH_ID video_out_ctrl,HD_VIDEOOUT_SYSCAPS *p_video_out_syscaps)
{
HD_RESULT ret = HD_OK;
HD_DEVCOUNT video_out_dev = {0};
ret = hd_videoout_get(video_out_ctrl, HD_VIDEOOUT_PARAM_DEVCOUNT, &video_out_dev);
if (ret != HD_OK) {
return ret;
}
printf("##devcount %d\r\n", (int)video_out_dev.max_dev_count);
ret = hd_videoout_get(video_out_ctrl, HD_VIDEOOUT_PARAM_SYSCAPS, p_video_out_syscaps);
if (ret != HD_OK) {
return ret;
}
return ret;
}
static HD_RESULT set_out_param(HD_PATH_ID video_out_path, HD_DIM *p_dim)
{
HD_RESULT ret = HD_OK;
HD_VIDEOOUT_IN video_out_param={0};
video_out_param.dim.w = p_dim->w;
video_out_param.dim.h = p_dim->h;
video_out_param.pxlfmt = HD_VIDEO_PXLFMT_YUV420;
video_out_param.dir = HD_VIDEO_DIR_NONE;
ret = hd_videoout_set(video_out_path, HD_VIDEOOUT_PARAM_IN, &video_out_param);
if (ret != HD_OK) {
return ret;
}
memset((void *)&video_out_param,0,sizeof(HD_VIDEOOUT_IN));
ret = hd_videoout_get(video_out_path, HD_VIDEOOUT_PARAM_IN, &video_out_param);
if (ret != HD_OK) {
return ret;
}
printf("##video_out_param w:%d,h:%d %x %x\r\n", (int)video_out_param.dim.w, (int)video_out_param.dim.h, (int)video_out_param.pxlfmt, (int)video_out_param.dir);
return ret;
}
#endif
///////////////////////////////////////////////////////////////////////////////
typedef struct _VIDEO_LIVEVIEW {
// (1)
HD_VIDEOCAP_SYSCAPS cap_syscaps;
HD_PATH_ID cap_ctrl;
HD_PATH_ID cap_path;
HD_DIM cap_dim;
HD_DIM proc_max_dim;
HD_DIM proc_dim;
// (2)
HD_VIDEOPROC_SYSCAPS proc_syscaps;
HD_PATH_ID proc_ctrl;
HD_PATH_ID proc_path;
HD_DIM out_max_dim;
HD_DIM out_dim;
// (3)
HD_VIDEOOUT_SYSCAPS out_syscaps;
HD_PATH_ID out_ctrl;
HD_PATH_ID out_path;
HD_VIDEOOUT_HDMI_ID hdmi_id;
} VIDEO_LIVEVIEW;
static VIDEO_LIVEVIEW stream[1] = {0}; //0: main stream
static UINT32 out_type = 1;
static void fast_open_sensor(void)
{
#if 0
VENDOR_VIDEOCAP_FAST_OPEN_SENSOR cap_cfg = {0};
snprintf(cap_cfg.sen_cfg.sen_dev.driver_name, HD_VIDEOCAP_SEN_NAME_LEN-1, SEN_DRVIVER_NAME);
cap_cfg.sen_cfg.sen_dev.if_type = SEN_IF_TYPE;
cap_cfg.sen_cfg.sen_dev.pin_cfg.pinmux.sensor_pinmux = SEN_PINMUX;
cap_cfg.sen_cfg.sen_dev.pin_cfg.pinmux.serial_if_pinmux = SERIAL_IF_PINMUX;
cap_cfg.sen_cfg.sen_dev.pin_cfg.pinmux.cmd_if_pinmux = CMD_IF_PINMUX;
cap_cfg.sen_cfg.sen_dev.pin_cfg.clk_lane_sel = CLK_LANE_SEL;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[0] = PIN_MAP_0;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[1] = PIN_MAP_1;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[2] = PIN_MAP_2;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[3] = PIN_MAP_3;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[4] = PIN_MAP_4;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[5] = PIN_MAP_5;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[6] = PIN_MAP_6;
cap_cfg.sen_cfg.sen_dev.pin_cfg.sen_2_serial_pin_map[7] = PIN_MAP_7;
cap_cfg.sen_mode = 0;
cap_cfg.frc = HD_VIDEO_FRC_RATIO(30,1);
#if (AE_PRESET_FUNC == ENABLE)
cap_cfg.ae_preset.enable = TRUE;
get_ae_preset(&cap_cfg.ae_preset.exp_time, &cap_cfg.ae_preset.gain_ratio);
#endif
vendor_videocap_set(0, VENDOR_VIDEOCAP_PARAM_FAST_OPEN_SENSOR, &cap_cfg);
#endif
}
static HD_RESULT init_module_cap_proc(void)
{
HD_RESULT ret;
if ((ret = hd_videocap_init()) != HD_OK)
return ret;
if ((ret = hd_videoproc_init()) != HD_OK)
return ret;
return HD_OK;
}
#if (_PACKAGE_DISPLAY_)
static HD_RESULT init_module_videoout(void)
{
HD_RESULT ret;
if ((ret = hd_videoout_init()) != HD_OK) {
printf("failed to hd_videoout_init:%d\n", ret);
return ret;
}
return HD_OK;
}
#endif
static HD_RESULT open_module_cap_proc(VIDEO_LIVEVIEW *p_stream, HD_DIM* p_proc_max_dim, UINT32 out_type)
{
HD_RESULT ret;
// set videocap config
ret = set_cap_cfg(&p_stream->cap_ctrl);
if (ret != HD_OK) {
printf("set cap-cfg fail=%d\n", ret);
return HD_ERR_NG;
}
// set videoproc config
ret = set_proc_cfg(&p_stream->proc_ctrl, p_proc_max_dim);
if (ret != HD_OK) {
printf("set proc-cfg fail=%d\n", ret);
return HD_ERR_NG;
}
if ((ret = hd_videocap_open(HD_VIDEOCAP_0_IN_0, HD_VIDEOCAP_0_OUT_0, &p_stream->cap_path)) != HD_OK)
return ret;
if ((ret = hd_videoproc_open(HD_VIDEOPROC_0_IN_0, HD_VIDEOPROC_0_OUT_0, &p_stream->proc_path)) != HD_OK)
return ret;
return HD_OK;
}
#if (_PACKAGE_DISPLAY_)
static HD_RESULT open_module_videoout(VIDEO_LIVEVIEW *p_stream, HD_DIM* p_proc_max_dim, UINT32 out_type)
{
HD_RESULT ret;
// set videoout config
ret = set_out_cfg(&p_stream->out_ctrl, out_type,p_stream->hdmi_id);
if (ret != HD_OK) {
printf("set out-cfg fail=%d\n", ret);
return HD_ERR_NG;
}
if ((ret = hd_videoout_open(HD_VIDEOOUT_0_IN_0, HD_VIDEOOUT_0_OUT_0, &p_stream->out_path)) != HD_OK)
return ret;
return HD_OK;
}
#endif
static THREAD_RETTYPE thread_sensor(void *ptr)
{
fastboot_wait_done(BOOT_INIT_SENSOR);
// vos_perf_list_mark("ss", __LINE__, 0);
//quick sensor setup flow
fast_open_sensor();
// vos_perf_list_mark("ss", __LINE__, 1);
vos_flag_set(flag_task, FLAG_SENSOR_TASK_EXIT);
THREAD_RETURN(0);
}
static THREAD_RETTYPE thread_cap_proc(void *ptr)
{
HD_RESULT ret;
UIAPP_PHOTO_SENSOR_INFO *pSensorInfo = UIAppPhoto_get_SensorInfo(0);
ISPT_TOTAL_GAIN total_gain = {0};
// wait sensor setup ready
#if 0
int join_ret;
pthread_t *p_handle_sensor = (pthread_t *)ptr;
int pthread_ret = pthread_join(*p_handle_sensor, (void *)&join_ret);
if (0 != pthread_ret) {
printf("thread_sensor pthread_join failed, ret %d\r\n", pthread_ret);
pthread_exit((void *)-1);
return NULL;
}
#endif
// wait driver init ready
fastboot_wait_done(BOOT_INIT_CAPTURE);
vos_perf_list_mark("capproc", __LINE__, 0);
stream[0].hdmi_id=HD_VIDEOOUT_HDMI_1920X1080I60;//default
// init capture, proc
ret = init_module_cap_proc();
if (ret != HD_OK) {
DBG_ERR("init fail=%d\n", ret);
goto exit;
}
// open capture, proc
stream[0].proc_max_dim.w = pSensorInfo->sSize.w; //assign by user
stream[0].proc_max_dim.h = pSensorInfo->sSize.h; //assign by user
ret = open_module_cap_proc(&stream[0], &stream[0].proc_max_dim, out_type);
if (ret != HD_OK) {
DBG_ERR("open fail=%d\n", ret);
goto exit;
}
// set videocap parameter
stream[0].cap_dim.w = pSensorInfo->sSize.w; //assign by user
stream[0].cap_dim.h = pSensorInfo->sSize.h; //assign by user
ret = set_cap_param(stream[0].cap_path, &stream[0].cap_dim);
if (ret != HD_OK) {
DBG_ERR("set cap fail=%d\n", ret);
goto exit;
}
// set videoproc parameter (main)
#if 0
stream[0].proc_dim.w = LCD_SIZE_W;
stream[0].proc_dim.h = LCD_SIZE_H;
#else
stream[0].proc_dim.w = pSensorInfo->sSize.w;
stream[0].proc_dim.h = pSensorInfo->sSize.h;
#endif
ret = set_proc_param(stream[0].proc_path, &stream[0].proc_dim);
if (ret != HD_OK) {
DBG_ERR("set proc fail=%d\n", ret);
goto exit;
}
// bind video_liveview modules (main)
hd_videocap_bind(HD_VIDEOCAP_0_OUT_0, HD_VIDEOPROC_0_IN_0);
// start video_liveview modules (main)
hd_videocap_start(stream[0].cap_path);
vos_perf_list_mark("capproc", __LINE__, 1);
hd_videoproc_start(stream[0].proc_path);
total_gain.id = 0;
total_gain.gain = preset_param.gain/10;
vendor_isp_set_common(ISPT_ITEM_TOTAL_GAIN, &total_gain);
#if 0
// get first frame
HD_VIDEO_FRAME video_frame = {0};
hd_videoproc_pull_out_buf(stream[0].proc_path, &video_frame, -1);
hd_videoproc_release_out_buf(stream[0].proc_path, &video_frame);
#endif
vos_perf_list_mark("capproc", __LINE__, 2);
exit:
vos_flag_set(flag_task, FLAG_CAP_PROC_TASK_EXIT);
THREAD_RETURN(0);
}
#if (_PACKAGE_DISPLAY_)
static THREAD_RETTYPE thread_videoout(void *ptr)
{
HD_RESULT ret;
UIAPP_PHOTO_SENSOR_INFO *pSensorInfo = UIAppPhoto_get_SensorInfo(0);
fastboot_wait_done(BOOT_INIT_DISPLAY);
vos_perf_list_mark("disp", __LINE__, 0);
// init videoout
ret = init_module_videoout();
if (ret != HD_OK) {
DBG_ERR("init fail=%d\n", ret);
goto exit;
}
// open capture, proc modules (main)
stream[0].proc_max_dim.w = pSensorInfo->sSize.w; //assign by user
stream[0].proc_max_dim.h = pSensorInfo->sSize.h; //assign by user
ret = open_module_videoout(&stream[0], &stream[0].proc_max_dim, out_type);
if (ret != HD_OK) {
DBG_ERR("open fail=%d\n", ret);
goto exit;
}
// get videoout capability
ret = get_out_caps(stream[0].out_ctrl, &stream[0].out_syscaps);
if (ret != HD_OK) {
DBG_ERR("get out-caps fail=%d\n", ret);
goto exit;
}
stream[0].out_max_dim = stream[0].out_syscaps.output_dim;
// set videoout parameter (main)
stream[0].out_dim.w = stream[0].out_max_dim.w; //using device max dim.w
stream[0].out_dim.h = stream[0].out_max_dim.h; //using device max dim.h
ret = set_out_param(stream[0].out_path, &stream[0].out_dim);
if (ret != HD_OK) {
DBG_ERR("set out fail=%d\n", ret);
goto exit;
}
if (hd_videoout_start(stream[0].out_path) != HD_OK) {
DBG_ERR("hd_videoout_start fail\n");
goto exit;
}
vos_perf_list_mark("disp", __LINE__, 1);
exit:
vos_flag_set(flag_task, FLAG_VOUT_TASK_EXIT);
THREAD_RETURN(0);
}
#endif
void flow_preview_get_path(HD_PATH_ID *pPath, FLOW_PREIVEW_PATH PathType, UINT32 id)
{
switch (PathType) {
case FLOW_PREIVEW_VCAP_PATH:
break;
case FLOW_PREIVEW_VPRC_PATH:
*pPath = stream[0].proc_path;
break;
case FLOW_PREIVEW_VOUT_PATH:
*pPath = stream[0].out_path;
break;
case FLOW_PREIVEW_VENC_PATH:
break;
default:
DBG_ERR("No path type is selected\r\n");
break;
}
}
extern void Set_NIGHTMODE(UINT32 id, UINT8 isSnapVideo);
extern void DrvGOIO_Turn_Onoff_IRCUT(UINT8 onoff);
int flow_preview(void)
{
int ret;
// int join_ret;
VK_TASK_HANDLE handle_sensor = 0;
VK_TASK_HANDLE handle_cap_proc = 0;
VK_TASK_HANDLE handle_preview = 0;
// int policy;
PHOTO_SENSOR_INFO sen_cfg = {0};
PHOTO_SENSOR_INFO *pSenCfg = &sen_cfg;
HD_RESULT hd_ret;
// struct sched_param schedparam = {0};
T_CFLG cflg = {0};
FLGPTN flag_ptn;
#if (_PACKAGE_DISPLAY_)
VK_TASK_HANDLE handle_videoout = 0;
#endif
if(!flag_task){
if ((ret = vos_flag_create(&flag_task, &cflg, "flow_preview")) != E_OK) {
DBG_ERR("create flag failed!(%d)\n", ret);
return -1;
}
}
#if HUNTING_CAMERA_MCU == ENABLE
if(sf_is_night_mode(0) !=TRUE)
{
DrvGOIO_Turn_Onoff_IRCUT(1);
}
#else
DrvGOIO_Turn_Onoff_IRCUT(1);
#endif
// quick sensor setup
vos_flag_clr(flag_task, FLAG_SENSOR_TASK_EXIT);
handle_sensor = vos_task_create(thread_sensor, NULL, "init_sensor", 10, DEFAULT_TASK_STACK_SIZE);
if(!handle_sensor){
DBG_ERR("create thread_sensor failed\r\n");
return -1;
}
else
vos_task_resume(handle_sensor);
//hd_common_init(including vds), must wait until insmod_capture()
fastboot_wait_done(BOOT_INIT_CAPTURE);
// init hdal
ret = fastflow_common_init();
if (ret != HD_OK) {
DBG_ERR("init fail\r\n");
}
ret = flowpreview_mem_relayout();
if (ret != HD_OK) {
DBG_ERR("relayout fail\r\n");
}
//load ae/awb/iq
System_GetSensorInfo(0, SENSOR_AE_PATH, &(sen_cfg.ae_path));
System_GetSensorInfo(0, SENSOR_AWB_PATH, &(sen_cfg.awb_path));
System_GetSensorInfo(0, SENSOR_IQ_PATH, &(sen_cfg.iq_path));
System_GetSensorInfo(0, SENSOR_IQ_SHADING_PATH, &(sen_cfg.iq_shading_path));
System_GetSensorInfo(0, SENSOR_IQ_DPC_PATH, &(sen_cfg.iq_dpc_path));
System_GetSensorInfo(0, SENSOR_IQ_LDC_PATH, &(sen_cfg.iq_ldc_path));
if ((hd_ret = vendor_isp_init()) != HD_OK) {
DBG_ERR("vendor_isp_init fail(%d)\n", hd_ret);
}
if (strlen(pSenCfg->ae_path.path) != 0) {
AET_DTSI_INFO ae_dtsi_info;
ae_dtsi_info.id = pSenCfg->ae_path.id;
strncpy(ae_dtsi_info.node_path, pSenCfg->ae_path.path, 31);
strncpy(ae_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
ae_dtsi_info.buf_addr = (UINT8 *)pSenCfg->ae_path.addr;
if ((hd_ret = vendor_isp_set_ae(AET_ITEM_RLD_DTSI, &ae_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_ae fail(%d)\r\n", hd_ret);
}
}
if (strlen(pSenCfg->awb_path.path) != 0) {
AWBT_DTSI_INFO awb_dtsi_info;
awb_dtsi_info.id = pSenCfg->awb_path.id;
strncpy(awb_dtsi_info.node_path, pSenCfg->awb_path.path, 31);
strncpy(awb_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
awb_dtsi_info.buf_addr = (UINT8 *)pSenCfg->awb_path.addr;
if ((hd_ret = vendor_isp_set_awb(AWBT_ITEM_RLD_DTSI, &awb_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_awb fail(%d)\r\n", hd_ret);
}
}
if (strlen(pSenCfg->iq_path.path) != 0) {
IQT_DTSI_INFO iq_dtsi_info;
iq_dtsi_info.id = pSenCfg->iq_path.id;
strncpy(iq_dtsi_info.node_path, pSenCfg->iq_path.path, 31);
strncpy(iq_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
iq_dtsi_info.buf_addr = (UINT8 *)pSenCfg->iq_path.addr;
if ((hd_ret = vendor_isp_set_iq(IQT_ITEM_RLD_DTSI, &iq_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_iq fail(%d)\r\n", hd_ret);
}
}
if (strlen(pSenCfg->iq_shading_path.path) != 0) {
IQT_DTSI_INFO iq_dtsi_info;
iq_dtsi_info.id = pSenCfg->iq_shading_path.id;
strncpy(iq_dtsi_info.node_path, pSenCfg->iq_shading_path.path, 31);
strncpy(iq_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
iq_dtsi_info.buf_addr = (UINT8 *)pSenCfg->iq_shading_path.addr;
if ((hd_ret = vendor_isp_set_iq(IQT_ITEM_RLD_DTSI, &iq_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_iq fail(%d)\r\n", hd_ret);
ret = E_SYS;
}
}
if (strlen(pSenCfg->iq_dpc_path.path) != 0) {
IQT_DTSI_INFO iq_dtsi_info;
iq_dtsi_info.id = pSenCfg->iq_dpc_path.id;
strncpy(iq_dtsi_info.node_path, pSenCfg->iq_dpc_path.path, 31);
strncpy(iq_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
iq_dtsi_info.buf_addr = (UINT8 *)pSenCfg->iq_dpc_path.addr;
if ((hd_ret = vendor_isp_set_iq(IQT_ITEM_RLD_DTSI, &iq_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_iq fail(%d)\r\n", hd_ret);
ret = E_SYS;
}
}
if (strlen(pSenCfg->iq_ldc_path.path) != 0) {
IQT_DTSI_INFO iq_dtsi_info;
iq_dtsi_info.id = pSenCfg->iq_ldc_path.id;
strncpy(iq_dtsi_info.node_path, pSenCfg->iq_ldc_path.path, 31);
strncpy(iq_dtsi_info.file_path, "null", DTSI_NAME_LENGTH);
iq_dtsi_info.buf_addr = (UINT8 *)pSenCfg->iq_ldc_path.addr;
if ((hd_ret = vendor_isp_set_iq(IQT_ITEM_RLD_DTSI, &iq_dtsi_info)) != HD_OK) {
DBG_ERR("vendor_isp_set_iq fail(%d)\r\n", hd_ret);
ret = E_SYS;
}
}
if ((hd_ret = vendor_isp_uninit()) != HD_OK) {
DBG_ERR("vendor_isp_uninit fail(%d)\n", hd_ret);
}
vos_flag_clr(flag_task, FLAG_CAP_PROC_TASK_EXIT);
handle_cap_proc = vos_task_create(thread_cap_proc, NULL, "cap_proc", 10, DEFAULT_TASK_STACK_SIZE);
if(!handle_cap_proc){
DBG_ERR("create thread_cap_proc failed\r\n");
return -1;
}
else
vos_task_resume(handle_cap_proc);
Set_NIGHTMODE(0, 0);
#if (_PACKAGE_DISPLAY_)
vos_flag_clr(flag_task, FLAG_VOUT_TASK_EXIT);
handle_videoout = vos_task_create(thread_videoout, NULL, "vout", 9, DEFAULT_TASK_STACK_SIZE);
if(!handle_videoout){
DBG_ERR("create thread_videoout failed\r\n");
return -1;
}
else
vos_task_resume(handle_videoout);
#endif
vos_flag_wait(&flag_ptn, flag_task, FLAG_CAP_PROC_TASK_EXIT, (TWF_ORW | TWF_CLR));
vos_task_destroy(handle_cap_proc);
#if (_PACKAGE_DISPLAY_)
vos_flag_wait(&flag_ptn, flag_task, FLAG_VOUT_TASK_EXIT, (TWF_ORW | TWF_CLR));
vos_task_destroy(handle_videoout);
#endif
// DrvGOIO_Turn_Onoff_IRCUT(0);
// start video_preview
// nvt_cmdsys_runcmd("nvtmpp info");
vos_flag_clr(flag_task, FLAG_FLOW_PREVIEW_TASK_EXIT);
handle_preview = vos_task_create(PhotoFast_FlowPreviewThread, NULL, "flow_preview", 10, FLOW_PREVIEW_TASK_STACK_SIZE);
if(!handle_preview){
DBG_ERR("create thread_preview failed\r\n");
return -1;
}
else
vos_task_resume(handle_preview);
return 0;
}
void flow_preview_close_module(void)
{
HD_RESULT hd_ret;
hd_ret = hd_videocap_stop(stream[0].cap_path);
if (hd_ret != HD_OK) {
DBG_ERR("vcap stop failed, hd_ret = %d\r\n", hd_ret);
}
hd_ret = hd_videoproc_stop(stream[0].proc_path);
if (hd_ret != HD_OK) {
DBG_ERR("vprc stop failed, hd_ret = %d\r\n", hd_ret);
}
hd_ret = hd_videocap_close(stream[0].cap_path);
if (hd_ret != HD_OK) {
DBG_ERR("vcap close failed, hd_ret = %d\r\n", hd_ret);
}
hd_ret = hd_videoproc_close(stream[0].proc_path);
if (hd_ret != HD_OK) {
DBG_ERR("vprc close failed, hd_ret = %d\r\n", hd_ret);
}
hd_ret = hd_videocap_unbind(HD_VIDEOCAP_0_OUT_0);
if (hd_ret != HD_OK) {
DBG_ERR("vcap unbind failed, hd_ret = %d\r\n", hd_ret);
}
}
void flow_preview_uninit_module(void)
{
HD_RESULT hd_ret;
hd_ret = hd_videocap_uninit();
if (hd_ret != HD_OK) {
DBG_ERR("vcap uninit failed, hd_ret = %d\r\n", hd_ret);
}
hd_ret = hd_videoproc_uninit();
if (hd_ret != HD_OK) {
DBG_ERR("vprc uninit failed, hd_ret = %d\r\n", hd_ret);
}
}
#if 1 //for pre set ae
static UINT32 ae_adc_tbl[57][3] = {
#if 0 //for 200K RSS photodie
{980, 120, 1000},
{970, 250, 1000},//{970, 300, 1000},
{960, 300, 1000},//{960, 500, 1000},
{945, 400, 1000},
{930, 500, 1000},
{910, 600, 1000},
{900, 700, 1000},
{885, 800, 1000},
{870, 1000, 1000},//{870, 2000, 1000},
{850, 1200, 1000},
{840, 2700, 1000},
{832, 4201, 1000},
{820, 5801, 1000},
{816, 7332, 1000},
{810, 8333, 1000},
{805, 8333, 1000},
{800, 8333, 1000},
{787, 25000, 1000},
{750, 25000, 1000},
{723, 25000, 1000},
{671, 33333, 1000},
{641, 33333, 1000},
{600, 16666, 1000},// night
{538, 16666, 1000},
{503, 16666, 1000},
{484, 16666, 1000},
{466, 16666, 1500},
{414, 16666, 1500},
{368, 16666, 1500},
{313, 16666, 2000},
{257, 25000, 2000},
{218, 16666, 2000},
{185, 16666, 2000},//6890
{165, 16666, 2000},
{143, 16666, 2000},//6610
{124, 16666, 2000},//7280
{109, 16666, 2000},//8130
{84, 16666, 2000},//10260
{76, 16666, 2000},
{60, 16666, 2000},
{49, 25000, 2000},
{36, 25000, 2000},//25070
{31, 25000, 2000},
{26, 25000, 2000},//33740},
{19, 25000, 2000},//45740},
{17, 25000, 2000},//48740},
{15, 25000, 2000},//54740},
{13, 25000, 2000},//58740},
{12, 33333, 2000},//61040},
{11, 33333, 2000},//68040},
{10, 33333, 2000},//69920},//
{9, 33333, 2000},//74920},
{8, 33333, 2000},//77740},
{6, 33333, 2000},//83740},
{5, 33333, 2000},//10740},
{2, 33333, 2000},//128000},
{0, 33333, 6000},//128000},
#else // 1K RSS
{980, 120, 1000},
{970, 250, 1000},
{960, 250, 1000},
{945, 250, 1000},
{930, 250, 1000},
{910, 250, 1000},
{900, 250, 1000},
{885, 250, 1000},
{870, 300, 1000},
{850, 300, 1000},
{840, 300, 1000},
{832, 300, 1000},
{820, 300, 1000},
{816, 300, 1000},
{810, 300, 1000},
{805, 400, 1000},
{800, 400, 1000},
{787, 400, 1000},
{750, 400, 1000},
{723, 400, 1000},
{671, 400, 1000},
{641, 500, 1000},
{600, 500, 1000},
{538, 500, 1000},
{503, 500, 1000},
{484, 500, 1000},
{466, 600, 1000},
{414, 600, 1000},
{347, 600, 1000},
{353, 800, 1000},
{330, 800, 1000},
{324, 800, 1000},
{314, 800, 1000},
{306, 900, 1000},
{277, 1000, 1000},
{257, 1200, 1000},
{109, 2700, 1000},
{84, 4201, 1000},
{76, 4201, 1000},// night
{60, 5801, 1000},
{49, 5801, 1000},
{36, 5801, 1000},
{31, 7332, 1000},
{26, 7332, 1000},
{19, 8333, 1000},
{17, 8333, 1000},
{15, 8333, 1000},
{13, 8333, 1000},
{12, 8333, 1000},
{11, 8333, 1000},
{10, 8333, 1000},
{9, 8333, 1000},
{8, 16666, 1000},
{6, 16666, 2000},
{5, 16666, 2000},
{2, 33333, 2000},
{0, 33333, 6000},
#endif
};
void ae_adc_get_exp_photo(UINT16 adc_value, UINT32 *exptime, UINT32 *isogain)
{
UINT32 idx0=0, idx1=0;
UINT32 exptime0, exptime1, isogain0, isogain1;
UINT32 adc_ev, ev0, ev1;
for(idx1=1; idx1<57; idx1++) {
//if(adc_value > ae_adc_tbl[idx1][0])
if(adc_value>=ae_adc_tbl[idx1][0])
{
break;
}
}
if(adc_value>ae_adc_tbl[0][0]) {
*exptime = ae_adc_tbl[0][1];
*isogain = ae_adc_tbl[0][2];
}
else {
idx0 = idx1-1;
exptime0 = ae_adc_tbl[idx0][1];
isogain0 = (ae_adc_tbl[idx0][2]);
exptime1 = ae_adc_tbl[idx1][1];
isogain1 = (ae_adc_tbl[idx1][2]);
ev0 = (exptime0 * isogain0);
ev1 = (exptime1 * isogain1);
adc_ev = ((ev1 - ev0) * (adc_value - ae_adc_tbl[idx1][0]))/(ae_adc_tbl[idx0][0] - ae_adc_tbl[idx1][0]) + ev0;
*exptime = exptime0;
*isogain = (adc_ev / exptime0);
}
DBG_WRN("idx = %d, %d, adc = %d, fast open preset exp = %d, %d\r\n", idx0, idx1, adc_value, *exptime, *isogain);
}
void get_preset_param(void)
{
static BOOL get_preset_flag=FALSE;
UINT32 adc_expt, adc_gain;
if(get_preset_flag==FALSE)
{
ae_adc_get_exp_photo(IRSHTTER, &adc_expt, &adc_gain);
preset_param.expt= adc_expt;
preset_param.gain= adc_gain;
DBG_WRN("adc_value = %d, adc_exp =========== %d, %d\r\n", IRSHTTER, (unsigned int)adc_expt, (unsigned int)adc_gain);
get_preset_flag=TRUE;
}
}
void setet_preset_param(void)
{
AET_STATUS_INFO ae_status_info = {0};
ae_status_info.id = 0;
vendor_isp_get_ae(AET_ITEM_STATUS, &ae_status_info);
DBG_WRN(">> aet status exp %d iso %d\r\n",ae_status_info.status_info.expotime[0],ae_status_info.status_info.iso_gain[0]);
preset_param.expt= ae_status_info.status_info.expotime[0];
preset_param.gain= ae_status_info.status_info.iso_gain[0];
}
#endif