📄 csiclass.cpp
字号:
//
// Copyright (C) 2003, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// Freescale Semiconductor, Inc.
//
//------------------------------------------------------------------------------
//
// File: csi.cpp
//
// Implementation of CMOS Sensor Interface Product Device Driver
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <NKIntr.h>
#include <ceddk.h>
#include "mxarm11.h"
#include "cameradbg.h"
#include "CsiClass.h"
//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPGetDefaultCameraFromRegistry();
extern void BSPSetupCamera();
extern void BSPDeleteCamera();
extern UINT32 BSPGetSensorClockRatio();
extern void BSPSetDigitalZoom(BOOL);
extern BOOL BSPCameraSetOutputResolution(csiSensorOutputResolution);
extern BOOL BSPCameraSetOutputFormat(csiSensorOutputFormat);
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define CSI_FUNCTION_ENTRY() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define CSI_FUNCTION_EXIT() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
//
// Function: CsiClass
//
// CsiClass constructor. Calls CsiInit to initialize module.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
CsiClass::CsiClass()
{
CsiInit();
}
//-----------------------------------------------------------------------------
//
// Function: ~CsiClass
//
// CsiClass destructor. Calls CsiDeinit to deinitialize module.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
CsiClass::~CsiClass()
{
CsiDeinit();
}
//-----------------------------------------------------------------------------
//
// Function: CsiInit
//
// This function initializes the Camera Sensor Interface and
// Image Converter modules.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
void CsiClass::CsiInit()
{
CSI_FUNCTION_ENTRY();
CsiEnable();
// Get camera-in-use from registry key. Otherwise use default
if (!BSPGetDefaultCameraFromRegistry())
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Interrupt initialization failed! (IPU Error Interrupt)\r\n"), __WFUNCTION__));
goto Error;
}
CSI_FUNCTION_EXIT();
return;
Error:
CsiDeinit();
return;
}
//-----------------------------------------------------------------------------
//
// Function: CsiDeinit
//
// This function deinitializes the Camera Sensor Interface module.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CsiClass::CsiDeinit()
{
CSI_FUNCTION_ENTRY();
CsiDisable();
BSPDeleteCamera();
CSI_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: CiConfigureSensor
//
// This function configures the camera sensor and preprocessing module.
//
// Parameters:
// sensorConfig
// [in] pCsiSensorConfig_t structure describing how
// to configure the sensor
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CsiClass::CsiConfigureSensor(csiSensorOutputFormat outFormat, csiSensorOutputResolution outResolution)
{
static BOOL isCameraInitialized = FALSE;
UINT32 sensClkDivider;
CSI_FUNCTION_ENTRY();
// Only set up camera once.
if(!isCameraInitialized)
{
BSPSetupCamera();
// Get camera divider ratio
sensClkDivider = BSPGetSensorClockRatio();
/*
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
IPU_CSI_SENS_CONF_DIV_RATIO, sensClkDivider);
*/
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
IPU_CSI_SENS_CONF_SENS_CLK_SRC, IPU_CSI_SENS_CONF_SENS_CLK_SRC_HSP_CLK);
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
IPU_CSI_SENS_CONF_DIV_RATIO, 2);
isCameraInitialized = TRUE;
}
// TODO: Reenable
/*
// Set the output resolution for the BSP-specific camera module.
if (!BSPCameraSetOutputResolution(outResolution))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Invalid camera sensor output resolution.\r\n"), __WFUNCTION__));
return FALSE;
}
// Set the output format for the BSP-specific camera module.
if (!BSPCameraSetOutputFormat(outFormat))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Invalid camera sensor output format.\r\n"), __WFUNCTION__));
return FALSE;
}
*/
// TODO: See if this works on Virtio
// Set data format from the sensor.
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
IPU_CSI_SENS_CONF_EXT_VSYNC,
IPU_CSI_SENS_CONF_EXT_VSYNC_EXTERNAL);
// Set IC configuration parameters and sensor protocol based on the output format.
switch (outFormat)
{
case csiSensorOutputFormat_YUV422:
// Set data format from the sensor.
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
IPU_CSI_SENS_CONF_SENS_DATA_FORMAT,
IPU_CSI_SENS_CONF_SENS_DATA_FORMAT_YUV422);
// Set timing and data protocol to Progressive CCIR mode.
INSREG32BF(&m_pIPU->CSI_SENS_CONF, IPU_CSI_SENS_CONF_SENS_PRTCL,
IPU_CSI_SENS_CONF_SENS_PRTCL_GATED_CLOCK_MODE);
// IPU_CSI_SENS_CONF_SENS_PRTCL_CCIR_PROGRESSIVE_MODE);
// Set up CCIR code registers
INSREG32BF(&m_pIPU->CSI_CCIR_CODE_3,
IPU_CSI_CCIR_CODE_3_CCIR_PRECOM, 0xFF0000);
INSREG32BF(&m_pIPU->CSI_CCIR_CODE_1,
IPU_CSI_CCIR_CODE_1_STRT_FLD0_BLNK_1ST, 6);
INSREG32BF(&m_pIPU->CSI_CCIR_CODE_1,
IPU_CSI_CCIR_CODE_1_END_FLD0_ACTV, 4);
INSREG32BF(&m_pIPU->CSI_CCIR_CODE_1,
IPU_CSI_CCIR_CODE_1_STRT_FLD0_ACTV, 0);
/*
INSREG32BF(&m_pIPU->CSI_OUT_FRM_CTRL,
IPU_CSI_OUT_FRM_CTRL_HSC, 9);
INSREG32BF(&m_pIPU->CSI_OUT_FRM_CTRL,
IPU_CSI_OUT_FRM_CTRL_VSC, 0x64);
*/
break;
case csiSensorOutputFormat_YUV444:
// Set data format from the sensor.
INSREG32BF(&m_pIPU->CSI_SENS_CONF,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -