Camera | 1.Camera基础知识
Camera | 2.MIPI、CSI基础
Camera | 4.瑞芯微平台MIPI摄像头应用程序编写
Camera | 5.Linux v4l2架构(基于rk3568)
Camera | 6.v4l2拓扑架构(基于rk3568)
Camera | 7.瑞芯微rk3568平台摄像头控制器MIPI-CSI驱动架构梳理
一、目标
本文主要目标是,支持前置摄像头0v5648、后置摄像头ov13850,以及移植过程遇到的一些小问题的解决。
1. 摄像头连接图
参考上图,摄像头详细信息如下:
- 2个摄像头均连接在I2C通道42个摄像头共用同一个MIPI数据通道2个摄像头各自有独立的rst、pwdn引脚rkw提供的sdk中已经提供camera时钟的设备树信息,此处选择对应时钟即可ov13850用到4个lane,0v5648用到2个lane摄像头的片选通过select-gpios来选择,拉低选择0v13850,拉高选择ov5684
三、设备树
根据上述摄像头硬件信息,设备树信息如下:
- reg:该模块输入端点序号remot-endpoint :输出端点的名字,在下面设备树信息中列举出来data-lanes :数据通道信息
在这里插入图片描述
四、驱动
rxw sdk中已经有这两个摄像头的驱动,但是需要增加片选的逻辑,
根据前面文章,
《Camera | 4.瑞芯微平台MIPI摄像头应用程序编写》
可知开启和关闭摄像头视频流通过以下命令:
VIDIOC_STREAMON, VIDIOC_STREAMOFF
对应的回调函数
static int ov5648_s_stream(struct v4l2_subdev *sd, int on)
除此之外,power控制的回调函数
static int ov5648_s_power(struct v4l2_subdev *sd, int on)
我们只需要在这对应的回调函数中增加select-gpio的操作即可。
所有修改代码如下:
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+static int select_gpios;//前置摄像头使能
static int ov5648_s_stream(struct v4l2_subdev *sd, int on)
{
……
if (on) {
+ gpio_direction_output(select_gpios, 1);
+ usleep_range(1000, 2000);
……
} else {
……
+ gpio_direction_output(select_gpios, 0);
+ usleep_range(1000, 2000);
}
……
}
static int ov5648_s_power(struct v4l2_subdev *sd, int on)
{
……
if (on) {
+ gpio_direction_output(select_gpios, 1);
+ usleep_range(1000, 2000);
……
} else {
+ gpio_direction_output(select_gpios, 0);
……
}
……
}
static void __ov5648_power_off(struct ov5648 *ov5648)
{
int ret;
struct device *dev = &ov5648->client->dev;
+ gpio_direction_output(select_gpios, 0);
……
}
static int ov5648_probe(struct i2c_client *client,
……
+ struct device_node *np;
+
+ np = dev->of_node;
……
+ select_gpios = of_get_named_gpio(np, "select-gpios", 0);
+
+ ret = gpio_request(select_gpios, "select-gpios");
+ if (ret < 0) {
+ dev_err(dev,"Failed to request GPIO:%d, ERRNO:%d", (s32) select_gpios, ret);
+ //return ret;
+ }
+ printk("ov5648 select_gpios=%d",select_gpios);
……
五、拓扑结构
加载成功后查看拓扑结构,会有以下entity 信息:
- entity 70: m01_f_ov5648 4-0036 (1 pad, 1 link)
type V4L2 subdev subtype Sensor
device node name /dev/v4l-subdev3
pad0: Source
[fmt:SBGGR10/2592x1944]
-> "rockchip-csi2-dphy0":0 []
- entity 74: m00_b_ov13850 4-0010 (1 pad, 1 link)
type V4L2 subdev subtype Sensor
device node name /dev/v4l-subdev4
pad0: Source
[fmt:SBGGR10/4224x3136]
-> "rockchip-csi2-dphy0":0 [ENABLED]
说明pipe通路ok。
六、xml配置文件
要让安卓识别前后置摄像头,还需要在以下文件增加后置摄像头ov13850、前置摄像头ov5684信息
@hardware/rockchip/camera/etc/camera/camera3_profiles.xml
@hardware/rockchip/camera/etc/camera/camera3_profiles_rk356x.xml
在这两个xml文件中增加这两个摄像头信息即可,
一口君是按照其他摄像头内容修改的,
ov5684因为分辨率问题,需要注意不要超过最大值。
成功后,摄像头app界面会有切换的按钮出现
七、切换后,前置摄像头打不开bug
开机后用命令抓帧,用的是前置摄像头
打开app后,界面显示的是后置摄像头信息
但是点解界面的切换按钮,获取不到前置摄像头图像,
在不重启的情况下要操作后置摄像头,执行下面操作即可。
Settings->apps¬ifications
SEE ALL 16 APPS
选择最近应用 Camera
Storage&cache
点击
clear storage
然后退出重新打开摄像头APP即可
1. 错误分析
- 首先在ov5648驱动的加上log
static int ov5648_s_stream(struct v4l2_subdev *sd, int on)
{
……
on = !!on;
printk("6902 %s(%d) enter! %dn", __func__, __LINE__,on);
if (on == ov5648->streaming)
goto unlock_and_return;
if (on) {
……
} else {
……
}
ov5648->streaming = on;
}
发现切换的时候没有执行该函数,所以定位是APP测出了问题
2. 查看catlog
03-01 02:40:30.062 1699 1749 I CAM_Profiler: [ 67.906ms] GUARD: CaptureModule.openCameraAndStartPreview() - [67.565ms] mOneCameraOpener.open()
03-01 02:40:30.062 1699 1749 I CAM_Profiler: [ 67.906ms] GUARD: CaptureModule.openCameraAndStartPreview() - STOP
03-01 02:40:30.063 1699 1741 E CAM_OneCamFtrCnfgCrtr: Unknown support level: 0
03-01 02:40:30.063 1699 1741 I CAM_OneCamCreator: Camera support level: LIMITED_JPEG
03-01 02:40:30.063 1699 1741 W CAM_Log : Tag SimpleOneCameraFactory is 3 chars longer than limit.
03-01 02:40:30.063 1699 1741 I CAM_OneCamCreator: Picture Size Configuration: PictureSizeCalculator.Configuration{native size=3264x2448, crop=Rect(0, 0 - 3264, 2448)}
03-01 02:40:30.065 1699 1741 D CAM_CaptureModule: onCameraOpened: com.android.camera.one.v2.initialization.GenericOneCameraImpl@200eae9
03-01 02:40:30.065 1699 1741 D CAM_CaptureModule: picturesize:3264x2448,previewBuffer:1280x960
03-01 02:40:30.065 1699 1741 D CAM_CaptureModule: starting preview ...
03-01 02:40:30.068 1699 1699 W CAM_IndicatorIconCtrlr: Trying to sync a pano indicator that is not initialized.
03-01 02:40:30.068 349 349 W CameraDeviceClient: createSurfaceFromGbp: Camera 1 with consumer usage flag: 256: Forcing asynchronous mode for stream
03-01 02:40:30.068 349 349 W CameraDeviceClient: createSurfaceFromGbp: Camera 1: Overriding format 0x1 to IMPLEMENTATION_DEFINED
03-01 02:40:30.069 265 265 D Camera3HAL: configure_streams: streams list ptr: 0xf6242dd0, num 2
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2GraphConfig: @selectSensorOutputFormat : App stream size(3264x2448) larger than Sensor full size(2592x1944), Check camera3_profiles.xml
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2GraphConfigManager: Couldn't get mediaCtl config
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> V4L2Subdev: queryDvTimings, ret:-1, I:0, wxh:0x0
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> V4L2Subdev: VIDIOC_SUBDEV_QUERY_DV_TIMINGS failed: Inappropriate ioctl for device
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> PlatformData: Error queryDvTimings ret:-2147483648 (/dev/v4l-subdev3)
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> PlatformData: Error closing device (/dev/v4l-subdev3)
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2GraphConfig: getMediaDevInfo info.model:rkisp0
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2GraphConfigManager: Couldn't get Imgu mediaCtl config
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2ImguUnit: Processing tasks creation failed (ret = -2147483648)
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2CameraHw: Unable to configure stream for imgunit
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RequestThread: Error configuring the streams @handleConfigureStreams:213
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RequestThread: error -2147483648 in handling message: 3
03-01 02:40:30.071 349 349 E Camera3-Device: Camera 1: configureStreamsLocked: Set of requested inputs/outputs not supported by HAL
03-01 02:40:30.071 349 349 E CameraDeviceClient: endConfigure: Camera 1: Unsupported set of inputs/outputs provided
03-01 02:40:30.071 1699 1741 W CameraDevice-JV-1: Stream configuration failed due to: endConfigure:505: Camera 1: Unsupported set of inputs/outputs provided
03-01 02:40:30.072 1699 1741 E CameraCaptureSession: Session 0: Failed to create capture session; configuration failed
03-01 02:40:30.072 1699 1817 E CAM_CaptureModule: Could not set up preview.
03-01 02:40:30.079 1699 1699 D CAM_LoggingImageReader: Closing: ImageReader{width=3264, height=2448, format=JPEG}
03-01 02:40:30.081 349 349 I Camera3-Device: disconnectImpl: E
03-01 02:40:30.088 349 349 I Camera3-Device: disconnectImpl: X
03-01 02:40:30.094 349 349 I CameraService: disconnect: Disconnected client for camera 1 for PID 1699
其中:
03-01 02:40:30.070 265 1812 E RkCamera: <HAL> RKISP2GraphConfig: @selectSensorOutputFormat : App stream size(3264x2448) larger than Sensor full size(2592x1944), Check camera3_profiles.xml
提示分辨率不支持,
于是打开camera3_profiles.xml,将所有3264x2448修改为2592x1944
<jpeg.maxSize value="5038848"/> <!-- 3264*2448*1.5 2592x1944*1.5= 5038848 -->
<sensor.info.activeArraySize value="0,0,2592,1944"/>
<sensor.info.pixelArraySize value="2592x1944"/>
<supportTuningSize value="2592x1944"/>
将下面几个属性所有关3264x2448的全部删除
<scaler.availableStreamConfigurations value="BLOB,3264x2448,OUTPUT,
<scaler.availableMinFrameDurations value=
<scaler.availableStallDurations value="
2592*1944*1.5= 5038848
八、其他问题
1. 前置摄像头旋转了180°
修改xml文件
<sensor.orientation value="90"/>
2. 闪光灯
<flash.info.available value="TRUE"/>