You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
9.4 KiB

/*
* 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 I2Cthe Inter-Integrated CircuitCNend
* \param N/A CNcomment:CNend
* \retval 0 Success CNcomment:CNend
* \retval ::SOC_ERR_I2C_OPEN_ERR Open I2c Error CNcomment:I2CCNend
* \see \n
* N/A
*/
td_s32 uapi_i2c_init(td_void);
/* *
* \brief DeInit the I2C device.
* CNcomment:\brief I2CCNend
* \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:I2CCNend
* \see \n
* N/A
*/
td_s32 uapi_i2c_deinit(td_void);
/* *
* \brief Get the number of I2C module.
* CNcomment:\brief I2CCNend
* \attention \n
* Call this API to get the number of I2C module befor read/write data.\n
* CNcomment:使I2CI2C\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_i2cCNend
* \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:GPIO027CNend
* \param[in] scl_gpio_bit SCL Pin bit number, ranging from 0 to 7,
* \ranging is different in otherness chip type
* \CNcomment:GPIObit07CNend
* \param[in] sda_gpio_group SDA gpio group number, ranging from 0 to 27,
* \ranging is different in otherness chip type
* \CNcomment:GPIO027CNend
* \param[in] sda_gpio_bit SDA Pin number, ranging from 0 to 7,
* \ranging is different in otherness chip type
* \CNcomment:SDAGPIObit07CNend
* \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 GpioI2cCNend
* \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 I2CCNend
* \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:BufferCNend
* \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:I2CCNend
* \retval ::SOC_ERR_I2C_NULL_PTR The I2C pointer is invalid. CNcomment:I2CCNend
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2CCNend
* \retval ::SOC_ERR_I2C_FAILED_READ Data fails to be read by using the I2C bus. CNcomment:I2CCNend
* \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 I2CI2CI2C线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:BufferCNend
* \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:I2CCNend
* \retval ::SOC_ERR_I2C_NULL_PTR The I2C pointer is invalid. CNcomment:I2CCNend
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2CCNend
* \retval ::SOC_ERR_I2C_FAILED_WRITE Data fails to be written by using the I2C bus. CNcomment:I2CCNend
* \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 I2CCNend
* \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:i2cgpio 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,400KCNend
* \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:I2CCNend
* \retval ::SOC_ERR_I2C_INVALID_PARA The I2C parameter is invalid. CNcomment:I2CCNend
* \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 */