/本文档适用于R31版本/实现相机传感器驱动器使得能够通过传感器提供的原始格式通过CSI总线获取相机数据。根据相机和应用程序的不同,有两种类型的相机编程路径。
相机核心用户模式库提供应用程序和内核模式V4L2驱动程序之间的所有控件和数据处理。使用相机核心库界面的典型用例包括:
•使用TegraISP功能的应用程序•必须将RGB格式转换为YUV格式并为拜耳传感器执行各种后处理任务的应用程序
具有应用程序和内核模式V4L2驱动程序的LinuxforTegra架构框架是:
DirectV4L2Interface在支持直接V4L2接口的应用程序中,使用此接口与NVIDIAV4L2驱动程序进行通信,而无需使用相机核心用户模式库。使用此路径从传感器捕获RAW数据或验证传感器驱动程序。应用程序使用内核模式V4L2驱动程序如下:
提供一个拜耳像素格式传感器需要客户开发:•DeviceTreeinthekernel•V4L2sensordriver有两种不同版本的驱动程序可用于传感器驱动程序开发。版本是:•版本0:过去版本中使用的设计。某些版本0功能在以后的版本中不可用。•0版:使用新的TegraV4L2CameraFramework来模块化代码,简化传感器驱动程序架构并将冗余代码封装在一个公共位置的新版本。NVIDIA建议将此版本用于任何新的驱动程序开发。
提供的示例使用SonyIMX185传感器。索尼IMX185传感器的源代码在以下文件中:•Version0driver:imx185_vc•Version0driver:imx18c
相机模块和设备树CameraModulesandDeviceTree
安装在目标平台上的相机模块可以包括一个或多个设备。典型的后置摄像头模块包括互补金属氧化物半导体传感器。典型的前置摄像头模块可以包括单个CMOS传感器。
将一个或多个摄像头模块添加到设备树
在内核源代码树中找到或创建tegra-camera-platform设备节点:/hardware/nvidia/platform/t19x/common/kernel-dts/t19x-common-modules/tegra194-camera-imx185-a00.dtsi在Tegra-camera-platform设备节点中,使用一个或多个模块创建模块表。每个module必须包含其基本信息以及该模块内部设备的定义。
注意: 相机相关设备节点中的所有值字段必须使用字符串数据类型,但引用其他设备节点的文件除外。
tegra-camera-platform {
compatible = "nvidia, tegra-camera-platform";
modules {
module0 {
badge = "imx185_bottom_liimx185";
position = "bottom";
orientation = "0";
drivernode0 {
pcl_id = "v4l2_sensor";
devname = "imx185 30-001a";
proc-device-tree = "/proc/device-tree/i2c@3180000/tca9546@70/i2c@0/imx185_a@1a";
};
};
};
};
模块属性
个人成像设备InpidualImagingDevice
一个成像设备可以是一个相机模块内的组件,他可以是:•传感器sensor•聚焦器focuser•闪光灯flash必须将所需信息添加到设备树节点以支持设备操作。每个设备树节点对应一个设备,分配一个设备树节点包含以下内容:•Thenameofthedevice设备名称•Theslaveaddressforthedevice设备从机地址•Acompatiblestringthatidentifiesthenode标识该节点的匹配字符串
注意: 除引用其他设备节点的设备外,相机相关设备节点中的所有值字段都必须使用字符串数据类型。 An example device-tree node for the IMX185 V4L2 sensor driver is:
imx185_a@1a {
compatible = "nvidia,imx185";
reg = <0x1a>;
physical_w = "15.0";
physical_h = "12.5";
sensor_model ="imx185";
post_crop_frame_drop = "0";
use_decibel_gain = "true";
delayed_gain = "true";
use_sensor_mode_id = "true";
mode0 {
mclk_khz = "37125";
num_lanes = "4";
tegra_sinterface = "serial_a";
phy_mode = "DPHY";
discontinuous_clk = "no";
dpcm_enable = "false";
cil_settletime = "0";
dynamic_pixel_bit_depth = "12";
csi_pixel_bit_depth = "12";
mode_type = "bayer";
pixel_phase = "rggb";
active_w = "1920";
active_h = "1080";
readout_orientation = "0";
line_length = "2200";
inherent_gain = "1";
mclk_multiplier = "2";
pix_clk_hz = "74250000";
gain_factor = "10";
min_gain_val = "0"; /* 0dB */
max_gain_val = "480"; /* 48dB */
step_gain_val = "3"; /* 0.3 */
default_gain = "0";
min_hdr_ratio = "1";
max_hdr_ratio = "1";
framerate_factor = "1000000";
min_framerate = "1500000";
max_framerate = "30000000"; /* 30 */
min_exp_time = "30"; /* us */
max_exp_time = "660000"; /* us */
step_exp_time = "1";
default_exp_time = "33334"; /* us */
embedded_metadata_height = "1";
};
. . .
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
reg = <0>;
liimx185_imx185_out0: endpoint {
port-index = <0>;
bus-width = <4>;
remote-endpoint = <&liimx185_csi_in0>;
};
};
设备属性对于V4L2传感器设备的设备树节点,请为设备定义所需的硬件资源,如下所示:
property-valuepairs适用于V4L2实现的传感器模式的属性-值对是:
注意:
下表中的所有属性均按模式设置,必须精确设置。
Inputsignalhas16-bitdepth•Outputsignalhas12-bitdepth•csi_pixel_bit_depth=“12”•dynamic_pixel_bit_depth=“16”Thecontrolpointpropertiesare:
num_control_point | 4 |
control_point_x_0 | 0 |
control_point_x_1 | 2048 |
control_point_x_2 | 16384 |
control_point_x_3 | 65536 |
control_point_y_0 | 0 |
control_point_y_1 | 2048 |
control_point_y_2 | 2944 |
control_point_y_3 | 3712 |
示例数字重叠WDR曝光帧该示出了双曝光DOL多帧的示例。
适用于4K数字重叠WDR帧的此的值为:
•LI标题像素有助于区分垂直空白周期行和不同的曝光行。上中有三种LI:VBP,长曝光和短曝光。VP由VI模块基于LI滤除。•num_of_exposure表示每次数字重叠捕获中的曝光次数。对于4K数字重叠WDR的上述示例,这是•num_of_ignored_lines表示位于每个曝光帧顶部且未包含在输出帧中的行数。这包括OB行和IgnoredAreaEffectivePixel行,两者都使用与它们所在的曝光帧相同的LI头。这些行由VI模块读取并被裁剪掉。对于上面的示例,此值为14行=8OB行+6个忽略区域有效像素行。•num_of_lines_offset_0表示在双曝光DOL多帧中单次曝光和帧中出现的VBP行数。相同数量的VBP行出现在长曝光帧的末尾和短曝光帧的开始处。对于上面的示例,该值为50。•num_of_ignored_pixels表示每行开头的LI像素,用于区分不同的曝光行和VBP行。对于上面的示例,此值为•num_of_left_margin_pixels表示每行上像日期之前左侧的边距像素。这些是裁剪对齐所必需的。对于上面的示例,此值为1•num_of_right_margin_pixels表示每行像日期后右侧的边距像素。这些是裁剪对齐所必需的。对于上面的示例,此值为0。•active_w表示像素活动区域的总宽度。在这种情况下,它是3840+4+12+0=385•active_h表示像素活动区域的总高度。在这种情况下,它是+*2=444PortBinding端口绑定
vi {
num-channels = <1>;
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
reg = <0>;
liimx185_vi_in0: endpoint {
port-index = <2>;
bus-width = <4>;
remote-endpoint = <&liimx185_csi_out0>;
};
};
};
};
nvcsi {
num-channels = <1>;
#address-cells = <1>;
#size-cells = <0>;
channel@0 {
reg = <0>;
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
reg = <0>;
liimx185_csi_in0: endpoint@0 {
port-index = <0>;
bus-width = <4>;
remote-endpoint = <&liimx185_imx185_out0>;
};
};
port@1 {
reg = <1>;
liimx185_csi_out0: endpoint@1 {
remote-endpoint = <&liimx185_vi_in0>;
};
};
};
};
};
端口绑定属性是:
验证相机接口绑定
执行以下命令
//if have sudo apt-get install media-player-info
sudo media-ctl -p -d /dev/media0
对于本身不带该命令的系统可以通过apt-get install进行安装:
sudo apt-get install v4l-utils
返回的输出类似于以下内容:
Media controller API version 0.1.0
Media device information
------------------------
driver tegra-vi4
model NVIDIA Tegra Video Input Device
serial
bus info
hw revision 0x3
driver version 0.0.0
Device topology
- entity 1: 150c0000.nvcsi-0 (2 pads, 2 links)
type V4L2 subdev subtype Unknown flags 0
device node name /dev/v4l-subdev0
pad0: Sink
<- "imx185 30-001a":0 [ENABLED]
pad1: Source
-> "vi-output, imx185 30-001a":0 [ENABLED]
- entity 2: imx185 30-001a (1 pad, 1 link)
type V4L2 subdev subtype Sensor flags 0
device node name /dev/v4l-subdev1
pad0: Source
[fmt:SRGGB12/1920x1080 field:none]
-> "150c0000.nvcsi-0":0 [ENABLED]
- entity 3: vi-output, imx185 30-001a (1 pad, 1 link)
type Node subtype V4L flags 0
device node name /dev/video0
pad0: Sink
<- "150c0000.nvcsi-0":1 [ENABLED]
SensorPixelClock传感器像素时钟
相机软件使用传感器像素时钟来计算传感器的曝光和帧速率。必须正确设置才能避免潜在问题。根据传感器供应商提供的信息,有几种方法可以获得正确的传感器像素时钟频率:
UsingPLLmultiplierandPLLpre/postpiders:MCLKMultiplier=PLLMultiplier/PLLPre-pider/PLLPost-piderpixel_clk_hz=MCLK*MCLKMultiplierForexample:MCLK=24MHzPLLMultiplier=30PLLPre-pider=3PLLPost-pider=3MCLKMultiplier=30/3/3=67Pixel_clk_hz=24000000*67=160000000•UsingsensorCSIlaneoutputrate:pixel_clk_hz=sensordatarateperlane*numberoflanes/bitsperpixelForexample:Sensordatarate=891MbpsNumberoflanes=4Bitsperpixel=10pixel_clk_hz=891Mbps*4/10=356400000•Usingframesizeandframeratepixel_clk_hz=sensoroutputsize*framerate
注意:
传感器输出大小不是最终输出大小。 它是传感器用于生成最终输出大小的总像素数。
例如:
传感器输出尺寸= 2200 * 1125(实际输出尺寸1920 * 1080)
帧速率= 30 FPS
pixel_clk_hz = 2200 * 1125 * 30 = 742500000
文章为作者独立观点,不代表观点