📄 cameramagna.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2006,2007, 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: CameraMagna.cpp
//
// Definitions for MagnaChip camera module specific
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "cameradbg.h"
#include "bsp.h"
#include "ipu.h"
#include "i2cbus.h"
#include "CsiClass.h"
#include "bspcsi.h"
#include "CameraMagna.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
extern csiSensorId gSensorInUse;
extern HANDLE hI2C;
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define MAGNA521DA_I2C_ADDRESS 0x22
#define MAGNA521DA_I2C_SPEED 81000
#define CAMERA_FUNCTION_ENTRY() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define CAMERA_FUNCTION_EXIT() \
DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: CameraMagnaInit
//
// Initializes the Magna camera sensor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void CameraMagnaInit()
{
INT iResult;
DWORD dwFrequency;
BYTE bySlaveAddr, byCsiAddr;
CAMERA_FUNCTION_ENTRY();
byCsiAddr = CSI_I2C_ADDRESS;
switch (gSensorInUse)
{
case csiSensorId_Magna521DA:
dwFrequency = MAGNA521DA_I2C_SPEED;
bySlaveAddr = MAGNA521DA_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__));
}
// Wavetable script, generated by WaveMan
I2CWriteOneByte(hI2C, bySlaveAddr, 0xff, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x01, 0x10, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x10, 0x64, &iResult);
// state 0
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x02, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 1
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x41, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x70, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x03, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 2
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x02, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x55, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x03, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 3
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x03, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x5A, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x02, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 4
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x7A, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 5
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x05, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x9C, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x0F, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 6
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x73, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x31, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 7
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x07, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x2D, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x3B, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 8
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x08, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x32, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x33, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 9
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x09, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x67, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x63, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 10
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x0a, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x6C, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x23, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x0E, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 11
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x0b, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x71, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x23, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 12
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x0c, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x30, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x2F, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// state 13
I2CWriteOneByte(hI2C, bySlaveAddr, 0x03, 0x0d, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x04, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x05, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x06, 0x06, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x08, 0x00, &iResult);
// wave table length
I2CWriteOneByte(hI2C, bySlaveAddr, 0x07, 0x0e, &iResult);
// set frame height: 1355 (Changed by Ke on 03/16/2006)
I2CWriteOneByte(hI2C, bySlaveAddr, 0x1c, 0x13, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x1d, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x0e, 0x4b, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x0f, 0x05, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x9e, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x9d, 0xc6, &iResult);
// set fram0xe width: 1845
I2CWriteOneByte(hI2C, bySlaveAddr, 0x0c, 0x35, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x0d, 0x07, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x9b, 0x10, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x9c, 0x07, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x93, 0x21, &iResult);
// disable 0xautodark
I2CWriteOneByte(hI2C, bySlaveAddr, 0x01, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x40, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x41, 0x00, &iResult);
// 1D BPC setting for
I2CWriteOneByte(hI2C, bySlaveAddr, 0x42, 0xf0, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x43, 0x03, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x44, 0x0a, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x45, 0x00, &iResult);
//Turn on sensor row n
I2CWriteOneByte(hI2C, bySlaveAddr, 0x3b, 0x40, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x38, 0x18, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x3c, 0x00, &iResult);
// 1x channel gain
I2CWriteOneByte(hI2C, bySlaveAddr, 0x20, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x21, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x22, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x23, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x24, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x25, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x26, 0x00, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x27, 0x01, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xb9, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xb8, 0xc3, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xbb, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xba, 0xc3, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xbf, 0x04, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0xbe, 0xc3, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x57, 0x07, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x56, 0xd6, &iResult);
I2CWriteOneByte(hI2C, bySlaveAddr, 0x55, 0x03, &iResult);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -