📄 xllp_camera.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//
/******************************************************************************
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
**
********************************************************************************/
#include "xllp_defs.h"
#include "xllp_serialization.h"
#include "xllp_bcr.h"
#include "xllp_clkmgr.h"
#include "xllp_ost.h"
#include "xllp_gpio.h"
#include "xllp_camera.h"
#include "xllp_ci.h"
/***********************************************************************
*
* Declarations
*
***********************************************************************/
#define SINGLE_DESCRIPTOR_TRANSFER_MAX 8000
// map of xllp camera image format (xllp_camera.h) ==> capture interface format (xllp_ci.h)
static const XLLP_CI_IMAGE_FORMAT FORMAT_MAPPINGS[] = {
XLLP_CI_RAW8, //RAW
XLLP_CI_RAW9,
XLLP_CI_RAW10,
XLLP_CI_RGB444, //RGB
XLLP_CI_RGB555,
XLLP_CI_RGB565,
XLLP_CI_RGB666_PACKED, //RGB Packed
XLLP_CI_RGB666,
XLLP_CI_RGB888_PACKED,
XLLP_CI_RGB888,
XLLP_CI_RGBT555_0, //RGB+Transparent bit 0
XLLP_CI_RGBT888_0,
XLLP_CI_RGBT555_1, //RGB+Transparent bit 1
XLLP_CI_RGBT888_1,
XLLP_CI_INVALID_FORMAT,
XLLP_CI_YCBCR422, //YCBCR
XLLP_CI_YCBCR422_PLANAR, //YCBCR Planaried
XLLP_CI_INVALID_FORMAT,
XLLP_CI_INVALID_FORMAT
};
/***********************************************************************
*
* Init/Deinit APIs
*
***********************************************************************/
XLLP_STATUS_T XllpCameraInit(P_XLLP_Camera_Context_T camera_context)
{
XLLP_STATUS_T status = XLLP_STATUS_SUCCESS;
P_XLLP_GPIO_T pGPIO = (P_XLLP_GPIO_T)camera_context->gpio_reg_base;
// parameter check
if (camera_context->sensor_type > XLLP_CAMERA_TYPE_MAX)
return XLLP_STATUS_WRONG_PARAMETER;
if (camera_context->Video_capture_input_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Video_capture_output_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Still_capture_input_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Still_capture_output_format > XLLP_CAMERA_IMAGE_FORMAT_MAX)
{
return XLLP_STATUS_WRONG_PARAMETER;
}
// check the function dispatch table according to the sensor type
if ( !camera_context->camera_functions )
return XLLP_STATUS_WRONG_PARAMETER;
if ( !camera_context->camera_functions->init ||
!camera_context->camera_functions->deinit ||
!camera_context->camera_functions->set_capture_format ||
!camera_context->camera_functions->start_capture ||
!camera_context->camera_functions->stop_capture )
return XLLP_STATUS_WRONG_PARAMETER;
// gpio pins init
{
// the first entry is size
static const XLLP_UINT32_T lowpins[]= {12, 27, 114, 116, 115, 90, 91, 17, 12, 23, 26, 24, 25};
static const XLLP_UINT32_T inpins[] = {11, 27, 114, 116, 115, 90, 91, 17, 12, 26, 25, 24};
static const XLLP_UINT32_T outpins[] = {1, 23};
static const XLLP_UINT32_T altpins[] = {12, 27, 114, 116, 115, 90, 91, 17, 12, 23, 26, 25, 24};
static const XLLP_UINT32_T altfunc[] = {12, 3, 1, 1, 2, 3, 3, 2, 2, 1, 2, 1, 1};
// configure processor pins
// Mux Pin GPIO Alt Direction
// CIF_DD[0]: SSP_EXTCLK 27 alt3 in
// 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;
// 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;
// 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;
XLLP_CI_IMAGE_FORMAT ci_input_format, ci_output_format;
XLLP_CI_MP_TIMING timing;
// set capture interface
if (camera_context->Video_capture_input_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Video_capture_output_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Still_capture_input_format > XLLP_CAMERA_IMAGE_FORMAT_MAX ||
camera_context->Still_capture_output_format > XLLP_CAMERA_IMAGE_FORMAT_MAX)
{
return XLLP_STATUS_WRONG_PARAMETER;
}
if (camera_context->capture_mode != XLLP_CAMERA_MODE_STILL)
{
ci_input_format = FORMAT_MAPPINGS[camera_context->Video_capture_input_format];
ci_output_format = FORMAT_MAPPINGS[camera_context->Video_capture_output_format];
}
else
{
ci_input_format = FORMAT_MAPPINGS[camera_context->Still_capture_input_format];
ci_output_format = FORMAT_MAPPINGS[camera_context->Still_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);
return status;
}
/***********************************************************************
*
* 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 + -