K230 Camera Sensor适配指南
1. 概述
本文档主要描述K230平台Camera Sensor基本框架以及如何新增支持一款新的Camera Sensor。
K230平台支持多种接口类型的sensor,我们以当前最常用的MIPI CSI接口Sensor为例进行说明。Sensor与主控平台的硬件连接示 意图如下:
主控通过I2C接口下发配置寄存器控制sensor的工作方式,sensor通过MIPI CSI接口将图像数据发送至主控SOC。
2. Camera Sensor框架
2.1 框架简介
Camera Sensor框架如图2-1所示,最底层是sensor驱动层
图2-1 camera sensor框架
从上到下依次是:媒体接口层,驱动层以及硬件层
- 媒体接口层:该层对上提供kd_mpi_sensor_xxx接口给外部模块操作和访问sensor设备,对下通过ioctl操作具体的sensor设备
- 驱动层:该层包括sensor公共操作接口具体的sensor设备驱动。公共操作接口主要是ioctl操作命令和sensor i2c读写接口,sensor驱动主要提供设备节点以及操作接口的实现。这部分也是sensor适配的主要工作。
- 硬件层:对应各个具体的sensor硬件
3. Sensor适配准备工作
用户在适配新的sensor之前需要做以下一些准备工作:
- 从正规渠道获取 Sensor datasheet、初始化序列。
- 查看 Sensor datasheet 和相关应用手册,特别关注 Sensor 曝光、增益控制方法,不同模式下曝光和增益的限制,长曝光实现方法,黑电平值,bayer 数据输出顺序等。
- 跟 Sensor 厂家索要所需模式初始化序列,了解各序列的数据数率,Sensor 输出总的宽高,精确的帧率是多少等。
- 确认 Sensor 控制接口是 I2C、SPI 还是其他接口,Sensor 的设备地址可以通过硬件设置。对于多个摄像头的场景,sensor 尽量不要复用 I2C 总线。不同场景的Sensor IO 电平可能是 1.8V 或者 3.3V,设计时需要保证 sensor 的 IO 电平与SOC 对应的 GPIO 供电电压一致。如 sensor 电平是 1.8V,则用于 sensor 控制的GPIO,如 Reset,I2C,PRDN,需要使用 1.8V 供电。
- 确认 Sensor 输出数据接口和协议类型。当前仅支持MIPI CSI接口。
- 确认 wdr mode 是 VC、DT 或者 DOL 等。
- 确认不同时序是否需要图像裁剪。
4. Sensor适配示例
本节将按照如何增加支持一个新的camera sensor的步骤来进行详细描述。
这里以ov5647驱动作为示例进行说明,对应的驱动文件源码路径如下:
src/big/mpp/kernel/sensor/src/ov5647_drv.c
4.1 定义支持的sensor类型
系统支持的Sensor类型是由如下枚举变量定义:
typedef enum {
OV_OV9732_MIPI_1280X720_30FPS_10BIT_LINEAR = 0,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_LINEAR_IR = 1,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_LINEAR_SPECKLE = 2,
OV_OV9286_MIPI_1280X720_60FPS_10BIT_LINEAR_IR = 3,
OV_OV9286_MIPI_1280X720_60FPS_10BIT_LINEAR_SPECKLE = 4,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_LINEAR_IR_SPECKLE = 5,
OV_OV9286_MIPI_1280X720_60FPS_10BIT_LINEAR_IR_SPECKLE = 6,
IMX335_MIPI_2LANE_RAW12_1920X1080_30FPS_LINEAR = 7,
IMX335_MIPI_2LANE_RAW12_2592X1944_30FPS_LINEAR = 8,
IMX335_MIPI_4LANE_RAW12_2592X1944_30FPS_LINEAR = 9,
IMX335_MIPI_2LANE_RAW12_1920X1080_30FPS_MCLK_7425_LINEAR = 10,
IMX335_MIPI_2LANE_RAW12_2592X1944_30FPS_MCLK_7425_LINEAR = 11,
IMX335_MIPI_4LANE_RAW12_2592X1944_30FPS_MCLK_7425_LINEAR = 12,
IMX335_MIPI_4LANE_RAW10_2XDOL = 13,
IMX335_MIPI_4LANE_RAW10_3XDOL = 14,
SC_SC035HGS_MIPI_1LANE_RAW10_640X480_120FPS_LINEAR = 15,
SC_SC035HGS_MIPI_1LANE_RAW10_640X480_60FPS_LINEAR = 16,
SC_SC035HGS_MIPI_1LANE_RAW10_640X480_30FPS_LINEAR = 17,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_MCLK_25M_LINEAR_SPECKLE = 18,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_MCLK_25M_LINEAR_IR = 19,
OV_OV9732_MIPI_1280X720_30FPS_10BIT_MCLK_16M_LINEAR = 20,
OV_OV5647_MIPI_1920X1080_30FPS_10BIT_LINEAR = 21,
OV_OV5647_MIPI_2592x1944_10FPS_10BIT_LINEAR = 22,
OV_OV5647_MIPI_640x480_60FPS_10BIT_LINEAR = 23,
OV_OV5647_MIPI_CSI0_1920X1080_30FPS_10BIT_LINEAR = 24,
SC_SC201CS_MIPI_1LANE_RAW10_1600X1200_30FPS_LINEAR = 25,
SC_SC201CS_SLAVE_MODE_MIPI_1LANE_RAW10_1600X1200_30FPS_LINEAR = 26,
OV_OV5647_MIPI_CSI1_1920X1080_30FPS_10BIT_LINEAR = 27,
OV_OV5647_MIPI_CSI2_1920X1080_30FPS_10BIT_LINEAR = 28,
XS9922B_MIPI_CSI0_1280X720_30FPS_YUV422_DOL3 = 29,
XS9950_MIPI_CSI0_1280X720_30FPS_YUV422 = 30,
XS9950_MIPI_CSI1_1280X720_30FPS_YUV422 = 31,
XS9950_MIPI_CSI2_1280X720_30FPS_YUV422 = 32,
XS9950_MIPI_CSI0_1920X1080_30FPS_YUV422 = 33,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_MCLK_25M_LINEAR_SPECKLE_V2 = 34,
OV_OV9286_MIPI_1280X720_30FPS_10BIT_MCLK_25M_LINEAR_IR_V2 = 35,
OV_OV9732_MIPI_1280X720_30FPS_10BIT_MCLK_16M_LINEAR_V2 = 36,
OV_OV5647_MIPI_CSI0_1920X1080_30FPS_10BIT_LINEAR_V2 = 37,
OV_OV5647_MIPI_CSI1_1920X1080_30FPS_10BIT_LINEAR_V2 = 38,
OV_OV5647_MIPI_CSI2_1920X1080_30FPS_10BIT_LINEAR_V2 = 39,
GC2053_MIPI_CSI0_1920X1080_30FPS_10BIT_LINEAR = 40,
SENSOR_TYPE_MAX,
} k_vicap_sensor_type;
用户需要增加新的sensor支持类型时,首先需要在这里增加对应类型的定义,该类型是应用程序获取sensor配置的唯一标志
4.2 sensor驱动适 配
sensor驱动适配在整个环节中最重要的环节,用户可以通过拷贝现有的sensor驱动文件来修改,其中关于sensor的AE相关寄存器配置和计算方式需要查看对应的手册或者寻求专业人事协助。
4.2.1 定义sensor寄存器配置列表
sensor寄存器配置由数据类型 k_sensor_reg_list 定义:
typedef struct {
k_u16 reg_addr;
k_u8 reg_val;
} k_sensor_reg_list;
以下是ov5647的寄存器配置列表
static const k_sensor_reg ov5647_mipi2lane_1080p_30fps_linear[] = {
//pixel_rate = 81666700
{0x0103, 0x01},
{0x0100, 0x00},
{0x3034, 0x1a},
{0x3035, 0x21},
...
{0x3501, 0x02},
{0x3502, 0xa0},
{0x3503, 0x07},
{0x350b, 0x10},
{REG_NULL, 0x00},
};