Driver for the VIN peripheral on RA MCUs. This module implements the CAPTURE Interface.
Overview
The VIN peripheral relies on the use of a Camera Serial Interface (CSI-2) Host, physical layer (D-PHY), and supporting sub-systems. Together, these form a high-speed graphics serial bus that formats and writes image data to memory according to the MIPI_CSI and R_VIN configurations.
Features
The module has one video channel that can control the capture of data into a capture area of up to 4096 × 4096 pixels when scaling is off (2048 × 2048 pixels when scaling is on). It can also provide vertical and horizontal scaling of the data by up to three and two times, respectively.
For captured video data, the VIN provides a color space conversion function from YCbCr-422 to RGB or RGB to YCbCr-422 and a format conversion function from RGB to ARGB.
As the VIN internally generates a field signal, it can capture progressive data.
Supported Data Types:
Image Format | Input Camera Format (MIPI CSI) | Output Memory Format |
YCbCr-422 8-bit | Supported | Supported |
YCbCr-422 10-bit | Supported | Supported |
RGB-565 | | Supported |
ARGB-1555 | | Supported |
RGB-888 | Supported | |
ARGB-8888 | | Supported |
RAW8 | Supported | Supported |
Configuration
Build Time Configurations for r_vin
The following build time configurations are defined in fsp_cfg/r_vin_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Clock Configuration
AXI bus clock (aclk) runs on ICLK and is the main clock for VIN, processing one pixel per clock cycle. In the case of CSI-2, VIN processes the following depths with aclk, so select a clock that is higher than the transfer rate.
- RGB 888: depth = 24 bit
- YCbCr8bit: depth = 16 bit
- YCbCr10bit: depth = 20 bit
- RAW8: depth = 16 bit Example: When setting up for a 720 Mbps 2 lane MIPI CSI transfer rate, with YCbCr 8bit scaling bypass, aclk must be set to a frequency of 720*2/16 = 90 MHz or higher.
Pin Configuration
VIN does not require pin configuration.
Usage Notes
Color Space Conversion
VIN may (optionally) be configured to convert between RGB and YCbCr data.
RGB to YCbCr Conversion
Formulas are below for the conversion of RGB to YCbCr formats Y = ((C_RtoY × R + C_GtoY × G + C_BtoY × B) × 2 ^ YCLSFT) + Y_Addition Cb = ((C_RtoCb × R + C_GtoCb × G + C_BtoCb × B) × 2 ^ CBCLSFT) + Cb_Addition Cr = ((C_RtoCr × R + C_GtoCr × G + C_BtoCr × B) × 2 ^ CRCLSFT) + Cr_Addition
- Note
- : YCLSFT, CBCLSFT, and CRCLSFT values are all fixed to 10.
YCbCr to RGB Conversion
When enabled, YCbCr to RGB conversion is carried out according to the configured matrix coefficients. The color conversion input is extended to 12 bits by the data extension selection. See User Manual for additional information.
Examples
Basic Example
This is a basic example showing the minimum code required to initialize and start the VIN module.
void vin_minimal_example (void)
{
assert(FSP_SUCCESS == err);
USER_CODE_camera_open();
assert(FSP_SUCCESS == err);
USER_CODE_camera_stream_on();
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
{
switch (event)
{
{
USER_CODE_vin_process_notify(module_status, interrupt_status);
if (interrupt_status.bits.frame_complete)
{
USER_CODE_vin_process_completed_frame(p_args->
p_buffer, module_status.bits.latest_buffer);
}
break;
}
{
USER_CODE_vin_process_error(module_status, interrupt_status);
break;
}
default:
{
break;
}
}
}
void USER_CODE_camera_open (void)
{
}
void USER_CODE_camera_stream_on (void)
{
}
{
}
{
}
void USER_CODE_vin_process_completed_frame (uint8_t * p_complete_frame, uint8_t frame_idx)
{
}
◆ vin_input_ctrl_t
VIN Input Control Structure
◆ vin_output_ctrl_t
VIN Output Control Structure
Data Fields |
uint8_t * |
image_buffer[3] |
Pointer to Image Buffer Memory Base (64-byte aligned) |
◆ vin_conversion_ctrl_t
struct vin_conversion_ctrl_t |
VIN Conversion Control Structure
◆ vin_conversion_data_t
struct vin_conversion_data_t |
VIN Conversion Data Structure
◆ vin_module_status_t
union vin_module_status_t |
◆ vin_interrupt_status_t
union vin_interrupt_status_t |
◆ vin_irq_cfg_t
Data Fields |
uint8_t |
ipl |
Interrupt priority. |
IRQn_Type |
irq |
Interrupt vector number. |
◆ vin_interrupt_cfg_t
struct vin_interrupt_cfg_t |
◆ vin_instance_ctrl_t
struct vin_instance_ctrl_t |
VIN instance control block.
◆ vin_extended_cfg_t
struct vin_extended_cfg_t |
Extended configuration structure for VIN.
◆ vin_interlace_mode_t
VIN Interface Mode Type
Enumerator |
---|
VIN_INTERLACE_MODE_ODD_FIELD_CAPTURE | Odd-field (field 1) Capture Mode.
|
VIN_INTERLACE_MODE_ODD_EVEN_FIELD_CAPTURE | Odd/Even-field Capture Mode.
|
VIN_INTERLACE_MODE_EVEN_FEILD_CAPTURE | Even-field Cature Mode.
|
◆ vin_dithering_mode_t
VIN Dithering Mode
Enumerator |
---|
VIN_DITHERING_MODE_WITH_ADDITION | Dithereing with Cumulative Addition.
|
VIN_DITHERING_MODE_ORDERED_1 | Ordered Dithering 1.
|
VIN_DITHERING_MODE_ORDERED_2 | Ordered Dithering 2.
|
◆ vin_input_format_t
VIN Input format
Enumerator |
---|
VIN_INPUT_FORMAT_YCBCR422_8_BIT | Input Format 8-Bit YCbCr-422.
|
VIN_INPUT_FORMAT_YCBCR422_10_BIT | Input Format 10-Bit YCbCr-42.
|
VIN_INPUT_FORMAT_RAW8 | Input Format RAW8.
|
VIN_INPUT_FORMAT_RGB888_24_BIT | Input Format 24-Bit RGB888.
|
◆ vin_data_type_t
VIN Data Type Select
Enumerator |
---|
VIN_DATA_TYPE_YUV422_8_BIT | Data Type YUV422 8-bit.
|
VIN_DATA_TYPE_YUV422_10_BIT | Data Type YUV422 10-bit.
|
VIN_DATA_TYPE_RGB888_BIT | Data Type RGB888.
|
VIN_DATA_TYPE_RAW8_BIT | Data Type RAW8.
|
◆ vin_yuv444_conversion_mode_t
VIN Input YUV444 Conversion Mode
Enumerator |
---|
VIN_YUV444_CONVERSION_MODE_DATA_EXTEND | The data of CbCr to be interpolated holds the data one pixel before.
|
VIN_YUV444_CONVERSION_MODE_INTERPOLATE | Generates CbCr data to be interpolated.
|
◆ vin_pixel_data_clipping_t
VIN Pixel Data Clipping
Enumerator |
---|
VIN_PIXEL_DATA_CLIPPING_DEFAULT | Default clipping mode.
|
VIN_PIXEL_DATA_CLIPPING_NIBBLE | Lower 4-bits clipping mode.
|
VIN_PIXEL_DATA_CLIPPING_DISABLED | Clipping mode disabled.
|
◆ vin_conversion_mode_t
VIN Conversion Mode
Enumerator |
---|
VIN_CONVERSION_MODE_NONE | Data is not converted before output.
|
VIN_CONVERSION_MODE_RGB_TO_ARGB | RGB input Data is converted to ARGB before output.
|
VIN_CONVERSION_MODE_YC_SEPARATED | Y and CbCr data are separated before output.
|
◆ vin_yc_transform_mode_t
VIN YC Transform Mode
Enumerator |
---|
VIN_YC_TRANSFORM_MODE_Y_CBCR | Y and CbCr data are transferred to memory.
|
VIN_YC_TRANSFORM_MODE_Y | Y data is transferred to memory as 8-bit data.
|
VIN_YC_TRANSFORM_MODE_Y10_CBCR | 10-bit Y data and 8-bit CbCr data are transferred to memory
|
VIN_YC_TRANSFORM_MODE_Y10 | 10-bit Y data is transferred to memory
|
◆ vin_interpolation_mode_t
VIN Interpolation Mode
Enumerator |
---|
VIN_INTERPOLATION_MODE_BILINEAR | Y and CbCr data are transferred to memory.
|
VIN_INTERPOLATION_MODE_NEIGHBOR | Y data is transferred to memory as 8-bit data.
|
◆ vin_event_t
VIN instance control block. Implements
Enumerator |
---|
VIN_EVENT_NONE | No Event.
|
VIN_EVENT_NOTIFY | Notification Event.
|
VIN_EVENT_ERROR | Error Event.
|
◆ R_VIN_Open()
Initialize the VIN peripheral.
- Return values
-
FSP_SUCCESS | The channel was successfully opened. |
FSP_ERR_ASSERTION | One or both of the parameters was NULL. |
FSP_ERR_ALREADY_OPEN | The instance is already opened. |
◆ R_VIN_Close()
Close VIN and display data instances, disable interrupts, and power-off the module.
- NOTE: Application shall issue stop command to the peripheral and wait at least one full frame before calling CSI_Stop, after ensuring MIPI CSI reception is no longer active by checking data returned by MIPI_CSI GetStatus()
- Return values
-
FSP_SUCCESS | The channel is successfully closed. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Instance is not open. |
◆ R_VIN_CaptureStart()
Start video capture.
- NOTE: For best results, camera should not be transmitting data until after VIN capture start has been called.
- Return values
-
FSP_SUCCESS | Data is successfully written to the D/A Converter. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Instance is not open. |
FSP_ERR_IN_USE | The physical interface is currently in use. |
FSP_ERR_INVALID_STATE | VIN is already in video mode. |
FSP_ERR_UNSUPPORTED | p_buffer parameter is not supported. |
◆ R_VIN_StatusGet()
Provide information about current VIN status.
- Return values
-
FSP_SUCCESS | Information read successfully. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Instance is not open. |