hi3516 camera im178


原文链接: hi3516 camera im178

基于海思HI3559CV100移植IMX178 - mango_yang226的博客 - CSDN博客

主芯片:HI3559CV100

主芯片手册:Hi3559A╱C V100 ultra-HD Mobile Camera SoC 用户指南.pdf

主芯片MPP手册:HiMPP V4_Password_Removed.pdf

SENSOR:IMX178

SENSOR手册:IMX178LQJ-C_Data_Sheet.pdf

SDK:Hi3559AV100R001C02SPC010


IMX178的移植,主要涉及SENSOR端寄存器的配置、主芯片端VI各模块的配置,本文主要基于这两点进行移植过程的描述,其他功能模调用、PINMUX配置、驱动调用、Makefile修改等,可参考IMX334。

IMX178调试

根据SDK中的IMX334,首先拷贝sony_imx334文件夹,重命名为sony_imx178,并将所有334相关字段全部改为178

sony_imx178文件夹中主要包含imx178_cmos.c(图像质量相关)、imx178_sensor_ctl.c(寄存器配置相关),IMX178的调试主要包括I2C调试和寄存器配置,主要集中在imx178_sensor_ctl.c文件中

IMX178的I2C调试

参考IMX178手册,获取I2C Slave Address为0x34,Slave Address长度为8bit,Register Address长度为16比特,高位在前、低位在后

I2C写寄存器写入方式如下

int imx178_write_register(VI_PIPE ViPipe, int addr, int data){    if (0 > g_fd[ViPipe])    {        return HI_SUCCESS;    }     int idx = 0;    int ret;    char buf[8];     if (imx178_addr_byte == 2)    {        buf[idx] = (addr >> 8) & 0xff;        idx++;        buf[idx] = addr & 0xff;        idx++;    }    else    {        buf[idx] = addr & 0xff;        idx++;    }     if (imx178_data_byte == 2)    {        buf[idx] = (data >> 8) & 0xff;        idx++;        buf[idx] = data & 0xff;        idx++;    }    else    {        buf[idx] = data & 0xff;        idx++;    }     ret = write(g_fd[ViPipe], buf, (imx178_addr_byte + imx178_data_byte));    if (ret < 0)    {        ISP_TRACE(HI_DBG_ERR, "I2C_WRITE DATA error!\n");        return HI_FAILURE;    }     return HI_SUCCESS;}

IMX178的寄存器配置

参考IMX178手册,将SENSOR配置为1080P60、12bit位宽、4通道,INCK选择27MHz模式

寄存器配置代码片段如下

void imx178_linear_1080P60_12bit_init(VI_PIPE ViPipe){    /* imx178 1080@60fps */    imx178_write_register(ViPipe, 0x3000, 0x07); /* standby */     imx178_write_register(ViPipe, 0x300E, 0x01); /* MODE, Window cropping 5.0M (4:3) */    imx178_write_register(ViPipe, 0x300F, 0x00); /* WINMODE, Window cropping 5.0M (4:3) */    imx178_write_register(ViPipe, 0x3010, 0x00); /* TCYCLE */    imx178_write_register(ViPipe, 0x3066, 0x03); /* VNDMY */    imx178_write_register(ViPipe, 0x302C, 0x72);    imx178_write_register(ViPipe, 0x302D, 0x06); /* VMAX */    imx178_write_register(ViPipe, 0x302F, 0xEE);    imx178_write_register(ViPipe, 0x3030, 0x02); /* HMAX */    imx178_write_register(ViPipe, 0x300D, 0x05); /* ADBIT, ADBITFREQ  (ADC 12-bit) */    imx178_write_register(ViPipe, 0x3059, 0x31); /* ODBIT, OPORTSEL   (12-BIT), 4CH */    imx178_write_register(ViPipe, 0x3004, 0x03); /* STBLVDS, 4CH ACTIVE */     /* register setting details */    imx178_write_register(ViPipe, 0x3101, 0x30); /* FREQ[1:0] */     /* FREQ setting (INCK=27MHz) */    imx178_write_register(ViPipe, 0x310C, 0x00);    imx178_write_register(ViPipe, 0x33BE, 0x21);    imx178_write_register(ViPipe, 0x33BF, 0x21);    imx178_write_register(ViPipe, 0x33C0, 0x2C);    imx178_write_register(ViPipe, 0x33C1, 0x2C);    imx178_write_register(ViPipe, 0x33C2, 0x21);    imx178_write_register(ViPipe, 0x33C3, 0x2C);    imx178_write_register(ViPipe, 0x33C4, 0x2C);    imx178_write_register(ViPipe, 0x33C5, 0x00);    imx178_write_register(ViPipe, 0x311C, 0x34);    ...}

HI3559主芯片配置

主芯片调试主要分为MIPI_Rx配置、VI配置、ISP配置

MIPI_RX配置

查看SENSOR手册,确认SENSOR图像输出信号为LVDS

◆ Supports I/O switching
Low voltage LVDS (150 mVp-p) serial (4 ch / 8 ch / 10 ch switching) DDR output

查看主芯片手册,确认MIPI_Rx支持LVDS信号,将视频输入接口配置为LVDS即可

MIPI Rx 支持 MIPI D-PHY 、 LVDS ( Low-Voltage Differential Signal )、 HiSPi ( High-Speed Serial Pixel Interface )等串行视频信号输入,串行视频接口可以提供更高的传输带宽,增强传输的稳定性。

mpp/sample/common/sample_comm_vi.c文件中,配置MIPI_RX的combo-PHY属性为LVDS、12bit位宽、4通道、分辨率1920*1080

combo_dev_attr_t LVDS_4lane_SENSOR_IMX178_12BIT_1080p_ATTR ={    /* input mode */	.devno = 0,    .input_mode = INPUT_MODE_LVDS,    .data_rate = MIPI_DATA_RATE_X1,    .img_rect = {0, 0, 1920, 1080},    {        .lvds_attr = {        	DATA_TYPE_RAW_12BIT,            HI_WDR_MODE_NONE,             LVDS_SYNC_MODE_SAV,			.vsync_attr = {LVDS_VSYNC_NORMAL, 0, 0},			.fid_attr = {LVDS_FID_NONE, HI_TRUE},             LVDS_ENDIAN_BIG,            LVDS_ENDIAN_BIG,            .lane_id = {0, 1, 2, 3, -1, -1, -1, -1},            .sync_code = {                    {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}},                     {{0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0},                    {0xab0, 0xb60, 0x800, 0x9d0}}                }        }    }};

drv/interdrv/sysconfig/sys_config.c文件中,配置bus_type为I2C、配置输出给SENSOR的参考时钟为24MHz

备注:按手册将参考时钟配置为27MHz时,SENSOR输出帧率为77FPS,而参考时钟配置为24MHz时,SENSOR输出帧率为58FPS,因此配置为24MHz

static BUS_TYPE parse_sensor_bus_type(char *name){    ...    bus_type = BUS_TYPE_I2C;    ...    return bus_type;}
/*0x0: 74.25MHz; 0x1: 72MHz;0x2: 54MHz;0x3: 50MHz;0x4: 24MHz;0x6: 32.4MHz;0x8: 37.125MHz;0x9: 36MHz;0xA: 27MHz;0xB: 25MHz;0xC: 12MHz;*/static int parse_sensor_clock(char *name){    int clock = 0x0;    ...    clock = 0x4;	// 24MHZ    ...    return clock;}

drv/interdrv/mipi/hi_mipi.h文件中,修改LVDS最大支持4通道

#define MAX_LANE_NUM_PER_LINK   2  /* one link has 2 lanes at most */...#define LVDS_LANE_NUM           (MAX_LANE_NUM_PER_LINK * 4)

VI配置

mpp/sample/common/sample_comm_vi.c中修改VI相关配置

VI DEV配置,主要配置输入接口LVDS、掩码0xFFF00000、图像格式RGB、分辨率1920*1080

VI_DEV_ATTR_S DEV_ATTR_IMX178_LVDS_BASE ={    /* interface mode */    VI_MODE_LVDS,    /* multiplex mode */    VI_WORK_MODE_1Multiplex,    /* r_mask    g_mask    b_mask*/    {0xFFF00000,    0x0},    /* progessive or interleaving */    VI_SCAN_PROGRESSIVE,    /*AdChnId*/    {-1, -1, -1, -1},    /*enDataSeq, only support yuv*/	VI_DATA_SEQ_YUYV,     /* synchronization information */    {    /*port_vsync   port_vsync_neg     port_hsync        port_hsync_neg        */    VI_VSYNC_PULSE, VI_VSYNC_NEG_LOW, VI_HSYNC_VALID_SINGNAL,VI_HSYNC_NEG_HIGH,VI_VSYNC_VALID_SINGAL,VI_VSYNC_VALID_NEG_HIGH,     /*hsync_hfb    hsync_act    hsync_hhb*/    {0,            1280,        0,    /*vsync0_vhb vsync0_act vsync0_hhb*/     0,            720,        0,    /*vsync1_vhb vsync1_act vsync1_hhb*/     0,            0,            0}    },    /* input data type */    VI_DATA_TYPE_RGB,    /* bRever */    HI_FALSE,    {1920 , 1080},    {        {            {1920 , 1080},        },        {            VI_REPHASE_MODE_NONE,            VI_REPHASE_MODE_NONE        }    },    {        WDR_MODE_NONE,		1080    },    DATA_RATE_X1};

DEV需要注意掩码的配置,根据芯片手册,12bit位宽,掩码为0xFFF00000,掩码如果配置不对,会导致VI采集失败

VI PIPE配置

VI_PIPE_ATTR_S PIPE_ATTR_1920x1080_RAW12_420_3DNR_RFR ={    VI_PIPE_BYPASS_NONE, HI_FALSE, HI_FALSE,    1920, 1080,	PIXEL_FORMAT_RGB_BAYER_12BPP,	COMPRESS_MODE_LINE,	DATA_BITWIDTH_12,	HI_FALSE,    {    	PIXEL_FORMAT_YVU_SEMIPLANAR_420,        DATA_BITWIDTH_10,        VI_NR_REF_FROM_RFR,        COMPRESS_MODE_NONE    },    HI_FALSE,    { -1, -1}};

VI CHN配置

VI_CHN_ATTR_S CHN_ATTR_1920x1080_420_SDR8_LINEAR ={    {1920, 1080},	PIXEL_FORMAT_YVU_SEMIPLANAR_420,	DYNAMIC_RANGE_SDR8,    VIDEO_FORMAT_LINEAR,    COMPRESS_MODE_NONE,    0,      0,    0,    { -1, -1}};

ISP配置

mpp/sample/common/sample_comm_isp.c中修改ISP相关配置

ISP_PUB_ATTR_S ISP_PUB_ATTR_IMX178_2K_60FPS ={    {0, 0, 1920, 1080},    {1920, 1080},    60,	BAYER_GBRG,    WDR_MODE_NONE,    0,};

需要注意BAYER_FORMAT,这里配置为BAYER_GBRG,如果配置不对,会导致采集到的图像颜色异常

至此,IMX178的移植相关配置已全部完成。

`