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

📄 cameraimagic.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       case  csiSensorId_Imagic8803:
               bySlaveAddr = IM8803_I2C_ADDRESS;
               break;
                 
       case csiSensorId_Imagic8201:
               bySlaveAddr = IM8201_I2C_ADDRESS;
               break;

       default:
               DEBUGMSG(ZONE_ERROR, (TEXT("%s: We don't support this kind of sensor!\r\n"), __WFUNCTION__));
               return;
   }    
 
    I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x01, 0x00, 0x01, &iResult); // select IFP register

    switch (outputResolution)
    {
        case csiSensorOutputResolution_VGA:
            if (gSensorInUse == csiSensorId_Imagic8803)
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x46, 0x00, 0x00, &iResult); // VGA
            }
            else
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xA7, 0x02, 0x80, &iResult); // VGA
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xAA, 0x01, 0xE0, &iResult);
            }
            break;

        case csiSensorOutputResolution_QVGA:
            if (gSensorInUse == csiSensorId_Imagic8803)
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x46, 0x00, 0x01, &iResult); // QVGA
            }
            else
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xA7, 0x01, 0x40, &iResult); // QVGA
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xAA, 0x00, 0xF0, &iResult);
            }
            break;

        case csiSensorOutputResolution_CIF:
            if (gSensorInUse == csiSensorId_Imagic8803)
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x46, 0x00, 0x02, &iResult); // CIF
            }
            else
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xA7, 0x01, 0x60, &iResult); // CIF
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xAA, 0x01, 0x20, &iResult);
            }
            break;

        case csiSensorOutputResolution_QCIF:
            if (gSensorInUse == csiSensorId_Imagic8803)
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x46, 0x00, 0x03, &iResult); // QCIF
            }
            else
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xA7, 0x00, 0xB0, &iResult); // QCIF
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xAA, 0x00, 0x90, &iResult);
            }
            break;

        case csiSensorOutputResolution_QQVGA:
            if (gSensorInUse == csiSensorId_Imagic8803)
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x46, 0x00, 0x04, &iResult); // QQVGA
            }
            else
            {
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xA7, 0x00, 0xA0, &iResult); // QQVGA
                I2CWriteTwoBytes(hI2C, bySlaveAddr, 0xAA, 0x00, 0x78, &iResult);
            }
            break;
    }

    CAMERA_FUNCTION_EXIT();
}


//------------------------------------------------------------------------------
//
// Function: CameraImagicSetDigitalZoom
//
// Sets the camera digital zoom level to 1x or 2x zoom.
//
// Parameters:
//      zoom
//          [in] Camera zoom value that will be set
//              TRUE - 2x zoom
//              FALSE - 1x zoom
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void CameraImagicSetDigitalZoom(BOOL zoom)
{
    INT iResult;
    BYTE bySlaveAddr;

    if (csiSensorId_Saa7113h == gSensorInUse)
        return;

    CAMERA_FUNCTION_ENTRY();

    switch (gSensorInUse)
    {
       case csiSensorId_Imagic8803:
              bySlaveAddr = IM8803_I2C_ADDRESS;
              break;
                 
       case csiSensorId_Imagic8201:
              bySlaveAddr = IM8201_I2C_ADDRESS;
              break;

       default:
              DEBUGMSG(ZONE_ERROR, (TEXT("%s: We don't support this kind of sensor!\r\n"), __WFUNCTION__));
              return;
	}    
    
    I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x01, 0x00, 0x04, &iResult); // select IC register

    if (zoom)
    {
        I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x1E, 0x00, 0x01, &iResult);
    }
    else
    {
        I2CWriteTwoBytes(hI2C, bySlaveAddr, 0x1E, 0x00, 0x00, &iResult);
    }

    CAMERA_FUNCTION_EXIT();
}

//The following function for TV in module.

//------------------------------------------------------------------------------
//
// Function: Saa7113h_I2C_Test
//
// Check the TV in chip's I2C.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------

void Saa7113hI2CTest(void)
{
    UCHAR Chip_Ver;    //silicon ID
    UCHAR rData, wData;
    BOOL Error = TRUE;
    BYTE bySlaveAddr;
    INT iResult;

    CAMERA_FUNCTION_ENTRY();

    bySlaveAddr = SAA7113H_I2C_ADDRESS;

    //read silicon ID
    Chip_Ver = I2CReadOneByte(hI2C,bySlaveAddr,0x00, &iResult);

    printf("Chip version = 0x%02X\n", Chip_Ver);

    for(wData = 0x1; wData < 0xF; wData ++)
    {
    //register read write test
       I2CWriteOneByte(hI2C, bySlaveAddr, 0x0D, wData, &iResult);
        
       rData = I2CReadOneByte(hI2C,bySlaveAddr,0x0D, &iResult);

       if (rData != wData)
            Error = FALSE;
    }

    if ( FALSE == Error )
          DEBUGMSG(ZONE_ERROR, (TEXT("%s: I2C test failed!\r\n"), __WFUNCTION__));
    else
          DEBUGMSG(ZONE_ERROR, (TEXT("%s: I2C test OK!\r\n"), __WFUNCTION__));
    
    CAMERA_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: TvInInit
//
// Initializes the TV in sensor.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void TvInInit(void)
{
    INT iResult;
    DWORD dwFrequency;
    BYTE bySlaveAddr, byCsiAddr;
    UINT reg;
	
    CAMERA_FUNCTION_ENTRY();

    byCsiAddr = CSI_I2C_ADDRESS;

    switch (gSensorInUse)
    {
     case csiSensorId_Saa7113h:
           dwFrequency = SAA7113H_I2C_SPEED;
           bySlaveAddr = SAA7113H_I2C_ADDRESS;
           break;               

     default:
           DEBUGMSG(ZONE_ERROR, (TEXT("%s: We don't support this kind of sensor!\r\n"), __WFUNCTION__));
           return;
    }        

    hI2C = CreateFile(I2C_FID_CAM,                              // name of device
               GENERIC_READ|GENERIC_WRITE,              // desired access
               FILE_SHARE_READ|FILE_SHARE_WRITE,     // sharing mode
               NULL,                                                             // security attributes (ignored)
               OPEN_EXISTING,                                        // creation disposition
               FILE_FLAG_RANDOM_ACCESS,                  // flags/attributes
               NULL);

    if (hI2C == INVALID_HANDLE_VALUE)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s: CreateFile for I2C failed!\r\n"), __WFUNCTION__));
    }

    // Initialize the device internal fields
    if (!I2C_MACRO_SET_FREQUENCY(hI2C, dwFrequency))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s: Set I2C frequency failed!\r\n"), __WFUNCTION__));
    }
    if (!I2C_MACRO_SET_SELF_ADDR(hI2C, byCsiAddr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s: Set I2C self address failed!\r\n"), __WFUNCTION__));
    }

    Saa7113hI2CTest();

    //recommended startup settings
    I2CWriteOneByte(hI2C,bySlaveAddr,0x01, 0x08, &iResult);    //increment delay
    
    if (CVBS  ==  gVideoPort)
        I2CWriteOneByte(hI2C,bySlaveAddr,0x02, 0xC0, &iResult);    //analog input control 1
    else
        I2CWriteOneByte(hI2C,bySlaveAddr,0x02, 0xC9, &iResult);    //analog input control 1 (S-video in)

    I2CWriteOneByte(hI2C,bySlaveAddr,0x03, 0x33, &iResult);    //analog input control 2
    I2CWriteOneByte(hI2C,bySlaveAddr,0x04, 0x00, &iResult);    //analog input control 3
    I2CWriteOneByte(hI2C,bySlaveAddr,0x05, 0x00, &iResult);    //analog input control 4
    I2CWriteOneByte(hI2C,bySlaveAddr,0x06, 0xE9, &iResult);    //HSYNC start
    I2CWriteOneByte(hI2C,bySlaveAddr,0x07, 0x0D, &iResult);    //HSYNC stop
    I2CWriteOneByte(hI2C,bySlaveAddr,0x08, 0x98, &iResult);    //SYNC control

    if (CVBS  ==  gVideoPort)
        I2CWriteOneByte(hI2C,bySlaveAddr,0x09, 0x01, &iResult);    //luminance control
    else
        I2CWriteOneByte(hI2C,bySlaveAddr,0x09, 0x81, &iResult);    //luminance control (S-video)

    I2CWriteOneByte(hI2C,bySlaveAddr,0x0A, 0x80, &iResult);    //luminance brightness
    I2CWriteOneByte(hI2C,bySlaveAddr,0x0B, 0x47, &iResult);    //luminance contrast
    I2CWriteOneByte(hI2C,bySlaveAddr,0x0C, 0x40, &iResult);    //chrom sat
    I2CWriteOneByte(hI2C,bySlaveAddr,0x0D, 0x00, &iResult);    //chrom hue
    I2CWriteOneByte(hI2C,bySlaveAddr,0x0E, 0x01, &iResult);    //chrom control
    I2CWriteOneByte(hI2C,bySlaveAddr,0x0F, 0x2A, &iResult);    //chrom gain control
    I2CWriteOneByte(hI2C,bySlaveAddr,0x10, 0x00, &iResult);    //format / delay control
    I2CWriteOneByte(hI2C,bySlaveAddr,0x11, 0x0C, &iResult);    //output control 1; 
//    I2CWriteOneByte(hI2C,bySlaveAddr,0x11, 0x0D, &iResult);    //output control 1; (color kill disable)
    I2CWriteOneByte(hI2C,bySlaveAddr,0x12, 0x7B, &iResult);    //output control 2 .from MX21
    I2CWriteOneByte(hI2C,bySlaveAddr,0x13, 0x00, &iResult);    //output control 3
    I2CWriteOneByte(hI2C,bySlaveAddr,0x15, 0x00, &iResult);    //VGATE start
    I2CWriteOneByte(hI2C,bySlaveAddr,0x16, 0x00, &iResult);    //VGATE stop
    I2CWriteOneByte(hI2C,bySlaveAddr,0x17, 0x00, &iResult);    //MSBs for VGATE control

    I2CWriteOneByte(hI2C,bySlaveAddr,0x40, 0x02, &iResult);    //silcer control 1

    for(reg = 0x41; reg <= 0x57; reg ++, &iResult)
        I2CWriteOneByte(hI2C,bySlaveAddr,reg, 0xFF, &iResult);    //line control register 2 to 24
    
    I2CWriteOneByte(hI2C,bySlaveAddr,0x58, 0x00, &iResult);    //framing code
    I2CWriteOneByte(hI2C,bySlaveAddr,0x59, 0x54, &iResult);    //horizontal offset for slicer
    I2CWriteOneByte(hI2C,bySlaveAddr,0x5A, 0x07, &iResult);    //vertical offset for slicer 
    I2CWriteOneByte(hI2C,bySlaveAddr,0x5B, 0x83, &iResult);    //field offset and SBs for H & V offset

    I2CWriteOneByte(hI2C,bySlaveAddr,0x5C, 0x00, &iResult);    //reserved
    I2CWriteOneByte(hI2C,bySlaveAddr,0x5D, 0x00, &iResult);    //reserved
    I2CWriteOneByte(hI2C,bySlaveAddr,0x5E, 0x00, &iResult);    //silced data ID code

    Sleep(100);

// TV in chip provide auto detect mode function ,but we don't use it, Our program only initialize Camera once.
// Actually, at this time. We may not connect to TV in module.So even if we change the Video format, The change will
// not take effect.
/*
    status = I2CReadOneByte(hI2C,bySlaveAddr,0x1F, &iResult);

    if (status & 0x20)
         gVideoFormat = NTSC; // 60Hz => NTSC
    else
         gVideoFormat = PAL;    //  50Hz => PAL
*/
    CAMERA_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: TvInDeinit
//
// Deinitialize the TV in Sensor.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void TvInDeinit(void)
{
    CAMERA_FUNCTION_ENTRY();

    CloseHandle(hI2C);

    CAMERA_FUNCTION_EXIT();
}

⌨️ 快捷键说明

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