⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xllp_camera.c

📁 Intel PXA270底层设备驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        //  CIF_DD[1]:  USIM_VS0    114 alt1    in
        //  CIF_DD[2]:  USIM_DET    116 alt1    in
        //  CIF_DD[3]:  USIM_EN     115 alt2    in
        //  CIF_DD[4]:  nUSIM_RST   90  alt3    in
        //  CIF_DD[5]:  USIM_CLK    91  alt3    in
        //  CIF_DD[6]:  PWM1        17  alt2    in
        //  CIF_DD[7]:  GPIO12      12  alt2    in
        //  CIF_MCLK:   SSP_SCLK    23  alt1    out
        //  CIF_PCLK:   SSP_RxD     26  alt2    in
        //  CIF_LV:     SSP_TxD     25  alt1    in
        //  CIF_FV:     SSP_SFRM    24  alt1    in
        XllpGpioSetOutput0(pGPIO, (XLLP_UINT32_T*)lowpins);
        XllpGpioSetDirectionIn (pGPIO, (XLLP_UINT32_T*)inpins); 
        XllpGpioSetDirectionOut(pGPIO, (XLLP_UINT32_T*)outpins);
        XllpGpioSetAlternateFn (pGPIO, (XLLP_UINT32_T*)altpins, (XLLP_UINT32_T*)altfunc);
    }   
        
    // capture interface init
    XllpCIInit(camera_context->ci_reg_base, camera_context->clk_reg_base);
    
    // sensor init
    status = camera_context->camera_functions->init(camera_context);    
    if (status)
        goto camera_init_err;
    
    // dma channel allocation
	if (camera_context->dma_channels[0] == 0xFF)
	{
		for(i=0; i<3; i++) {
			status = OS_DmaAllocChannel(&camera_context->dma_channels[i], XLLP_DMAC_CHANNEL_PRIORITY_HIGH);
			if (status)
				goto camera_init_err;
		}
	}

    // set frame rate
    XllpCameraSetCaptureFrameRate(camera_context);

    return XLLP_STATUS_SUCCESS;
        
camera_init_err:
    XllpCameraDeInit(camera_context);
    return XLLP_STATUS_FAILURE; 
}

XLLP_STATUS_T XllpCameraDeInit( P_XLLP_Camera_Context_T camera_context )
{
    XLLP_STATUS_T status;
    int i;
    
    // free dma channel
    for(i=0; i<3; i++)
	{
        if (camera_context->dma_channels[i] != 0xFF) 
		{
            OS_DmaFreeChannel(camera_context->dma_channels[i], CAMERA_DMA_DEVICE[i]);   
			camera_context->dma_channels[i] = 0xFF;
		}
    }
    // deinit sensor
    status = camera_context->camera_functions->deinit(camera_context);  
    
    // capture interface deinit
    XllpCIDeInit(camera_context->ci_reg_base, camera_context->clk_reg_base);

    return status;
}


/***********************************************************************
 *
 * Capture APIs
 *
 ***********************************************************************/
// Set the image format
XLLP_STATUS_T XllpCameraSetCaptureFormat( P_XLLP_Camera_Context_T camera_context )
{
    XLLP_STATUS_T status;

    unsigned frame_size;
    XLLP_CI_IMAGE_FORMAT ci_input_format, ci_output_format;
    XLLP_CI_MP_TIMING timing;
        
    // set capture interface
    if (camera_context->capture_input_format >  XLLP_CAMERA_IMAGE_FORMAT_MAX ||
        camera_context->capture_output_format > XLLP_CAMERA_IMAGE_FORMAT_MAX )
        return XLLP_STATUS_WRONG_PARAMETER;
    ci_input_format = FORMAT_MAPPINGS[camera_context->capture_input_format];
    ci_output_format = FORMAT_MAPPINGS[camera_context->capture_output_format];
    if (ci_input_format == XLLP_CI_INVALID_FORMAT || ci_output_format == XLLP_CI_INVALID_FORMAT)
        return XLLP_STATUS_WRONG_PARAMETER;
    XllpCISetImageFormat(camera_context->ci_reg_base, ci_input_format, ci_output_format);
    timing.BFW = timing.BLW = 0;            
    XllpCIConfigureMP(camera_context->ci_reg_base, camera_context->capture_width-1, camera_context->capture_height-1, &timing);
    
    // set sensor setting
    status = camera_context->camera_functions->set_capture_format(camera_context);
    if (status)
        return status;

    // ring buffer init
    switch(camera_context->capture_output_format) {
        case XLLP_CAMERA_IMAGE_FORMAT_RGB555:
        case XLLP_CAMERA_IMAGE_FORMAT_RGB565:
            frame_size = camera_context->capture_width * camera_context->capture_height * 2;
            camera_context->fifo0_transfer_size = frame_size;
            camera_context->fifo1_transfer_size = 0;
            camera_context->fifo2_transfer_size = 0;
            break;
        case XLLP_CAMERA_IMAGE_FORMAT_YCBCR422_PACKED:
            frame_size = camera_context->capture_width * camera_context->capture_height * 2;
            camera_context->fifo0_transfer_size = frame_size;
            camera_context->fifo1_transfer_size = 0;
            camera_context->fifo2_transfer_size = 0;
            break;
        case XLLP_CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR:
            frame_size = camera_context->capture_width * camera_context->capture_height * 2;
            camera_context->fifo0_transfer_size = frame_size / 2;
            camera_context->fifo1_transfer_size = frame_size / 4;
            camera_context->fifo2_transfer_size = frame_size / 4;
            break;
        default:
            return XLLP_STATUS_WRONG_PARAMETER;
            break;
    }
    camera_context->block_size = frame_size;
    camera_context->block_number = camera_context->buf_size / frame_size;
    camera_context->block_header = camera_context->block_tail = 0;
    
    return XLLP_STATUS_SUCCESS;
}

// take a picture and copy it into the ring buffer
XLLP_STATUS_T XllpCameraCaptureStillImage( P_XLLP_Camera_Context_T camera_context, unsigned int block_id )
{
    XLLP_STATUS_T status;
    status = PrvStartCapture( camera_context, block_id, 1 );
    return status;
}

// capture motion video and copy it to the ring buffer
XLLP_STATUS_T XllpCameraStartVideoCapture( P_XLLP_Camera_Context_T camera_context, unsigned int block_id )
{
    XLLP_STATUS_T status;
    status = PrvStartCapture( camera_context, block_id, 0 );
    return status;
}

// disable motion video image capture
void XllpCameraStopVideoCapture( P_XLLP_Camera_Context_T camera_context )
{
    XLLP_STATUS_T status;
    
    // stop capture
    status = camera_context->camera_functions->stop_capture(camera_context);    

    // stop dma
    PrvStopDMATransfer(camera_context);

    return;
}

/***********************************************************************
 *
 * Frame rate APIs
 *
 ***********************************************************************/
// Set desired frame rate
void XllpCameraSetCaptureFrameRate( P_XLLP_Camera_Context_T camera_context )
{
    XllpCISetFrameRate(camera_context->ci_reg_base, camera_context->frame_rate);
    return;
} 

// return current setting
void XllpCameraGetCaptureFrameRate( P_XLLP_Camera_Context_T camera_context )
{
    camera_context->frame_rate = XllpCIGetFrameRate(camera_context->ci_reg_base);
    return;
} 


/***********************************************************************
 *
 * Interrupt APIs
 *
 ***********************************************************************/
// set interrupt mask 
void XllpCameraSetInterruptMask( P_XLLP_Camera_Context_T camera_context, unsigned int mask )
{
    // set CI interrupt
    XllpCISetInterruptMask( camera_context->ci_reg_base, mask & XLLP_CI_CICR0_INTERRUPT_MASK );
}
 
// get interrupt mask 
unsigned int XllpCameraGetInterruptMask( P_XLLP_Camera_Context_T camera_context )
{
    // get CI mask
    return ( XllpCIGetInterruptMask( camera_context->ci_reg_base ));
} 

// clear interrupt status
void XllpCameraClearInterruptStatus( P_XLLP_Camera_Context_T camera_context, unsigned int status )
{
    XllpCIClearInterruptStatus( camera_context->ci_reg_base, (status & 0xFFFF) );   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -