Skip to main content

7.3.4 Video Input

Overview

The Video Input Module (VIN) handles video data reception via the MIPI Rx interface and processes this data for further use. It captures raw video images, stores them in designated memory regions, and applies optional preprocessing to the data.

Terminology

  • Video Input Device: Primarily refers to SIF (Sensor Image Format), an interface that receives image data from camera modules and sends it directly to the ISP (Image Signal Processor) for processing without or with real-time adjustments.

  • Video Input PIPE (ISP): Bound to the device backend, responsible for image processing, core function configuration, and supports multi-context. It can handle up to 8 sensor inputs.

  • Lens Distortion Correction (LDC): Corrects image distortion caused by lens curvature, especially in low-end lenses, by applying distortion correction based on the degree of distortion.

  • Digital Image Stabilization (DIS): Compares current frames with previous ones to calculate displacement vectors along each axis using different degrees of freedom in anti-shake algorithms. This helps stabilize the image.

  • DWE: Integrates LDC and DIS functionality, combining both distortion correction and stabilization results.

Function Description

VIN is divided into four software components as shown below:

image-20220329195124946

Video Input Device

  • SIF primarily receives image data from camera modules and sends it to the ISP for processing in RAW8/RAW10/RAW12/RAW14/RAW16 formats, or YUV422 8-bit/10-bit. It supports up to 8 sensor connections.

Video Input PIPE

  • The ISP performs image processing, core function configuration, and supports multi-context with a maximum of 8 inputs. It pipelines image data and outputs in YUV format to channels. It also includes LDC and DIS functionalities.

Video Physical Channels

  • VIN has two physical channels: Channel 0 connects the ISP output to DDR or forwards it to the next module VPS, while Channel 1 routes the ISP output online to VPS. The relationship between VIN and VPS is detailed in the "System Control" section.

Binding Relationships

  • The binding relationship between VIN and VPS is described in the "System Control" chapter: HB_SYS_SetVINVPSMode.

API Reference

int HB_MIPI_SetBus(MIPI_SENSOR_INFO_S *snsInfo, uint32_t busNum);
int HB_MIPI_SetPort(MIPI_SENSOR_INFO_S *snsInfo, uint32_t port);
int HB_MIPI_SensorBindSerdes(MIPI_SENSOR_INFO_S *snsInfo, uint32_t serdesIdx, uint32_t serdesPort);
int HB_MIPI_SensorBindMipi(MIPI_SENSOR_INFO_S *snsInfo, uint32_t mipiIdx);
int HB_MIPI_SetExtraMode(MIPI_SENSOR_INFO_S *snsInfo, uint32_t ExtraMode);
int HB_MIPI_InitSensor (uint32_t DevId, MIPI_SENSOR_INFO_S *snsInfo);
int HB_MIPI_DeinitSensor (uint32_t DevId);
int HB_MIPI_ResetSensor(uint32_t DevId);
int HB_MIPI_UnresetSensor(uint32_t DevId);
int HB_MIPI_EnableSensorClock(uint32_t mipiIdx);
int HB_MIPI_DisableSensorClock(uint32_t mipiIdx);
int HB_MIPI_SetSensorClock(uint32_t mipiIdx, uint32_t snsMclk);
int HB_MIPI_ResetMipi(uint32_t mipiIdx);
int HB_MIPI_UnresetMipi(uint32_t mipiIdx);
int HB_MIPI_SetMipiAttr(uint32_t mipiIdx, MIPI_ATTR_S mipiAttr);
int HB_MIPI_Clear(uint32_t mipiIdx);
int HB_MIPI_ReadSensor(uint32_t devId, uint32_t regAddr, char *buffer, uint32_t size);
int HB_MIPI_WriteSensor (uint32_t devId, uint32_t regAddr, char *buffer, uint32_t size);
int HB_MIPI_GetSensorInfo(uint32_t devId, MIPI_SENSOR_INFO_S *snsInfo);
int HB_MIPI_SwSensorFps(uint32_t devId, uint32_t fps);
int HB_VIN_SetMipiBindDev(uint32_t devId, uint32_t mipiIdx);
int HB_VIN_GetMipiBindDev(uint32_t devId, uint32_t *mipiIdx);
int HB_VIN_SetDevAttr(uint32_t devId, const VIN_DEV_ATTR_S *stVinDevAttr);
int HB_VIN_GetDevAttr(uint32_t devId, VIN_DEV_ATTR_S *stVinDevAttr);
int HB_VIN_SetDevAttrEx(uint32_t devId, const VIN_DEV_ATTR_EX_S *stVinDevAttrEx);
int HB_VIN_GetDevAttrEx(uint32_t devId, VIN_DEV_ATTR_EX_S *stVinDevAttrEx);
int HB_VIN_EnableDev(uint32_t devId);
int HB_VIN_DisableDev (uint32_t devId);
int HB_VIN_DestroyDev(uint32_t devId);
int HB_VIN_SetDevBindPipe(uint32_t devId, uint32_t pipeId);
int HB_VIN_GetDevBindPipe(uint32_t devId, uint32_t *pipeId);
int HB_VIN_CreatePipe(uint32_t pipeId, const VIN_PIPE_ATTR_S * stVinPipeAttr);
int HB_VIN_DestroyPipe(uint32_t pipeId);
int HB_VIN_StartPipe(uint32_t pipeId);
int HB_VIN_StopPipe(uint32_t pipeId);
int HB_VIN_EnableChn(uint32_t pipeId, uint32_t chnId);
int HB_VIN_DisableChn(uint32_t pipeId, uint32_t chnId);
int HB_VIN_SetChnLDCAttr(uint32_t pipeId, uint32_t chnId,const VIN_LDC_ATTR_S *stVinLdcAttr);
int HB_VIN_GetChnLDCAttr(uint32_t pipeId, uint32_t chnId, VIN_LDC_ATTR_S*stVinLdcAttr);
int HB_VIN_SetChnDISAttr(uint32_t pipeId, uint32_t chnId, const VIN_DIS_ATTR_S *stVinDisAttr);
int HB_VIN_GetChnDISAttr(uint32_t pipeId, uint32_t chnId, VIN_DIS_ATTR_S *stVinDisAttr);
int HB_VIN_SetChnAttr(uint32_t pipeId, uint32_t chnId);
int HB_VIN_DestroyChn(uint32_t pipeId, uint32_t chnId);
int HB_VIN_GetChnFrame(uint32_t pipeId, uint32_t chnId, void *pstVideoFrame, int32_t millSec);
int HB_VIN_ReleaseChnFrame(uint32_t pipeId, uint32_t chnId, void *pstVideoFrame);
int HB_VIN_SendPipeRaw(uint32_t pipeId, void *pstVideoFrame,int32_t millSec);
int HB_VIN_SetPipeAttr(uint32_t pipeId, VIN_PIPE_ATTR_S *stVinPipeAttr);
int HB_VIN_GetPipeAttr(uint32_t pipeId, VIN_PIPE_ATTR_S *stVinPipeAttr);
int HB_VIN_CtrlPipeMirror(uint32_t pipeId, uint8_t on);
int HB_VIN_MotionDetect(uint32_t pipeId);
int HB_VIN_InitLens(uint32_t pipeId, VIN_LENS_FUNC_TYPE_ElensType,const VIN_LENS_CTRL_ATTR_S *lenCtlAttr);
int HB_VIN_DeinitLens(uint32_t pipeId);
int HB_VIN_RegisterDisCallback(uint32_t pipeId,VIN_DIS_CALLBACK_S *pstDISCallback);
int HB_VIN_SetDevVCNumber(uint32_t devId, uint32_t vcNumber);
int HB_VIN_GetDevVCNumber(uint32_t devId, uint32_t *vcNumber);
int HB_VIN_AddDevVCNumber(uint32_t devId, uint32_t vcNumber);
int HB_VIN_SetDevMclk(uint32_t devId, uint32_t devMclk, uint32_t vpuMclk);
int HB_VIN_GetChnFd(uint32_t pipeId, uint32_t chnId);
int HB_VIN_CloseFd(void);
int HB_VIN_EnableDevMd(uint32_t devId);
int HB_VIN_DisableDevMd(uint32_t devId);
int HB_VIN_GetDevFrame(uint32_t devId, uint32_t chnId, void *videoFrame, int32_t millSec);
int HB_VIN_ReleaseDevFrame(uint32_t devId, uint32_t chnId, void *buf);

These functions provide control over the MIPI interface, sensor configuration, video input pipeline management, and various video processing operations.

HB_MIPI_SetBus

Function Declaration

int HB_MIPI_SetBus(MIPI_SENSOR_INFO_S *snsInfo, uint32_t busNum)

Function Description

Configures the bus number for the sensor

Parameter Descriptions

Parameter NameDescriptionInput/Output
snsInfoSensor configuration informationInput
busNumBus number to be setInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples in HB_MIPI_InitSensor and HB_MIPI_DeinitSensor

HB_MIPI_SetPort

Function Declaration

int HB_MIPI_SetPort(MIPI_SENSOR_INFO_S *snsInfo, uint32_t port)

Function Description

Sets the port for the sensor, valid range is 0~7

Parameter Descriptions

Parameter NameDescriptionInput/Output
snsInfoSensor configuration informationInput
portCurrent sensor's port number (0~7)Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples in HB_MIPI_InitSensor and HB_MIPI_DeinitSensor

HB_MIPI_SensorBindSerdes

Function Declaration

int HB_MIPI_SensorBindSerdes(MIPI_SENSOR_INFO_S *snsInfo, uint32_t serdesIdx, uint32_t serdesPort)

Function Description

Assigns the sensor to a specific Serdes interface

Parameter Descriptions

Parameter NameDescriptionInput/Output
snsInfoSensor configuration informationInput
serdesIdxIndex of the Serdes, 0~1Input
serdesPortSerdes port number (954:01, 960:03)Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples in HB_MIPI_InitSensor and HB_MIPI_DeinitSensor

HB_MIPI_SensorBindMipi

Function Declaration

int HB_MIPI_SensorBindMipi(MIPI_SENSOR_INFO_S *snsInfo, uint32_t mipiIdx)

Function Description

Binds the sensor to a specific MIPI host

Parameter Descriptions

Parameter NameDescriptionInput/Output
snsInfoSensor configuration informationInput
mipiIdxIndex of the MIPI host, 0~3Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to example in HB_MIPI_InitSensor

HB_MIPI_SetExtraMode

Function Declaration

int HB_MIPI_SetExtraMode(MIPI_SENSOR_INFO_S *snsInfo, uint32_t ExtraMode)

Function Description

Sets the sensor's working mode in DOL2 or DOL3

Parameter Descriptions

Parameter NameDescriptionInput/Output
snsInfoSensor configuration informationInput
ExtraModeMode selection (see notes below)1. Single DOL2 mode, value 0
2. DOL2 split into two linear lanes, one with value 1, the other with value 2
3. Single DOL3 mode, value 0
4. One DOL2 lane (value 1) + one linear lane (value 4)
5. DOL3 split into three linear lanes, lane 2, 3, and 4

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Reference Code

Refer to examples in HB_MIPI_InitSensor and HB_MIPI_DeinitSensor

HB_MIPI_InitSensor / HB_MIPI_DeinitSensor

Function Declaration

int HB_MIPI_InitSensor (uint32_t DevId, MIPI_SENSOR_INFO_S  *snsInfo);
int HB_MIPI_DeinitSensor (uint32_t DevId);

Function Description

Initializes and releases resources for the sensor

Parameter Descriptions

Parameter NameDescriptionInput/Output
DevIdChannel index, 0~7Input
snsInfoSensor informationInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

    MIPI_SENSOR_INFO_S  snsInfo;
MIPI_ATTR_S mipiAttr;
int DevId = 0, mipiIdx = 1;
int bus = 1, port = 0, serdes_index = 0, serdes_port = 0;
int ExtraMode= 0;

memset(snsInfo, 0, sizeof(MIPI_SENSOR_INFO_S));
memset(mipiAttr, 0, sizeof(MIPI_ATTR_S));
snsInfo.sensorInfo.bus_num = 0;
snsInfo.sensorInfo.bus_type = 0;
snsInfo.sensorInfo.entry_num = 0;
snsInfo.sensorInfo.sensor_name = "imx327";
snsInfo.sensorInfo.reg_width = 16;
snsInfo.sensorInfo.sensor_mode = NORMAL_M;
snsInfo.sensorInfo.sensor_addr = 0x36;

mipiAttr.dev_enable = 1;
mipiAttr.mipi_host_cfg.lane = 4;
mipiAttr.mipi_host_cfg.datatype = 0x2c;
mipiAttr.mipi_host_cfg.mclk = 24;
mipiAttr.mipi_host_cfg.mipiclk = 891;
mipiAttr.mipi_host_cfg.fps = 25;
mipiAttr.mipi_host_cfg.width = 1952;
mipiAttr.mipi_host_cfg.height = 1097;
mipiAttr.mipi_host_cfg->linelenth = 2475;
mipiAttr.mipi_host_cfg->framelenth = 1200;
mipiAttr.mipi_host_cfg->settle = 20;

HB_MIPI_SetBus(snsInfo, bus);
HB_MIPI_SetPort(snsinfo, port);
HB_MIPI_SensorBindSerdes(snsinfo, sedres_index, sedres_port);
HB_MIPI_SensorBindMipi(snsinfo, mipiIdx);
HB_MIPI_SetExtraMode (snsinfo, ExtraMode);
ret = HB_MIPI_InitSensor(DevId, snsInfo);
if(ret < 0) {
printf("HB_MIPI_InitSensor error!\n");
return ret;
}
ret = HB_MIPI_SetMipiAttr(mipiIdx, mipiAttr);
if(ret < 0) {
printf("HB_MIPI_SetMipiAttr error! do sensorDeinit\n");
HB_MIPI_SensorDeinit(DevId);
return ret;
}
ret = HB_MIPI_ResetSensor(DevId);
if(ret < 0) {
printf("HB_MIPI_ResetSensor error! do mipi deinit\n");
HB_MIPI_DeinitSensor(DevId);
HB_MIPI_Clear(mipiIdx);
return ret;
}
ret = HB_MIPI_ResetMipi(mipiIdx);
if(ret < 0) {
printf("HB_MIPI_ResetMipi error!\n");
HB_MIPI_UnresetSensor(DevId);
HB_MIPI_DeinitSensor(DevId);
HB_MIPI_Clear(mipiIdx);
return ret;
}
HB_MIPI_UnresetSensor(DevId);
HB_MIPI_UnresetMipi(mipiIdx);
HB_MIPI_DeinitSensor(DevId);
HB_MIPI_Clear(mipiIdx);

HB_MIPI_ResetSensor/HB_MIPI_UnresetSensor

Function Declaration

int HB_MIPI_ResetSensor(uint32_t DevId);
int HB_MIPI_UnresetSensor(uint32_t DevId);

Function Description

Control the opening and closing of the sensor data stream, equivalent to sensor_start/sensor_stop.

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdSensor channel index, range 0~7Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

None

Reference Code

Refer to examples for HB_MIPI_InitSensor/HB_MIPI_DeinitSensor.

HB_MIPI_EnableSensorClock/HB_MIPI_DisableSensorClock

Function Declaration

int HB_MIPI_EnableSensorClock(uint32_t mipiIdx);
int HB_MIPI_DisableSensorClock(uint32_t mipiIdx);

Function Description

Enable or disable the sensor_clk.

Parameter Descriptions

Parameter NameDescriptionInput/Output
mipiIdxMipi host index, range 0~3Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

Use this interface with the subboard crystal removed.

Reference Code

No example provided.

HB_MIPI_SetSensorClock

Function Declaration

int HB_MIPI_SetSensorClock(uint32_t mipiIdx, uint32_t snsMclk)

Function Description

Set the sensor_mclk. There are four sensor_mclk available, currently used for sensor0_mclk and sensor1_mclk. Mipi0 connects to sensor_mclk1, and mipi1 connects to sensor_mclk0; the hardware connection details are defined in the DTS.

Parameter Descriptions

Parameter NameDescriptionInput/Output
mipiIdxMipi host index, range 0~3Input
snsMclkFrequency in Hz, e.g., 24MHzInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

Use this interface with the subboard crystal removed.

Reference Code

  • Initialization:

    Set sensor_mclk first, then enable. HB_MIPI_SetSensorClock(mipiIdx, 24000000); HB_MIPI_EnableSensorClock(mipiIdx);

  • Shutdown:

    HB_MIPI_Clear(mipiIdx); HB_MIPI_DeinitSensor(devId); HB_MIPI_DisableSensorClock(mipiIdx);

HB_MIPI_ResetMipi/HB_MIPI_UnresetMipi

Function Declaration

int HB_MIPI_ResetMipi(uint32_t  mipiIdx);
int HB_MIPI_UnresetMipi(uint32_t mipiIdx)

Function Description

Control the start and stop of the Mipi functionality.

Parameter Descriptions

Parameter NameDescriptionInput/Output
mipiIdxMipi host index, range 0~3Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

None

Reference Code

Refer to examples for HB_MIPI_InitSensor/HB_MIPI_DeinitSensor.

HB_MIPI_SetMipiAttr

Function Declaration

int HB_MIPI_SetMipiAttr(uint32_t  mipiIdx, MIPI_ATTR_S  mipiAttr)

Function Description

Set the Mipi attributes, including host and device initialization.

Parameter Descriptions

Parameter NameDescriptionInput/Output
mipiIdxMipi host indexInput
mipiAttrMipi bus attribute informationInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

None

Reference Code

Refer to examples for HB_MIPI_InitSensor/HB_MIPI_DeinitSensor.

HB_MIPI_Clear

Function Declaration

int HB_MIPI_Clear(uint32_t  mipiIdx);

Function Description

Clear device-related configurations, equivalent to deinitializing the Mipi host/device and corresponds to the interface HB_MIPI_SetMipiAttr.

Parameter Descriptions

Parameter NameDescriptionInput/Output
mipiIdxMipi host index, range 0~3Input

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Notes

None

Reference Code

Refer to examples for HB_MIPI_InitSensor/HB_MIPI_DeinitSensor.

HB_MIPI_ReadSensor

Function Declaration

int HB_MIPI_ReadSensor(uint32_t devId, uint32_t regAddr, char *buffer, uint32_t size)

Function Description

Reads data from a sensor via I2C.

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdSensor channel index, range 0-7Input
regAddrRegister address to readInput
bufferAddress to store the read dataOutput
sizeLength of data to readInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

Must call HB_MIPI_InitSensor before using this function.

Example Code

(Example with imx327)

    int i;
char buffer[] = {0x34, 0x56};
char rev_buffer[30] = {0};
printf("HB_MIPI_InitSensor end\n");
ret = HB_MIPI_ReadSensor(devId, 0x3018, rev_buffer, 2);
if(ret < 0) {
printf("HB_MIPI_ReadSensor error\n");
}
for(i = 0; i < strlen(rev_buffer); i++) {
printf("rev_buffer[%d] 0x%x \n", i, rev_buffer[i]);
}
ret = HB_MIPI_WriteSensor(devId, 0x3018, buffer, 2);
if(ret < 0) {
printf("HB_MIPI_WriteSensor error\n");
}
ret = HB_MIPI_ReadSensor(devId, 0x3018, rev_buffer, 2);
if(ret < 0) {
printf("HB_MIPI_ReadSensor error\n");
}
for(i = 0; i < strlen(rev_buffer); i++) {
printf("rev_buffer[%d] 0x%x \n", i, rev_buffer[i]);
}

HB_MIPI_WriteSensor

Function Declaration

int HB_MIPI_WriteSensor (uint32_t devId, uint32_t regAddr, char *buffer, uint32_t size)

Function Description

Writes data to a sensor's register via I2C.

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdSensor channel index, range 0-7Input
regAddrRegister address to writeInput
bufferAddress containing data to writeInput
sizeLength of data to writeInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

Must call HB_MIPI_InitSensor before using this function.

Example Code

Refer to the HB_MIPI_ReadSensor example.

HB_MIPI_GetSensorInfo

Function Declaration

int HB_MIPI_GetSensorInfo(uint32_t devId, MIPI_SENSOR_INFO_S *snsInfo)

Function Description

Retrieves sensor configuration information.

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdSensor channel index, range 0-7Input
snsInfoStructure containing sensor infoOutput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

Must call HB_MIPI_InitSensor before using this function.

Example Code

    MIPI_SENSOR_INFO_S *snsinfo = NULL;
snsinfo = malloc(sizeof(MIPI_SENSOR_INFO_S));
if(snsinfo == NULL) {
printf("malloc error\n");
return -1;
}
memset(snsinfo, 0, sizeof(MIPI_SENSOR_INFO_S));
ret = HB_MIPI_GetSensorInfo(devId, snsinfo);
if(ret < 0) {
printf("HB_MIPI_InitSensor error!\n");
return ret;
}

HB_MIPI_SwSensorFps

Function Declaration

int HB_MIPI_SwSensorFps(uint32_t devId, uint32_t fps)

Function Description

Switches the sensor's frame rate.

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdSensor channel index, range 0-7Input
fpsDesired sensor frame rateInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

Must call HB_MIPI_InitSensor before using this function.

Example Code

No code provided as there is no specific example given.

HB_VIN_SetMipiBindDev/HB_VIN_GetMipiBindDev

Function Declaration:

int HB_VIN_SetMipiBindDev(uint32_t devId, uint32_t mipiIdx)
int HB_VIN_GetMipiBindDev(uint32_t devId, uint32_t *mipiIdx)

Function Description:

Sets the binding between a device and a Mipi_host, specifying which Mipi_host the device uses.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input
mipiIdxIndex of the Mipi_hostInput

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

No additional notes.

Reference Code:

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetDevAttr/HB_VIN_GetDevAttr

Function Declaration:

int HB_VIN_SetDevAttr(uint32_t devId, const VIN_DEV_ATTR_S *stVinDevAttr)
int HB_VIN_GetDevAttr(uint32_t devId, VIN_DEV_ATTR_S *stVinDevAttr)

Function Description:

Sets or retrieves the attributes of a device.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input
stVinDevAttrDevice attribute structureInput/Output

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Notes:

For multi-process scenarios with DOL3 split, the first process should run one second before the second. Also, setting attributes after destroying a device is currently not supported. If encountering an error like SIF_IOC_BIND_GROUT ioctl failed, it's usually due to a previous pipeid call that didn't exit before being called again.

Reference Code:

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetDevAttrEx/HB_VIN_GetDevAttrEx

Function Declaration:

int HB_VIN_SetDevAttrEx(uint32_t devId, const VIN_DEV_ATTR_EX_S *stVinDevAttrEx)
int HB_VIN_GetDevAttrEx(uint32_t devId, VIN_DEV_ATTR_EX_S *stVinDevAttrEx)

Function Description:

Sets or retrieves the extended attributes of a device.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input
stVinDevAttrExExtended device attribute structureInput/Output

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Notes:

This interface is not yet supported.

Reference Code:

No code example provided.

HB_VIN_EnableDev/HB_VIN_DisableDev

Function Declaration:

int HB_VIN_EnableDev(uint32_t devId);
int HB_VIN_DisableDev(uint32_t devId);

Function Description:

Enables or disables a device module.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Notes:

No additional notes.

Reference Code:

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_DestroyDev

Function Declaration:

int HB_VIN_DestroyDev(uint32_t devId)

Function Description:

Destroys a device module, releasing its resources.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Notes:

No additional notes.

Reference Code:

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetDevBindPipe/HB_VIN_GetDevBindPipe

Function Declaration:

int HB_VIN_SetDevBindPipe(uint32_t devId, uint32_t pipeId)
int HB_VIN_GetDevBindPipe(uint32_t devId, uint32_t *pipeId)

Function Description:

Sets the binding between a device's channel output and a pipe's channel input, as well as between a pipe's channel input and output.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdDevice index, range 0~7Input
pipeIdPipe index, same rangeInput

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

The HB_VIN_GetDevBindPipe interface is not yet implemented.

Reference Code:

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_CreatePipe/HB_VIN_DestroyPipe

Function Declaration

int HB_VIN_CreatePipe(uint32_t pipeId, const VIN_PIPE_ATTR_S *stVinPipeAttr);
int HB_VIN_DestroyPipe(uint32_t pipeId);

Function Description

Create a pipe and destroy a pipe

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdUnique identifier for each input channel, range 0~7Input
stVinPipeAttrPointer to the structure describing pipe attributesInput

Return Values

Return ValueMeaning
0Success
Non-zeroFailure

Note

None

Reference Code

    VIN_DEV_ATTR_S  stVinDevAttr;
VIN_PIPE_ATTR_S stVinPipeAttr;
VIN_DIS_ATTR_S stVinDisAttr;
VIN_LDC_ATTR_S stVinLdcAttr;
MIPI_SNS_TYPE_E sensorId = 1;
MIPI_SENSOR_INFO_S snsInfo;
MIPI_ATTR_S mipiAttr;
MIPI_SNS_TYPE_E sensorId = 1;
int PipeId = 0;
int DevId = 0, mipiIdx = 1;
int ChnId = 1, bus = 1, port = 0, serdes_index = 0, serdes_port = 0;

memset(snsInfo, 0, sizeof(MIPI_SENSOR_INFO_S));
memset(mipiAttr, 0, sizeof(MIPI_ATTR_S));
memset(stVinDevAttr, 0, sizeof(VIN_DEV_ATTR_S));
memset(stVinPipeAttr, 0, sizeof(VIN_PIPE_ATTR_));
memset(stVinDisAttr, 0, sizeof(VIN_DIS_ATTR_S));
memset(stVinLdcAttr, 0, sizeof(VIN_LDC_ATTR_S));
snsInfo.sensorInfo.bus_num = 0;
snsInfo.sensorInfo.bus_type = 0;
snsInfo.sensorInfo.entry_num = 0;
snsInfo.sensorInfo.sensor_name = "imx327";
snsInfo.sensorInfo.reg_width = 16;
snsInfo.sensorInfo.sensor_mode = NORMAL_M;
snsInfo.sensorInfo.sensor_addr = 0x36;

mipiAttr.dev_enable = 1;
mipiAttr.mipi_host_cfg.lane = 4;
mipiAttr.mipi_host_cfg.datatype = 0x2c;
mipiAttr.mipi_host_cfg.mclk = 24;
mipiAttr.mipi_host_cfg.mipiclk = 891;
mipiAttr.mipi_host_cfg.fps = 25;
mipiAttr.mipi_host_cfg.width = 1952;
mipiAttr.mipi_host_cfg.height = 1097;
mipiAttr.mipi_host_cfg->linelenth = 2475;
mipiAttr.mipi_host_cfg->framelenth = 1200;
mipiAttr.mipi_host_cfg->settle = 20;
stVinDevAttr.stSize.format = 0;
stVinDevAttr.stSize.width = 1952;
stVinDevAttr.stSize.height = 1097;
stVinDevAttr.stSize.pix_length = 2;
stVinDevAttr.mipiAttr.enable = 1;
stVinDevAttr.mipiAttr.ipi_channels = 1;
stVinDevAttr.mipiAttr.enable_frame_id = 1;
stVinDevAttr.mipiAttr.enable_mux_out = 1;
stVinDevAttr.DdrIspAttr.enable = 1;
stVinDevAttr.DdrIspAttr.buf_num = 4;
stVinDevAttr.DdrIspAttr.raw_feedback_en = 0;
stVinDevAttr.DdrIspAttr.data.format = 0;
stVinDevAttr.DdrIspAttr.data.width = 1952;
stVinDevAttr.DdrIspAttr.data.height = 1907;
stVinDevAttr.DdrIspAttr.data.pix_length = 2;
stVinDevAttr.outIspAttr.isp_enable = 1;
stVinDevAttr.outIspAttr.dol_exp_num = 4;
stVinDevAttr.outIspAttr.enable_flyby = 0;
stVinDevAttr.outDdrAttr.enable = 1;
stVinDevAttr.outDdrAttr.mux_index = 0;
stVinDevAttr.outDdrAttr.buffer_num = 10;
stVinDevAttr.outDdrAttr.raw_dump_en = 0;
stVinDevAttr.outDdrAttr.stride = 2928;
stVinDevAttr.outIpuAttr.enable_flyby = 0;

stVinPipeAttr.ddrOutBufNum = 8;
stVinPipeAttr.pipeDmaEnable = 1;
stVinPipeAttr.snsMode = 3;
stVinPipeAttr.stSize.format = 0;
stVinPipeAttr.stSize.width = 1920;
stVinPipeAttr.stSize.height = 1080;
stVinDisAttr.xCrop.rg_dis_start = 0;
stVinDisAttr.xCrop.rg_dis_end = 1919;
stVinDisAttr.yCrop.rg_dis_start = 0;
stVinDisAttr.yCrop.rg_dis_end = 1079
stVinDisAttr.disHratio = 65536;
stVinDisAttr.disVratio = 65536;
stVinDisAttr.disPath.rg_dis_enable = 0;
stVinDisAttr.disPath.rg_dis_path_sel = 1;
stVinDisAttr.picSize.pic_w = 1919;
stVinDisAttr.picSize.pic_h = 1079;
stVinLdcAttr->ldcEnable = 0;
stVinLdcAttr->ldcPath.rg_h_blank_cyc = 32;
stVinLdcAttr->yStartAddr = 524288;
stVinLdcAttr->cStartAddr = 786432;
stVinLdcAttr->picSize.pic_w = 1919;
stVinLdcAttr->picSize.pic_h = 1079;
stVinLdcAttr->lineBuf = 99;
stVinLdcAttr->xParam.rg_algo_param_a = 1;
stVinLdcAttr->xParam.rg_algo_param_b = 1;
stVinLdcAttr->yParam.rg_algo_param_a = 1;
stVinLdcAttr->yParam.rg_algo_param_b = 1;
stVinLdcAttr->xWoi.rg_length = 1919;
stVinLdcAttr->xWoi.rg_start = 0;
stVinLdcAttr->yWoi.rg_length = 1079;
stVinLdcAttr->yWoi.rg_start = 0;

ret = HB_VIN_CreatePipe(PipeId, pipeInfo);
if(ret < 0) {
printf("HB_VIN_CreatePipe t error!\n");
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetMipiBindDev(pipeId, mipiIdx);
if(ret < 0) {
printf("HB_VIN_SetMipiBindDev error!\n");
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetDevVCNumber(pipeId, deseri_port);
if(ret < 0) {
printf("HB_VIN_SetDevVCNumber error!\n");
return ret;
}
ret = HB_VIN_SetDevAttr(DevId, devInfo);
if(ret < 0) {
printf("HB_VIN_SetDevAttr error!\n");
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetPipeAttr (PipeId, pipeInfo);
if(ret < 0) {
printf("HB_VIN_SetPipeAttr error!\n");
HB_VIN_DestroyDev(DevId);
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetChnDISAttr(PipeId, ChnId, disInfo);
if(ret < 0) {
printf("HB_VIN_SetChnDISAttr error!\n");
HB_VIN_DestroyDev(DevId);
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetChnLDCAttr(PipeId, ChnId, ldcInfo);
if(ret < 0) {
printf("HB_VIN_SetChnLDCAttr error!\n");
HB_VIN_DestroyDev(DevId);
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_VIN_SetChnAttr(PipeId, ChnId );
if(ret < 0) {
printf("HB_VIN_SetChnAttr error!\n");
HB_VIN_DestroyPipe(PipeId);
return ret;
}
HB_VIN_SetDevBindPipe(DevId, PipeId);

HB_MIPI_SetBus(snsInfo, bus);
HB_MIPI_SetPort(snsinfo, port);
HB_MIPI_SensorBindSerdes(snsinfo, sedres_index, sedres_port);
HB_MIPI_SensorBindMipi(snsinfo, mipiIdx);
ret = HB_MIPI_InitSensor(devId, snsInfo);
if(ret < 0) {
printf("HB_MIPI_InitSensor error!\n");
HB_VIN_DestroyPipe(PipeId);
return ret;
}
ret = HB_MIPI_SetMipiAttr(mipiIdx, mipiAttr);
if(ret < 0) {
printf("HB_MIPI_SetMipiAttr error! do sensorDeinit\n");
HB_MIPI_SensorDeinit(sensorId);
HB_VIN_DestroyPipe(PipeId);
return ret;
}

ret = HB_VIN_EnableChn(PipeId, ChnId );
if(ret < 0) {
printf("HB_VIN_EnableChn error!\n");
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DestroyDev(pipeId);
HB_VIN_DestroyChn(pipeId, ChnId);
HB_VIN_DestroyPipe(pipeId);
return ret;
}
ret = HB_VIN_StartPipe(PipeId);
if(ret < 0) {
printf("HB_VIN_StartPipe error!\n");
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DisableChn(pipeId, ChnId);
HB_VIN_DestroyDev(pipeId);
HB_VIN_DestroyChn(pipeId, ChnId);
HB_VIN_DestroyPipe(pipeId);
return ret;
}
ret = HB_VIN_EnableDev(DevId);
if(ret < 0) {
printf("HB_VIN_EnableDev error!\n");
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DisableChn(pipeId, ChnId);
HB_VIN_StopPipe(pipeId);
HB_VIN_DestroyDev(pipeId);
HB_VIN_DestroyChn(pipeId, ChnId);
HB_VIN_DestroyPipe(pipeId);
return ret;
}
ret = HB_MIPI_ResetSensor(DevId );
if(ret < 0) {
printf("HB_MIPI_ResetSensor error! do mipi deinit\n");
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DisableDev(pipeId);
HB_VIN_StopPipe(pipeId);
HB_VIN_DisableChn(pipeId, ChnId);
HB_VIN_DestroyDev(pipeId);
HB_VIN_DestroyChn(pipeId, ChnId);
HB_VIN_DestroyPipe(pipeId);
return ret;
}
ret = HB_MIPI_ResetMipi(mipiIdx);
if(ret < 0) {
printf("HB_MIPI_ResetMipi error!\n");
HB_MIPI_UnresetSensor(DevId );
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DisableDev(pipeId);
HB_VIN_StopPipe(pipeId);
HB_VIN_DisableChn(pipeId, ChnId);
HB_VIN_DestroyDev(pipeId);
HB_VIN_DestroyChn(pipeId, ChnId);
HB_VIN_DestroyPipe(pipeId);
return ret;
}

HB_MIPI_UnresetSensor(DevId );
HB_MIPI_UnresetMipi(mipiIdx);
HB_VIN_DisableDev(PipeId);
HB_VIN_StopPipe(PipeId);
HB_VIN_DisableChn(PipeId, ChnId);
HB_MIPI_DeinitSensor(DevId );
HB_MIPI_Clear(mipiIdx);
HB_VIN_DestroyDev(DevId);
HB_VIN_DestroyChn(PipeId, ChnId);
HB_VIN_DestroyPipe(PipeId);

HB_VIN_StartPipe/HB_VIN_StopPipe

Function Declaration

int HB_VIN_StartPipe(uint32_t pipeId);
int HB_VIN_StopPipe(uint32_t pipeId);

Function Description

Start and stop the pipe.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_EnableChn/HB_VIN_DisableChn

Function Declaration

int HB_VIN_EnableChn(uint32_t pipeId, uint32_t chnId);
int HB_VIN_DisableChn(uint32_t pipeId, uint32_t chnId);

Function Description

Enable or disable a channel on the pipe.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input
chnIdInput 1 is sufficientInput

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetChnLDCAttr/HB_VIN_GetChnLDCAttr

Function Declaration

int HB_VIN_SetChnLDCAttr(uint32_t pipeId, uint32_t chnId, const VIN_LDC_ATTR_S *stVinLdcAttr);
int HB_VIN_GetChnLDCAttr(uint32_t pipeId, uint32_t chnId, VIN_LDC_ATTR_S*stVinLdcAttr);

Function Description

Set or get the LDC attribute for a channel.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input (Output for getting attribute)
chnIdInput 1 is sufficientInput (Output for getting attribute)
stVinLdcAttrLDC attribute informationInput (Output for getting attribute)

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

When VIN_ISP and VPS are in online mode, LDC parameters must be configured through this interface. Otherwise, VPS may encounter an exception. LDC parameter configuration is not required when VIN_ISP and VPS are in offline mode.

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetChnDISAttr/HB_VIN_GetChnDISAttr

Function Declaration

int HB_VIN_SetChnDISAttr(uint32_t pipeId, uint32_t chnId, const VIN_DIS_ATTR_S *stVinDisAttr);
int HB_VIN_GetChnDISAttr(uint32_t pipeId, uint32_t chnId, VIN_DIS_ATTR_S *stVinDisAttr);

Function Description

Set or get the DIS attribute for a channel.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input (Output for getting attribute)
chnIdInput 1 is sufficientInput (Output for getting attribute)
stVinDisAttrDIS attribute informationInput (Output for getting attribute)

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_SetChnAttr

Function Declaration

int HB_VIN_SetChnAttr(uint32_t pipeId, uint32_t chnId);

Function Description

Set the attributes for a channel.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input
chnIdInput 1 is sufficientInput

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

The LDC and DIS attributes are actually set in this interface. HB_VIN_SetChnLDCAttr and HB_VIN_SetChnDISAttr only assign values to the attributes. This 'chn' refers to one of ISP's output channels, with a fixed value of 1.

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_DestroyChn

Function Declaration

int HB_VIN_DestroyChn(uint32_t pipeId, uint32_t chnId)

Function Description

Destroy a channel.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input channel ID, range 0~7Input
chnIdInput 1 is sufficientInput

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

Currently, it is not supported to re-configure HB_VIN_SetChnAttr after HB_VIN_DestroyChn.

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_GetChnFrame/HB_VIN_ReleaseChnFrame

Function Declaration

int HB_VIN_GetChnFrame(uint32_t pipeId, uint32_t chnId, void *pstVideoFrame, int32_t millSec);
int HB_VIN_ReleaseChnFrame(uint32_t pipeId, uint32_t chnId, void *pstVideoFrame);

Function Description

Retrieve data after ISP processing on the pipe channel

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdCorresponding input pipe, range 0~7Input
chnIdCan be set to 0Input
pstVideoFrameData informationOutput
millSecTimeout parameter
-1 for blocking interface;
0 for non-blocking interface;
positive value for timeout in milliseconds (ms)
Input

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Notes

This interface retrieves the image processed by the ISP

Reference Code

Refer to HB_VIN_CreatePipe/HB_VIN_DestroyPipe examples

HB_VIN_GetDevFrame/HB_VIN_ReleaseDevFrame

Function Declaration

int HB_VIN_GetDevFrame(uint32_t devId, uint32_t chnId, void *videoFrame, int32_t millSec);
int HB_VIN_ReleaseDevFrame(uint32_t devId, uint32_t chnId, void *buf);

Function Description

Retrieve data after SIF processing, where chnId is 0

Parameter Descriptions

Parameter NameDescriptionInput/Output
devIdCorresponding input pipe, range 0~7Input
chnIdCan be set to 0Input
videoFrameData informationOutput
millSecTimeout parameter
-1 for blocking interface;
0 for non-blocking interface;
positive value for timeout in milliseconds (ms)
Input

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Notes

This interface retrieves the image processed by SIF, useful when SIF is offline-ISP and can dump raw images. Scenarios:

VIN_OFFLINE_VPS_ONLINE VIN_OFFLINE_VPS_OFFINE VIN_SIF_OFFLINE_ISP_OFFLINE_VPS_ONLINE

Additionally, when SIF is online-ISP with DDR, it can also dump raw images. Scenarios:

VIN_SIF_ONLINE_DDR_ISP_DDR_VPS_ONLINE VIN_SIF_ONLINE_DDR_ISP_ONLINE_VPS_ONLINE

Example Code

    typedef struct {
uint32_t frame_id;
uint32_t plane_count;
uint32_t xres[MAX_PLANE];
uint32_t yres[MAX_PLANE];
char *addr[MAX_PLANE];
uint32_t size[MAX_PLANE];
} raw_t;
typedef struct {
uint8_t ctx_id;
raw_t raw;
} dump_info_t;
dump_info_t dump_info = {0};
hb_vio_buffer_t *sif_raw = NULL;
int pipeId = 0;
sif_raw = (hb_vio_buffer_t *) malloc(sizeof(hb_vio_buffer_t));
memset(sif_raw, 0, sizeof(hb_vio_buffer_t));

ret = HB_VIN_GetDevFrame(pipeId, 0, sif_raw, 2000);
if (ret < 0) {
printf("HB_VIN_GetDevFrame error!!!\n");
} else {
if (sif_raw->img_info.planeCount == 1) {
dump_info.ctx_id = info->group_id;
dump_info.raw.frame_id = sif_raw->img_info.frame_id;
dump_info.raw.plane_count = sif_raw->img_info.planeCount;
dump_info.raw.xres[0] = sif_raw->img_addr.width;
dump_info.raw.yres[0] = sif_raw->img_addr.height;
dump_info.raw.addr[0] = sif_raw->img_addr.addr[0];
dump_info.raw.size[0] = size;
printf("pipe(%d)dump normal raw frame id(%d),plane(%d)size(%d)\n",
dump_info.ctx_id, dump_info.raw.frame_id,
dump_info.raw.plane_count, size);
} else if (sif_raw->img_info.planeCount == 2) {
dump_info.ctx_id = info->group_id;
dump_info.raw.frame_id = sif_raw->img_info.frame_id;
dump_info.raw.plane_count = sif_raw->img_info.planeCount;
for (int i = 0; i < sif_raw->img_info.planeCount; i ++) {
dump_info.raw.xres[i] = sif_raw->img_addr.width;
dump_info.raw.yres[i] = sif_raw->img_addr.height;
dump_info.raw.addr[i] = sif_raw->img_addr.addr[i];
dump_info.raw.size[i] = size;
}
if(sif_raw->img_info.img_format == 0) {
printf("pipe(%d)dump dol2 raw frame id(%d),plane(%d)size(%d)\n",
dump_info.ctx_id, dump_info.raw.frame_id,
dump_info.raw.plane_count, size);
}
} else if (sif_raw->img_info.planeCount == 3) {
dump_info.ctx_id = info->group_id;
dump_info.raw.frame_id = sif_raw->img_info.frame_id;
dump_info.raw.plane_count = sif_raw->img_info.planeCount;
for (int i = 0; i < sif_raw->img_info.planeCount; i ++) {
dump_info.raw.xres[i] = sif_raw->img_addr.width;
dump_info.raw.yres[i] = sif_raw->img_addr.height;
dump_info.raw.addr[i] = sif_raw->img_addr.addr[i];
dump_info.raw.size[i] = size;
}
printf("pipe(%d)dump dol3 raw frame id(%d),plane(%d)size(%d)\n",
dump_info.ctx_id, dump_info.raw.frame_id,
dump_info.raw.plane_count, size);
} else {
printf("pipe(%d)raw buf planeCount wrong !!!\n", info->group_id);
}
for (int i = 0; i < dump_info.raw.plane_count; i ++) {
if(sif_raw->img_info.img_format == 0) {
sprintf(file_name, "pipe%d_plane%d_%ux%u_frame_%03d.raw",
dump_info.ctx_id,
i,
dump_info.raw.xres[i],
dump_info.raw.yres[i],
dump_info.raw.frame_id);
dumpToFile(file_name, dump_info.raw.addr[i], dump_info.raw.size[i]);
}
}
if(sif_raw->img_info.img_format == 8) {
sprintf(file_name, "pipe%d_%ux%u_frame_%03d.yuv",
dump_info.ctx_id,
dump_info.raw.xres[i],
dump_info.raw.yres[i],
dump_info.raw.frame_id);
dumpToFile2plane(file_name, sif_raw->img_addr.addr[0],
sif_raw->img_addr.addr[1], size, size/2);
}
}
ret = HB_VIN_ReleaseDevFrame(pipeId, 0, sif_raw);
if (ret < 0) {
printf("HB_VIN_ReleaseDevFrame error!!!\n");
}
free(sif_raw);
sif_raw = NULL;
}

int dumpToFile(char *filename, char *srcBuf, unsigned int size)
{
FILE *yuvFd = NULL;
char *buffer = NULL;

yuvFd = fopen(filename, "w+");
if (yuvFd == NULL) {
vio_err("ERRopen(%s) fail", filename);
return -1;
}
buffer = (char *)malloc(size);
if (buffer == NULL) {
vio_err(":malloc file");
fclose(yuvFd);
return -1;
}
memcpy(buffer, srcBuf, size);
fflush(stdout);
fwrite(buffer, 1, size, yuvFd);
fflush(yuvFd);
if (yuvFd)
fclose(yuvFd);
if (buffer)
free(buffer);
vio_dbg("filedump(%s, size(%d) is successed\n", filename, size);
return 0;
}
int dumpToFile2plane(char *filename, char *srcBuf, char *srcBuf1,
unsigned int size, unsigned int size1)
{
FILE *yuvFd = NULL;
char *buffer = NULL;

yuvFd = fopen(filename, "w+");
if (yuvFd == NULL) {
vio_err("open(%s) fail", filename);
return -1;
}
buffer = (char *)malloc(size + size1);
if (buffer == NULL) {
vio_err("ERR:malloc file");
fclose(yuvFd);
return -1;
}
memcpy(buffer, srcBuf, size);
memcpy(buffer + size, srcBuf1, size1);
fflush(stdout);
fwrite(buffer, 1, size + size1, yuvFd);
fflush(yuvFd);
if (yuvFd)
fclose(yuvFd);
if (buffer)
free(buffer);
vio_dbg("filedump(%s, size(%d) is successed\n", filename, size);
return 0;
}

HB_VIN_SendPipeRaw

Function Declaration

int HB_VIN_SendPipeRaw(uint32_t pipeId, void *pstVideoFrame, int32_t millSec)

Function Description

Sends raw data to the ISP for processing.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdID of each input, range 0~7Input
pstVideoFramePointer to the raw data informationInput
millSecTimeout parameter
-1 for blocking interface
0 for non-blocking interface
Positive value for timeout in milliseconds (ms)
Input

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

None

Reference Code

int pipeId = 0;
hb_vio_buffer_t *feedback_buf;
hb_vio_buffer_t *isp_yuv = NULL;
isp_yuv = (hb_vio_buffer_t *) malloc(sizeof(hb_vio_buffer_t));
memset(isp_yuv, 0, sizeof(hb_vio_buffer_t));
ret = HB_VIN_SendPipeRaw(pipeId, feedback_buf, 1000);
if (ret) {
printf("HB_VIN_SendFrame error!!!\n");
}
ret = HB_VIN_GetChnFrame(pipeId, 0, isp_yuv, -1);
if (ret < 0) {
printf("HB_VIN_GetPipeFrame error!!!\n");
}
ret = HB_VIN_ReleaseChnFrame(pipeId, 0, isp_yuv);
if (ret < 0) {
printf("HB_VPS_ReleaseDevRaw error!!!\n");
}

HB_VIN_SetPipeAttr/HB_VIN_GetPipeAttr

Function Declaration

int HB_VIN_SetPipeAttr(uint32_t pipeId, VIN_PIPE_ATTR_S *stVinPipeAttr);
int HB_VIN_GetPipeAttr(uint32_t pipeId, VIN_PIPE_ATTR_S *stVinPipeAttr);

Function Description

Sets or retrieves pipe (ISP) attributes.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdID of each input, range 0~7Input (set), Output (get)
stVinPipeAttrPointer to the structure describing pipe attributesInput (set), Output (get)

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

None

Reference Code

Refer to examples for HB_VIN_CreatePipe/HB_VIN_DestroyPipe.

HB_VIN_CtrlPipeMirror

Function Declaration

int HB_VIN_CtrlPipeMirror(uint32_t pipeId, uint8_t on);

Function Description

Controls mirroring of the pipe.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdID of each input, range 0~7Input
on0 to disable, non-zero to enable mirrorInput

Return Values

Return ValueDescription
0Success
Non-zeroFailure

Note

Flip functionality requires GDC support; first enable mirroring and then rotate by 180 degrees if needed.

HB_VIN_MotionDetect

Function Declaration

int HB_VIN_MotionDetect(uint32_t pipeId)

Function Description

Detects motion in MD (Motion Detection) and returns if an interrupt is detected.

Parameter Descriptions

Parameter NameDescriptionInput/Output
pipeIdID of each input, range 0~7Input

Return Values

Return ValueDescription
0Motion detected, blocking call until motion detected.
Non-zeroNo motion detected.

Note

None

Reference Code

Refer to examples for HB_VIN_EnableDevMd.

HB_VIN_InitLens

Function Declaration:

int HB_VIN_InitLens(uint32_t pipeId, VIN_LENS_FUNC_TYPE_E lensType, const VIN_LENS_CTRL_ATTR_S *lenCtlAttr)

Function Description:

Motor driver initialization.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
pipeIdCorresponding input for each path, range 0-7Input
lensTypeLens function type (AF, Zoom)Input
lenCtlAttrControl attributesInput

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

If using AF, call this interface once. For both AF and Zoom functions, call initialization twice. Call when needed; not recommended if not used.

Reference Code:

None provided

HB_VIN_DeinitLens

Function Declaration:

int HB_VIN_DeinitLens(uint32_t pipeId)

Function Description:

Motor deinitialization.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
pipeIdCorresponding input for each path, range 0-7Input

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

No additional information.

Reference Code:

None provided

HB_VIN_RegisterDisCallback

Function Declaration:

int HB_VIN_RegisterDisCallback(uint32_t pipeId, VIN_DIS_CALLBACK_S *pstDISCallback)

Function Description:

Register dis callback function.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
pipeIdCorresponding input for each path, range 0-7Input
pstDISCallbackCallback interface pointerInput

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

No additional information.

Reference Code:

None provided

HB_VIN_SetDevVCNumber / HB_VIN_GetDevVCNumber

Function Declarations:

int HB_VIN_SetDevVCNumber(uint32_t devId, uint32_t vcNumber);
int HB_VIN_GetDevVCNumber(uint32_t devId, uint32_t *vcNumber);

Function Description:

Set and get the device's vc_index, which MIPI VC to use.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdCorresponding input for each path, range 0-7Input/Output (Output for Get)
vcNumberCorresponding MIPI VC, range 0-3Input (Input for Set, Output for Get)

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

No additional information.

Reference Code:

None provided

HB_VIN_AddDevVCNumber

Function Declaration:

int HB_VIN_AddDevVCNumber(uint32_t devId, uint32_t vcNumber)

Function Description:

Set the device's vc_index, which MIPI VC to use.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdCorresponding input for each path, range 0-7Input
vcNumberCorresponding MIPI VC, range 0-3Input

Return Values:

Return ValueDescription
0Success
Non-zeroFailure

Note:

In linear mode, this interface is not used. In DOL2 mode, call with vcNumber set to 1. In DOL3 mode, call twice HB_VIN_AddDevVCNumber with vcNumber set to 0 and 1, respectively.

Reference Code Snippet (for DOL2 mode):

  1. Bind dev0 to mipi0 HB_VIN_SetMipiBindDev(0, 0)

  2. Bind mipi0's virtual channel 0 to dev0 HB_VIN_SetDevVCNumber(0, 0)

  3. Bind mipi0's virtual channel 1 to dev0 HB_VIN_AddDevVCNumber(0, 1);

  4. Bind dev0 to ISP pipe0 HB_VIN_SetDevBindPipe(0, 0)

    ret = HB_SYS_SetVINVPSMode(pipeId, vin_vps_mode);
if(ret < 0) {
printf("HB_SYS_SetVINVPSMode%d error!\n", vin_vps_mode);
return ret;
}
ret = HB_VIN_CreatePipe(pipeId, pipeinfo); // isp init
if(ret < 0) {
printf("HB_MIPI_InitSensor error!\n");
return ret;
}
ret = HB_VIN_SetMipiBindDev(pipeId, mipiIdx);
if(ret < 0) {
printf("HB_VIN_SetMipiBindDev error!\n");
return ret;
}
ret = HB_VIN_SetDevVCNumber(pipeId, deseri_port);
if(ret < 0) {
printf("HB_VIN_SetDevVCNumber error!\n");
return ret;
}
ret = HB_VIN_AddDevVCNumber(pipeId, vc_num);
if(ret < 0) {
printf("HB_VIN_AddDevVCNumber error!\n");
return ret;
}
ret = HB_VIN_SetDevAttr(pipeId, devinfo);
if(ret < 0) {
printf("HB_MIPI_InitSensor error!\n");
return ret;
}
ret = HB_VIN_SetPipeAttr(pipeId, pipeinfo);
if(ret < 0) {
printf("HB_VIN_SetPipeAttr error!\n");
goto pipe_err;
}
ret = HB_VIN_SetChnDISAttr(pipeId, 1, disinfo);
if(ret < 0) {
printf("HB_VIN_SetChnDISAttr error!\n");
goto pipe_err;
}
ret = HB_VIN_SetChnLDCAttr(pipeId, 1, ldcinfo);
if(ret < 0) {
printf("HB_VIN_SetChnLDCAttr error!\n");
goto pipe_err;
}
ret = HB_VIN_SetChnAttr(pipeId, 1);
if(ret < 0) {
printf("HB_VIN_SetChnAttr error!\n");
goto chn_err;
}
HB_VIN_SetDevBindPipe(pipeId, pipeId);

HB_VIN_SetDevMclk

Function Declaration:

int HB_VIN_SetDevMclk(uint32_t devId, uint32_t devMclk, uint32_t vpuMclk);

Function Description:

Sets the SIF mclk and VPU clk for a given input channel.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdInput ID (0-7) for each channelInput
devMclkSIF mclk value to set, refer to SIF MCLKInput, kHz
vpuMclkVPU clk value to set, refer to VPU CLKInput, kHz

Return Values:

Return ValueMeaning
0Success
Non-zeroFailure

Note:

None

Reference Code:

Not provided

HB_VIN_GetChnFd

Function Declaration:

int HB_VIN_GetChnFd(uint32_t pipeId, uint32_t chnId)

Function Description:

Retrieves the file descriptor (FD) for a specified channel.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
pipeIdInput ID (0-7) for each channelInput
chnIdChannel number, set to 0Input

Return Values:

Return ValueMeaning
PositiveSuccess
NegativeFailure

Note:

None

Reference Code:

Not provided

HB_VIN_CloseFd

Function Declaration:

int HB_VIN_CloseFd(void)

Function Description:

Closes the file descriptor associated with a channel.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
voidNo inputNo output

Return Values:

Return ValueMeaning
0Success
Non-zeroFailure

Note:

None

Reference Code:

Not provided

HB_VIN_EnableDevMd

Function Declaration:

int HB_VIN_EnableDevMd(uint32_t devId)

Function Description:

Enables motion detect functionality for a given input channel.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdInput ID (0-7) for each channelInput

Return Values:

Return ValueMeaning
0Success
Non-zeroFailure

Note:

This function should be called after HB_VIN_SetDevAttrEx, as HB_VIN_SetDevAttrEx sets MD-related attributes. An example of using it is shown below:

VIN_DEV_ATTR_EX_S devAttr;
devAttr.path_sel = 0;
devAttr.roi_top = 0;
devAttr.roi_left = 0;
devAttr.roi_width = 1280;
devAttr.roi_height = 640;
devAttr.grid_step = 128;
devAttr.grid_tolerance =10;
devAttr.threshold = 10;
devAttr.weight_decay = 128;
devAttr.precision = 0;
ret = HB_VIN_SetDevAttrEx(pipeId, &devAttr);
if (ret < 0) {
printf("HB_VIN_SetDevAttrEx error!\n");
return ret;
}
ret = HB_VIN_EnableDevMd(pipeId);
if (ret < 0) {
printf("HB_VIN_EnableDevMd error!\n");
return ret;
}

A separate thread can be created to call HB_VIN_MotionDetect upon receiving an MD interrupt, followed by disabling MD with HB_VIN_DisableDevMd.

    int md_func(work_info_t * info)
{
int ret = 0;
int pipeId = info->group_id;
ret = HB_VIN_MotionDetect(pipeId);
if (ret < 0) {
printf("HB_VIN_MotionDetect error!!! ret %d \n", ret);
} else {
HB_VIN_DisableDevMd(pipeId);
printf("HB_VIN_DisableDevMd success!!! ret %d \n", ret);
}
return ret;
}

HB_VIN_DisableDevMd

Function Declaration:

int HB_VIN_DisableDevMd(uint32_t devId)

Function Description:

Disables motion detect functionality for a given input channel.

Parameter Descriptions:

Parameter NameDescriptionInput/Output
devIdInput ID (0-7) for each channelInput

Return Values:

Return ValueMeaning
0Success
Non-zeroFailure

Note:

This function is used by the user after receiving an MD interrupt to disable the MD feature.

Reference Code:

Please refer to the example provided for HB_VIN_EnableDevMd.

Data Structures

MIPI_INPUT_MODE_E

typedef enum HB_MIPI_INPUT_MODE_E
{
INPUT_MODE_MIPI = 0x0, /* mipi */
INPUT_MODE_DVP = 0x1, /* Digital Video Port (DVP) */
INPUT_MODE_BUTT
} MIPI_INPUT_MODE_E;

Function Description:

Sensor connection method

Member Descriptions:

  • MII (M-PHY Interface) connection
  • DVP (Digital Video Port) connection

MIPI_SENSOR_MODE_E

typedef enum HB_MIPI_SENSOR_MODE_E
{
NORMAL_M = 0x0,
DOL2_M = 0x1,
DOL3_M = 0x2,
PWL_M = 0x3,
} MIPI_SENSOR_MODE_E;

Function Description: Sensor working mode

Member Descriptions:

  • linear mode
  • DOL2 mode
  • DOL3 mode
  • PWM mode

MIPI_DESERIAL_INFO_T

typedef struct HB_MIPI_DESERIAL_INFO_T {
int bus_type;
int bus_num;
int deserial_addr;
int physical_entry;
char *deserial_name;
} MIPI_DESERIAL_INFO_T;

Function Description: Defines the attributes for SerDes initialization

Member Descriptions:

  • bus_type: Bus type, 0 for I2C, 1 for SPI
  • bus_num: Bus number, determined by the hardware schematic, currently set to 5
  • deserial_addr: SerDes address
  • physical_entry: Reserved
  • deserial_name: SerDes name

MIPI_SNS_INFO_S

typedef struct HB_MIPI_SNS_INFO_S {
int port;
int dev_port;
int bus_type;
int bus_num;
int fps;
int resolution;
int sensor_addr;
int serial_addr;
int entry_index;
MIPI_SENSOR_MODE_E sensor_mode;
int reg_width;
char *sensor_name;
int extra_mode;
int deserial_index;
int deserial_port;
int gpio_num;
int gpio_pin[GPIO_NUM];
int gpio_level[GPIO_NUM];
MIPI_SPI_DATA_S spi_info;
} MIPI_SNS_INFO_S;

Function Description: Defines the attributes for initializing a sensor

Member Descriptions:

  • port: Logical sensor identifier, must start from 0
  • dev_port: Driver node for each sensor path, one driver supports multiple nodes
  • bus_type: Bus type, 0 for I2C, 1 for SPI
  • bus_num: Bus number (default I2C5 based on hardware schematic)
  • fps: Frame rate
  • resolution: Sensor resolution
  • sensor_addr: Sensor address
  • serial_addr: Internal SerDes address of the sensor
  • entry_index: MIPI index used by the sensor
  • sensor_mode: Sensor working mode, 1 is normal, 2 is DOL2, 3 is DOL3
  • reg_width: Register address width
  • sensor_name: Sensor name
  • extra_mode: To distinguish sensor characteristics, specific to the sensor driver implementation
  • deserial_index: Index of the current SerDes
  • deserial_port: Port within the SerDes the sensor belongs to
  • gpio_num: Number of GPIO pins required for the sensor
  • gpio_pin: Array of GPIO pins used
  • gpio_level: Initial values for GPIO pins (0 for low-high, 1 for high-low)
  • spi_info: Sensor SPI information, some sensors access via SPI bus

MIPI_SENSOR_INFO_S

Structure Definition

typedef struct HB_MIPI_SENSOR_INFO_S {
int deseEnable;
MIPI_INPUT_MODE_E inputMode;
MIPI_DESERIAL_INFO_T deserialInfo;
MIPI_SNS_INFO_S sensorInfo;
} MIPI_SENSOR_INFO_S;

Function Description

Defines the property information for device initialization

Member Descriptions

MemberMeaning
deseEnableWhether the sensor has serdes
inputModeSensor connection mode
deserialInfoSerdes information
sensorInfoSensor information

MIPI_HOST_CFG_S

Structure Definition

typedef struct HB_MIPI_HOST_CFG_S {
uint16_t lane;
uint16_t datatype;
uint16_t mclk;
uint16_t mipiclk;
uint16_t fps;
uint16_t width;
uint16_t height;
uint16_t linelenth;
uint16_t framelenth;
uint16_t settle;
uint16_t channel_num;
uint16_t channel_sel[4];
} MIPI_HOST_CFG_S;

Function Description

Defines the initialization parameters for the MIPI host

Member Descriptions

MemberMeaning
laneNumber of lanes, 0~4
datatypeData format, see DATA TYPE
mclkMain clock of the MIPI module, currently fixed at 24MHz
mipiclkSensor's total MIPI bitrate, units Mbits per second
fpsActual frame rate of the sensor output
widthActual width of the sensor output
heightActual height of the sensor output
linelenthTotal line length with blanking
framelenthTotal frame length with blanking
settleActual Ttx-zero + Ttx-prepare time (in clock units)
channel_numNumber of virtual channels used
channel_sel[4]Array storing values for each virtual channel

MIPI_ATTR_S

Structure Definition

typedef struct HB_MIPI_ATTR_S {
MIPI_HOST_CFG_S mipi_host_cfg;
uint32_t dev_enable;
} MIPI_ATTR_S;

Function Description

Defines the initialization parameters for the MIPI host and device

Member Descriptions

MemberMeaning
mipi_host_cfgMIPI host configuration structure
dev_enableMIPI device enable, 1 for enabled, 0 for disabled

MIPI_SPI_DATA_S

Structure Definition

typedef struct HB_MIPI_SPI_DATA_S {
int spi_mode;
int spi_cs;
uint32_t spi_speed;
} MIPI_SPI_DATA_S;

Function Description

Defines sensor-related SPI information

Member Descriptions

MemberMeaning
spi_modeSPI operating mode
spi_csSPI Chip Select
spi_speedSPI data transfer rate

VIN_DEV_SIZE_S

Structure Definition

typedef struct HB_VIN_DEV_SIZE_S {
uint32_t format;
uint32_t width;
uint32_t height;
uint32_t pix_length;
} VIN_DEV_SIZE_S;

Function Description

Defines the attribute information for device initialization

Member Descriptions

MemberMeaning
formatPixel format, format 0 represents raw8~raw16, indicating whether it's raw8 or raw16 based on pix_length.
widthData width
heightData height
pix_lengthLength of each pixel point

VIN_MIPI_ATTR_S

Structure Definition

typedef struct HB_VIN_MIPI_ATTR_S {
uint32_t enable; /* Mipi enable, 0 is off, 1 is on */
uint32_t ipi_channels; /* Ipi channels used, starts from 0, e.g., 2 means using channels 0 and 1 */
uint32_t ipi_mode; /* 2 for DOL2 split into two linear, 3 for DOL3 split into DOL2 and one linear, or three linear */
uint32_t enable_mux_out; /* Enable Mux output selection */
uint32_t enable_frame_id; /* Enable Frame ID */
uint32_t enable_bypass; /* Enable bypass functionality */
uint32_t enable_line_shift; /* Unused */
uint32_t enable_id_decoder; /* Unused */
uint32_t set_init_frame_id; /* Initial Frame ID value, usually 1 */
uint32_t set_line_shift_count; /* Unused */
uint32_t set_bypass_channels; /* Unused */
uint32_t enable_pattern; /* Enable test pattern */
} VIN_MIPI_ATTR_S;

Function Description

Defines the initialization information for dev Mipi

Member Descriptions

MemberMeaning
enableMipi enable, 0 for disabled, 1 for enabled
ipi_channelsNumber of IPI channels used, starting from 0, e.g., 2 indicates channels 0 and 1 are in use
ipi_modeValue for DOL2 split into two linear (2), DOL3 split into DOL2 and one linear (3), or three linear
enable_mux_outEnables Mux output selection
enable_frame_idEnables Frame ID
enable_bypassEnables bypass functionality
enable_line_shiftUnused
enable_id_decoderUnused
set_init_frame_idInitial Frame ID value, commonly set to 1
set_line_shift_countUnused
set_bypass_channelsUnused
enable_patternEnables test pattern

VIN_DEV_INPUT_DDR_ATTR_S

Structure Definition

typedef struct HB_VIN_DEV_INPUT_DDR_ATTR_S {
uint32_t stride; /* Hardware stride matches format, e.g., 12-bit: stride = width * 1.5, 10-bit: stride = width * 1.25 */
uint32_t buf_num; /* Number of buffers for offline or feedback */
uint32_t raw_feedback_en; /* Enables feedback mode, exclusive with offline mode, can be used independently */
VIN_DEV_SIZE_S data; /* Data format, see VIN_DEV_SIZE_S */
} VIN_DEV_INPUT_DDR_ATTR_S;

Function Description

Defines the input information for dev, applicable for offline and feedback scenarios

Member Descriptions

MemberMeaning
strideHardware stride matching the format, e.g., for 12-bit: 1952x1.5
buf_numNumber of buffers for offline or feedback operations
raw_feedback_enEnables raw feedback mode, mutually exclusive with offline mode, can be used separately
dataData format details, as described in VIN_DEV_SIZE_S

VIN_DEV_OUTPUT_DDR_S

Structure Definition

typedef struct HB_VIN_DEV_OUTPUT_DDR_S {
uint32_t stride; /* Hardware stride matches format, currently set for 12-bit at 1952x1.5 */
uint32_t buffer_num; /* Number of buffers for DDR output */
uint32_t frameDepth; /* Maximum frames to get, recommended max is ddrOutBufNum - 4 */
} VIN_DEV_OUTPUT_DDR_S;

Function Description

Defines the DDR output initialization information for dev

Member Descriptions

MemberMeaning
strideHardware stride matching the format, currently for 12-bit at 1952x1.5
buffer_numNumber of buffers for DDR output to the device
frameDepthThe maximum number of frames that can be fetched, typically set to ddrOutBufNum minus 4 for optimal use

VIN_DEV_OUTPUT_ISP_S

Structure Definition

typedef struct HB_VIN_DEV_OUTPUT_ISP_S {
uint32_t dol_exp_num; // Exposure mode, 1 for normal, dol 2 or 3 with corresponding count
uint32_t enable_dgain; // ISP internal debug parameter, currently ignored
uint32_t set_dgain_short; // ISP internal debug parameter, currently ignored
uint32_t set_dgain_medium; // ISP internal debug parameter, currently ignored
uint32_t set_dgain_long; // ISP internal debug parameter, currently ignored
uint32_t short_maxexp_lines; // Maximum exposure lines for shortest frame, usually found in sensor mode registers, DOL2/3 values needed for IRAM allocation
uint32_t medium_maxexp_lines; // Maximum exposure lines for normal frame, usually found in sensor mode registers, DOL3 value needed for IRAM allocation
uint32_t vc_short_seq; // Sequence for DOL2/3 mode's shortest frames
uint32_t vc_medium_seq; // Sequence for DOL2/3 mode's normal frames
uint32_t vc_long_seq; // Sequence for DOL2/3 mode's longest frames
} VIN_DEV_OUTPUT_ISP_S;

Function Description

Defines the information for initializing dev output to the pipe.

Member Descriptions

MemberMeaning
dol_exp_numExposure mode, 1 for standard, dol 2 or 3 set to respective counts.
enable_dgainISP internal debugging parameter, temporarily ignored.
set_dgain_shortISP internal debugging parameter, temporarily ignored.
set_dgain_mediumISP internal debugging parameter, temporarily ignored.
set_dgain_longISP internal debugging parameter, temporarily ignored.
short_maxexp_linesMaximum exposure lines for the shortest frame, typically found in the sensor mode register table, DOL2/3 values required for IRAM allocation.
medium_maxexp_linesMaximum exposure lines for a normal frame, typically found in the sensor mode register table, DOL3 value required for IRAM allocation.
vc_short_seqDescribes the sequence for DOL2/3 mode's shortest frames.
vc_medium_seqDescribes the sequence for DOL2/3 mode's normal frames.
vc_long_seqDescribes the sequence for DOL2/3 mode's longest frames.

VIN_DEV_ATTR_S

Structure Definition

typedef struct HB_VIN_DEV_ATTR_S {
VIN_DEV_SIZE_S stSize; // Input data size
union {
VIN_MIPI_ATTR_S mipiAttr; // Mipi attributes
VIN_DVP_ATTR_S dvpAttr; // Dvp attributes
};
VIN_DEV_INPUT_DDR_ATTR_S DdrIspAttr; // DDR input attribute configuration for ISP (offline or refill)
VIN_DEV_OUTPUT_DDR_S outDdrAttr; // DDR output configuration for sif(dev)
VIN_DEV_OUTPUT_ISP_S outIspAttr; // Output attributes for sif to ISP
} VIN_DEV_ATTR_S;

Function Description

Defines the initialization attributes for dev.

Member Descriptions

MemberMeaning
stSizeSize of input data
enIntfModeInterface mode for sif(dev), either mipi or dvp, currently mipi.
DdrIspAttrInput DDR attribute configuration for ISP, offline or refill.
outDdrAttrDDR output configuration for sif(dev) connection.
outIspAttrAttributes for sif to ISP connections.

VIN_DEV_ATTR_EX_S

Structure Definition

typedef struct HB_VIN_DEV_ATTR_EX_S {
uint32_t path_sel; // 0: sif-isp path; 1: sif-ipu path
uint32_t roi_top;
uint32_t roi_left;
uint32_t roi_width;
uint32_t roi_height;
uint32_t grid_step; // Grid step size, a power of 2 between 4 and 128
uint32_t grid_tolerance;
uint32_t threshold;
uint32_t weight_decay;
uint32_t precision;
} VIN_DEV_ATTR_EX_S;

Function Description

Defines metadata-related information.

Member Descriptions

MemberMeaning
path_sel0: SIF-ISP path; 1: SIF-IPU path
roi_topY-coordinate of ROI
roi_leftX-coordinate of ROI
roi_widthROI width, must be a multiple of grid_step
roi_heightROI height, must be a multiple of grid_step
grid_stepWidth and height of each region in the motion detection grid, a power of 2 between 4 and 128.
grid_toleranceThreshold for comparing adjacent regions in a motion detection. A difference exceeds this to trigger a mot_det interrupt.
thresholdNumber of differing regions in the ROI exceeding this threshold triggers a mot_det interrupt.
weight_decayWeighting factor for the current frame when updating the reference buffer, not a full replacement.
precisionNumber of decimal places to retain during block calculations, valid range is 1 to 4.

VIN_PIPE_SENSOR_MODE_E

【Structure Definition】

typedef enum HB_VIN_PIPE_SENSOR_MODE_E {
SENSOR_NORMAL_MODE = 1,
SENSOR_DOL2_MODE,
SENSOR_DOL3_MODE,
SENSOR_DOL4_MODE,
SENSOR_PWL_MODE,
SENSOR_INVAILD_MODE
} VIN_PIPE_SENSOR_MODE_E;

【Function Description】

Sensor operation mode

【Member Descriptions】

Normal mode, DOL2 mode, DOL3 mode, PWL mode (compressed mode)

VIN_PIPE_CFA_PATTERN_E

【Structure Definition】

typedef enum HB_VIN_PIPE_CFA_PATTERN_E {
PIPE_BAYER_RGGB = 0,
PIPE_BAYER_GRBG,
PIPE_BAYER_GBRG,
PIPE_BAYER_BGGR,
PIPE_MONOCHROME,
} VIN_PIPE_CFA_PATTERN_E;

【Function Description】

Data format layout

【Member Descriptions】

Different data storage formats

VIN_PIPE_SIZE_S

【Structure Definition】

typedef struct HB_VIN_PIPE_SIZE_S {
uint32_t format;
uint32_t width;
uint32_t height;
} VIN_PIPE_SIZE_S;

【Function Description】

Defines pipe size data information

【Member Descriptions】

MemberMeaning
formatData format
widthData width
heightData height

VIN_PIPE_CALIB_S

【Structure Definition】

typedef struct HB_VIN_PIPE_CALIB_S {
uint32_t mode;
unsigned char *lname;
} VIN_PIPE_CALIB_S;

【Function Description】

Sensor calibration data loading

【Member Descriptions】

MemberMeaning
modeEnables sensor calibration loading (1 enabled, 0 disabled)
lnameCalibration library name pointer

VIN_PIPE_ATTR_S

【Structure Definition】

typedef struct HB_VIN_PIPE_ATTR_S {
uint32_t ddrOutBufNum;
uint32_t frameDepth;
VIN_PIPE_SENSOR_MODE_E snsMode;
VIN_PIPE_SIZE_S stSize;
VIN_PIPE_CFA_PATTERN_E cfaPattern;
uint32_t temperMode;
uint32_t ispBypassEn;
uint32_t ispAlgoState;
uint32_t ispAfEn;
uint32_t bitwidth;
uint32_t startX;
uint32_t startY;
VIN_PIPE_CALIB_S calib;
} VIN_PIPE_ATTR_S;

【Function Description】

Defines pipe attribute information

【Member Descriptions】

MemberMeaning
ddrOutBufNumData bit width (8, 10, 12, 14, 16, 20)
frameDepthMaximum number of frames to be fetched, frameDepth is the maximum when ddrOutBufNum is frameDepth - 3
snsModeSensor operating mode
stSizeSensor data information, see previous definition
cfaPatternData format layout, consistent with the sensor
temperModeTemper mode, 0 off, 2 on
BypassEnableEnables ISP bypass
ispAlgoStateEnables 3A algorithm library, 1 enabled, 0 disabled
bitwidthBit depth (8, 10, 12, 14, 16, 20)
startXX offset relative to the origin
startYY offset relative to the origin
calibCalibration data loading status, 1 enabled, 0 disabled

VIN_LDC_PATH_SEL_S

【Structure Definition】

typedef struct HB_VIN_LDC_PATH_SEL_S {
uint32_t rg_y_only:1;
uint32_t rg_uv_mode:1;
uint32_t rg_uv_interpo:1;
uint32_t reserved1:5;
uint32_t rg_h_blank_cyc:8;
uint32_t reserved0:16;
} VIN_LDC_PATH_SEL_S;

【Function Description】

Defines LDC attribute information

【Member Descriptions】

MemberMeaning
rg_y_onlyOutput type
rg_uv_modeOutput type
rg_uv_interpoTurning related
rg_h_blank_cycTurning related

VIN_LDC_PICSIZE_S

Structure Definition

typedef struct HB_VIN_LDC_PICSIZE_S {
uint16_t pic_w;
uint16_t pic_h;
} VIN_LDC_PICSIZE_S;

Function Description

Defines the LDC width and height input information.

Member Descriptions

MemberMeaning
pic_wSet the size minus 1, e.g., if ISP output is 1920, set it to 1919.
pic_hDo not change this value except for size, ldc, and dis settings.

VIN_LDC_ALGOPARAM_S

Structure Definition

typedef struct HB_VIN_LDC_ALGOPARAM_S {
uint16_t rg_algo_param_b;
uint16_t rg_algo_param_a;
} VIN_LDC_ALGOPARAM_S;

Function Description

Defines LDC property information.

Member Descriptions

MemberMeaning
rg_algo_param_bParameters that require tuning.
rg_algo_param_aParameters that require tuning.

VIN_LDC_OFF_SHIFT_S

Structure Definition

typedef struct HB_VIN_LDC_OFF_SHIFT_S {
uint32_t rg_center_xoff:8;
uint32_t rg_center_yoff:8;
uint32_t reserved0:16;
} VIN_LDC_OFF_SHIFT_S;

Function Description

Defines LDC property information.

Member Descriptions

MemberMeaning
rg_center_xoffCorrection for processing area.
rg_center_yoffCorrection for processing area.

VIN_LDC_WOI_S

Structure Definition

typedef struct HB_VIN_LDC_WOI_S {
uint32_t rg_start:12;
uint32_t reserved1:4;
uint32_t rg_length:12;
uint32_t reserved0:4;
} VIN_LDC_WOI_S;

Function Description

Defines LDC property information.

Member Descriptions

MemberMeaning
rg_startCorrection for processing area.
rg_lengthCorrection for processing area.

VIN_LDC_ATTR_S

Structure Definition

typedef struct HB_VIN_LDC_ATTR_S {
uint32_t ldcEnable;
VIN_LDC_PATH_SEL_S ldcPath;
uint32_t yStartAddr;
uint32_t cStartAddr;
VIN_LDC_PICSIZE_S picSize;
uint32_t lineBuf;
VIN_LDC_ALGOPARAM_S xParam;
VIN_LDC_ALGOPARAM_S yParam;
VIN_LDC_OFF_SHIFT_S offShift;
VIN_LDC_WOI_S xWoi;
VIN_LDC_WOI_S yWoi;
} VIN_LDC_ATTR_S;

Function Description

Defines LDC property information.

Member Descriptions

MemberMeaning
ldcEnableEnables or disables the LDC.
ldcPathOutput type selection.
yStartAddrAddress in Iram for usage.
cStartAddrAddress in Iram for usage.
picSizeInput dimension size (excluding padding).
lineBufValue set to 99.
xParamParameters that require tuning.
yParamParameters that require tuning.
offShiftCorrection for the processing area.
xWoiCorrection for the processing area in the X direction.
yWoiCorrection for the processing area in the Y direction.

VIN_DIS_PICSIZE_S

Structure Definition

typedef struct HB_VIN_DIS_PICSIZE_S {
uint16_t pic_w;
uint16_t pic_h;
} VIN_DIS_PICSIZE_S;

Function Description

Defines DIS property information.

Member Descriptions

MemberMeaning
pic_wSet the size minus 1, e.g., if ISP output is 1920, set it to 1919.
pic_hSet the size minus 1.

VIN_DIS_PATH_SEL_S

Structure Definition

typedef struct HB_VIN_DIS_PATH_SEL_S {
uint32_t rg_dis_enable:1;
uint32_t rg_dis_path_sel:1;
uint32_t reserved0:30;
} VIN_DIS_PATH_SEL_S;

Function Description

Defines DIS property information.

Member Descriptions

MemberMeaning
rg_dis_enableDis output type selection.
rg_dis_path_selDis output type selection.

VIN_DIS_CROP_S

Structure Definition

typedef struct HB_VIN_DIS_CROP_S {
uint16_t rg_dis_start;
uint16_t rg_dis_end;
};

Function Description

Defines the DIS cropping information.

Member Descriptions

MemberMeaning
rg_dis_startStart of the cropping area for processing.
rg_dis_endEnd of the cropping area for processing.

VIN_DIS_CALLBACK_S

Structure Definition

typedef struct HB_VIN_DIS_CALLBACK_S {
void (*VIN_DIS_DATA_CB)(uint32_t pipeId, uint32_t event,
VIN_DIS_MV_INFO_S *disData, void *userData);
};

Function Description

Defines the callback interface for DIS data.

Member Descriptions

MemberMeaning
VIN_DIS_DATA_CBCallback function that returns data to the user after receiving it.

VIN_DIS_MV_INFO_S

Structure Definition

typedef struct HB_VIN_DIS_MV_INFO_S {
int gmvX;
int gmvY;
int xUpdate;
int yUpdate;
};

Function Description

Defines information about coordinate movement.

Member Descriptions

MemberMeaning
gmvXAbsolute position relative to the camera center, with gmv being the movement relative to the fixed lock position.
gmvYAbsolute position relative to the camera center.
xUpdateRelative change in x position compared to the previous frame, regardless of whether the camera was locked or not.
yUpdateRelative change in y position compared to the previous frame.

VIN_DIS_ATTR_S

Structure Definition

typedef struct HB_VIN_DIS_ATTR_S {
VIN_DIS_PICSIZE_S picSize;
VIN_DIS_PATH_SEL_S disPath;
uint32_t disHratio;
uint32_t disVratio;
VIN_DIS_CROP_S xCrop;
VIN_DIS_CROP_S yCrop;
};

Function Description

Defines DIS attribute information.

Member Descriptions

MemberMeaning
picSizeInput image size
disPathOutput type
disHratioSet to 65536
disVratioSet to 65536
xCropCropping area adjustment for X axis
yCropCropping area adjustment for Y axis

VIN_LENS_FUNC_TYPE_E

Structure Definition

typedef enum HB_VIN_LENS_FUNC_TYPE_E {
VIN_LENS_AF_TYPE = 1,
VIN_LENS_ZOOM_TYPE,
VIN_LENS_INVALID,
};

Function Description

Lens motor function types.

Member Descriptions

  • AF: Automatic focus, changing focus distance.
  • ZOOM: Zoom, changing focal length.

VIN_LENS_CTRL_ATTR_S

Structure Definition

typedef struct HB_VIN_LENS_CTRL_ATTR_S {
uint16_t port;
VIN_LENS_MOTOR_TYPE_E motorType;
uint32_t maxStep;
uint32_t initPos;
uint32_t minPos;
uint32_t maxPos;
union {
struct {
uint16_t pwmNum;
uint32_t pwmDuty;
uint32_t pwmPeriod;
} pwmParam;
struct {
uint16_t pulseForwardNum;
uint16_t pulseBackNum;
uint32_t pulseDuty;
uint32_t pulsePeriod;
} pulseParam;
struct {
uint16_t i2cNum;
uint32_t i2cAddr;
} i2cParam;
struct {
uint16_t gpioA1;
uint16_t gpioA2;
uint16_t gpioB1;
uint16_t gpioB2;
} gpioParam;
};
} VIN_LENS_CTRL_ATTR_S;

Function Description

Defines attributes for lens control.

Member Descriptions

MemberMeaning
portCorresponds to each input, with pipeId.
motorTypeMotor driver type, see VIN_LENS_MOTOR_TYPE_E.
maxStepMaximum motor steps.
initPosInitial motor position.
minPosMinimum motor position.
maxPosMaximum motor position.
pwmNumPWM device number for motor control.
pwmDutyPWM duty cycle for motor control.
pwmPeriodPWM frequency for motor control.
pulseForwardNumPulse device number for forward motor control.
pulseBackNumPulse device number for backward motor control.
pulseDutyPulse duty cycle for motor control.
pulsePeriodPulse frequency for motor control.
i2cNumI2C device number for motor control.
i2cAddrI2C address for motor control.
gpioA1GPIO number for motor control A+.
gpioA2GPIO number for motor control A-.
gpioB1GPIO number for motor control B+.
gpioB2GPIO number for motor control B-.

VIN_LENS_MOTOR_TYPE_E

Structure Definition

typedef enum HB_VIN_LENS_MOTOR_TYPE_E {
VIN_LENS_PWM_TYPE = 0,
VIN_LENS_PULSE_TYPE,
VIN_LENS_I2C_TYPE,
VIN_LENSSPI_TYPE,
VIN_LENS_GPIO_TYPE
} VIN_LENS_MOTOR_TYPE_E;

Function Description

Motor drive type, available options include PWM, pulse count, I2C control, SPI communication, and GPIO timing control. GPIO method has been tested and validated due to hardware environment factors.

DATA TYPE

DataType Description
0x28RAW6
0x29RAW7
0x2ARAW8
0x2BRAW10
0x2CRAW12
0x2DRAW14
0x2EReserved
0x18YUV 420 8-bit
0x19YUV 420 10-bit
0x1ALegacy YUV420 8-bit
0x1BReserved
0x1CYUV 420 8-bit (Chroma Shifted Pixel Sampling)
0x1DYUV 420 10-bit (Chroma Shifted Pixel Sampling)
0x1EYUV 422 8-bit
0x1FYUV 422 10-bit

SIF MCLK

ISP Application ScenarioSIF_MCLK(MHz)
8M 30fps Input326.4
2M 30fps 2-Stream TDM148.36
2M 30fps Single Stream102.00
8M DOL2 30fps544.00
2M 15fps 4-Stream TDM148.36

VPU CLK

VPU Application ScenarioCodecVPU_BCLK/VPU_CCLK(MHz)
8M@30fpsAVC326.4
HEVC408
2M*4@30fpsAVC544
HEVC544
2M @30fpsAVC204
HEVC204

Error Codes

VIN error codes are listed below:

Error CodeMacro DefinitionDescription
-268565505HB_ERR_VIN_CREATE_PIPE_FAILFailed to create PIPE
-268565506HB_ERR_VIN_SIF_INIT_FAILDEV(Sif) initialization failure
-268565507HB_ERR_VIN_DEV_START_FAILDEV(Sif) start failure
-268565508HB_ERR_VIN_PIPE_START_FAILISP start failure
-268565509HB_ERR_VIN_CHN_UNEXISTChannel does not exist
-268565510HB_ERR_VIN_INVALID_PARAMInvalid interface parameter
-268565511HB_ERR_VIN_ISP_INIT_FAILISP initialization failure
-268565512HB_ERR_VIN_ISP_FRAME_CORRUPTEDISP frame corrupted; driver may drop frames
-268565513HB_ERR_VIN_CHANNEL_INIT_FAILFailure initializing two ISP channels
-268565514HB_ERR_VIN_DWE_INIT_FAILDWE initialization failure
-268565515HB_ERR_VIN_SET_DEV_ATTREX_FAILSIF extended attribute initialization fail
-268565516HB_ERR_VIN_LENS_INIT_FAILLens motor initialization failure
-268565517HB_ERR_VIN_SEND_PIPERAW_FAILFailed to send SIF raw data
-268565518HB_ERR_VIN_NULL_POINTVIN module has a null pointer
-268565519HB_ERR_VIN_GET_CHNFRAME_FAILFailed to get ISP output data
-268565520HB_ERR_VIN_GET_DEVFRAME_FAILFailed to get SIF output data
-268565521HB_ERR_VIN_MD_ENABLE_FAILMotionDetect enable failed
-268565522HB_ERR_VIN_MD_DISABLE_FAILMotionDetect disable failed
-268565523HB_ERR_VIN_SWITCH_SNS_TABLE_FAILFailed to switch ISP mode (linear/DOL)

Reference Code

Example code for the VIN part can be referred to in the get_sif_data and get_isp_data functions.