📄 i2c.c
字号:
/*****************************************************************************File Name : i2c.cDescription : Wrapper layer for STI2C.Copyright (C) 2000 STMicroelectronicsRevision History : 10/02/00 Created module to hide STAPI I2C dependency from all low-level components that are required to use the I2C bus.Reference :*****************************************************************************//* Includes --------------------------------------------------------------- */#include <string.h> /* C libs */ #include <stdio.h>#include "stlite.h" /* Standard includes */#include "stddefs.h"#include "i2c.h" /* I2C wrapper layer include */#include "sti2c.h" /* STI2C include *//* Private types/constants ------------------------------------------------ *//* Private variables ------------------------------------------------------ *//* Private macros --------------------------------------------------------- */#define I2C_HANDLE(x) (*((STI2C_Handle_t *)x))/* Private function prototypes -------------------------------------------- *//* API routines ----------------------------------------------------------- *//*****************************************************************************Name: I2C_Transfer()Description: Performs and I2C transfer i.e., a read or write with or without a prefix 1 byte subaddress.Parameters: Handle, pointer to a STI2C_Handle_t. Operation, determinates the operation type required. SubAddr, subaddress of slave device to communicate with - only applicable to I2C_SUBADDR_XXXX operations. TransferSize, number of bytes to read or write. Timeout, operation timeout in milliseconds. 0 => wait forever.Return Value: ST_NO_ERROR, The operation completed withouth error. STI2C_xxxx, I2C error.See Also: I2C_Operation_t*****************************************************************************/ST_ErrorCode_t I2C_Transfer(void *Handle, I2C_Operation_t Operation, U8 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout){ ST_ErrorCode_t Error = ST_NO_ERROR; U32 Size; switch ( Operation ) { case I2C_SUBADDR_READ: Error = STI2C_WriteNoStop(I2C_HANDLE(Handle), &SubAddr, 1, Timeout, &Size); case I2C_READ: if (Error == ST_NO_ERROR) Error = STI2C_Read(I2C_HANDLE(Handle), Data, TransferSize, Timeout, &Size); break; case I2C_SUBADDR_WRITE: Error = STI2C_WriteNoStop(I2C_HANDLE(Handle), &SubAddr, 1, Timeout, &Size); case I2C_WRITE: if (Error == ST_NO_ERROR) Error = STI2C_Write(I2C_HANDLE(Handle), Data, TransferSize, Timeout, &Size); break; default: break; } return Error;} /* I2C_Transfer() *//* End of i2c.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -