Files
TAIXIN/sdk/lib/bus/iic/sensor/sensor_h62.c

355 lines
14 KiB
C
Raw Permalink Normal View History

#include "sys_config.h"
#include "typesdef.h"
#include "lib/video/dvp/cmos_sensor/csi.h"
#include "tx_platform.h"
#include "list.h"
#include "dev.h"
#include "hal/isp.h"
#if DEV_SENSOR_H62
SENSOR_INIT_SECTION const unsigned char H62InitTable[CMOS_INIT_LEN]=
{
0x12,0x40,
0x0C,0x00,
0x0D,0x58,
0x0E,0x17,
0x0F,0x06,
0x10,0x20,
0x11,0x80, //*/
/*0x12,0x40,
0x0E,0x11,
0x0F,0x09,
0x10,0x24,
0x11,0x80,//*/
//0x20,0x40,//;60
//0x21,0x0b,//;09
//0x22,0xee,
//0x23,0x02,
0x20,0x90,//;60
0x21,0x09,//;09
0x22,0x20,
0x23,0x03,
#if 0
0x24,0x05, //Сģ×é 0x04
//0x25,0xD0,
0x25,0xd4,
0x26,0x25,
0x27,0xd2,
0x28,0x15,
//0x29,0x02,
0x29,0x02,
#else
#if 0
//0x24,0x04,
//0x25,0xd4,
//0x26,0x25,
#else
0x24,0x00,
0x25,0xd0,
0x26,0x25,
#endif
0x27,0xd4,
0x28,0x15,
0x29,0x02,//*///
#endif
0x2A,0x63,
0x2B,0x21,
0x2C,0x08,
0x2D,0x01,
0x2E,0xBC,
0x2F,0xC0,
0x30,0x98,
0x31,0x0C,
0x32,0xF0,
0x33,0x4C,
0x34,0x2F,
0x35,0xA3,
0x36,0x05,
0x38,0x53,
0x39,0x94,
0x3A,0x08,
0x41,0x88,
0x42,0x12,
0x46,0xC2,
0x48,0x7E,
0x60,0x03,
0x62,0x40,
0x63,0x80,
0x66,0x28,
0x67,0xf8,
0x68,0x04,
0x69,0x74,
0x6A,0x30,
0x59,0x9C,
0x6C,0xC0,
0x6E,0x5C,
0x56,0x02,
0x57,0x80,
0x58,0x33,
0x5a,0x04,
0x5b,0xB6,
0x5c,0x08,
0x5d,0x67,
0x5e,0x04,
0x5f,0x08,
0x7D,0x57,
0x7E,0x28,
0x80,0x00,
0x1D,0xFF,
0x1E,0x1F,
//0x4A,0x05,
0x4A,0x05,
0x4C,0x08,
0x4D,0x08,
0x49,0x08,
//0x13,0x81,
0x13,0x81,
0x12,0x00,
0x47,0x47,
//sleep 500
0x47,0x44,
0x1F,0x01,
// 0x02,0x03,
// 0x01,0x20,
// 0x00,0x10,
0x02,0x01,
0x01,0x40,
0x00,0x00,
0x19,0x68,
0xff,0xff//
};
const _Sensor_CCM h62_ccm_init =
{
// 5500k, gamma2p2
0x209, 0xf8b, 0xfe7,
0xf0d, 0x1d7, 0xf0c,
0xfe8, 0xf9a, 0x1f6,
0xffb, 0xffd, 0xffb,
};
const _Sensor_BLC h62_blc_init =
{
25, 25, 24, 23,
};
const _Sensor_AWB h62_awb_init =
{
// r, gr, gb, b
454, 256, 256, 466, // default
306, 256, 256, 466, // min
454, 256, 256, 644, // max
};
const _Sensor_AE h62_ae_init =
{
.max_analog_gain = 32<<8,
.min_analog_gain = 1<<8,
.default_exposure_line = 0x320,
.max_exposure_line = 900,
.min_exposure_line = 10,
.row_time_us = 2448/24,
.expo_frame_interval = 2,
};
const _Sensor_CSUPP h62_csupp_init = {
// u8 U_luma_thr_lo, U_luma_slop_lo, U_luma_shfb_lo, U_luma_gmin_lo,
// u8 U_luma_thr_hi, U_luma_slop_hi, U_luma_shfb_hi, U_luma_gmin_hi,
// u8 V_luma_thr_lo, V_luma_slop_lo, V_luma_shfb_lo, V_luma_gmin_lo,
// u8 V_luma_thr_hi, V_luma_slop_hi, V_luma_shfb_hi, V_luma_gmin_hi,
// u8 chroma_thr_lo, chroma_slop_lo, chroma_shfb_lo, chroma_gmin_lo,
31, 4, 0, 0,
209, 4, 0, 0,
31, 4, 0, 0,
209, 4, 0, 0,
31, 4, 0, 0,
};
const _Sensor_SHARP h62_sharp_init = {
255 , //smooth_filt_alpha
0 , //shrink_thr
127 , //filt_clip_hi
127 , //filt_clip_lo
10 , //sp_thr2
5 , //sp_thr1
15 , //enha_clip_hi
25 , //enha_clip_lo
5 ,10 ,15 ,//e1,e2,e3
0 ,64 ,128 ,128 ,//k0,k1,k2,k3
0 ,10 ,30 ,//y1,y2,y3
3 ,4 ,5 , //filt_w11,filt_w12,filt_w13
4 ,6 ,7 , //filt_w21,filt_w22,filt_w23
5 ,7 ,12 , //filt_w31,filt_w32,filt_w33
1 , //filt_type
7 , //filt_sbit
0 , // lpf scale
};
const _Sensor_YUVNR h62_yuvnr_init = {
20,20,20,20,20,20,20,20,
205,255,0,
};
const _Sensor_COLENH h62_colenh_init = {
50,
50,
50,
0,
0,128,128,
0,128,128,
};
const _Sensor_BV2NR h62_bv2nr_init[BV2RAWNR_ARRAY_NUM] = {
// ev, bnr_range_weight_index, bnr_invksigma, bnr_intensity_threshold, yuvnr_idx, csupp_idx
{ 46, 14, 511, 45, 0, 0}, // 646lux
{ 124, 14, 407, 45, 0, 0}, // 240lux
{ 1469, 14, 407, 45, 0, 0}, // 20lux
{ 2959, 14, 244, 45, 0, 0}, // 10lux
{ 5906, 16, 244, 45, 1, 0}, // 5p03lux
{ 11864, 16, 122, 35, 2, 1}, // 2p5lux
{ 23752, 16, 81, 35, 2, 1}, // 1p25lux
{ 47277, 18, 48, 35, 3, 1}, // 0p62lux
{ 94554, 18, 48, 35, 3, 1}, // 0p31lux
{ 283662, 18, 48, 35, 4, 1}, // 0p1lux
{ 2836620, 31, 40, 35, 5, 1}, // 0p01lux
};
const uint32 h62_lsc_tbl[] = {
//R channel
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
//GR channel
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
//GB channel
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
//B channel
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,0x00040100,
};
const _Sensor_LSC h62_lsc_init = {
.p_lsc_tbl = (uint32 *)h62_lsc_tbl,
};
void h62_ae_adjust(struct isp_exposure_opt *p_cfg)
{
uint8 gain_segment[] = {1, 2, 4, 8, 16, 32};
uint8 sensor_gain_part1 = 0;
uint8 i = 0;
uint8 sensor_gain_reg = 0;
uint8 analog_gain = p_cfg->analog_gain>>8;
uint16 sensor_gain_part2 = 0;
uint32 exposure_line = p_cfg->exposure_line;
uint8 *addr = (uint8 *)p_cfg->data.addr;
// convert the analog gain to match the SFR configure value of H62
for(i=0;i<5;i++){
// note: ae_param->analog_gain is UQ16.8
if(analog_gain < gain_segment[i+1]){
sensor_gain_part1 = i;
break;
}
}
sensor_gain_part2 = (((ae_param->analog_gain >> sensor_gain_part1) - 256) >> 4) & 0x0f;
sensor_gain_reg = (sensor_gain_part1 << 4) | sensor_gain_part2;
i = 0;
addr[i++] = 0x02;
addr[i++] = (exposure_line >> 8) & 0xff;
addr[i++] = 0x01;
addr[i++] = exposure_line & 0xff;
addr[i++] = 0x00;
addr[i++] = sensor_gain_reg;
p_cfg->data.size = i;
p_cfg->cmd_len = 1+1;
}
SENSOR_OP_SECTION const _Sensor_Adpt_ h62_cmd=
{
.typ = 1, //YUV
.pixelw = 1280,
.pixelh= 720,
.hsyn = 1,
.vsyn = 0,
.rduline = 0,//
.rawwide = 1,//10bit
.colrarray = 2,//0:_RGRG_ 1:_GRGR_,2:_BGBG_,3:_GBGB_
.init = (uint8 *)H62InitTable,
.init_len = sizeof(H62InitTable),
.rotate_adapt = {0},
.hvb_adapt = {0x80,0x0a,0x80,0x0a},
.mclk = 20000000,
.p_fun_adapt = {NULL,NULL,NULL},
};
const _Sensor_Ident_ h62_init=
{
0x62,0x60,0x61,0x01,0x01,0x0b
};
const _Sensor_ISP_Init h62_isp_init =
{
.type = ISP_INPUT_DAT_SRC_DVP,
.pixel_h = 720,
.pixel_w = 1280,
.bayer_patten = ISP_BAYER_FORMAT_BGGR,
.input_format = ISP_INPUT_DAT_FORMAT_RAW10,
.adjust_func = (isp_ae_func )h62_ae_adjust,
.p_adpt = (_Sensor_Adpt_ *)&h62_cmd,
.p_ident = (_Sensor_Ident_ *)&h62_init,
.p_blc = (_Sensor_BLC *)&h62_blc_init,
.p_ccm = (_Sensor_CCM *)&h62_ccm_init,
.p_awb = (_Sensor_AWB *)&h62_awb_init,
.p_ae = (_Sensor_AE *)&h62_ae_init,
.p_csupp = (_Sensor_CSUPP *)&h62_csupp_init,
.p_sharp = (_Sensor_SHARP *)&h62_sharp_init,
.p_yuvnr = (_Sensor_YUVNR *)&h62_yuvnr_init,
.p_colenh = (_Sensor_COLENH *)&h62_colenh_init,
.p_bv2nr = (_Sensor_BV2NR *)h62_bv2nr_init,
.p_lsc = (_Sensor_LSC *)&h62_lsc_init,
};
#endif