nxp-mcuxpresso / mcux-sdk

MCUXpresso SDK
BSD 3-Clause "New" or "Revised" License
323 stars 142 forks source link

video/camera/receiver/isi/fsl_isi_camera_adapter component should support output frame with raw8/raw10 format. #73

Closed SimonFu0506 closed 2 years ago

SimonFu0506 commented 2 years ago

Is your enhancement proposal related to a problem? Please describe. There are some camera only support raw8/raw10 format. So it is batter that video/camera/receiver/isi/fsl_isi_camera_adapter component should support output frame with raw8/raw10 format.

Describe the solution you'd like video/camera/receiver/isi/fsl_isi_camera_adapter component can output the raw8/raw10 format.

zejiang0jason commented 2 years ago

Hi @SimonFu0506 , thanks for feedback. There is RAW8 support, the example is here: https://github.com/NXPmicro/mcux-sdk-examples/blob/main/evkbimxrt1050/driver_examples/csi/raw8/csi_raw8.c

Would you please check whether it meets the RAW8 requirement? If so, RAW10 can be added similarly.

Thanks.

SimonFu0506 commented 2 years ago

Hi @zejiang0jason,

Thanks for your response. I have different hw with the example. Following is my board and MCU. Board: mekmimx8qm Devices: MIMX8QM6 Camera: OV7251 (Frame is Raw8)

My MCU supports the ISI module. So the camera receiver is based on ISI module. In the camera receiver module, there is a map that covert the video format to ISI format.

 static const isi_output_format_map_t s_isiOutputFormatMap[] = {{
                                                                   .fourccFormat = kVIDEO_PixelFormatXRGB8888,
                                                                   .isiFormat    = kISI_OutputXRGB8888,
                                                               },
                                                               {
                                                                   .fourccFormat = kVIDEO_PixelFormatRGB888,
                                                                   .isiFormat    = kISI_OutputRGB888,
                                                               },
                                                               {
                                                                   .fourccFormat = kVIDEO_PixelFormatRGB565,
                                                                   .isiFormat    = kISI_OutputRGB565,
                                                               },
                                                               {
                                                                   .fourccFormat = kVIDEO_PixelFormatYUYV,
                                                                   .isiFormat    = kISI_OutputYUV422_1P8P,
                                                               }};

But there is no item for raw8. In order to support raw8 format, I add a item in the map.

                                                               {
                                                                   .fourccFormat = kVIDEO_PixelFormatRAW8,
                                                                   .isiFormat = kISI_OutputRaw8,
                                                               },

It almost work. But I got following frames of color bar test pattern. fb_test_1

Following picture is the photo. fb_g30_e3000_5

The frames only have 4 gray levels and lost most of the information. Could you help check the SDK for my hw platform? Or give me some suggestion for it?

Thanks Simon

zejiang0jason commented 2 years ago

Hi @SimonFu0506 ,

Please try to modify the function MIPI_CSI2RX_InitInterface in file fsl_mipi_csi2rx.c, change csr->DATA_TYPE_DIS = 0U; to csr->DATA_TYPE_DIS = 0x80000000U;.

Thanks. Jason

SimonFu0506 commented 2 years ago

Hi @zejiang0jason,

Unfortunately, there is no any improvement after changing csr->DATA_TYPE_DIS to 0x80000000U.

Could you help review my configuration? If anything is wrong, please correct me.

Following is my configuration of camera.

const camera_config_t cameraConfig = {
        .pixelFormat = kVIDEO_PixelFormatRAW8,
        .bytesPerPixel = CAMERA_BYTE_PER_PIXEL,                            // 1
        .resolution = FSL_VIDEO_RESOLUTION(CAMERA_SINGLE_FRAME_WIDTH, (CAMERA_FRAME_HEIGHT + CAMERA_FRAME_METADATA_LINES)),       // 640 * 481
        .frameBufferLinePitch_Bytes = CAMERA_SINGLE_FRAME_WIDTH * CAMERA_BYTE_PER_PIXEL,    // 480 * 1
        .interface = kCAMERA_InterfaceMIPI,
        .controlFlags = 0,
        .framePerSec = CAMERA_FRAME_RATE,                                  // 60
        .mipiChannel = OV7251_MIPI_VIRTUAL_CHANNEL,                 // 0
        .csiLanes = 1,
    };

    Status = CAMERA_RECEIVER_Init(&(camRx->CameraReceiver), &cameraConfig, OVCameraRx_Callback, camRx);

CSI2 receiver configuration is:

    csi2rx_config_t csi2rxConfig =
    {
        .laneNum = 1,
        .tHsSettle_EscClk = 0x07,
    };

    CSI2RX_Init(MIPI_CSI_0__MIPI_CSI2RX, &csi2rxConfig);

MCU clock is:

mipiCsiEscClkFreq_Hz = 48000000;
err = sc_pm_set_clock_rate(ipc, SC_R_CSI_0, SC_PM_CLK_MISC, &mipiCsiEscClkFreq_Hz);
mipiCsiCoreClkFreq_Hz = 360000000;
err = sc_pm_set_clock_rate(ipc, SC_R_CSI_0, SC_PM_CLK_PER, &mipiCsiCoreClkFreq_Hz);

OV7251 camera clock:

pix-clk             48MHz
mipi-clk            384MHz
sys-clk             46.08MHz
ADC-clk             230.4MHz

Hope these information is helpful.

Thanks Simon

zejiang0jason commented 2 years ago

Hi @SimonFu0506 ,

After confirming internally, there is a system hardware integration issue with MIPI CSI and ISI. For RAW data, the total data bus width from CSI to ISI is 14-bit, and the input data is aligned with MSB. In other word, when you use RAW8 data, the RAW8 data is fed to ISI input bit13-bit6, the ISI input bit5-bit0 is always 0, so in the result, only 2-bit are saved in memory, as you see.

The fix is only applied to imx8qx_c0, with this fix, the offset can be corrected by setting CSR register bit31. IMX8QM can't support the RAW8 data.

Thanks. Jason

mcuxsusan commented 2 years ago

Closed the issue as the feedback from @zejiang0jason stated that the RAW8 data cannot be supported on IMX8QM.