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

📄 bspcsi.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//
//  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 BSP_CSI_FUNCTION_ENTRY() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define BSP_CSI_FUNCTION_EXIT() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
#define CAMERA_SENSOR_MODULE    csiSensorId_Imagic8201 // Imagic as default Sensor


//------------------------------------------------------------------------------
// Types


//------------------------------------------------------------------------------
// Global Variables

// Camera in Used - Default iMagic
csiSensorId gSensorInUse = CAMERA_SENSOR_MODULE;
DWORD       gVideoPort = CVBS;   // 0 for CVBS  port, 1 for S-Video port.
DWORD       gVideoFormat = PAL;   // The format will detect by TV in chip automatically.

//------------------------------------------------------------------------------
// Local Variables

//static BOOL isCameraInitialized = FALSE;

//------------------------------------------------------------------------------
// Local Functions
BOOL BSPSensorSetClockGatingMode(BOOL);

//-----------------------------------------------------------------------------
//
// Function:  BSPCSIGPIOConfig
//
// This function makes the DDK call to configure the GPIO
// pins required for the CSI.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success; FALSE if failure.
//
//-----------------------------------------------------------------------------
BOOL BSPCSIGPIOConfig(BOOL control)
{
    DDK_GPIO_CFG ioctl;
    BOOL retVal = TRUE;
    BOOL rc = FALSE;

    BSP_CSI_FUNCTION_ENTRY();

    // Enable CSI module pins
    DDK_GPIO_SET_CONFIG(ioctl, CSI);  

    if ( control == TRUE)
         retVal = DDKGpioEnable(&ioctl);
    else
         retVal = DDKGpioDisable(&ioctl);
	
    if(retVal == FALSE)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("BSPCSIGPIOConfig: cannot control module pins!\r\n")));
    }    

    BSP_CSI_FUNCTION_EXIT();

    return retVal;
}

//------------------------------------------------------------------------------
//
// Function: BSPSetupCamera
//
// This function initializes the camera sensor module.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------

void BSPSetupCamera(void) 
{
    BSP_CSI_FUNCTION_ENTRY();

  	switch (gSensorInUse)
    {
        case csiSensorId_Imagic8201:
        case csiSensorId_Imagic8803:
            DEBUGMSG(ZONE_INIT,(TEXT("setupCamera: Imagic sensor initialization\r\n")));
            CameraImagicInit();
            break;
			
        case csiSensorId_Saa7113h:
            TvInInit();
            break;

        default:
            DEBUGMSG(ZONE_INIT,(TEXT("setupCamera: Imagic sensor initialization\r\n")));
            break;
    }
    BSP_CSI_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: BSPDeleteCamera
//
// This function deinitializes the camera sensor module.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPDeleteCamera(void)
{
    BSP_CSI_FUNCTION_ENTRY();

    switch (gSensorInUse)
    {
        case csiSensorId_Imagic8803:
        case csiSensorId_Imagic8201:
            CameraImagicDeinit();
            break;

       case csiSensorId_Saa7113h:
            TvInDeinit();
            break;

       default:
            break;
    }

    BSP_CSI_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: BSPEnableCamera
//
// This function enable the camera.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPEnableCamera(void)
{
    BSP_CSI_FUNCTION_ENTRY();

    BSPSensorSetClockGatingMode(TRUE); //it should be here.
	
    BSP_CSI_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: BSPDisableCamera
//
// This function disable the camera.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPDisableCamera(void)
{
    BSP_CSI_FUNCTION_ENTRY();

    BSPSensorSetClockGatingMode(FALSE); 

    BSP_CSI_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: BSPResetCamera
//
// This function Reset the camera.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPResetCamera(void)
{
   PHYSICAL_ADDRESS phyAddr;
   CSP_PBC_REGS *pPBC;

   BSP_CSI_FUNCTION_ENTRY();

   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->BCTRL2_CLEAR, 0x400); //Clear the pin
   Sleep(100);
   OUTREG16(&pPBC->BCTRL2_SET, 0x400);	//Set up the pin	
         
   BSP_CSI_FUNCTION_EXIT();
}


//------------------------------------------------------------------------------
//
// 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;

    BSP_CSI_FUNCTION_ENTRY();

    DDKClockGetFreq(DDK_CLOCK_SIGNAL_CSI, &freq);

    BSP_CSI_FUNCTION_EXIT();

    // 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;
    DWORD    videoPort,videoFormat;
 
    BSP_CSI_FUNCTION_ENTRY();

    // 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));
    }

    if ( csiSensorId_Saa7113h == gSensorInUse)
    {
       dwSize = sizeof(DWORD);
       error = RegQueryValueEx(hKey, TEXT(CSI_REG_VIDEOPORT_KEYWORD), NULL, NULL,(LPBYTE)&videoPort, (LPDWORD)&dwSize);
       if (error == ERROR_SUCCESS)
       {
          if(videoPort == SVIDEO)
          {
              gVideoPort = videoPort;
          }
          else
          {
              gVideoPort = CVBS;
          }
       }
       else
       {
           DEBUGMSG(ZONE_ERROR,(TEXT("Failed to get the default VideoPort [Error:0x%x]\r\n"),error));
       }

       dwSize = sizeof(DWORD);
       error = RegQueryValueEx(hKey, TEXT(CSI_REG_VIDEOFORMAT_KEYWORD), NULL, NULL,(LPBYTE)&videoFormat, (LPDWORD)&dwSize);
       if (error == ERROR_SUCCESS)
       {
           if(videoFormat == NTSC)
           {
               gVideoFormat = videoFormat;
           }
           else
           {
               gVideoFormat = PAL;
           }
       }
       else
       {
           DEBUGMSG(ZONE_ERROR,(TEXT("Failed to get the default VideoFormat [Error:0x%x]\r\n"),error));
       }
   }

   // Close registry key
    RegCloseKey(hKey);
    BSP_CSI_FUNCTION_EXIT();

    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)
{
   BSP_CSI_FUNCTION_ENTRY();

   *pSensorFormat = csiSensorOutputFormat_YUV422;

   BSP_CSI_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: BSPGetSensorResolution
//
// This function returns the sensor data format.
//
// Parameters:
//      pSensorResolution
//          [out] Pointer to DWORD to hold return value of sensor resolution.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPGetSensorResolution(DWORD *pSensorResolution)
{
    BSP_CSI_FUNCTION_ENTRY();
	

⌨️ 快捷键说明

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