1、 Amba A12 平台 Sensor ov4689 驱动 简介 以及 Ti DS90UB949、 940 MiPi 评审 DVR 汤聪 2017/06/13 目录 Sensor ov4689 成像原理 2 一、 Sensor ov4689 文件建立与编译 3 二、 Sensor ov4689 原理图 3 三、 Sensor ov4689 底层驱动 3 四、 Sensor ov4689 i2c 读写 4 五、 Sensor ov4689 驱动框架分析 5 六、 Sensor ov4689 各时钟关系: 6 七、 Ti DS90UB940 i2c 读写 . 6 八、 Ti DS90UB949、
2、940 MiPi 各时钟关系: . 7 九、 Sensor ov4689 总结 : . 8 Sensor ov4689 成像原理 景物通过镜头( LENS) 和 ir-cut 过滤后 生成的光学图像投射到图像传感器 (Sensor)表面上,然后转为模拟的电信号,经过 A/D(模数转换)转换后变为数字图像信号,再送到数字信号处理芯片( DSP)中加工处理, (一小部分像素用来校正和插值) 再通过 IO 接口传输到 CPU 中处理,通过 LCD 看到图像 。 ( 所以单反等高精密设备最好不要经过地铁的安检 x 光射线) 一 、 Sensor ov4689 文件建立与编译 驱动 文件 路径 : rt
3、osperipheralsensor 相关驱动: AmbaSensor_OV4689Table.c、 AmbaSensor_OV4689.c、 AmbaSensor_OV4689.h AmbaSensor.c 等 添加 kconfig 选项 config SENSOR_OV4689 bool “OmniVision OV4689“ default n Sensor ov4689 编译: ifdef CONFIG_SENSOR_OV4689 libperipheral-objs += $(VINPATH)/AmbaSensor_OV4689.o $(VINPATH)/AmbaSensor_OV4
4、689Table.o $(VINPATH)/AmbaCalibInfo_OV4689.o endif 二 、 Sensor ov4689 原理图 见产品硬件原理图 三、 Sensor ov4689 底层驱动 Sensor ov4689 驱动 配置 : AMBA_SENSOR_OBJ_s AmbaSensor_OV4689Obj = .Init = OV4689_Init, .Enable = OV4689_Enable, .Disable = OV4689_Disable, .Config = OV4689_Config, .GetStatus = OV4689_GetStatus, .Get
5、ModeInfo = OV4689_GetModeInfo, .GetDeviceInfo = OV4689_GetDeviceInfo, .GetCurrentGainFactor = OV4689_GetCurrentGainFactor, .GetCurrentShutterSpeed = OV4689_GetCurrentShutterSpeed, .GetHdrInfo = OV4689_GetHdrInfo, .ConvertGainFactor = OV4689_ConvertGainFactor, .ConvertShutterSpeed = OV4689_ConvertShu
6、tterSpeed, .SetAnalogGainCtrl = OV4689_SetAnalogGainCtrl, .SetDigitalGainCtrl = OV4689_SetDigitalGainCtrl, .SetShutterCtrl = OV4689_SetShutterCtrl, .SetHdrAnalogGainCtrl = OV4689_SetHdrAnalogGainCtrl, .SetHdrDigitalGainCtrl = OV4689_SetHdrDigitalGainCtrl, .SetHdrShutterCtrl = OV4689_SetHdrShutterCtr
7、l, .SetSlowShutterCtrl = OV4689_SetSlowShutterCtrl, .RegisterRead = OV4689_RegisterRead, .RegisterWrite = OV4689_RegisterWrite, ; 注册服务: int AppSensor_register_ov4689_a12(void) APPLIB_SENSOR_s Dev = 0; char DevName = o,v,4,6,8,9,_,a,1,2,0; Dev.ID = 0; strcpy(Dev.Name, DevName); Dev.SysCapacity = SENS
8、OR_SYS_NTSC | SENSOR_SYS_PAL; Dev.DzoomCapacity = 0; Dev.Rotate = SENSOR_ROTATE_0; Dev.VideoResNum = sensor_video_res_table_size; Dev.PjpegConfigNormalNum = PHOTO_CONFIG_NORMAL_TABLE_SIZE; Dev.PjpegConfigCollageNum = 0; Dev.PjpegConfigBurstNum = PHOTO_CONFIG_BURST_TABLE_SIZE; Dev.PhotoMaxVcapWidth =
9、 800; Dev.PhotoMaxVcapHeight = 517; Dev.PhotoMaxEncWeight = 800; Dev.PhotoMaxEncHeight = 517; Dev.PhotoMaxPrevWidth = 1920; Dev.PhotoMaxPrevHeight = 1080; Dev.Init = sensor_ov4689_a12_init; Dev.GetVideoResID = sensor_ov4689_a12_get_videoResID; 详细见代码。 四、 Sensor ov4689 i2c 读写 Sensor ov4689 I2c 读写详细见代码
10、 Ov 4689 通过 i2c 寄存器控制的有: 1. 图像的反转映像等: 2. 控制 mipi 接口的 lane 数 ,输出 mipi 数据格式 3. 控制 mclk 分频。 4. 配置测试模式图像输出 5. Gain and exposure control 五 、 Sensor ov4689 驱动框架分析 基于 Amba A12 Audio 框架分析 : Application Middle Driver AMBA_SENSOR_OBJ_s AmbaSensor_OV4689Obj = .Init = OV4689_Init, .Enable = OV4689_Enable, .Disa
11、ble = OV4689_Disable, .Config = OV4689_Config, .GetStatus = OV4689_GetStatus, .GetModeInfo = OV4689_GetModeInfo, .GetDeviceInfo = OV4689_GetDeviceInfo, int AppSensor_register_ov4689_a12(void) APPLIB_SENSOR_s Dev = 0; Char DevName = o,v,4,6,8,9,_,a,1,2,0; Dev.ID = 0; strcpy(Dev.Name, DevName); Dev.Sy
12、sCapacity = SENSOR_SYS_NTSC | SENSOR_SYS_PAL; Dev.DzoomCapacity = 0; Dev.Rotate = SENSOR_ROTATE_0; 上层调用: ApplibSys_Sensor.c AmbaSensor.h ApplibCalibBpc.c ApplibRecorder_StillEncUtility.c Appmaintask.c 加载 AmbaSensor_Hook(AppEncChannel, AmbaCalibInfo_Hook(AppEncChannel, ReturnValue = 0; #endif Handler
13、.c 注册 AppSensor_register_ov4689_a12(void) AppIQParamOv4689_A12_Register(UINT32 chNo); AmbaIQParamOv4689Hdr_A12_Register(UINT32 chNo); 六 、 Sensor ov4689 各时钟关系 : Mclk : 24Mhz Mipi clk: 依据分辨率 和 mode Mclk 来决定 SCLK: 支持 高 中 低速 , 10-126M 七、 Ti DS90UB940 i2c 读写 I2C 读: static int OV4689_RegRead(UINT16 Addr,
14、UINT8 *pRxData) UINT16 pTxData4; MY_TRACE_LINE; pTxData0 = AMBA_I2C_RESTART_FLAG | (0x58); pTxData1 = Addr; pTxData2 = AMBA_I2C_RESTART_FLAG | (0x59); return AmbaI2C_ReadAfterWrite(AMBA_I2C_CHANNEL0, AMBA_I2C_SPEED_FAST, 3, (UINT16 *) pTxData, 1, pRxData, AMBA_KAL_WAIT_FOREVER); I2C 写 : static int O
15、V4689_RegWrite(UINT16 Addr, UINT8 Data) UINT8 TxDataBuf3; TxDataBuf0 = (UINT8) (Addr TxDataBuf1 = Data; if (AmbaI2C_Write(AMBA_I2C_CHANNEL0, AMBA_I2C_SPEED_FAST, 0x58, 2, TxDataBuf, AMBA_KAL_WAIT_FOREVER) = NG) AmbaPrint(“I2C does not work!“); AmbaPrint(“Addr = 0x%02x, Data = 0x%02x“, Addr, Data); M
16、Y_TRACE_LINE; return OK; 八 、 Ti DS90UB949、 940 MiPi 各时钟关系: 使用 1 lane FPD-Link III Input, 4 MIPI lanes Output: Data rate: 175Mbps PCLK:25MHZ CSI0_D0 Rin0 CSI0_D1 CSI0_D2 Rin1 CSI0_D3 CSI0_CLK Mipi clk: 87.5MHZ DATA rate = PCLK *7 Mipi clk = PCLK*3.5 DATA rate = Mipi clk *2(mipi协议上升沿下降沿都传输数据 ) DS90UB9
17、49 DS90UB940 DS90UB940 与 A12 mipi 参数匹配: DS90UB940 A12 九 、 Sensor ov4689 总结 : 1.检查几组电源是否正常供应。 2.调试 I2C 通讯: 注意排除 i2c 总线上的其它设备干扰 、 确认 i2c 地址是否正确 、 硬件上 i2c 是否需滤波和上拉 (两端电平是否匹配) ,示波器测量时钟是否正常, 从机是否有 ACK 回应(第九 bit 低电平表示应答 ok,高电平表示无应答) 最后检查 i2c 数据是否与波形一致。 3. mipi 调试还在进行中。 LANE:4 Resolution: 800x525( 640x480)
18、 Frame rate:: 60fps PCLK:25Mhz Mipi 时钟: 87.5Mhz Mipi 数据格式: RAW10 DATA Rate: 175Mbps Pixel rate: 70000000 pixel/sec .MipiCtrl .HsSettleTime = 120, .HsTermTime = 48, .ClkSettleTime = 95, .ClkTermTime = 38, .ClkMissTime = 60, .RxInitTime = 200, LANE:4 Resolution: 800x525( 640x480) Frame rate:: 60fps Mipi 时钟: 87.5Mhz Mipi 数据格式: RAW10 DATA Rate: 175Mbps Pixel rate: 70000000 pixel/sec .MipiCtrl .HsSettleTime = 120, .HsTermTime = 48, .ClkSettleTime = 95, .ClkTermTime = 38, .ClkMissTime = 60, .RxInitTime = 200,