📄 i2c.c
字号:
//
// 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.
//
//------------------------------------------------------------------------------
//
// File: i2c.c
//
#include <windows.h>
#include <oal.h>
#include <omap2420.h>
#include <ceddkex.h>
#include "kerneli2c.h"
//------------------------------------------------------------------------------
#define I2C_TRANS_ADDRESS 0x2C
//------------------------------------------------------------------------------
BOOL WriteUcharI2C(UCHAR reg, UCHAR data)
{
I2CTRANS trans;
ZeroMemory(&trans,sizeof(trans));
trans.mClk_HL_Divisor = I2C_CLOCK_100Khz;
trans.mOpCode[0] = I2C_OPCODE_WRITE;
trans.mTransLen[0] = 2;
trans.mBufferOffset[0] = 0;
trans.mBuffer[0] = reg;
trans.mBuffer[1] = data;
KERNELI2C_PreemptibleSubmit(I2C_TRANS_ADDRESS, 7, &trans);
if (trans.mErrorCode)
return FALSE;
return TRUE;
}
//------------------------------------------------------------------------------
BOOL ReadUshortI2C( UCHAR reg, USHORT *pData )
{
I2CTRANS trans;
ZeroMemory(&trans,sizeof(trans));
trans.mClk_HL_Divisor = I2C_CLOCK_100Khz;
/* write the register offset to read from */
trans.mOpCode[0] = I2C_OPCODE_WRITE;
trans.mTransLen[0] = 1;
trans.mBufferOffset[0] = 0;
trans.mBuffer[0] = reg;
/* read the 2 bytes from that location */
trans.mOpCode[1] = I2C_OPCODE_READ;
trans.mTransLen[1] = 2;
trans.mBufferOffset[1] = 0;
KERNELI2C_PreemptibleSubmit(I2C_TRANS_ADDRESS, 7, &trans);
if (trans.mErrorCode)
return FALSE;
*pData = *(USHORT *)trans.mBuffer;
return TRUE;
}
//------------------------------------------------------------------------------
BOOL InitI2cController()
{
return TRUE;
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -