|
|
|
|
/*
|
|
|
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2001-2020. All rights reserved.
|
|
|
|
|
* Description: Application programming interfaces (APIs) of the external chip software (ECS)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef UAPI_I2C_H
|
|
|
|
|
#define UAPI_I2C_H
|
|
|
|
|
|
|
|
|
|
#include "td_type.h"
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
#if __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
td_u8 dev_address; /* Address of a device on the I2C bus */ /* CNcomment:设备在I2C总线上的地址。CNend */
|
|
|
|
|
td_u32 reg_addr; /* On-chip offset address of a device */ /* CNcomment:设备的片内偏移地址。CNend */
|
|
|
|
|
td_u32 reg_addr_count; /* Length of an on-chip offset address. */ /* CNcomment:片内偏移地址的长度单位。CNend */
|
|
|
|
|
/* 1: 8-bit sub address CNcomment:1:表示8bit子地址;CNend */
|
|
|
|
|
/* 2: 16-bit sub address CNcomment:2:表示16bit子地址;CNend */
|
|
|
|
|
/* 3: 24-bit sub address CNcomment:3:表示24bit子地址;CNend */
|
|
|
|
|
/* 4: 32-bit sub address CNcomment:4:表示32bit子地址。CNend */
|
|
|
|
|
} uapi_i2c_addr_info;
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Init the I2C device.
|
|
|
|
|
* CNcomment:\brief 初始化I2C(the Inter-Integrated Circuit)设备。CNend
|
|
|
|
|
|
|
|
|
|
* \param N/A CNcomment:无。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_OPEN_ERR Open I2c Error CNcomment:I2C无效参数。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_init(td_void);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief DeInit the I2C device.
|
|
|
|
|
* CNcomment:\brief 去初始化I2C设备。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* This API is called after I2C operations are completed.\n
|
|
|
|
|
* CNcomment:在I2C操作结束后调用此接口\n CNend
|
|
|
|
|
|
|
|
|
|
* \param N/A CNcomment:无。CNend
|
|
|
|
|
* \retval 0 Success CNcomment: 成功。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_CLOSE_ERR Close I2c Error. CNcomment:I2C设备未初始化。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_deinit(td_void);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Get the number of I2C module.
|
|
|
|
|
* CNcomment:\brief 去初始化I2C设备。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* Call this API to get the number of I2C module befor read/write data.\n
|
|
|
|
|
* CNcomment:在使用I2C读写数据之前调用此接口获取芯片的I2C模块数目\n CNend
|
|
|
|
|
|
|
|
|
|
* \param N/A CNcomment:无。CNend
|
|
|
|
|
* \retval 0 Success CNcomment: 成功。CNend
|
|
|
|
|
* \retval ::
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_get_total_num(td_u32 *i2c_num);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* The I2C device is not initialized.
|
|
|
|
|
* CNcomment:\brief 创建一路gpio_i2c。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* If the specified GPIO pins are used, this API fails to be called.\n
|
|
|
|
|
* CNcomment:如果gpio已被占用会失败\n CNend
|
|
|
|
|
|
|
|
|
|
* \param[out] i2c_id ID of the obtained I2C bus CNcomment:得到I2C总线号。CNend
|
|
|
|
|
* \param[in] scl_gpio_group SCL gpio group number, ranging from 0 to 27,
|
|
|
|
|
* \ranging is different in otherness chip type
|
|
|
|
|
* \CNcomment:GPIO组数,取值范围为0~27,不同的芯片类型范围不一样。CNend
|
|
|
|
|
* \param[in] scl_gpio_bit SCL Pin bit number, ranging from 0 to 7,
|
|
|
|
|
* \ranging is different in otherness chip type
|
|
|
|
|
* \CNcomment:所在GPIO组的bit数,取值范围为0~7,不同的芯片类型范围不一样。CNend
|
|
|
|
|
* \param[in] sda_gpio_group SDA gpio group number, ranging from 0 to 27,
|
|
|
|
|
* \ranging is different in otherness chip type
|
|
|
|
|
* \CNcomment:GPIO组数,取值范围为0~27,不同的芯片类型范围不一样。CNend
|
|
|
|
|
* \param[in] sda_gpio_bit SDA Pin number, ranging from 0 to 7,
|
|
|
|
|
* \ranging is different in otherness chip type
|
|
|
|
|
* \CNcomment:SDA所在GPIO组bit数,取值范围为0~7,不同的芯片类型范围不一样。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::TD_FAILURE Create gpioi2c failed CNcomment:失败。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NULL_PTR The pointer parameter is NULL CNcomment:指针参数为空。CNend
|
|
|
|
|
* \retval ::SOC_ERR_GPIO_INVALID_PARA The parameter is invalid. CNcomment:参数非法。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_create_gpio_i2c(td_u32 scl_gpio_group, td_u32 scl_gpio_bit,
|
|
|
|
|
td_u32 sda_gpio_group, td_u32 sda_gpio_bit, td_u32 *i2c_id);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Destroys a inter-integrated circuit (I2C) channel that simulates
|
|
|
|
|
* \the general-purpose input/output (GPIO) function.
|
|
|
|
|
* CNcomment:\brief 销毁一路GpioI2c。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* If the I2C channel is not used, a code indicating success is returned.\n
|
|
|
|
|
* CNcomment:如果该GpioI2c未使用,直接返回成功\n CNend
|
|
|
|
|
|
|
|
|
|
* \param[in] i2c_id ID of the I2C bus to be destroyed CNcomment:要销毁的I2C总线号。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::TD_FAILURE Destroy gpioi2c failed CNcomment:失败。CNend
|
|
|
|
|
* \retval ::SOC_ERR_GPIO_INVALID_PARA The parameter is invalid. CNcomment:参数非法。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_destroy_gpio_i2c(td_u32 i2c_id);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Reads data by using the I2C bus.
|
|
|
|
|
* CNcomment:\brief 通过I2C读数据。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* N/A
|
|
|
|
|
* \param[in] i2c_id I2C bus of the device to be read CNcomment:所读取设备使用的I2C总线。CNend
|
|
|
|
|
* \param[in] i2c_addr_info struct i2c addr CNcomment:i2c地址信息结构体
|
|
|
|
|
* \param[out] buf Buffer for storing the data to be read CNcomment:读Buffer,存放读取数据。CNend
|
|
|
|
|
* \param[in] length length of the data to be read CNcomment:要读取的数据长度。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::TD_FAILURE Read data failed CNcomment:失败。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NOT_INIT The I2C device is not initialized. CNcomment:I2C设备未初始化。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NULL_PTR The I2C pointer is invalid. CNcomment:I2C无效指针。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2C无效参数。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_FAILED_READ Data fails to be read by using the I2C bus. CNcomment:I2C读数据失败。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_read(td_u32 i2c_id, const uapi_i2c_addr_info *i2c_addr_info, td_u8 *buf, td_u32 length);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Writes data by using the I2C bus. That is, you can call this API to write data to
|
|
|
|
|
* \the device mounted on the I2C bus through the I2C channel.
|
|
|
|
|
* CNcomment:\brief 通过I2C写数据。通过I2C通道,向I2C总线上挂接的设备进行写操作。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* N/A
|
|
|
|
|
* \param[in] i2c_id I2C bus of the device to be written CNcomment:待写设备使用的I2C总线。CNend
|
|
|
|
|
* \param[in] i2c_addr_info struct i2c addr CNcomment:i2c地址信息结构体
|
|
|
|
|
* \param[in] buf Buffer for storing the data to be written CNcomment:写Buffer,存放待写入数据。CNend
|
|
|
|
|
* \param[in] length Length of the data to be written CNcomment:要写入的数据的长度。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::TD_FAILURE Write data failed CNcomment:失败。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NOT_INIT The I2C device is not initialized. CNcomment:I2C设备未初始化。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NULL_PTR The I2C pointer is invalid. CNcomment:I2C无效指针。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2C无效参数。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_FAILED_WRITE Data fails to be written by using the I2C bus. CNcomment:I2C写数据失败。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_write(td_u32 i2c_id, const uapi_i2c_addr_info *i2c_addr_info, td_u8 *buf, td_u32 length);
|
|
|
|
|
|
|
|
|
|
/* *
|
|
|
|
|
* \brief Sets the transfer rate of the I2C bus.
|
|
|
|
|
* CNcomment:\brief 设置I2C的传输速率。CNend
|
|
|
|
|
|
|
|
|
|
* \attention \n
|
|
|
|
|
* Call this API Only be effect in standard i2c, gpio simulate i2c is noneffective.\n
|
|
|
|
|
* If you do not call this API to set the transfer rate, the rate 100 kbit/s is used by default.\n
|
|
|
|
|
* CNcomment:此接口仅对标准的i2c通道有效,对gpio 模拟 i2c 无效。\n
|
|
|
|
|
* 如果不调用此接口,系统采用400Kbit/s作为缺省速率。\n CNend
|
|
|
|
|
|
|
|
|
|
* \param[in] i2c_id D of channel corresponding to the device to be written on the I2C bus
|
|
|
|
|
* \CNcomment:所写设备在I2C总线上的通道号。CNend
|
|
|
|
|
* \param[in] rate_kbps I2C clock rate.Max rate is 400K CNcomment:I2C时钟速率,最大支持设置400K。CNend
|
|
|
|
|
* \retval 0 Success CNcomment:成功。CNend
|
|
|
|
|
* \retval ::TD_FAILURE Set rate failed CNcomment:失败。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_NOT_INIT The I2C device is not initialized. CNcomment:I2C设备未初始化。CNend
|
|
|
|
|
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2C无效参数。CNend
|
|
|
|
|
* \see \n
|
|
|
|
|
* N/A
|
|
|
|
|
*/
|
|
|
|
|
td_s32 uapi_i2c_set_rate(td_u32 i2c_id, td_u32 rate_kbps);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
#if __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
|
#endif /* UAPI_I2C_H */
|