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

📄 i2c.h

📁 mstar 776 开发的车载dvd
💻 H
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (¨MStar Confidential Information〃) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

#ifndef _I2C_H_
#define _I2C_H_

#include "DataType.h"
#include "board.h"

#if (ENABLE_EEPROM)

#ifdef _I2C_C_
#define _I2CDEC_
#else
#define _I2CDEC_ extern
#endif

/////////////////////////////////////////////
// I2C common definition
/////////////////////////////////////////////
#define _HIGH    1
#define _LOW     0

#define i2cSetSCL(is_hl)     ( is_hl? SetPinI2cSCL() : ClrPinI2cSCL() )
#define i2cSetSDA(is_hl)     ( is_hl? SetPinI2cSDA() : ClrPinI2cSDA() )

#define I2C_CHECK_PIN_TIME   1000 // unit: 1 us
#define I2C_CHECK_PIN_CYCLE  8    // cycle of check pin loopp
#define I2C_CHECK_PIN_DUMMY  ((I2C_CHECK_PIN_TIME / I2C_CHECK_PIN_CYCLE) * 2)

// type definition
typedef enum _I2cIoTransType
{
    I2C_TRANS_READ,
    I2C_TRANS_WRITE
} I2cIoTransType;

#define I2C_DEVICE_ADR_WRITE(slave_adr)   (slave_adr & ~_BIT0)
#define I2C_DEVICE_ADR_READ(slave_adr)    (slave_adr | _BIT0)

#define I2C_ACCESS_DUMMY_TIME   3

#define I2C_ACKNOWLEDGE        _LOW
#define I2C_NON_ACKNOWLEDGE    _HIGH

/////////////////////////////////////////////
// I2C subroutines
/////////////////////////////////////////////
_I2CDEC_ void i2c_Delay(void);

_I2CDEC_ void i2cSetSCL_Chk(bit bSet);
_I2CDEC_ void i2cSetSDA_Chk(bit bSet);

_I2CDEC_ BOOL i2c_Start(void);
_I2CDEC_ void i2c_Stop(void);

_I2CDEC_ BYTE i2c_ReceiveByte(BOOL bAck);
_I2CDEC_ BIT  i2c_SendByte(BYTE ucVal);

_I2CDEC_ BOOL i2c_AccessStart(BYTE ucSlaveAdr, I2cIoTransType trans_t);

#if (RM_EEPROM_TYPE == RM_TYPE_24C16)
    _I2CDEC_ void i2cBurstReadBytes(BYTE ucSlaveAdr, BYTE ucSubAdr, BYTE *pBuf, BYTE ucBufLen);
    _I2CDEC_ void i2cBurstReadBytes_2(BYTE ucSlaveAdr, BYTE *pBuf, BYTE ucBufLen);
    _I2CDEC_ void i2cBurstWriteBytes(BYTE ucSlaveAdr, BYTE ucSubAdr, BYTE *pBuf, BYTE ucBufLen);
#else
    _I2CDEC_ void i2cBurstReadBytes(BYTE ucSlaveAdr, unsigned int ucSubAdr, BYTE *pBuf, BYTE ucBufLen);
    _I2CDEC_ void i2cBurstWriteBytes(BYTE ucSlaveAdr, unsigned int ucSubAdr, BYTE *pBuf, BYTE ucBufLen);
#endif

#if (KEEP_UNUSED_FUNC == 1)
_I2CDEC_ void i2cBurstWriteBytes_2(BYTE ucSlaveAdr, BYTE *pBuf, BYTE ucBufLen);
#endif


#if (RM_EEPROM_TYPE == RM_TYPE_24C16)
_I2CDEC_ BYTE i2cReadByte(BYTE ucSlaveAdr, BYTE ucSubAdr);
_I2CDEC_ void i2cWriteByte(BYTE ucSlaveAdr, BYTE ucSubAdr, BYTE ucVal);
#else
_I2CDEC_ BYTE i2cReadByte(BYTE ucSlaveAdr, U16 ucSubAdr);
_I2CDEC_ void i2cWriteByte(BYTE ucSlaveAdr, U16  ucSubAdr, BYTE ucVal);
#endif

_I2CDEC_ BYTE i2cReadCurrent(BYTE ucSlaveAdr);
_I2CDEC_ void i2cWriteCurrent(BYTE ucSlaveAdr, BYTE ucVal);

#endif

#endif // _I2C_H_

⌨️ 快捷键说明

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