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

📄 adcm2650_hw.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//
/****************************************************************************** 
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.  
** Title to the Material remains with Intel Corporation or its suppliers and licensors. 
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.  
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise 
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
**
********************************************************************************/

#include <windows.h>
#include "xllp_defs.h"
#include "xllp_ost.h"
#include "xllp_i2c.h"
#include "ADCM2650_hw.h"

static int PrvChangeBlock( XLLP_UINT8_T block);
static int PrvRequestRead( XLLP_UINT8_T offset);
static int PrvReadReg( XLLP_UINT8_T offset, XLLP_UINT16_T * pRegValue);
static int PrvWriteReg( XLLP_UINT8_T offset, XLLP_UINT16_T regValue);


FIRMUPDATE firmUpdate[] = {
{0x00fc, 0x0008},  // index 1
{0x00fe, 0x000c},  // index 2
{0x42cc, 0x0002},  // index 3
{0x42ce, 0xfd13},  // index 4
{0x4308, 0x0002},  // index 5
{0x430a, 0xfd2d},  // index 6
{0x430c, 0x0002},  // index 7
{0x430e, 0xfd00},  // index 8
{0x4400, 0x0000},  // index 9
{0x4402, 0x060e},  // index 10
{0x4404, 0x0003},  // index 11
{0x4406, 0x03b9},  // index 12
{0x4408, 0x000d},  // index 13
{0x440a, 0x3e80},  // index 14
{0x440c, 0x0000},  // index 15
{0x440e, 0x02ac},  // index 16
{0x4410, 0x0000},  // index 17
{0x4412, 0x5c04},  // index 18
{0x4414, 0x0000},  // index 19
{0x4416, 0x02a7},  // index 20
{0x4418, 0x0000},  // index 21
{0x441a, 0x093e},  // index 22
{0x441c, 0x0000},  // index 23
{0x441e, 0x0436},  // index 24
{0x4420, 0x0000},  // index 25
{0x4422, 0x5445},  // index 26
{0x4424, 0x0000},  // index 27
{0x4426, 0x042d},  // index 28
{0x4428, 0x0000},  // index 29
{0x442a, 0x041d},  // index 30
{0x442c, 0x0000},  // index 31
{0x442e, 0x026e},  // index 32
{0x4430, 0x0000},  // index 33
{0x4432, 0x01a6},  // index 34
{0x4434, 0x000d},  // index 35
{0x4436, 0x3300},  // index 36
{0x4438, 0x0000},  // index 37
{0x443a, 0x0175},  // index 38
{0x443c, 0x000e},  // index 39
{0x443e, 0xc350},  // index 40
{0x4440, 0x0007},  // index 41
{0x4442, 0x0681},  // index 42
{0x4444, 0x000e},  // index 43
{0x4446, 0x61a8},  // index 44
{0x4448, 0x0002},  // index 45
{0x444a, 0x0681},  // index 46
{0x444c, 0x0003},  // index 47
{0x444e, 0x01ba},  // index 48
{0x4450, 0x0003},  // index 49
{0x4452, 0x03b9},  // index 50
{0x4454, 0x0000},  // index 51
{0x4456, 0x5c04},  // index 52
{0x4458, 0x0000},  // index 53
{0x445a, 0x02bc},  // index 54
{0x445c, 0x000f},  // index 55
{0x445e, 0x010b},  // index 56
{0x4460, 0x0000},  // index 57
{0x4462, 0x0267},  // index 58
{0x4464, 0x0000},  // index 59
{0x4466, 0x01a7},  // index 60
{0x4468, 0x0000},  // index 61
{0x446a, 0x043f},  // index 62
{0x446c, 0x0000},  // index 63
{0x446e, 0x01fb},  // index 64
{0x4470, 0x0004},  // index 65
{0x4472, 0xfd1e},  // index 66
{0x4474, 0x0000},  // index 67
{0x4476, 0x0197},  // index 68
{0x4478, 0x0000},  // index 69
{0x447a, 0x5845},  // index 70
{0x447c, 0x000d},  // index 71
{0x447e, 0x3000},  // index 72
{0x4480, 0x0000},  // index 73
{0x4482, 0x02ae},  // index 74
{0x4484, 0x0000},  // index 75
{0x4486, 0x0196},  // index 76
{0x4488, 0x0000},  // index 77
{0x448a, 0x0177},  // index 78
{0x448c, 0x0007},  // index 79
{0x448e, 0xfd25},  // index 80
{0x4490, 0x0000},  // index 81
{0x4492, 0x0937},  // index 82
{0x4494, 0x0000},  // index 83
{0x4496, 0x5b30},  // index 84
{0x4498, 0x0000},  // index 85
{0x449a, 0x0416},  // index 86
{0x449c, 0x0000},  // index 87
{0x449e, 0x0436},  // index 88
{0x44a0, 0x0000},  // index 89
{0x44a2, 0x041f},  // index 90
{0x44a4, 0x0000},  // index 91
{0x44a6, 0x0417},  // index 92
{0x44a8, 0x0000},  // index 93
{0x44aa, 0x037e},  // index 94
{0x44ac, 0x0000},  // index 95
{0x44ae, 0x7b30},  // index 96
{0x44b0, 0x0000},  // index 97
{0x44b2, 0x01ff},  // index 98
{0x44b4, 0x0000},  // index 99
{0x44b6, 0x5c44},  // index 100
{0x44b8, 0x0000},  // index 101
{0x44ba, 0x5845},  // index 102
{0x44bc, 0x0000},  // index 103
{0x44be, 0x0416},  // index 104
{0x44c0, 0x0000},  // index 105
{0x44c2, 0x0277},  // index 106
{0x44c4, 0x0000},  // index 107
{0x44c6, 0x01a7},  // index 108
{0x44c8, 0x0000},  // index 109
{0x44ca, 0x043f},  // index 110
{0x44cc, 0x0000},  // index 111
{0x44ce, 0x0647},  // index 112
{0x44d0, 0x0004},  // index 113
{0x44d2, 0xfd36},  // index 114
{0x44d4, 0x0000},  // index 115
{0x44d6, 0x0427},  // index 116
{0x44d8, 0x0000},  // index 117
{0x44da, 0x5863},  // index 118
{0x44dc, 0x0000},  // index 119
{0x44de, 0x017e},  // index 120
{0x44e0, 0x0007},  // index 121
{0x44e2, 0xfd41},  // index 122
{0x44e4, 0x0000},  // index 123
{0x44e6, 0x5864},  // index 124
{0x44e8, 0x0000},  // index 125
{0x44ea, 0x017e},  // index 126
{0x44ec, 0x0007},  // index 127
{0x44ee, 0xfd41},  // index 128
{0x44f0, 0x0000},  // index 129
{0x44f2, 0x5865},  // index 130
{0x44f4, 0x0000},  // index 131
{0x44f6, 0x017e},  // index 132
{0x44f8, 0x0007},  // index 133
{0x44fa, 0xfd41},  // index 134
{0x44fc, 0x0000},  // index 135
{0x44fe, 0x0607},  // index 136
{0x4500, 0x0002},  // index 137
{0x4502, 0x05e7},  // index 138
{0x4504, 0x0000},  // index 139
{0x4506, 0x0627},  // index 140
{0x4508, 0x0000},  // index 141
{0x450a, 0x5c29},  // index 142
{0x450c, 0x000e},  // index 143
{0x450e, 0x0100},  // index 144
{0x4510, 0x0000},  // index 145
{0x4512, 0x00f7},  // index 146
{0x4514, 0x0000},  // index 147
{0x4516, 0x0407},  // index 148
{0x4518, 0x0000},  // index 149
{0x451a, 0x0077},  // index 150
{0x451c, 0x0002},  // index 151
{0x451e, 0x05ed},  // index 152
};

extern P_XLLP_I2C_T    v_pI2C;
extern P_XLLP_GPIO_T   v_pGPIORegs;
extern P_XLLP_CLKMGR_T v_pClkRegs;
extern P_XLLP_OST_T    v_pOSTRegs;

int OS_I2CInit()
{
        int status;

        status = XllpI2cInit((P_XLLP_I2C_T)(v_pI2C), (P_XLLP_GPIO_T) v_pGPIORegs, (P_XLLP_CLKMGR_T) v_pClkRegs, (XLLP_UINT32_T) 0);

        return status;
}


int OS_I2CMasterWriteData(XLLP_UINT8_T slaveAddr, const XLLP_UINT8_T * bytesBuf, int bytesCount)
{
        int status;
        XLLP_BOOL_T bSENDSTOP = XLLP_TRUE;

        status = XllpI2CWrite((P_XLLP_I2C_T)(v_pI2C), (P_XLLP_OST_T)(v_pOSTRegs), slaveAddr, bytesBuf, bytesCount, bSENDSTOP);

        return status;
}

int OS_I2CMasterReadData(XLLP_UINT8_T slaveAddr, XLLP_UINT8_T * bytesBuf, int bufLen)
{
        int status;

        XLLP_BOOL_T bSENDSTOP = XLLP_TRUE;

        status = XllpI2CRead((P_XLLP_I2C_T)(v_pI2C), (P_XLLP_OST_T)(v_pOSTRegs), slaveAddr, bytesBuf, bufLen, bSENDSTOP);

        return status;
}

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

////////////////////////////////////////////////////////////////////////////////////
static int PrvChangeBlock( XLLP_UINT8_T block)
{
    XLLP_UINT8_T ch[2];
    int status;

    ch[0] = BLOCK_SWITCH_CMD;
    ch[1] = block;

    status = OS_I2CMasterWriteData(PIPE_SLAVE_ADDR, ch, 2);
        
    return status;
}

static int PrvRequestRead( XLLP_UINT8_T offset)
{
    XLLP_UINT8_T ch;
    int status;
    ch = ( offset << 1 ) | 0x01;

    status = OS_I2CMasterWriteData(PIPE_SLAVE_ADDR, &ch, 1);
    
    return status;
}

static int PrvReadReg( XLLP_UINT8_T offset, XLLP_UINT16_T * pRegValue)
{
    int status;

    // Following Programming Guide 0.11
    status = PrvRequestRead(offset);
    OS_I2CMasterReadData(PIPE_SLAVE_ADDR, (XLLP_UINT8_T*)pRegValue, 2);
    return status;
}

static int PrvWriteReg( XLLP_UINT8_T offset, XLLP_UINT16_T regValue)
{
    XLLP_UINT8_T ch[3];
    int status;
    ch[0] = offset << 1;
    ch[1] = regValue & 0xFF;
    ch[2] = ( regValue >> 8 ) & 0xFF;

    status = OS_I2CMasterWriteData(PIPE_SLAVE_ADDR, ch, 3);
    return status;  
}


int ADCM2650PipelineRead( XLLP_UINT16_T regAddr, XLLP_UINT16_T * pRegValue)
{
    int status;
    status = PrvChangeBlock( BLOCK(regAddr));
    if( status == 0)
    {
        status = PrvReadReg( OFFSET(regAddr), pRegValue);  
    }
    if( status == 0 )
        return ADCM_ERR_NONE;
    return ADCM_ERR_TIMEOUT;

}

int ADCM2650PipelineWrite( XLLP_UINT16_T regAddr, XLLP_UINT16_T regValue)
{
    int status;
    status = PrvChangeBlock( BLOCK(regAddr));
    if( status == 0 )
    {
        status = PrvWriteReg( OFFSET(regAddr), regValue);
    }
    if( status == 0 )
        return ADCM_ERR_NONE;
    return ADCM_ERR_TIMEOUT;
}

int ADCM2650PipelineReadRL( XLLP_UINT16_T regAddr, XLLP_UINT16_T mask, XLLP_UINT16_T field )
{
    XLLP_UINT16_T regValue;
    int retry = ADCM2650_TIMEOUT;
    
    while( retry-- )
    {
        ADCM2650PipelineRead( regAddr, &regValue );
        if( (regValue & mask) == field )
        {
            //*pRegValue = regValue;
            return ADCM_ERR_NONE;
        }   
    
        ADCM2650Wait( 1 );
    }
    
    return ADCM_ERR_TIMEOUT;

}

int ADCM2650PipelineWriteWA( XLLP_UINT16_T regAddr, XLLP_UINT16_T mask )
{
    XLLP_UINT16_T regValue;
    
    ADCM2650PipelineRead( regAddr, &regValue );
    regValue &= mask;
    ADCM2650PipelineWrite( regAddr, regValue );

    return ADCM_ERR_NONE;
}


int ADCM2650PipelineWriteWO( XLLP_UINT16_T regAddr, XLLP_UINT16_T field )
{

    XLLP_UINT16_T regValue;

    ADCM2650PipelineRead( regAddr, &regValue );
    regValue |= field;
    ADCM2650PipelineWrite( regAddr, regValue );

    return ADCM_ERR_NONE;
}


/////////////////////////////////////////////////////////////////////////


int ADCM2650SensorReadRS( XLLP_UINT8_T regAddr, XLLP_UINT8_T * pRegValue )
{
    XLLP_UINT16_T value;
    int   retry = ADCM2650_TIMEOUT;

    // Loads SENSOR_ADDRESS (0x004a) with address 0x55 and register
    // address for a read operation.
    value = SENSOR_SLAVE_ADDR | (regAddr << 8);
    ADCM2650PipelineWrite( SENSOR_ADDRESS, value );

    // Loads SENSOR_CTRL (0x0050) with a read request
    value = SENSOR_CTRL_RW | SENSOR_CTRL_GO;
    ADCM2650PipelineWrite( SENSOR_CTRL, value );

    // Checks if the request is complete and if data is available to read
    while( --retry )
    {
        // Reads the SENSOR_CTRL (0x0050) address for status
        value = 0xFF;
        ADCM2650PipelineRead( SENSOR_CTRL, &value );
        
        if (!(value & SENSOR_CTRL_GO))
        {
            ADCM2650PipelineRead( SENSOR_DATA_1, &value );
            *pRegValue = value & 0xFF;
            return ADCM_ERR_NONE;
        }   
         
        ADCM2650Wait( 1 );
    
    }
    return ADCM_ERR_TIMEOUT;
}

int ADCM2650SensorWriteWS( XLLP_UINT8_T regAddr, XLLP_UINT8_T regValue )
{
    XLLP_UINT16_T value;
    int   retry = ADCM2650_TIMEOUT;

    // Loads SENSOR_ADDRESS (0x004a) with address 0x55 and register
    // a write operation.
    value = SENSOR_SLAVE_ADDR | (regAddr << 8);
    ADCM2650PipelineWrite( SENSOR_ADDRESS, regValue );

    // Loads SENSOR_DATA0 (0x004c)
    value = regValue;
    ADCM2650PipelineWrite( SENSOR_DATA_1, regValue );

    // Loads SENSOR_CTRL (0x0050) with a write request
    value = SENSOR_CTRL_GO;
    ADCM2650PipelineWrite( SENSOR_CTRL, value | 0x1); // write one byte
    
    while( --retry )
    {
        value = 0xFF;
        ADCM2650PipelineRead( SENSOR_CTRL, &value );
        
        if (!(value & SENSOR_CTRL_GO))
        {
            return ADCM_ERR_NONE;
        }   
        ADCM2650Wait( 1 );
    }
    return ADCM_ERR_TIMEOUT;
}


///////////////////////////////////////////////////////////////
//
//   Programming Guide Chapter 1: Basic Programming
//
///////////////////////////////////////////////////////////////

int ADCM2650PowerOn( XLLP_UINT8_T clk )
{
    // 1 Turn on M_VCC and wait for 20 ms.
    // 2 Turn on M_CLK using xx MHz and wait for 150 ms.
    // 3 Complete auto configuration 
    ADCM2650AutoConfigComplete();
    
    // 4 Load the firmware upgrade
    //ADCM2650FirmwareUpgrade();
        
    // 5 Program the master clock
    ADCM2650MasterClock( clk );
         
    // 6 Select the sensor voltage mode 
//    ADCM2650SensorVoltage( VOLTS_28 );
    
    // 7 Change factory overwrite 
    ADCM2650FactoryOverwrite();
    
    /* The following are optional steps that may be required to meet 
        specifications.
    // 8 Configure gamma correction 
    // 9 Configure color correction 
    // 10 Configure flare correction 
    // 11 Configure for JPEG quality for still frame mode 
    */

    return ADCM_ERR_NONE;
}

int ADCM2650PowerOff()
{
    // 1 Turn off M_CLK and wait for 30 ms.
    // 2 Turn off M_VCC and wait for 30 ms.
    
    return ADCM_ERR_NONE;   
}

int ADCM2650ChangeViewfinderMode(ADCM_WINDOWSIZE * pInputWin, ADCM_WINDOWSIZE *pVfOutputWin, ADCM_WINDOWSIZE *pSfOutputWin )
{
    // 1 Turn viewfinder off 
    ADCM2650ViewfinderOff();
    
    // 2 Set the input size for viewfinder and still frame modes 
    ADCM2650ViewfinderInputSize( pInputWin );
    ADCM2650StillframeInputSize( pInputWin );
    
    // 3 Set the output size for viewfinder mode 
    ADCM2650ViewfinderOutputSize( pVfOutputWin );
    
    // 4 Set the output size for still frame mode 
    ADCM2650StillframeOutputSize( pSfOutputWin );

    // 5 Turn the viewfinder back on 
    ADCM2650ViewfinderOn();

    return ADCM_ERR_NONE;   
}


int ADCM2650JpegSlowStillFrame()
{
    return 0;
}

int ADCM2650JpegFastStillFrame()
{
    return 0;
}

int ADCM2650Pll(void)
{
    return 0;
}



/////////////////////////////////////////////////////////////////////////////////////
//   
//  Programming Guide Chapter 2: Configuration Methods 
//
/////////////////////////////////////////////////////////////////////////////////////

int ADCM2650AutoConfigComplete()
{
    int ret;
    ret = RL( CMD_2, CMD_2_ACS|CMD_2_AVT|CMD_2_AST, 0x00 );
    return ret;

⌨️ 快捷键说明

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