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

📄 ov7660_hw.c

📁 wince 6.0 摄像头(ov7670)驱动,已在ce6测试通过
💻 C
📖 第 1 页 / 共 5 页
字号:
    0x9f, 0x9d,
    0xa0, 0xe0,
    0x4f, 0x40,
    0x50, 0x43,
    0x51, 0x03,
    0x52, 0x10,
    0x53, 0x28,
    0x54, 0x38,
    0x55, 0x40,
    0x56, 0x40,
    0x57, 0x40,
    0x58, 0x0d,
    0x8b, 0xcc,
    0x8c, 0xcc,
    0x8d, 0xcf,
    0x6c, 0x40,
    0x6d, 0x30,
    0x6e, 0x4b,
    0x6f, 0x60,
    0x70, 0x70,
    0x71, 0x70,
    0x72, 0x70,
    0x73, 0x70,
    0x74, 0x60,
    0x75, 0x60,
    0x76, 0x50,
    0x77, 0x48,
    0x78, 0x3a,
    0x79, 0x2e,
    0x7a, 0x28,
    0x7b, 0x22,
    0x7c, 0x04,
    0x7d, 0x07,
    0x7e, 0x10,
    0x7f, 0x28,
    0x80, 0x36,
    0x81, 0x44,
    0x82, 0x52,
    0x83, 0x60,
    0x84, 0x6c,
    0x85, 0x78,
    0x86, 0x8c,
    0x87, 0x9e,
    0x88, 0xbb,
    0x89, 0xd2,
    0x8a, 0xe6,
    0x14, 0x4e,
    0x24, 0x68,
    0x25, 0x58,
    OV7660_REGEND, 0x00        // End of list delimiter.
};

const static UINT8 gYUV_VGA_15fps_INITIALIZE[] =
{
    0x12, 0x80,
    0x11, 0x81,
    0x92, 0x48,
    0x93, 0x01,
    0x9d, 0x4c,
    0x9e, 0x3f,
    0x3b, 0x02,
    0x13, 0xf2,
    0x10, 0x00,
    0x00, 0x00,
    0x01, 0x80,
    0x02, 0x80,
    0x13, 0xf7,
    0x12, 0x00,
    0x04, 0x00,
    0x18, 0x01,
    0x17, 0x13,
    0x32, 0x92,
    0x19, 0x01,
    0x1a, 0x7a,
    0x03, 0x0a,
    0x0e, 0x84,
    0x0f, 0x62,
    0x15, 0x02,
    0x16, 0x02,
    0x1b, 0x01,
    0x1e, 0x01,
    0x29, 0x3c,
    0x33, 0x00,
    0x34, 0x07,
    0x35, 0x84,
    0x36, 0x00,
    0x38, 0x13,
    0x39, 0x43,
    0x3a, 0x0c,
    0x3c, 0x6c,
    0x3d, 0x90,
    0x3f, 0x29,
    0x40, 0xc1,
    0x41, 0x20,
    0x6b, 0x0a,
    0xa1, 0xc8,
    0x69, 0x80,
    0x43, 0xf0,
    0x44, 0x10,
    0x45, 0x78,
    0x46, 0xa8,
    0x47, 0x60,
    0x48, 0x80,
    0x59, 0xba,
    0x5a, 0x9a,
    0x5b, 0x22,
    0x5c, 0xb9,
    0x5d, 0x9b,
    0x5e, 0x10,
    0x5f, 0xe0,
    0x60, 0x85,
    0x61, 0x60,
    0x9f, 0x9d,
    0xa0, 0xa0,
    0x4f, 0x66,
    0x50, 0x6b,
    0x51, 0x05,
    0x52, 0x19,
    0x53, 0x40,
    0x54, 0x59,
    0x55, 0x40,
    0x56, 0x40,
    0x57, 0x40,
    0x58, 0x0d,
    0x8b, 0xcc,
    0x8c, 0xcc,
    0x8d, 0xcf,
    0x6c, 0x40,
    0x6d, 0x30,
    0x6e, 0x4b,
    0x6f, 0x60,
    0x70, 0x70,
    0x71, 0x70,
    0x72, 0x70,
    0x73, 0x70,
    0x74, 0x60,
    0x75, 0x60,
    0x76, 0x50,
    0x77, 0x48,
    0x78, 0x3a,
    0x79, 0x2e,
    0x7a, 0x28,
    0x7b, 0x22,
    0x7c, 0x04,
    0x7d, 0x07,
    0x7e, 0x10,
    0x7f, 0x28,
    0x80, 0x36,
    0x81, 0x44,
    0x82, 0x52,
    0x83, 0x60,
    0x84, 0x6c,
    0x85, 0x78,
    0x86, 0x8c,
    0x87, 0x9e,
    0x88, 0xbb,
    0x89, 0xd2,
    0x8a, 0xe6,
    0x14, 0x2e,
    0x24, 0x68,
    0x25, 0x5c,
    0x92, 0x48,
    0x93, 0x01,
    OV7660_REGEND, 0x00        // End of list delimiter.
};

const static UINT8 gYUV_VGA_5fps_INITIALIZE[] =
{
    0x12, 0x80,
    0x11, 0x81,
    0x92, 0x48,
    0x93, 0x01,
    0x9d, 0x19,
    0x9e, 0x15,
    0x3b, 0x02,
    0x13, 0xf2,
    0x10, 0x00,
    0x00, 0x00,
    0x01, 0x80,
    0x02, 0x80,
    0x13, 0xf7,
    0x12, 0x00,
    0x04, 0x00,
    0x18, 0x01,
    0x17, 0x13,
    0x32, 0x92,
    0x19, 0x02,
    0x1a, 0x7a,
    0x03, 0x00,
    0x0e, 0x84,
    0x0f, 0x62,
    0x15, 0x02,
    0x16, 0x02,
    0x1b, 0x01,
    0x1e, 0x01,
    0x29, 0x3c,
    0x33, 0x00,
    0x34, 0x07,
    0x35, 0x84,
    0x36, 0x00,
    0x38, 0x13,
    0x39, 0x43,
    0x3a, 0x0c,
    0x3c, 0x6c,
    0x3d, 0x99,
    0x3f, 0x3c,
    0x40, 0xc1,
    0x41, 0x00,
    0x6b, 0x0a,
    0xa1, 0xc8,
    0x69, 0x80,
    0x43, 0xf0,
    0x44, 0x10,
    0x45, 0x78,
    0x46, 0xa8,
    0x47, 0x60,
    0x48, 0x80,
    0x59, 0xba,
    0x5a, 0x9a,
    0x5b, 0x22,
    0x5c, 0xb9,
    0x5d, 0x9b,
    0x5e, 0x10,
    0x5f, 0xe0,
    0x60, 0x85,
    0x61, 0x60,
    0x9f, 0x9d,
    0xa0, 0xe0,
    0x4f, 0x40,
    0x50, 0x43,
    0x51, 0x03,
    0x52, 0x10,
    0x53, 0x28,
    0x54, 0x38,
    0x55, 0x40,
    0x56, 0x40,
    0x57, 0x40,
    0x58, 0x0d,
    0x8b, 0xcc,
    0x8c, 0xcc,
    0x8d, 0xcf,
    0x6c, 0xf0,
    0x6d, 0xf0,
    0x6e, 0xf0,
    0x6f, 0x70,
    0x70, 0x58,
    0x71, 0x58,
    0x72, 0x48,
    0x73, 0x48,
    0x74, 0x38,
    0x75, 0x40,
    0x76, 0x34,
    0x77, 0x34,
    0x78, 0x2e,
    0x79, 0x28,
    0x7a, 0x24,
    0x7b, 0x22,
    0x7c, 0x0f,
    0x7d, 0x1e,
    0x7e, 0x3c,
    0x7f, 0x58,
    0x80, 0x63,
    0x81, 0x6e,
    0x82, 0x77,
    0x83, 0x80,
    0x84, 0x87,
    0x85, 0x8f,
    0x86, 0x9c,
    0x87, 0xa9,
    0x88, 0xc0,
    0x89, 0xd4,
    0x8a, 0xe6,
    0x14, 0x4e,
    0x24, 0x68,
    0x25, 0x58,
    OV7660_REGEND, 0x00        // End of list delimiter.
};

const static UINT8 Premier_Lens[] =
{
    OV7660_AWBTH3   , 0x5C,
    OV7660_AWBTH4   , 0x6e,
    OV7660_AWBTH5   , 0x46,
    OV7660_AWBTH6   , 0x4D,
    OV7660_AWBC1    , 0x23,
    OV7660_AWBC2    , 0x41,
    OV7660_AWBC3    , 0x43,
    OV7660_AWBC4    , 0x74,
    OV7660_AWBC5    , 0x6e,

    OV7660_REGEND,     0x00        // End of list delimiter.
};

const static UINT8 LiteOn_Lens[] =
{
    OV7660_AWBTH3   , 0x58,
    OV7660_AWBTH4   , 0x6c,
    OV7660_AWBTH5   , 0x46,
    OV7660_AWBTH6   , 0x48,
    OV7660_AWBC1    , 0x23,
    OV7660_AWBC2    , 0x41,
    OV7660_AWBC3    , 0x54,
    OV7660_AWBC4    , 0x74,
    OV7660_AWBC5    , 0x5c,

    OV7660_REGEND,     0x00        // End of list delimiter.
}; 

const static UINT8 gSensorSlaveAddr = 0x21;

struct OV7660_SETTING
{
    int   format;
    int   resolution;
    const UINT8 *setting;
};

struct OV7660_SETTING ov7660_setting_table[] = 
{
    {OV_FORMAT_RAW8   , OV_SIZE_QQVGA, gRAW_QQVGA_INITIALIZE},
    {OV_FORMAT_RAW8   , OV_SIZE_QVGA , gRAW_QVGA_INITIALIZE},
    {OV_FORMAT_RAW8   , OV_SIZE_VGA  , gRAW_VGA_INITIALIZE},
    {OV_FORMAT_RAW8   , OV_SIZE_QQCIF, gRAW_QQCIF_INITIALIZE},
    {OV_FORMAT_RAW8   , OV_SIZE_QCIF , gRAW_QCIF_INITIALIZE},
    {OV_FORMAT_RAW8   , OV_SIZE_CIF  , gRAW_CIF_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_QQVGA, gYUV_QQVGA_15fps_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_QVGA , gYUV_QVGA_15fps_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_VGA  , gYUV_VGA_15fps_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_QQCIF, gYUV_QQCIF_15fps_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_QCIF , gYUV_QCIF_15fps_INITIALIZE},
    {OV_FORMAT_YUV_422, OV_SIZE_CIF  , gYUV_CIF_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_QQVGA, gRGB565_QQVGA_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_QVGA , gRGB565_QVGA_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_VGA  , gRGB565_VGA_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_QQCIF, gRGB565_QQCIF_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_QCIF , gRGB565_QCIF_15fps_INITIALIZE},
    {OV_FORMAT_RGB_565, OV_SIZE_CIF  , gRGB565_CIF_15fps_INITIALIZE},
    {0, 0, 0}
} ;

/***********************************************************************
*  Private/helper api
***********************************************************************/
#ifdef PXA_DEBUG_PARAM_CHECK
static PXA_STATUS_T PrvGetRegValue( UINT8 *regP, UINT8 regAddr, UINT8 *regValueP )
{
    UINT32 index = 0;
    UINT8 curReg = 0;
    
    while( curReg < OV7660_REGEND )
    {
        curReg = regP[index << 1];
        if( curReg == regAddr )
        {
            *regValueP = regP[(index << 1) + 1];
            return PXA_STATUS_SUCCESS;
        }    
        index ++;
    } 
        
    return PXA_STATUS_FAILURE;

}

static PXA_STATUS_T PrvSetRegValue( UINT8 *regP, UINT8 regAddr, UINT8 regValue )
{
    UINT32 index = 0;
    UINT8 curReg = 0;
    
    while( curReg < OV7660_REGEND )
    {
        curReg = regP[index << 1];
        if( curReg == regAddr )
        {
            regP[(index << 1) + 1] = regValue;
            return PXA_STATUS_SUCCESS;
        }    
        index ++;
    } 
        
    return PXA_STATUS_FAILURE;

}
#endif
/***********************************************************************
*  Sensor read/write 
***********************************************************************/
static int PrvReadSensorReg( const UINT8 subAddress, UINT8 *bufP )
{
    UINT8 buffer[1];
    int status;
    buffer[0] = subAddress;
    
    //status = OS_I2CMasterWriteData( gSensorSlaveAddr, buffer, 1);
    status = I2C_WriteData(gSensorSlaveAddr, buffer, 1, TRUE, PXA_I2C_NORMAL_LEVEL);
    if (!status) {
        //status = OS_I2CMasterReadData( gSensorSlaveAddr, buffer, 1);
        status = I2C_ReadData(gSensorSlaveAddr, buffer, 1, TRUE, PXA_I2C_NORMAL_LEVEL);
        *bufP = buffer[0];
    }
    
    return status;
}

static int PrvWriteSensorReg( const UINT8 subAddress, UINT8 *bufP )
{
    UINT8 buffer[2];
    int status;
    buffer[0] = subAddress;
    buffer[1] = *bufP;
    
    //status = OS_I2CMasterWriteData( gSensorSlaveAddr, buffer, 2);
    status = I2C_WriteData(gSensorSlaveAddr, buffer, 2, TRUE, PXA_I2C_NORMAL_LEVEL);
    return status;
}

static int PrvRMWSensorReg( const UINT8 subAddress, UINT8 *bufP, UINT8 andMask, UINT8 orMask ) 
{
    int status;
    status = PrvReadSensorReg( subAddress, bufP );
    if (!status) {
        *bufP &= andMask;
        *bufP |= orMask;
        status = PrvWriteSensorReg( subAddress, bufP );
    }
    return status;
}

int OV7660ReadSensorReg( const UINT8 subAddress, UINT8 *bufP )
{
    return PrvReadSensorReg(subAddress, bufP);
}

int OV7660WriteSensorReg( const UINT8 subAddress, UINT8 *bufP )
{
    return PrvWriteSensorReg(subAddress, bufP);
}

PXA_STATUS_T OV7660SetRegs( const UINT8 *regP )
{
    UINT32    curReg = 0;
    PXA_STATUS_T    status = PXA_STATUS_SUCCESS;
        
    // The list is a register number followed by the value.
    while( regP[curReg << 1] < OV7660_REGEND )
    {
        UINT8 regVal = regP[(curReg << 1) + 1];

        status = (PrvWriteSensorReg( regP[curReg << 1], &regVal ) == 0) ?
                 PXA_STATUS_SUCCESS : PXA_STATUS_FAILURE;
        
        if( curReg == 0 )
            OV7660Wait( 5 );
            
        curReg++;
    }
        
    return status;
}

PXA_STATUS_T OV7660ReadAllRegs( UINT8 *bufP, UINT32 numRegs )
{
    UINT32    curReg;
    
    for( curReg = 0; curReg < numRegs; curReg++, bufP++ )
        PrvReadSensorReg( (UINT8)curReg, bufP );


    return PXA_STATUS_SUCCESS;
}

/***********************************************************************
*  Power & Reset
***********************************************************************/
void OV7660PowerDown(UINT8 powerMode )
{
    // OV7660 PWRDWN, 0 = NORMAL, 1=POWER DOWN
    if( powerMode == PXA_CAMERA_POWER_OFF )
        /* Call_GPX */ 
        GPX_SetOutputLevel(GPX_GPIO_CAMERA_LO_PWDN, PXA_HI );
    else
        /* Call_GPX */ 
        GPX_SetOutputLevel(GPX_GPIO_CAMERA_LO_PWDN, PXA_LO );

   PXA_OST_DelayMilliSeconds(100 );
}

void OV7660Reset( )
{
    return;

    // OV7660 RESET, 0 = inactive, 1 = active
    //XllpGpioSetOutputState1( (P_XLLP_GPIO_T) cameraContextP->gpio_reg_base, (UINT32 *)OV7660_RESET_GPIO );
    //PXA_OST_DelayMilliSeconds(1 );
    //XllpGpioSetOutput0( (P_XLLP_GPIO_T) cameraContextP->gpio_reg_base, (UINT32 *) OV7660_RESET_GPIO );
    //PXA_OST_DelayMilliSeconds(10 );
}

void OV7660Wait( int ms )
{
    Sleep( ms );
}


/***********************************************************************
*  Settings
***********************************************************************/
int OV7660VersionRevision(UINT8 * pCmRevision, UINT8 *pSensorRevision)
{
    PrvReadSensorReg( OV7660_PID, pCmRevision );
    PrvReadSensorReg( OV7660_VER, pSensorRevision );
    return PXA_STATUS_SUCCESS;
}

void OV7660SetHSYNC()
{
    UINT8    val;
    
    // Makes HREF become HSYNC
    PrvReadSensorReg( OV7660_COM10, &val );
    val |= 0x40;
    PrvWriteSensorReg( OV7660_COM10, &val );
}

void OV7660AutoFunctionOn()
{
    UINT8 val;
    PrvReadSensorReg( OV7660_COM8, &val );
    val |= 0x07;    // don't disturb AWB
    PrvWriteSensorReg( OV7660_COM8, &val );
}

void OV7660AutoFunctionOff()
{
    UINT8 val;
    PrvReadSensorReg( OV7660_COM8, &val );
    val &= ~0x07;    // don't disturb AWB
    PrvWriteSensorReg( OV7660_COM8, &val );
}


/***********************************************************************
*  Viewfinder, still 
***********************************************************************/
int OV7660ViewfinderOn()
{
    UINT8    com3;
    
    PrvReadSensorReg( OV7660_COM3, &com3 );
    com3 &= ~0x01;
    PrvWriteSensorReg( OV7660_COM3, &com3 );
        
    return OV_ERR_NONE;
}


int OV7660ViewfinderOff()
{
    UINT8    com3;
    
    PrvReadSensorReg( OV7660_COM3, &com3 );
    com3 |= 0x01;
    PrvWriteSensorReg( OV7660_COM3, &com3 );
    
    return OV_ERR_NONE;
}


int OV7660HaltVideoOutput()
{
    UINT8    com3;
    
    // Set the camera to only output 1 frame.
    PrvReadSensorReg( OV7660_COM3, &com3 );
    com3 |= 1;
    PrvWriteSensorReg( OV7660_COM3, &com3 );
    
    return OV_ERR_NONE;
}

int OV7660ResumetoFullOutputMode()
{
    UINT8    mode;
    
    // Output still frames continuously
    // Turn off single capture mode COM3.
    PrvRMWSensorReg( OV7660_COM3, (&mode), ((UINT8) ~1), 0 );
    return OV_ERR_NONE;
}

int OV7660GetSingleImage()
{
    UINT8    mode;
    
    PrvRMWSensorReg( OV7660_COM3, &mode, (UINT8) ~1, 1 );
    return OV_ERR_NONE;
}

#define MIN(x,y) ((x < y) ? x : y)
#define MAX(x,y) ((x > y) ? x : y)

/***********************************************************************
*  Format 
***********************************************************************/
PXA_STATUS_T OV7660SetFormat( UINT32 captureSizeFormat, UINT32 colorFormat, UINT32 mode)//, UINT32 light, UINT32 zoom)
{

    PXA_STATUS_T    status;
    UINT8    *regsP, regValue;
    const UINT8     *defaultDataP;
    struct OV7660_SETTING  *ov7660_setting;

    defaultDataP  = NULL;
    for(ov7660_setting = ov7660_setting_table; ov7660_setting->format != 0;ov7660_setting++)
    {
        if ((colorFormat == ov7660_setting->format) && (captureSizeFormat == ov7660_setting->resolution))
        {
            defaultDataP = ov7660_setting->setting;
            break;
        }
    }
    
    if (defaultDataP == NULL)
        return PXA_STATUS_UNSUPPORTED;

    // reset
    regValue = 0x80;
    PrvWriteSensorReg(OV7660_COM7, &regValue);

    // Get the pointer to the basic setting.  The pointer must be freed after exiting.
    regsP = (UINT8 *) defaultDataP;
    OV7660Wait( 5 );

    // Blast the entire parameter tree into the part.
    status = OV7660SetRegs( regsP );

    return PXA_STATUS_SUCCESS;
}

/***********************************************************************
 *
 * Contrast
 *
 ***********************************************************************/
const static UINT8 ContrastLowestSettings[] = {
    0x6C, 0x80,
    0x6D, 0xa0,
    0x6E, 0x78,
    0x6F, 0x50,
    0x70, 0x48,
    0x71, 0x40,
    0x72, 0x48,
    0x73, 0x40,
    0x74, 0x40,
    0x75, 0x40,
    0x76, 0x40,
    0x77, 0x40,
    0x78, 0x3e,
    0x79, 0x3c,
    0x7A, 0x3c,
    0x7B, 0x28,
    0x7C, 0x8,
    0x7D, 0x12,
    0x7E, 0x21,
    0x7F, 0x35,
    0x80, 0x3e,
    0x81, 0x46,
    0x82, 0x4f,
    0x83, 0x57,
    0x84, 0x5f,
    0x85, 0x67,
    0x86, 0x77,
    0x87, 0x87,
    0x88, 0xa6,
    0x89, 0xc4,
    0x8A, 0xe2,
    OV7660_REGEND,     0x00        // End of list delimiter.
};

const static UINT8 ContrastLowSettings[] = {
    0x6C, 0x70,
    0x6D, 0x80,
    0x6E, 0x40,
    0x6F, 0x54,
    0x70, 0x58,
    0x71, 0x60,
    0x72, 0x60,
    0x73, 0x60,
    0x74, 0x50,
    0x75, 0x58,
    0x76, 0x

⌨️ 快捷键说明

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