rk3399 mipi camera
Firefly-RK3399 开发板分别带有两个 MIPI,一个 DVP 摄像头接口
rk3399平台可以支持多种不同接口的Camera,如MIPI, DVP, UVC,USB camera
对于DVP,MIPI接口的,是在cam_board.xml文件注册camera,isp控制器接收
对于UVC,USB接口的只要移除此文件就可以,省得再去修改
输出格式:像素低的camera一般用yuv格式,像素高的camera一般用raw格式
官方支持的摄像头列表如下ː
13M:OV13850/IMX214-0AQH5
8M:OV8825/OV8820/OV8858-Z(R1A)/OV8858-R2A
5M:OV5648/OV5640/OV5645
2M:OV2680/OV2685
Android Camera驱动
1.hardware/rockchip/camera/SiliconImage/isi/drv
OVxxxx_MIPI_YUV/source/_PARREL.c 模组驱动文件,根据需求调试
OVxxxx_MIPI_YUV/source/_tables.c 模组初始化数据,需要摄像头原厂支持
OVxxxx_MIPI_YUV/include_priv/_priv.h 模组头文件,定义摄像头ID
OVxxxx_MIPI_YUV/calib/_lens_xxxx.xml raw输出格式,模组tunning参数
2.hardware/rockchip/camera/Config/ user.mk
添加编译规则,将驱动文件编译进系统,生成库文件
ifeq ($(strip $(TARGET_BOARD_PLATFORM)), rk3399)
PRODUCT_PACKAGES += \
libisp_isi_drv_OV2659 \
+ libisp_isi_drv_OVxxxx \
libisp_isi_drv_OV8825 \
libisp_isi_drv_OV8858 \
libisp_isi_drv_GS8604 \
libisp_isi_drv_OV5648 \
libisp_isi_drv_OV5640 \
libisp_isi_drv_OV13850 \
libisp_isi_drv_IMX214 \
libisp_isi_drv_HM2057 \
libisp_isi_drv_HM5040 \
libisp_isi_drv_SP2518 \
libisp_isi_drv_GC0308 \
libisp_isi_drv_GC2035 \
libisp_isi_drv_GC2155 \
libisp_isi_drv_GC2355 \
libisp_isi_drv_NT99252 \
libisp_isi_drv_OV2680 \
libisp_isi_drv_OV5645 \
libisp_isi_drv_TC358749XBG \
libisp_isi_drv_RN6752 \
libisp_isi_drv_OV2685 \
libisp_isi_drv_XC7022 \
libisp_isi_drv_XC6130
endif
out\target\product\rk3399_mid\system\lib\hw\libisp_isi_drv_OVxxxx.so
设备终端可以查看有没有/system/lib/hw/
3.hardware/rockchip/camera/Config/cam_board_rk3399.xml
例举一部分比较重要的参数配置,结合寄存器的值和模组规格书
<Sensor>
<SensorName name="OVxxxx" ></SensorName>
<SensorDevID IDname="CAMSYS_DEVID_SENSOR_1A"></SensorDevID>
<SensorHostDevID busnum="CAMSYS_DEVID_MARVIN" ></SensorHostDevID>
* <SensorI2cBusNum busnum="1"></SensorI2cBusNum>//填写 Sensor 所连接的主控 I2C 通道号
* <SensorI2cAddrByte byte="2"></SensorI2cAddrByte>//填写 Sensor 寄存器地址长度, 单位: Byte
<SensorI2cRate rate="100000"></SensorI2cRate>//I2C 频率
<SensorAvdd name="NC" min="28000000" max="28000000" delay="0"></SensorAvdd>
<SensorDvdd name="NC" min="12000000" max="12000000" delay="0"></SensorDvdd>
<SensorDovdd name="NC" min="18000000" max="18000000" delay="5000"></SensorDovdd>
* <SensorMclk mclk="24000000" delay="1000"></SensorMclk>//Sensor 输入时钟频率
* <SensorGpioPwen ioname="NC" active="1" delay="1000"></SensorGpioPwen>
* <SensorGpioRst ioname="NC" active="1" delay="1000"></SensorGpioRst>
* <SensorGpioPwdn ioname="NC" active="0" delay="2000"></SensorGpioPwdn>
<SensorFacing facing="front"></SensorFacing>
* <SensorInterface interface="MIPI"></SensorInterface>
<SensorMirrorFlip mirror="0"></SensorMirrorFlip>
<SensorOrientation orientation="90"></SensorOrientation>
<SensorPowerupSequence seq="1234"></SensorPowerupSequence>
<SensorFovParemeter h="60.0" v="60.0"></SensorFovParemeter>
<SensorAWB_Frame_Skip fps="15"></SensorAWB_Frame_Skip>
* <SensorPhy phyMode="CamSys_Phy_Mipi" lane="2" phyIndex="1" sensorFmt="CamSys_Fmt_Yuv422_8b"></SensorPhy>
</Sensor>
*<PreviewSize width="640" height="480"></PreviewSize>
<FaceDetect support="0" MaxNum="1"></FaceDetect>
<DV>
<DV_QCIF name="qcif" width="176" height="144" fps="10" support="1"></DV_QCIF>
<DV_QVGA name="qvga" width="320" height="240" fps="10" support="1"></DV_QVGA>
<DV_CIF name="cif" width="352" height="288" fps="10" support="1"></DV_CIF>
<DV_VGA name="480p" width="640" height="480" fps="10" support="1"></DV_VGA>
<DV_480P name="480p" width="720" height="480" fps="10" support="1"></DV_480P>
<DV_576P name="576p" width="720" height="576" fps="10" support="1"></DV_576P>
<DV_720P name="720p" width="1280" height="720" fps="10" support="1"></DV_720P>
<DV_1080P name="1080p" width="1920" height="1080" fps="10" support="1"></DV_1080P>
</DV>
4.将cam_board.xml配置文件编译进开发板
ifeq ($(strip $(TARGET_BOARD_PLATFORM)), rk3399)
PRODUCT_PACKAGES += \
$(MY_ISP_LIB_NAME)
PRODUCT_COPY_FILES += \
hardware/rockchip/camera/Config/cam_board_rk3399.xml:system/etc/cam_board.xml
5.添加好驱动局部编译和更新
hardware/rockchip/camera$ mm
adb root
adb remount
adb push cam_board.xml /system/etc/
adb push camera.rk30board.so libisp_isi_drv_OVxxxx.so /system/lib/hw/
adb shell sync
adb reboot
6.logcat输出日志
rk3399:$ logcat | grep CameraHal
7.调试遇到的问题
(1)I2C通信失败,按照日志信息逐一排查
CameraHal: WARNING: OVxxxx soft reset by i2c failed!, please check follow information:
CameraHal: Slave_addr: 0x5a 0x5a
CameraHal: Soft reset reg: 0x80 val: 0x61
CameraHal: Power/PowerDown/Reset/Mclk/I2cBus
CameraHal: OVxxxx device register failed!
检查I2C是否通信,硬件是否没有问题,示波器量信号,万用表量各引脚供电是否正常,Slave_addr地址是否配错,我是因为这个配错出现这个问题的
(2)驱动读取sensor id与设定默认值不匹配导致驱动注册失败
CameraHal: Check OVxxxx ID: reg: 0xfe val: 0x61 default: 0x05
CameraHal: Check OVxxxx ID: reg: 0xfd val: 0x61 default: 0x01
CameraHal: OVxxxx device register failed
解决方法:在OVxxxx_priv.h这个文件修改sensor id,如果还是有问题,发现val值是Soft_reset_val,那应该注意i2c_adrr_size是单字节还是双字节了
<SensorI2cAddrByte byte="2"></SensorI2cAddrByte> //cam_board.xml
// OVxxxx_PARREL.c
pSensorI2cInfo->i2c_addr = OV13850_SLAVE_ADDR;
pSensorI2cInfo->i2c_addr2 = OV13850_SLAVE_ADDR2;
pSensorI2cInfo->soft_reg_addr = OV13850_SOFTWARE_RST;
pSensorI2cInfo->soft_reg_value = 0x61;
* pSensorI2cInfo->reg_size = 2;// 2 0x300a 1 0xfe
pSensorI2cInfo->value_size = 1;
Linux Camera驱动
1.kernel/drivers/media/i2c/soc_camera/rockchip/ov13850_v4l2-i2c-subdev.c
Makefile和Kconfig添加模组编译规则,.Config所依赖的配置打开,生成二进制文件
2.kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator-linux.dts
&i2c1 {
status = "okay";
camera0: camera-module@2d {
status = "okay";
compatible = "ovti,ovXXXXX-v4l2-i2c-subdev";
reg = < 0x2d >;// Sensor I2C 设备地址
device_type = "v4l2-i2c-subdev";//设备类型
clocks = <&cru SCLK_CIF_OUT>;//sensor clickin 配置
clock-names = "clk_cif_out";
pinctrl-names = "rockchip,camera_default",
"rockchip,camera_sleep";
pinctrl-0 = <&cam0_default_pins>;
pinctrl-1 = <&cam0_sleep_pins>;
rockchip,pwr-gpio = <&gpio2 10 GPIO_ACTIVE_HIGH>;
rockchip,camera-module-mclk-name = "clk_cif_out";//mclk 时钟源配置
rockchip,camera-module-facing = "back";
rockchip,camera-module-name = "cmk-cb0695-fv1";//Camera 模组名称
rockchip,camera-module-len-name = "lg9569a2";//Camera 模组镜头
rockchip,camera-module-fov-h = "133.0";
rockchip,camera-module-fov-v = "100.1";
rockchip,camera-module-orientation = <0>;
rockchip,camera-module-iq-flip = <0>;
rockchip,camera-module-iq-mirror = <0>;
rockchip,camera-module-flip = <0>;
rockchip,camera-module-mirror = <0>;
rockchip,camera-module-defrect0 = <640 480 0 0 640 480>;
rockchip,camera-module-defrect1 = <640 480 0 0 640 480>;
rockchip,camera-module-defrect2 = <640 480 0 0 640 480>;
rockchip,camera-module-defrect3 = <640 480 0 0 640 480>;
rockchip,camera-module-flash-support = <0>;
rockchip,camera-module-mipi-dphy-index = <0>;
};
#配置需要使用的 camera 列表,连接到 ISP 设备节点
&cif_isp0 {
rockchip,camera-modules-attached =
<&camera0 &camera1 &camera2 &camera3 &camera5>;
status = "okay";
};
&isp0_mmu {
status = "okay";
};
根据模组电路图配置对应的GPIO脚,关于驱动是否加载成功,还有设备里有没有检测到这个I2C设备,可以用i2cdetect工具去检测,这样快速方便,还可以用i2cdump去检查寄存器配置的对不对,我这里有写好的脚本可以直接push,有需要的可以联系!