OpenHarmony开发者论坛

标题: OpenHarmony标准系统mipi摄像头适配 [打印本页]

作者: 润开鸿_贾佳豪    时间: 2024-9-19 11:07
标题: OpenHarmony标准系统mipi摄像头适配
[md]# OpenHarmony标准系统mipi摄像头适配

本文档以rk3568为例,讲述如何在OpenHarmony 标准系统rk设备上适配mipi摄像头。

> 开发环境
>
> - OpenHarmony标准系统4.1r
> - rk3568设备
> - 摄像头ov5648,ov8858

> 文档约定:
> 4.1r_3568为OpenHarmony标准系统源码根目录

## 1.适配准备:得到一份完整的kernel代码

OpenHarmony标准系统4.1r使用的是kernel 5.10的内核,在此基线基础上,回合CVE补丁及OpenHarmony特性,作为OpenHarmony Common Kernel基线。针对不同的芯片,各厂商合入对应的板级驱动补丁,完成对OpenHarmony的基线适配。

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_624,h_307)

首先得有一份完整的rk3568 kernel5.10代码。所以我们需要手动把4.1r_3568/kernel/linux/patches/linux-5.10/rk3568_patch/kernel.patch打进/4.1r_3568/kernel/linux/linux-5.10内核中

```
cd 4.1r_3568/kernel/linux/linux-5.10

patch -p1 < /home/jiajiahao/OpenHarmony/4.1r_3568/kernel/linux/patches/linux-5.10/rk3568_patch/kernel.patch
```

2.然后注释掉/4.1r_3568/device/board/hihope/rk3568/kernel/build_kernel.sh中的 `patch -p1 < ${KERNEL_PATCH}`

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_820,h_556)

然后就可以在4.1r_3568/kernel/linux/linux-5.10中得到一份完整的rk3568 kernel 5.10代码,

## 2.DTS配置

本文档以[触觉智能Purple Pi OH开源rk3566](http://www.industio.cn/product-item-58.html)为例修改 `设备树源文件包含文件`添加摄像头

- 设备树相关的教程可以参考泰山派3566:https://wiki.lckfb.com/zh-hans/t ... ne/device-tree.html

查阅[触觉智能Purple Pi OH开源rk3566的原理图](./rk设备树mipi摄像头配置/Purple%20Pi%20OH_OPENSOURCE-SCH-20230619.pdf)

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_820,h_934)

1.i2c4配置

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_820,h_921)

2.mipi配置
![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_817,h_990)

3.isp配置
![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_657,h_630)

## 3.驱动添加

1.内核添加ov5648.c编译,[4.1r_3568/kernel/linux/linux-5.10/drivers/media/i2c/ov5648.c](./ov5648/ov5648.c)

2.修改4.1r_3568/kernel/linux/linux-5.10/drivers/media/i2c/Makefile

```
obj-$(CONFIG_VIDEO_OV5648) += ov5648.o
```

3.修改4.1r_3568/kernel/linux/linux-5.10/drivers/media/i2c/Kconfig,添加OV5648配置

```
config VIDEO_OV5648
        tristate "OmniVision OV5648 sensor support"
        depends on I2C && VIDEO_V4L2
        depends on MEDIA_CAMERA_SUPPORT
        help
          This is a Video4Linux2 sensor driver for the OmniVision
          OV5648 camera.

          To compile this driver as a module, choose M here: the
          module will be called ov5648.
```

4.在4.1r_3568/kernel/linux/config/linux-5.10/rk3568/arch/arm64_defconfig中添加配置

```
CONFIG_VIDEO_OV5648=y
```

## 4.修改iq文件

需要添加ov5648的iq文件到OpenHarmony,修复画面的偏绿问题。有两种方法:

方法1:第一修改源码,随着固件编译,
修改device/soc/rockchip/rk3568/hardware/isp/etc/iqfil.json的内容为ov5648_LMM248_YXC-M804A2.json的内容。然后添加[ov5648_LMM248_YXC-M804A2.json](./ov5648/ov5648_LMM248_YXC-M804A2.json)到/device/soc/rockchip/rk3568/hardware/isp/etc/iqfiles目录下,然后修改device/soc/rockchip/rk3568/hardware/isp/BUILD.gn,将文件随着固件打包。

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_820,h_1398)

方法2:直接推到板子上(测试的时候可以使用),烧录好固件后,进入板子,将板子的vendor/etc/iqfiles/iqfil.json内容替换为ov5648_LMM248_YXC-M804A2.json的内容

## 5.安装调试hap

安装调试用的摄像头hap,[MultiMedia_api9.hap](./调试用的摄像头hap/MultiMedia_api9.hap)

- https://gitee.com/openharmony/ap ... ns/Media/MultiMedia

## 6.最后效果

![image.png](https://dl-harmonyos.51cto.com/i ... rocess=image/resize,w_820,h_928)

## 参考文档

1.https://forums.openharmony.cn/fo ... wthread&tid=617
[/md]
作者: admi    时间: 2024-9-19 17:05
大佬啥时候出个蓝牙的
作者: 润开鸿_贾佳豪    时间: 2024-9-19 17:50
回复 admi: 最近在搞usb wifi,还没搞定




欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/) Powered by Discuz! X3.5