0.前言
? 100ASK_V853-PRO開發(fā)板支持4LINE的MIPI攝像頭和2LINE的MIPI攝像頭,使用百問網(wǎng)提供的Tina SDK包生成的鏡像,系統(tǒng)已經(jīng)配置好了,可以直接使用。本章介紹如何去適配一個MIPI攝像頭,本文所用的2LINE的MIPI攝像頭,大家可以在百問網(wǎng)官方淘寶店鋪上購買。100ASK_V853-PRO開發(fā)板
全志Linux Tina-SDK開發(fā)完全手冊:https://tina.100ask.net/
如果您想適配自己的攝像頭,強(qiáng)烈建議您參照以下開發(fā)指南進(jìn)行操作:
Camera_開發(fā)指南:https://tina.100ask.net/SdkModule/Linux_Camera_DevelopmentGuide-01/
1.VIN框架介紹
V853支持并口CSI、MIPI,使用VIN camera驅(qū)動框架。
Camera 通路框架
? VIN 支持靈活配置單/雙路輸入雙ISP 多通路輸出的規(guī)格
? 引入media 框架實現(xiàn)pipeline 管理
? 將libisp 移植到用戶空間解決GPL 問題
? 將統(tǒng)計buffer 獨(dú)立為v4l2 subdev
? 將的scaler(vipp)模塊獨(dú)立為v4l2 subdev
? 將video buffer 修改為mplane 方式,使用戶層取圖更方便
? 采用v4l2-event 實現(xiàn)事件管理
? 采用v4l2-controls 新特性
VIN 框架
? 使用過程中可簡單的看成是vin 模塊+ device 模塊+af driver + flash 控制模塊的方式;
? vin.c 是驅(qū)動的主要功能實現(xiàn),包括注冊/注銷、參數(shù)讀取、與v4l2 上層接口、與各device 的下層接口、中斷處理、buffer 申請切換等;
? modules/sensor 文件夾里面是各個sensor 的器件層實現(xiàn),一般包括上下電、初始化,各分辨率切換,yuv sensor 包括絕大部分的v4l2 定義的ioctrl 命令的實
現(xiàn);而raw sensor 的話大部分ioctrl 命令在vin 層調(diào)用isp 庫實現(xiàn),少數(shù)如曝光/增益調(diào)節(jié)會透過vin 層到實際器件層;
? modules/actuator 文件夾內(nèi)是各種vcm 的驅(qū)動;
? modules/flash 文件夾內(nèi)是閃光燈控制接口實現(xiàn);
? vin-csi 和vin-mipi 為對csi 接口和mipi 接口的控制文件;
? vin-isp 文件夾為isp 的庫操作文件;
? vin-video 文件夾內(nèi)主要是video 設(shè)備操作文件;
驅(qū)動路徑位于linux-4.9/drivers/media/platform/sunxi-vin 下。
sunxi-vin:
│ vin.c ;v4l2驅(qū)動實現(xiàn)主體(包含視頻接口和ISP部分)
│ vin.h ;v4l2驅(qū)動頭文件
│ top_reg.c ;vin對各v4l2 subdev管理接口實現(xiàn)主體
│ top_reg.h ;管理接口頭文件
│ top_reg_i.h ;vin模塊接口層部分結(jié)構(gòu)體
├── modules
│ ├── actuator ;vcm driver
│ │ ├── actuator.c
│ │ ├── actuator.h
│ │ ├── dw9714_act.c
│ │ ├── Makefile
│ ├── flash ;閃光燈driver
│ │ ├── flash.c
│ │ └── flash.h
│ └── sensor ;sensor driver
│ ├── ar0144_mipi.c
│ ├── camera_cfg.h ;camera ioctl擴(kuò)展命令頭文件
│ ├── camera.h ;camera公用結(jié)構(gòu)體頭文件
│ ├── Makefile
│ ├── ov2775_mipi.c
│ ├── ov5640.c
│ ├── sensor-compat-ioctl32.c
│ ├── sensor_helper.c ;sensor公用操作接口函數(shù)文件
│ ├── sensor_helper.h
├── platform ;平臺相關(guān)的配置接口
├── utility
│ ├── bsp_common.c
│ ├── bsp_common.h
│ ├── cfg_op.c
│ ├── cfg_op.h
│ ├── config.c
│ ├── config.h
│ ├── sensor_info.c
│ ├── sensor_info.h
│ ├── vin_io.h
│ ├── vin_os.c
│ ├── vin_os.h
│ ├── vin_supply.c
│ └── vin_supply.h
├── vin-cci
│ ├── sunxi_cci.c
│ └── sunxi_cci.h
├── vin-csi
│ ├── parser_reg.c
│ ├── parser_reg.h
│ ├── parser_reg_i.h
│ ├── sunxi_csi.c
│ └── sunxi_csi.h
├── vin-isp
│ ├── sunxi_isp.c
│ └── sunxi_isp.h
├── vin-mipi
│ ├── sunxi_mipi.c
│ └── sunxi_mipi.h
├── vin-stat
│ ├── vin_h3a.c
│ ├── vin_h3a.h
│ ├── vin_ispstat.c
│ └── vin_ispstat.h
├── vin_test
├── vin-video
│ ├── vin_core.c
│ ├── vin_core.h
│ ├── vin_video.c
│ └── vin_video.h
└── vin-vipp
├── sunxi_scaler.c
├── sunxi_scaler.h
├── vipp_reg.c
├── vipp_reg.h
└── vipp_reg_i.h
2.驅(qū)動配置
? 100ASK_V853-PRO開發(fā)板支持4LINE雙攝鏡頭模組和2LINE單攝鏡頭模組,下面我僅演示2LINE的MIPI攝像頭如何進(jìn)行配置。我們使用的是GC2053攝像頭,使用的是全志已經(jīng)內(nèi)置的驅(qū)動程序,路徑為:
kernel/linux-4.9/drivers/media/platform/sunxi-vin/modules/sensor/gc2053_mipi.c
3.設(shè)備樹配置
設(shè)備樹配置路徑:
device/config/chips/v853/configs/100ask/board.dts
camera相關(guān)配置:
vind0:vind@0 {
vind0_clk = <300000000>;
status = "okay";
csi2:csi@2 {
pinctrl-names = "default","sleep";
pinctrl-0 = <&ncsi_pins_a>;
pinctrl-1 = <&ncsi_pins_b>;
status = "okay";
};
/*Online mode tp9953 uses online mode*/
tdm0:tdm@0 {
work_mode = <0>;
};
isp00:isp@0 {
work_mode = <0>;
};
scaler00:scaler@0 {
work_mode = <0>;
};
scaler10:scaler@4 {
work_mode = <0>;
};
scaler20:scaler@8 {
work_mode = <0>;
};
scaler30:scaler@12 {
work_mode = <0>;
};
actuator0:actuator@0 {
device_type = "actuator0";
actuator0_name = "ad5820_act";
actuator0_slave = <0x18>;
actuator0_af_pwdn = <>;
actuator0_afvdd = "afvcc-csi";
actuator0_afvdd_vol = <2800000>;
status = "disabled";
};
flash0:flash@0 {
device_type = "flash0";
flash0_type = <2>;
flash0_en = <>;
flash0_mode = <>;
flash0_flvdd = "";
flash0_flvdd_vol = <>;
status = "disabled";
};
sensor0:sensor@0 {
device_type = "sensor0";
sensor0_mname = "gc2053_mipi";
sensor0_twi_cci_id = <1>;
sensor0_twi_addr = <0x6e>;
sensor0_mclk_id = <0>;
sensor0_pos = "rear";
sensor0_isp_used = <1>;
sensor0_fmt = <1>;
sensor0_stby_mode = <0>;
sensor0_vflip = <0>;
sensor0_hflip = <0>;
sensor0_iovdd-supply = ;
sensor0_iovdd_vol = <1800000>;
sensor0_avdd-supply = ;
sensor0_avdd_vol = <2800000>;
sensor0_dvdd-supply = ;
sensor0_dvdd_vol = <1200000>;
sensor0_power_en = <>;
sensor0_reset = <&pio PA 18 1 0 1 0>;
sensor0_pwdn = <&pio PA 19 1 0 1 0>;
sensor0_sm_hs = <>;
sensor0_sm_vs = <>;
flash_handle = <&flash0>;
act_handle = <&actuator0>;
status = "okay";
};
sensor1:sensor@1 {
device_type = "sensor1";
sensor1_mname = "tp9953";
sensor1_twi_cci_id = <0>;
sensor1_twi_addr = <0x88>;
sensor1_mclk_id = <2>;
sensor1_pos = "front";
sensor1_isp_used = <0>;
sensor1_fmt = <0>;
sensor1_stby_mode = <0>;
sensor1_vflip = <0>;
sensor1_hflip = <0>;
sensor1_iovdd-supply = ;
sensor1_iovdd_vol = <1800000>;
sensor1_avdd-supply = <>; /*;*/
sensor1_avdd_vol = <3300000>;
sensor1_dvdd-supply = <>;//;
sensor1_dvdd_vol = <1200000>;
sensor1_power_en = <&pio PI 0 1 0 1 0>;
sensor1_reset = <&pio PH 13 1 0 1 0>;
sensor1_pwdn = <>;
/*sensor1_pwdn = <&pio PE 13 1 0 1 0>;*/
sensor1_sm_hs = <>;
sensor1_sm_vs = <>;
flash_handle = <>;
act_handle = <>;
status = "okay";
};
4.內(nèi)核配置
在Tina根目錄下執(zhí)行make kernel_menuconfig
book@100ask:~/workspaces/tina-v853-open$ make kernel_menuconfig
注意:在進(jìn)行內(nèi)核配置前需要配置環(huán)境變量才可以進(jìn)入內(nèi)核調(diào)試,即在配置前輸入
book@100ask:~/workspaces/tina-v853-open$ source build/envsetup.sh
...
book@100ask:~/workspaces/tina-v853-open$ lunch
... 輸入1,選擇方案1
在內(nèi)核配置界面中,進(jìn)入如下目錄,輸入M選中下面兩項。
→ Device Drivers
→ Multimedia support
→ V4L platform devices
sunxi video input (camera csi/mipi isp vipp)driver
v4l2 new driver for SUNXI
可以看到全志已經(jīng)支持了很多攝像頭,找到我們需要適配的攝像頭,輸入M將gc2053驅(qū)動編為模塊。
→ Device Drivers
→ Multimedia support
→ V4L platform devices
→ sensor driver select
use gc2053_mipi driver
注意:如果出現(xiàn)沒有的路徑,需要選擇上一級目錄才會打開。
5.Tina配置
在Tina根目錄下輸入make menuconfig
,進(jìn)入如下目錄
> Kernel modules
> Video Support
<*> kmod-vin-v4l2.............................. Video input support (staging)
如下圖所示
6.modules.mk配置
modules.mk主要完成兩個方面:
- 拷貝相關(guān)的ko模塊到小機(jī)rootfs中
- rootfs啟動時,按順序自動加載相關(guān)的ko模塊。
modules.mk文件路徑:
tina-v853-open/openwrt/target/v853/v853-100ask/modules.mk
驅(qū)動加載順序配置
define KernelPackage/vin-v4l2
SUBMENU:=$(VIDEO_MENU)
TITLE:=Video input support (staging)
DEPENDS:=
FILES:=$(LINUX_DIR)/drivers/media/v4l2-core/videobuf2-core.ko
FILES+=$(LINUX_DIR)/drivers/media/v4l2-core/videobuf2-dma-contig.ko
FILES+=$(LINUX_DIR)/drivers/media/v4l2-core/videobuf2-memops.ko
FILES+=$(LINUX_DIR)/drivers/media/v4l2-core/videobuf2-v4l2.ko
FILES+=$(LINUX_DIR)/drivers/media/platform/sunxi-vin/vin_io.ko
FILES+=$(LINUX_DIR)/drivers/media/platform/sunxi-vin/modules/sensor/gc2053_mipi.ko
# FILES+=$(LINUX_DIR)/drivers/media/platform/sunxi-vin/modules/sensor_power/sensor_power.ko
FILES+=$(LINUX_DIR)/drivers/media/platform/sunxi-vin/vin_v4l2.ko
FILES+=$(LINUX_DIR)/drivers/input/sensor/da380/da380.ko
AUTOLOAD:=$(call AutoProbe,videobuf2-core videobuf2-dma-contig videobuf2-memops videobuf2-v4l2 vin_io gc2053_mipi vin_v4l2 da380.ko)
endef
define KernelPackage/vin-v4l2/description
Kernel modules for video input support
endef
$(eval $(call KernelPackage,vin-v4l2))
7.S00mpp配置
V853平臺在完成modules.mk配置后,還需要完成.ko掛載腳本S00mpp的配置,以便開機(jī)快速啟動攝像頭模塊。
S00mpp配置路徑:
tina-v853-open/openwrt/target/v853/v853-100ask/busybox-init-base-files/etc/init.d/S00mpp
腳本對攝像頭驅(qū)動進(jìn)行了提前加載,應(yīng)用需要使用的時候即可快速配置并啟動。
#!/bin/sh
#
# Load mpp modules....
#
MODULES_DIR="/lib/modules/`uname -r`"
start() {
printf "Load mpp modulesn"
insmod $MODULES_DIR/videobuf2-core.ko
insmod $MODULES_DIR/videobuf2-memops.ko
insmod $MODULES_DIR/videobuf2-dma-contig.ko
insmod $MODULES_DIR/videobuf2-v4l2.ko
insmod $MODULES_DIR/vin_io.ko
# insmod $MODULES_DIR/sensor_power.ko
insmod $MODULES_DIR/gc4663_mipi.ko
insmod $MODULES_DIR/vin_v4l2.ko
insmod $MODULES_DIR/sunxi_aio.ko
insmod $MODULES_DIR/sunxi_eise.ko
# insmod $MODULES_DIR/vipcore.ko
}
stop() {
printf "Unload mpp modulesn"
# rmmod $MODULES_DIR/vipcore.ko
rmmod $MODULES_DIR/sunxi_eise.ko
rmmod $MODULES_DIR/sunxi_aio.ko
rmmod $MODULES_DIR/vin_v4l2.ko
rmmod $MODULES_DIR/gc4663_mipi.ko
# rmmod $MODULES_DIR/sensor_power.ko
rmmod $MODULES_DIR/vin_io.ko
rmmod $MODULES_DIR/videobuf2-v4l2.ko
rmmod $MODULES_DIR/videobuf2-dma-contig.ko
rmmod $MODULES_DIR/videobuf2-memops.ko
rmmod $MODULES_DIR/videobuf2-core.ko
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
8.增加攝像頭測試程序
在Tina根目錄下執(zhí)行make menuconfig
,進(jìn)入Tina配置界面后,進(jìn)入如下目錄,輸入Y選中camerademo測試程序。
> Allwinner
> Vision
<*> camerademo........................................ camerademo test sensor --->
9.編譯燒寫鏡像
在Tina的根目錄下,輸入make -j32
book@100ask:~/workspaces/tina-v853-open$ make -j32
...
book@100ask:~/workspaces/tina-v853-open$ pack
...
? 生成鏡像后,將tina-v853-open/out/v853/100ask/openwrt/目錄下的v853_linux_100ask_uart0.img鏡像拷貝到Windows電腦主機(jī)中,使用全志PhoenixSuit燒寫工具燒寫到開發(fā)板上。
? 上電前需要連接插上12V的電源線,和兩條Type-C,把開關(guān)撥向電源接口方向上電,燒寫新鏡像后等待啟動系統(tǒng),在命令行中輸入lsmod
root@TinaLinux:/# lsmod
Module Size Used by
vin_v4l2 181099 0
gc2053_mipi 8567 0
vin_io 21106 3 vin_v4l2,gc2053_mipi
videobuf2_v4l2 9304 1 vin_v4l2
videobuf2_dma_contig 8632 1 vin_v4l2
videobuf2_memops 948 1 videobuf2_dma_contig
videobuf2_core 22168 2 vin_v4l2,videobuf2_v4l2
xradio_wlan 598 0
xradio_core 431911 1 xradio_wlan
xradio_mac 222724 1 xradio_core
可以看到我們之前選中的VIN驅(qū)動和GC2053驅(qū)動已經(jīng)裝載進(jìn)去了
10.運(yùn)行camera測試程序
在開發(fā)板的串口終端界面輸入camedemo -h
可以輸出camera測試程序的使用教程
root@TinaLinux:/# camerademo -h
[CAMERA]**********************************************************
[CAMERA]* *
[CAMERA]* this is camera test. *
[CAMERA]* *
[CAMERA]**********************************************************
[CAMERA]******************** camerademo help *********************
[CAMERA] This program is a test camera.
[CAMERA] It will query the sensor to support the resolution, output format and test frame rate.
[CAMERA] At the same time you can modify the data to save the path and get the number of photos.
[CAMERA] When the last parameter is debug, the output will be more detailed information
[CAMERA] There are eight ways to run:
[CAMERA] 1.camerademo --- use the default parameters.
[CAMERA] 2.camerademo debug --- use the default parameters and output debug information.
[CAMERA] 3.camerademo setting --- can choose the resolution and data format.
[CAMERA] 4.camerademo setting debug --- setting and output debug information.
[CAMERA] 5.camerademo NV21 640 480 30 bmp /tmp 5 --- param input mode,can save bmp or yuv.
[CAMERA] 6.camerademo NV21 640 480 30 bmp /tmp 5 debug --- output debug information.
[CAMERA] 7.camerademo NV21 640 480 30 bmp /tmp 5 Num --- /dev/videoNum param input mode,can save bmp or yuv.
[CAMERA] 8.camerademo NV21 640 480 30 bmp /tmp 5 Num debug --- /dev/videoNum output debug information.
[CAMERA] 8.camerademo NV21 640 480 30 bmp /tmp 5 Num 1 --- 1/2: chose memory: V4L2_MEMORY_MMAP/USERPTR
[CAMERA]**********************************************************
在開發(fā)板的串口終端界面輸入camerademo NV21 640 480 30 bmp /tmp 5
,將會拍攝5張照片放在/tmp目錄下,將/tmp目錄下的文件拷貝到電腦端即可查看相應(yīng)的圖片。
具體教程可以參考:https://tina.100ask.net/SdkModule/Linux_Camera_DevelopmentGuide-06/
-
嵌入式
+關(guān)注
關(guān)注
5082文章
19126瀏覽量
305198 -
Linux
+關(guān)注
關(guān)注
87文章
11304瀏覽量
209499 -
攝像頭
+關(guān)注
關(guān)注
60文章
4841瀏覽量
95695 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5050瀏覽量
97471 -
MIPI
+關(guān)注
關(guān)注
11文章
310瀏覽量
48627
發(fā)布評論請先 登錄
相關(guān)推薦
評論