本文主要是介绍基于RK3399 Android11适配OV13850 MIPI摄像头,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 1、原理图分析
- 2、编写和配置设备树
- 3、调试方法
- 4、遇到的问题与解决
- 5、补丁
1、原理图分析
从上图可看出,我们需要关心的,①MIPI数据和时钟接口使用的是MIPI_TX1/RX1 ②I2C使用的是I2C4总线 ③RST复位引脚使用的是GPIO2_D2 ④PWDN使用的是GPIO1_C7 ⑤MCLK使用的是GPIO3_B7 ⑥需要保证红色框框的供电电源正常。
结合RK提供的文档,如下摄像头数据采集拓扑图所示,我们就可以开始编写配置设备树了,其实官方提供了很多类似的设备树配置给我们参考的。
2、编写和配置设备树
①配置OV13850设备树节点Ⅰ
②配置OV13850设备树节点Ⅱ 提示:下图复用功能是<. RK_PB7 3 &pcfg_pull_one>;
③配置dphy
④配置isp
3、调试方法
①移植成功后,使用dmesg指令查看对应驱动的log
②驱动加载成功后,会有生成以下的摄像头设备节点
③RKISP 驱动如果加载成功,会有 video 及 media 设备存在于/dev/目录下。系统中可能存在 多个/dev/video 设备,通过/sys 可以查询到 RKISP 注册的 video 节点
④查看拓扑结构
Ⅰ、通过media-ctl -p 查看rkisp1_selfpath 信息,可以知道打开哪些media设备
Ⅱ、再通过media-ctl -p /dev/media0 查看已打开的media设备的拓扑,下图是截取了一部分信息
⑤查看摄像头支持哪几种图像流格式,截图省略
指令:v4l2-ctl -d /dev/video0 --list-formats
⑥查看调试上层相关信息,截图省略
指令:dumpsys media.camera
⑦抓图
指令:v4l2-ctl -d /dev/video0 --set-fmt-video=width=800,height=600,pixelformat=NV12 --stream-mmap=3 --stream-to=/sdcard/out.yuv --stream-skip=9 --stream-count=1
查看YUV图片可以使用该网站:在线查看 YUV 文件的免费在线工具 - ImageToStl
4、遇到的问题与解决
①问题1:相机权限问题:解决问题的链接
②问题2:没有获取到对应IQ文件,后面查看编译生成的文件,并没有将IQ文件拷贝过去,报错如下图所示
解决方法:找到对应IQ目录上的.mk文件,在.mk文件中的PRODUCT_COPY_FILES节点下添加
$(call find-copy-subdir-files,*,$(CUR_PATH)/camera/rkisp1/,$(TARGET_COPY_OUT_VENDOR)/etc/camera/rkisp1/) \
这条语句,这条语句作用是拷贝所有的IQ文件到/vendor/etc/camera/rkisp1/目录下。
③问题3:屏幕显示UI为0度横屏,而默认\hardware\rockchip\camera\etc\camera\camera3_profiles_rk3399.xml文件中配置的是传感器成像方向是90度,导致相机成像出现拉伸现象。
解决方法:如下图所示。
④问题4:图像上下或者左右相反,可以通过修改OV13850寄存器完成上下或左右的翻转。
解决方法:如下图介绍。
5、补丁
commit ea5601611a8fdff4b5efaf6db0f947bab7d0447d
Author: dengjiawen <1411471554@qq.com>
Date: Thu Feb 22 10:52:28 2024 +0800适配MIPI摄像头OV13850diff --git a/frameworks/base/data/etc/privapp-permissions-platform.xml b/frameworks/base/data/etc/privapp-permissions-platform.xml
index 3b6abd50ee..0912e0ec6f 100644
--- a/frameworks/base/data/etc/privapp-permissions-platform.xml
+++ b/frameworks/base/data/etc/privapp-permissions-platform.xml
@@ -469,4 +469,8 @@ applications that come with the platform<privapp-permissions package="com.android.bips"><permission name="android.permission.SUBSTITUTE_SHARE_TARGET_APP_NAME_AND_ICON"/></privapp-permissions>
+
+ <privapp-permissions package="com.android.camera2">
+ <permission name="android.permission.SYSTEM_CAMERA"/>
+ </privapp-permissions></permissions>
diff --git a/hardware/rockchip/camera/etc/camera/camera3_profiles_rk3399.xml b/hardware/rockchip/camera/etc/camera/camera3_profiles_rk3399.xml
index 84dd8b5ed5..61ac244250 100755
--- a/hardware/rockchip/camera/etc/camera/camera3_profiles_rk3399.xml
+++ b/hardware/rockchip/camera/etc/camera/camera3_profiles_rk3399.xml
@@ -251,7 +251,7 @@<!-- ******************PSL specific section end **************************************************************--></Profiles>
- <Profiles cameraId="0" name="ov13850" moduleId="m00">
+ <Profiles cameraId="0" name="ov13850" moduleId="m01"><Supported_hardware><hwType value="SUPPORTED_HW_RKISP1"/></Supported_hardware>
@@ -291,7 +291,7 @@<lens.info.hyperfocalDistance value="0.0"/> <!-- HAL may override this value from CMC for RAW sensors --><lens.info.minimumFocusDistance value="0.1"/> <!-- HAL may override this value from CMC for RAW sensors --><!-- Lens -->
- <lens.facing value="BACK"/>
+ <lens.facing value="FRONT"/><!-- Request --><request.maxNumOutputStreams value="1,2,1"/><request.pipelineMaxDepth value="4"/>
@@ -463,7 +463,7 @@<sensor.baseGainFactor value="0,1"/> <!-- HAL may override this value from CMC for RAW sensors --><sensor.blackLevelPattern value="0,0,0,0"/><sensor.maxAnalogSensitivity value="2400"/> <!-- HAL may override this value from CMC for RAW sensors -->
- <sensor.orientation value="90"/>
+ <sensor.orientation value="0"/> <!-- 摄像头默认成像方向改为0, 这样和默认横屏0°才一致,成像才不会拉伸 --><sensor.profileHueSatMapDimensions value="0,0,0"/><sensor.availableTestPatternModes value="OFF,COLOR_BARS"/><!-- Info -->
diff --git a/hardware/rockchip/camera/etc/camera_etc.mk b/hardware/rockchip/camera/etc/camera_etc.mk
index ee01d12646..30328325bd 100755
--- a/hardware/rockchip/camera/etc/camera_etc.mk
+++ b/hardware/rockchip/camera/etc/camera_etc.mk
@@ -9,11 +9,13 @@ ifeq ($(filter box atv vr stbvr, $(strip $(TARGET_BOARD_PLATFORM_PRODUCT))), )ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \>= 26)))PRODUCT_COPY_FILES += \$(CUR_PATH)/camera/camera3_profiles_$(TARGET_BOARD_PLATFORM).xml:$(TARGET_COPY_OUT_VENDOR)/etc/camera/camera3_profiles.xml \
+ $(call find-copy-subdir-files,*,$(CUR_PATH)/camera/rkisp1/,$(TARGET_COPY_OUT_VENDOR)/etc/camera/rkisp1/) \#$(call find-copy-subdir-files,*,$(CUR_PATH)/firmware,$(TARGET_COPY_OUT_VENDOR)/firmware) \#$(call find-copy-subdir-files,*,$(CUR_PATH)/camera,$(TARGET_COPY_OUT_VENDOR)/etc/camera) elsePRODUCT_COPY_FILES += \$(CUR_PATH)/camera/camera3_profiles_$(TARGET_BOARD_PLATFORM).xml:$(TARGET_COPY_OUT_SYSTEM)/etc/camera/camera3_profiles.xml \
+ $(call find-copy-subdir-files,*,$(CUR_PATH)/camera/rkisp1/,$(TARGET_COPY_OUT_VENDOR)/etc/camera/rkisp1/) \$(call find-copy-subdir-files,*,$(CUR_PATH)/firmware,$(TARGET_COPY_OUT_SYSTEM)/etc/firmware) \$(call find-copy-subdir-files,*,$(CUR_PATH)/camera,$(TARGET_COPY_OUT_SYSTEM)/etc/camera) \$(call find-copy-subdir-files,*,$(CUR_PATH)/tools,$(TARGET_COPY_OUT_SYSTEM)/bin)
diff --git a/kernel/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi b/kernel/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
index 450c677864..9062188ed2 100644
--- a/kernel/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
@@ -335,7 +335,7 @@cif_clkout: cif-clkout {rockchip,pins =/*cif_clkout*/
- <2 RK_PB3 3 &pcfg_pull_none>;
+ <3 RK_PB7 3 &pcfg_pull_none>;};isp_dvp_d0d7: isp-dvp-d0d7 {
diff --git a/kernel/arch/arm64/boot/dts/rockchip/rk3399-excavator-sapphire.dtsi b/kernel/arch/arm64/boot/dts/rockchip/rk3399-excavator-sapphire.dtsi
index dd7d5f8952..d697023024 100644
--- a/kernel/arch/arm64/boot/dts/rockchip/rk3399-excavator-sapphire.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3399-excavator-sapphire.dtsi
@@ -303,26 +303,6 @@};};-&i2c4 {
- status = "disabled";
- i2c-scl-rising-time-ns = <600>;
- i2c-scl-falling-time-ns = <20>;
-
- mpu6500@68 {
- status = "disabled";
- compatible = "invensense,mpu6500";
- reg = <0x68>;
- irq-gpio = <&gpio1 22 IRQ_TYPE_EDGE_RISING>;
- mpu-int_config = <0x10>;
- mpu-level_shifter = <0>;
- mpu-orientation = <0 1 0 1 0 0 0 0 1>;
- orientation-x= <1>;
- orientation-y= <0>;
- orientation-z= <0>;
- mpu-debug = <1>;
- };
-};
-&i2c7 {status = "okay";rtc@51 {
diff --git a/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator-edp.dtsi b/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator-edp.dtsi
index 83b7560801..da84220e47 100644
--- a/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator-edp.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire-excavator-edp.dtsi
@@ -50,7 +50,7 @@vcc_lcd: vcc-lcd {compatible = "regulator-fixed";regulator-name = "vcc_lcd";
- gpio = <&gpio2 26 GPIO_ACTIVE_HIGH>;
+ //gpio = <&gpio2 26 GPIO_ACTIVE_HIGH>;startup-delay-us = <20000>;enable-active-high;regulator-min-microvolt = <3300000>;
@@ -423,15 +423,15 @@&isp1_mmu {
- status = "disabled";
+ status = "okay"; // isp 驱动使用了 iommu,所以 isp iommu 也需要打开};
@@ -451,16 +451,45 @@&mipi_dphy_tx1rx1 {
- status = "disabled";
+ status = "okay";
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ mipi_in_ucam0: endpoint@1 {
+ reg = <1>;
+ remote-endpoint = <&ucam_out0>; // sensor 端的 port 名
+ data-lanes = <1 2 3 4>;
+ };
+ };
+
+ port@1 {
+ reg = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ dphy_tx1rx1_out: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&isp1_mipi_in>;
+ };
+ };
+ };};&vopb {
@@ -484,19 +513,31 @@&rkisp1_1 {
- status = "disabled";
+ status = "okay";
+
+ port {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ isp1_mipi_in: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&dphy_tx1rx1_out>; // mipi dphy 端的 port 名
+ };
+ };};&pinctrl {
diff --git a/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi b/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
index 5b36e3c56d..ee56830ab5 100644
--- a/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3399-sapphire.dtsi
@@ -555,7 +555,7 @@};&i2c4 {
- status = "disabled";
+ status = "okay";i2c-scl-rising-time-ns = <475>;i2c-scl-falling-time-ns = <26>;@@ -568,6 +568,33 @@vbus-5v-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>;status = "disabled";};
+
+ ov13850: ov13850@10 {
+ compatible = "ovti,ov13850";
+ status = "okay";
+ reg = <0x10>;
+ clocks = <&cru SCLK_CIF_OUT>;
+ clock-names = "xvclk";
+
+ /* conflict with csi-ctl-gpios */
+ reset-gpios = <&gpio2 RK_PD2 GPIO_ACTIVE_HIGH>;
+ pwdn-gpios = <&gpio1 RK_PC7 GPIO_ACTIVE_HIGH>;
+ pinctrl-names = "rockchip,camera_default";
+ pinctrl-0 = <&cif_clkout>; // pinctl 设置
+
+ rockchip,camera-module-index = <1>; // 模组编号,该编号不要重复,因为xml文件中的moduleId="m01",所有设置1
+ rockchip,camera-module-facing = "front"; // 模组朝向,有"back"和"front"
+ rockchip,camera-module-name = "CMK-CT0116"; // 模组名
+ rockchip,camera-module-lens-name = "Largan-50013A1"; // lens 名
+ // 模组名和 lens 名被用来和 IQ xml 文件做匹配,使用的是hardware\rockchip\camera\etc\camera\rkisp1\ov13850_CMK-CT0116_Largan-50013A1.xml文件
+ //lens-focus = <&vm149c>; // vcm 驱动设置,支持 AF 时需要有这个设置
+ port {
+ ucam_out0: endpoint {
+ remote-endpoint = <&mipi_in_ucam0>; // mipi dphy 端的 port 名
+ data-lanes = <1 2 3 4>; // mipi lane 数
+ };
+ };
+ };};
这篇关于基于RK3399 Android11适配OV13850 MIPI摄像头的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!