Camera | 1.Camera基礎(chǔ)知識(shí)
Camera | 2.MIPI、CSI基礎(chǔ)
Camera | 3.瑞芯微平臺(tái)MIPI攝像頭常用調(diào)試命令
Camera | 4.瑞芯微平臺(tái)MIPI攝像頭應(yīng)用程序編寫
Camera | 5.Linux v4l2架構(gòu)(基于rk3568)
Camera | 6.v4l2拓?fù)浼軜?gòu)(基于rk3568)
Camera | 7.瑞芯微rk3568平臺(tái)攝像頭控制器MIPI-CSI驅(qū)動(dòng)架構(gòu)梳理
一、目標(biāo)
本文主要目標(biāo)是,支持前置攝像頭0v5648、后置攝像頭ov13850,以及移植過程遇到的一些小問題的解決。
1. 攝像頭連接圖
參考上圖,攝像頭詳細(xì)信息如下:
- 2個(gè)攝像頭均連接在I2C通道42個(gè)攝像頭共用同一個(gè)MIPI數(shù)據(jù)通道2個(gè)攝像頭各自有獨(dú)立的rst、pwdn引腳rkw提供的sdk中已經(jīng)提供camera時(shí)鐘的設(shè)備樹信息,此處選擇對(duì)應(yīng)時(shí)鐘即可ov13850用到4個(gè)lane,0v5648用到2個(gè)lane攝像頭的片選通過select-gpios來選擇,拉低選擇0v13850,拉高選擇ov5684
三、設(shè)備樹
根據(jù)上述攝像頭硬件信息,設(shè)備樹信息如下:
- reg:該模塊輸入端點(diǎn)序號(hào)remot-endpoint :輸出端點(diǎn)的名字,在下面設(shè)備樹信息中列舉出來data-lanes :數(shù)據(jù)通道信息
在這里插入圖片描述
四、驅(qū)動(dòng)
rxw sdk中已經(jīng)有這兩個(gè)攝像頭的驅(qū)動(dòng),但是需要增加片選的邏輯,
根據(jù)前面文章,
《Camera | 4.瑞芯微平臺(tái)MIPI攝像頭應(yīng)用程序編寫》
可知開啟和關(guān)閉攝像頭視頻流通過以下命令:
VIDIOC_STREAMON,?VIDIOC_STREAMOFF
對(duì)應(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)
我們只需要在這對(duì)應(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),會(huì)有以下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配置文件
要讓安卓識(shí)別前后置攝像頭,還需要在以下文件增加后置攝像頭ov13850、前置攝像頭ov5684信息
@hardware/rockchip/camera/etc/camera/camera3_profiles.xml
@hardware/rockchip/camera/etc/camera/camera3_profiles_rk356x.xml
在這兩個(gè)xml文件中增加這兩個(gè)攝像頭信息即可,
一口君是按照其他攝像頭內(nèi)容修改的,
ov5684因?yàn)榉直媛蕟栴},需要注意不要超過最大值。
成功后,攝像頭app界面會(huì)有切換的按鈕出現(xiàn)
?
七、切換后,前置攝像頭打不開bug
開機(jī)后用命令抓幀,用的是前置攝像頭
打開app后,界面顯示的是后置攝像頭信息
但是點(diǎn)解界面的切換按鈕,獲取不到前置攝像頭圖像,
在不重啟的情況下要操作后置攝像頭,執(zhí)行下面操作即可。
Settings->apps¬ifications
SEE?ALL?16?APPS
選擇最近應(yīng)用??Camera
Storage&cache
????點(diǎn)擊
????clear?storage
?然后退出重新打開攝像頭APP即可
1. 錯(cuò)誤分析
- 首先在ov5648驅(qū)動(dòng)的加上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)切換的時(shí)候沒有執(zhí)行該函數(shù),所以定位是APP測(cè)出了問題
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"/>
將下面幾個(gè)屬性所有關(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"/>