📄 bspcsi.cpp
字号:
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, 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: bspcsi.c
//
// Provides BSP-specific configuration routines for the CSI peripheral.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "bsp.h"
#include "bspcsi.h"
#include "CsiClass.h"
#include "CameraImagic.h"
#include "i2cbus.h"
#include "cameradbg.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define CAMERA_SENSOR_MODULE csiSensorId_Imagic8201 // Imagic as default Sensor
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
// Camera in Used - Default iMagic
csiSensorId gSensorInUse = CAMERA_SENSOR_MODULE;
//------------------------------------------------------------------------------
// Local Variables
static BOOL isCameraInitialized = FALSE;
//------------------------------------------------------------------------------
// Local Functions
BOOL BSPSensorSetClockGatingMode(BOOL);
//------------------------------------------------------------------------------
//
// Function: BSPSetupCamera
//
// This function initializes the camera sensor module.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void BSPSetupCamera(void)
{
PHYSICAL_ADDRESS phyAddr;
CSP_PBC_REGS *pPBC;
if(isCameraInitialized)
return;
BSPSensorSetClockGatingMode(TRUE);
phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;
// Map PBC registers to virtual address space
pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
if (pPBC == NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
return;
}
// Enable CSI in PBC
OUTREG16(&pPBC->BCTRL1_SET, 0x600);
switch (gSensorInUse)
{
case csiSensorId_Imagic8201:
case csiSensorId_Imagic8803:
default:
DEBUGMSG(ZONE_INIT,(TEXT("setupCamera: Imagic sensor initialization\r\n")));
CameraImagicInit();
isCameraInitialized = TRUE;
break;
}
return;
}
//------------------------------------------------------------------------------
//
// Function: BSPDeleteCamera
//
// This function deinitializes the camera sensor module.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void BSPDeleteCamera(void)
{
if(!isCameraInitialized)
return;
BSPSensorSetClockGatingMode(TRUE);
switch (gSensorInUse)
{
case csiSensorId_Imagic8803:
case csiSensorId_Imagic8201:
default:
CameraImagicDeinit();
isCameraInitialized = FALSE;
break;
}
return;
}
//------------------------------------------------------------------------------
//
// Function: BSPGetSensorClockRatio
//
// This function calculates the divider value to program into
// the CSI to achieve the required frame rate from the sensor.
//
// Parameters:
// None.
//
// Returns:
// Sensor clock divider value.
//
//------------------------------------------------------------------------------
UINT32 BSPGetSensorClockRatio()
{
UINT32 freq;
DDKClockGetFreq(DDK_CLOCK_SIGNAL_CSI, &freq);
// TODO: Change this
// For a target frame rate of 30 FPS, we want a sensor clock
// in the 24-27MHz range.
return (freq/24000000 - 1);
}
//------------------------------------------------------------------------------
//
// Function: BSPGetDefaultCameraFromRegistry
//
// This function reads the default camera sensor from the
// registry.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//------------------------------------------------------------------------------
BOOL BSPGetDefaultCameraFromRegistry(void)
{
UINT32 error;
HKEY hKey;
UINT32 dwSize;
csiSensorId sensorId;
// Open CSI registry path
error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(CSI_REG_PATH), 0 , 0, &hKey);
if (error != ERROR_SUCCESS) {
DEBUGMSG(ZONE_ERROR,(TEXT("Failed to open camera reg path:%s [Error:0x%x]\r\n"),CSI_REG_PATH,error));
return (FALSE);
}
// Get Default Camera
dwSize = sizeof(csiSensorId);
error = RegQueryValueEx(hKey, TEXT(CSI_REG_CAMERAID_KEYWORD), NULL, NULL,(LPBYTE)&sensorId, (LPDWORD)&dwSize);
if (error == ERROR_SUCCESS)
{
// Make sure it's valid CameraID
if(sensorId >= 0 && sensorId < CSI_SENSOR_NUMBER_SUPPORTED)
{
gSensorInUse = sensorId;
}
else
{
DEBUGMSG(ZONE_ERROR,(TEXT("Invalid Camera ID, set to default:%d\r\n"),CAMERA_SENSOR_MODULE));
}
}
else
{
DEBUGMSG(ZONE_ERROR,(TEXT("Failed to get the default CameraID [Error:0x%x]\r\n"),error));
}
// Close registry key
RegCloseKey(hKey);
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: BSPGetSensorFormat
//
// This function returns the sensor data format.
//
// Parameters:
// pSensorFormat
// [out] Pointer to DWORD to hold return value of sensor format.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void BSPGetSensorFormat(DWORD *pSensorFormat)
{
*pSensorFormat = csiSensorOutputFormat_YUV422;
}
//------------------------------------------------------------------------------
//
// Function: BSPSetDigitalZoom
//
// This function sets the zoom value on the camera sensor.
//
// Parameters:
// zoom
// [in] If TRUE, zoom set to 2x; if FALSE, zoom set to 1x
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void BSPSetDigitalZoom (BOOL zoom)
{
// Call Imagic method to set zoom
CameraImagicSetDigitalZoom(zoom);
}
//------------------------------------------------------------------------------
//
// Function: BSPCameraSetOutputResolution
//
// This function sets the output mode on the camera sensor.
//
// Parameters:
// outputMode
// [in] If TRUE, zoom set to 2x; if FALSE, zoom set to 1x
//
// Returns:
// TRUE if success
// FALSE if failure
//
//------------------------------------------------------------------------------
BOOL BSPCameraSetOutputResolution(csiSensorOutputResolution outputResolution)
{
// Call Imagic method to set output mode
CameraImagicSetOutputResolution(outputResolution);
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: BSPCameraSetOutputFormat
//
// This function sets the output format on the camera sensor.
//
// Parameters:
// outputFormat
// [in] Format specified to output sensor data.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -