加入星計劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長期合作伙伴
立即加入
  • 正文
    • 一、目標(biāo)
    • 三、設(shè)備樹
    • 四、驅(qū)動
    • 五、拓?fù)浣Y(jié)構(gòu)
    • 六、xml配置文件
    • 七、切換后,前置攝像頭打不開bug
    • 八、其他問題
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請入駐 產(chǎn)業(yè)圖譜

Camera | 8.讓rk3568支持前后置攝像頭

2023/04/18
4782
閱讀需 27 分鐘
加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
Camera | 1.Camera基礎(chǔ)知識

Camera | 2.MIPI、CSI基礎(chǔ)

Camera | 3.瑞芯微平臺MIPI攝像頭常用調(diào)試命令

Camera | 4.瑞芯微平臺MIPI攝像頭應(yīng)用程序編寫

Camera | 5.Linux v4l2架構(gòu)(基于rk3568)

Camera | 6.v4l2拓?fù)浼軜?gòu)(基于rk3568)

Camera | 7.瑞芯微rk3568平臺攝像頭控制器MIPI-CSI驅(qū)動架構(gòu)梳理

一、目標(biāo)

本文主要目標(biāo)是,支持前置攝像頭0v5648、后置攝像頭ov13850,以及移植過程遇到的一些小問題的解決。

1. 攝像頭連接圖

參考上圖,攝像頭詳細(xì)信息如下:

    2個攝像頭均連接在I2C通道42個攝像頭共用同一個MIPI數(shù)據(jù)通道2個攝像頭各自有獨(dú)立的rst、pwdn引腳rkw提供的sdk中已經(jīng)提供camera時鐘的設(shè)備樹信息,此處選擇對應(yīng)時鐘即可ov13850用到4個lane,0v5648用到2個lane攝像頭的片選通過select-gpios來選擇,拉低選擇0v13850,拉高選擇ov5684

三、設(shè)備樹

根據(jù)上述攝像頭硬件信息,設(shè)備樹信息如下:

    reg:該模塊輸入端點(diǎn)序號remot-endpoint :輸出端點(diǎn)的名字,在下面設(shè)備樹信息中列舉出來data-lanes :數(shù)據(jù)通道信息

在這里插入圖片描述

四、驅(qū)動

rxw sdk中已經(jīng)有這兩個攝像頭的驅(qū)動,但是需要增加片選的邏輯,

根據(jù)前面文章,

《Camera | 4.瑞芯微平臺MIPI攝像頭應(yīng)用程序編寫》

可知開啟和關(guān)閉攝像頭視頻流通過以下命令:

VIDIOC_STREAMON,?VIDIOC_STREAMOFF

對應(yīng)的回調(diào)函數(shù)

static?int?ov5648_s_stream(struct?v4l2_subdev?*sd,?int?on)

除此之外,power控制的回調(diào)函數(shù)

static?int?ov5648_s_power(struct?v4l2_subdev?*sd,?int?on)

我們只需要在這對應(yīng)的回調(diào)函數(shù)中增加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);
?……

五、拓?fù)浣Y(jié)構(gòu)

加載成功后查看拓?fù)浣Y(jié)構(gòu),會有以下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文件中增加這兩個攝像頭信息即可,

一口君是按照其他攝像頭內(nèi)容修改的,

ov5684因?yàn)榉直媛蕟栴},需要注意不要超過最大值。

成功后,攝像頭app界面會有切換的按鈕出現(xiàn)

?

七、切換后,前置攝像頭打不開bug

開機(jī)后用命令抓幀,用的是前置攝像頭

打開app后,界面顯示的是后置攝像頭信息

但是點(diǎn)解界面的切換按鈕,獲取不到前置攝像頭圖像,

在不重啟的情況下要操作后置攝像頭,執(zhí)行下面操作即可。

Settings->apps&notifications
SEE?ALL?16?APPS
選擇最近應(yīng)用??Camera
Storage&cache
????點(diǎn)擊
????clear?storage
?然后退出重新打開攝像頭APP即可

1. 錯誤分析

    首先在ov5648驅(qū)動的加上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;

}

發(fā)現(xiàn)切換的時候沒有執(zhí)行該函數(shù),所以定位是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"/>

將下面幾個屬性所有關(guān)3264x2448的全部刪除

<scaler.availableStreamConfigurations?value="BLOB,3264x2448,OUTPUT,
<scaler.availableMinFrameDurations?value=
<scaler.availableStallDurations?value="
2592*1944*1.5=?5038848

八、其他問題

1. 前置攝像頭旋轉(zhuǎn)了180°

修改xml文件

??<sensor.orientation?value="90"/>

2. 閃光燈

 <flash.info.available?value="TRUE"/>

相關(guān)推薦

電子產(chǎn)業(yè)圖譜

公眾號『一口Linux』號主彭老師,擁有15年嵌入式開發(fā)經(jīng)驗(yàn)和培訓(xùn)經(jīng)驗(yàn)。曾任職ZTE,某研究所,華清遠(yuǎn)見教學(xué)總監(jiān)。擁有多篇網(wǎng)絡(luò)協(xié)議相關(guān)專利和軟件著作。精通計算機(jī)網(wǎng)絡(luò)、Linux系統(tǒng)編程、ARM、Linux驅(qū)動、龍芯、物聯(lián)網(wǎng)。原創(chuàng)內(nèi)容基本從實(shí)際項目出發(fā),保持原理+實(shí)踐風(fēng)格,適合Linux驅(qū)動新手入門和技術(shù)進(jìn)階。