129 lines
3.3 KiB
C
129 lines
3.3 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef IOT_I2C_API_H
|
|
#define IOT_I2C_API_H
|
|
|
|
/* export includes */
|
|
#include "os_lock_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define IOT_I2C_PORT_0 0
|
|
#define IOT_I2C_PORT_1 1
|
|
#define IOT_I2C_PORT_2 2
|
|
/*just for kunlun3*/
|
|
#define IOT_I2C_PORT_3 3
|
|
|
|
//#define IOT_I2C_S_PORT_0 0
|
|
//#define IOT_I2C_S_PORT_1 1
|
|
|
|
#define IOT_I2C_DIRC_RD 1
|
|
#define IOT_I2C_DIRC_WR 0
|
|
|
|
typedef int (*iot_i2c_fun)(void *);
|
|
|
|
typedef struct _iot_i2c_gpio_sel {
|
|
uint8_t scl;
|
|
uint8_t sda;
|
|
} iot_i2c_gpio_sel_t;
|
|
|
|
typedef struct _iot_i2c_module_cfg {
|
|
/** i2c port number */
|
|
uint8_t port;
|
|
/** open i2c port count */
|
|
uint8_t open_cnt;
|
|
/** i2c resources lock */
|
|
os_mutex_h lock;
|
|
/** i2c baudrate, unit is Kb */
|
|
uint32_t baud;
|
|
/** wait nack number */
|
|
uint32_t nack_wait_num;
|
|
/** gpio number select */
|
|
iot_i2c_gpio_sel_t gpio;
|
|
} iot_i2c_module_cfg_t;
|
|
|
|
/**
|
|
* @brief iot_i2c_write() - i2c write bytes
|
|
*
|
|
* @param port 0-i2c0, 1-i2c1
|
|
* @param addr adress of slave address
|
|
* @param buf the pointer to write data buffer
|
|
* @param num the number of write data
|
|
*
|
|
* @return 0: write successful
|
|
* @return other: write failed
|
|
*
|
|
*/
|
|
uint8_t iot_i2c_write(uint8_t port, int32_t addr, char *buf, uint8_t num);
|
|
|
|
/**
|
|
* @brief iot_i2c_read() - read datas
|
|
*
|
|
* @param port 0-i2c0, 1-i2c1
|
|
* @param addr adress of slave address
|
|
* @param buf the pointer to read data buffer
|
|
* @param num the number of read data
|
|
*
|
|
* @return 0: read successful
|
|
* @return other: read failed
|
|
*
|
|
*/
|
|
uint8_t iot_i2c_read(uint8_t port, uint32_t addr, char *buf, uint8_t num);
|
|
|
|
/**
|
|
* @brief iot_i2c_open() - i2c open
|
|
*
|
|
* @param cfg the pointer of i2c module configure structure
|
|
*
|
|
* @return 0: i2c open successful
|
|
* @return other: i2c open failed
|
|
*
|
|
*/
|
|
uint8_t iot_i2c_open(iot_i2c_module_cfg_t *cfg);
|
|
|
|
/**
|
|
* @brief iot_i2c_close() - i2c close
|
|
*
|
|
* @param port i2c port
|
|
*
|
|
* @return 0: i2c close successful
|
|
* @return other: i2c close failed
|
|
*
|
|
*/
|
|
uint8_t iot_i2c_close(uint8_t port);
|
|
|
|
|
|
/**
|
|
* @brief iot_i2c_module_init() - i2c module initialize
|
|
*
|
|
* @param cfg the pointer of i2c module configure structure
|
|
*
|
|
* @return 0: i2c init successful
|
|
* @return other: i2c init failed
|
|
*
|
|
*/
|
|
uint8_t iot_i2c_module_init(iot_i2c_module_cfg_t *cfg);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_I2C_API_H */
|
|
|