RA Flexible Software Package Documentation  Release v6.0.0

 
Display Serial Interface (r_vin)

Functions

fsp_err_t R_VIN_Open (capture_ctrl_t *const p_api_ctrl, capture_cfg_t const *const p_cfg)
 
fsp_err_t R_VIN_Close (capture_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_VIN_CaptureStart (capture_ctrl_t *const p_api_ctrl, uint8_t *const p_buffer)
 
fsp_err_t R_VIN_StatusGet (capture_ctrl_t *const p_api_ctrl, capture_status_t *p_status)
 

Detailed Description

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:

ConfigurationOptionsDefaultDescription
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.

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)
{
fsp_err_t err = FSP_SUCCESS;
err = R_VIN_Open(&g_vin0_ctrl, &g_vin0_cfg);
assert(FSP_SUCCESS == err);
USER_CODE_camera_open(); // Prepare camera for capture
err = R_VIN_CaptureStart(&g_vin0_ctrl, NULL);
assert(FSP_SUCCESS == err);
USER_CODE_camera_stream_on(); // Camera begin outputting image data
capture_status_t capture_status;
err = R_VIN_StatusGet(&g_vin0_ctrl, &capture_status);
assert(FSP_SUCCESS == err);
err = R_VIN_Close(&g_vin0_ctrl);
assert(FSP_SUCCESS == err);
}
void vin0_callback (capture_callback_args_t * p_args)
{
vin_event_t event = (vin_event_t) p_args->event;
switch (event)
{
{
USER_CODE_vin_process_notify(module_status, interrupt_status);
if (interrupt_status.bits.frame_complete)
{
/* Capture Complete - Process data buffer pointer and index */
USER_CODE_vin_process_completed_frame(p_args->p_buffer, module_status.bits.latest_buffer);
}
break;
}
{
// Process Error based on interrupt and module status;
USER_CODE_vin_process_error(module_status, interrupt_status);
break;
}
default:
{
/* Do nothing */
break;
}
}
}
void USER_CODE_camera_open (void)
{
// Pre-transmission Camera Configuration
}
void USER_CODE_camera_stream_on (void)
{
// Begin Streaming Image Data
}
void USER_CODE_vin_process_error (vin_module_status_t module_status, vin_interrupt_status_t interrupt_status)
{
FSP_PARAMETER_NOT_USED(module_status);
FSP_PARAMETER_NOT_USED(interrupt_status);
// Process Error
}
void USER_CODE_vin_process_notify (vin_module_status_t module_status, vin_interrupt_status_t interrupt_status)
{
FSP_PARAMETER_NOT_USED(module_status);
FSP_PARAMETER_NOT_USED(interrupt_status);
// Process Status Notification
}
void USER_CODE_vin_process_completed_frame (uint8_t * p_complete_frame, uint8_t frame_idx)
{
FSP_PARAMETER_NOT_USED(p_complete_frame);
// Process Frame Data
}

Data Structures

struct  vin_input_ctrl_t
 
struct  vin_output_ctrl_t
 
struct  vin_conversion_ctrl_t
 
struct  vin_conversion_data_t
 
union  vin_module_status_t
 
union  vin_interrupt_status_t
 
struct  vin_irq_cfg_t
 
struct  vin_interrupt_cfg_t
 
struct  vin_instance_ctrl_t
 
struct  vin_extended_cfg_t
 

Enumerations

enum  vin_interlace_mode_t
 
enum  vin_dithering_mode_t
 
enum  vin_input_format_t
 
enum  vin_data_type_t
 
enum  vin_yuv444_conversion_mode_t
 
enum  vin_pixel_data_clipping_t
 
enum  vin_conversion_mode_t
 
enum  vin_yc_transform_mode_t
 
enum  vin_interpolation_mode_t
 
enum  vin_event_t
 

Data Structure Documentation

◆ vin_input_ctrl_t

struct vin_input_ctrl_t

VIN Input Control Structure

Data Fields
union vin_input_ctrl_t __unnamed__
struct vin_input_ctrl_t preclip
union vin_input_ctrl_t __unnamed__
union vin_input_ctrl_t __unnamed__
uint16_t image_stride Image Stride (Setting Unit: pixel)

◆ vin_output_ctrl_t

struct 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

Data Fields
uint32_t * uv_address Address for YC separation of YCbCr-422 UV data. (64-byte aligned)
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
union vin_conversion_data_t __unnamed__
struct vin_conversion_data_t rgb_to_yuv_conversion_settings[3]

◆ vin_module_status_t

union vin_module_status_t

VIN Module Status

◆ vin_interrupt_status_t

union vin_interrupt_status_t

VIN Interrupt Status

◆ vin_irq_cfg_t

struct vin_irq_cfg_t

VIN IRQ Configuration

Data Fields
uint8_t ipl Interrupt priority.
IRQn_Type irq Interrupt vector number.

◆ vin_interrupt_cfg_t

struct vin_interrupt_cfg_t

VIN Interrupt Control

Data Fields
vin_irq_cfg_t status
vin_irq_cfg_t error
union vin_interrupt_cfg_t __unnamed__
uint16_t scanline_compare_value 12-bit value to be compared with the received line count and trigger interrupt (0: disabled)

◆ vin_instance_ctrl_t

struct vin_instance_ctrl_t

VIN instance control block.

Data Fields

uint32_t open
 Interface is open.
 
void(* p_callback )(capture_callback_args_t *)
 Pointer to callback that is called when an adc_event_t occurs.
 
void * p_context
 Pointer to context to be passed into callback function.
 
capture_callback_args_tp_callback_memory
 Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory.
 

◆ vin_extended_cfg_t

struct vin_extended_cfg_t

Extended configuration structure for VIN.

Data Fields
mipi_csi_instance_t const * p_mipi_csi_instance Pointer to mipi physical layer instance.
vin_input_ctrl_t input_ctrl
vin_output_ctrl_t output_ctrl
vin_conversion_ctrl_t conversion_ctrl
vin_conversion_data_t conversion_data
vin_interrupt_cfg_t interrupt_cfg

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ R_VIN_Open()

fsp_err_t R_VIN_Open ( capture_ctrl_t *const  p_api_ctrl,
capture_cfg_t const *const  p_cfg 
)

Initialize the VIN peripheral.

Return values
FSP_SUCCESSThe channel was successfully opened.
FSP_ERR_ASSERTIONOne or both of the parameters was NULL.
FSP_ERR_ALREADY_OPENThe instance is already opened.

◆ R_VIN_Close()

fsp_err_t R_VIN_Close ( capture_ctrl_t *const  p_api_ctrl)

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_SUCCESSThe channel is successfully closed.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENInstance is not open.

◆ R_VIN_CaptureStart()

fsp_err_t R_VIN_CaptureStart ( capture_ctrl_t *const  p_api_ctrl,
uint8_t *const  p_buffer 
)

Start video capture.

  • NOTE: For best results, camera should not be transmitting data until after VIN capture start has been called.
Return values
FSP_SUCCESSData is successfully written to the D/A Converter.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENInstance is not open.
FSP_ERR_IN_USEThe physical interface is currently in use.
FSP_ERR_INVALID_STATEVIN is already in video mode.
FSP_ERR_UNSUPPORTEDp_buffer parameter is not supported.

◆ R_VIN_StatusGet()

fsp_err_t R_VIN_StatusGet ( capture_ctrl_t *const  p_api_ctrl,
capture_status_t p_status 
)

Provide information about current VIN status.

Return values
FSP_SUCCESSInformation read successfully.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENInstance is not open.