4G_module/include/cmiot/cm_i2c.h

154 lines
3.5 KiB
C
Raw Permalink Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_i2c.h
* @brief I2C驱动接口
* @copyright Copyright @2021 China Mobile IOT. All rights reserved.
* @author By tw
* @date 2021/05/18
*
* @defgroup i2c i2c
* @ingroup PI
* @{
*/
#ifndef __CM_I2C_H__
#define __CM_I2C_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/** 时钟频率 *//*仅支持以下时钟频率,不可任意更改*/
#define CM_I2C_CLK_100KHZ (100000U)
#define CM_I2C_CLK_400KHZ (400000U)
/****************************************************************************
* Public Types
****************************************************************************/
/**
* @brief I2C
*/
typedef enum
{
CM_I2C_DEV_0 = 0, /*!< ML305A系列CAMERA专用不支持配置*/
CM_I2C_DEV_1, /*!< I2C1 */
CM_I2C_DEV_2, /*!< I2C2 */
CM_I2C_DEV_NUM, /*!< I2C设备个数 */
} cm_i2c_dev_e;
/**
* @brief I2C
*/
typedef enum
{
CM_I2C_MODE_MASTER = 0, /*!< 主模式*/
CM_I2C_MODE_SLAVER, /*!< 从模式(不支持) */
} cm_i2c_mode_e;
/** 寻址 */
typedef enum
{
CM_I2C_ADDR_TYPE_7BIT, /*!< 7bit地址*/
CM_I2C_ADDR_TYPE_10BIT, /*!< 10bit地址(不支持)*/
} cm_i2c_addr_type_e;
/**
* @brief I2C
*/
typedef struct
{
cm_i2c_addr_type_e addr_type;
cm_i2c_mode_e mode;
int clk;
} cm_i2c_cfg_t;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/**
* @brief i2c开启
*
* @param [in] dev i2c设备ID
* @param [in] cfg i2c配置
* @return
* = 0 - . \n
* < 0 - , .
*
* @details .
*/
int32_t cm_i2c_open(cm_i2c_dev_e dev, cm_i2c_cfg_t *cfg);
/**
* @brief i2c关闭
*
* @param [in] dev i2c设备ID
* @return
* = 0 - . \n
* < 0 - , .
*
* @details More details
*/
int32_t cm_i2c_close(cm_i2c_dev_e dev);
/**
* @brief i2c写数据
*
* @param [in] dev i2c设备
* @param [in] slave_addr i2c设备地址
* @param [in] data
* @param [in] len
* @return
* = - . \n
* < 0 - , .
*
* @details More details
*/
int32_t cm_i2c_write(cm_i2c_dev_e dev, uint16_t slave_addr, const void *data, uint32_t len);
/**
* @brief i2c读数据
*
* @param [in] dev i2c设备
* @param [in] slave_addr i2c设备地址
* @param [out] data
* @param [in] len
* @return
* = - . \n
* < 0 - , .
*
* @details More details
*/
int32_t cm_i2c_read(cm_i2c_dev_e dev, uint16_t slave_addr, void *data, uint32_t len);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_I2C_H__ */
/** @}*/