📄 exti2cinterface.cpp
字号:
/*+++ *******************************************************************\
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Copyright (c) 2008 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "ExtI2CInterface.h"
#include "DriverI2C.h"
#include "debug.h"
#include "device.h"
/////////////////////////////////////////////////////////////////////////////////////////
ExtI2CInterface::ExtI2CInterface(DriverI2C* p_driver_i2c,DWORD rev_id):
_p_driver_i2c(p_driver_i2c),
_rev_id(rev_id)
{
DbgLogInfo(("DriverI2C::DriverI2C constructor\n"));
// Increase the reference count
_p_driver_i2c->addRef();
}
/////////////////////////////////////////////////////////////////////////////////////////
ExtI2CInterface::~ExtI2CInterface()
{
// Decrease the reference count
_p_driver_i2c->release();
}
/////////////////////////////////////////////////////////////////////////////////////////
INT ExtI2CInterface::addRef()
{
return _p_driver_i2c->addRef();
}
/////////////////////////////////////////////////////////////////////////////////////////
INT ExtI2CInterface::release()
{
return _p_driver_i2c->release();
}
NTSTATUS ExtI2CInterface::setCommandFormat(BOOLEAN first,BOOLEAN last)
{
if(!_p_driver_i2c)
return STATUS_UNSUCCESSFUL;
else
return _p_driver_i2c->setCommandFormat(first,last);
}
BOOLEAN ExtI2CInterface::read(
BYTE device_adr,
INT size,
BYTE *p_buf)
{
return TRUE;
}
BOOLEAN ExtI2CInterface::write(
BYTE device_adr,
INT size,
BYTE *p_buf)
{
int num_bytes = size - 1;
BOOLEAN iostatus = FALSE;
BYTE *data = p_buf+1;
int write_size =0;
BOOLEAN mult_write=FALSE;
NTSTATUS i2cstatus = STATUS_SUCCESS;
if(_rev_id == POLARIS_REVID_T0)
{
write_size = TRANSFER_SIZE_T0;
}
else if(_rev_id >=POLARIS_REVID_A0)
{
write_size = TRANSFER_SIZE_A0;
}
else
{
return FALSE;
}
if (num_bytes>write_size-1)
{
mult_write = TRUE;
int temp_num = num_bytes/write_size;
num_bytes = num_bytes - temp_num*write_size;
for (int DW=0;DW<temp_num;DW++)
{
if(_rev_id >=POLARIS_REVID_A0)
{
if(DW==0)//first time write to the address
{
i2cstatus = setCommandFormat(TRUE,FALSE);
}
else if((num_bytes==0) && (DW==temp_num-1)) //last time write to the address
{
i2cstatus = setCommandFormat(FALSE,TRUE);
}
else //middle time write to the address
{
i2cstatus = setCommandFormat(FALSE,FALSE);
}
if(!NT_SUCCESS(i2cstatus))
{
return FALSE;
}
}
iostatus = _p_driver_i2c->write(device_adr>>1,
1,
p_buf,
write_size,
(data+DW*write_size)
);
if(iostatus == FALSE)
{
if(_rev_id >=POLARIS_REVID_A0)
{
setCommandFormat(TRUE,TRUE);// change to common format
}
return FALSE;
}
}
}
if(_rev_id >=POLARIS_REVID_A0)
{
if(mult_write==TRUE)
i2cstatus = setCommandFormat(FALSE,TRUE); //the last time of multi time write to same address
else
i2cstatus = setCommandFormat(TRUE,TRUE); // only once write to the address
if(!NT_SUCCESS(i2cstatus))
return FALSE;
}
iostatus = _p_driver_i2c->write(device_adr>>1,
1,
p_buf,
num_bytes,
(p_buf+size-num_bytes));
if(_rev_id >=POLARIS_REVID_A0)
{
if(!NT_SUCCESS(setCommandFormat(TRUE,TRUE)))//change to the common format
return FALSE;
}
return iostatus;
}
BOOLEAN ExtI2CInterface::writeThenRead(
BYTE device_adr,
INT write_size,
const BYTE *p_write_buf,
INT read_size,
BYTE *p_read_buf)
{
return _p_driver_i2c->read(device_adr>>1,
write_size,
p_write_buf,
read_size,
p_read_buf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -