106 lines
3.3 KiB
C
106 lines
3.3 KiB
C
/** ##########################################################################
|
||
** Filename :
|
||
** Project :
|
||
** Module :
|
||
** Processor :
|
||
** Version : 1.0
|
||
** Compiler :
|
||
** Date/Time :
|
||
** Abstract :
|
||
** Contents :
|
||
** Note :
|
||
**
|
||
** (c) Copyright dmdz Co.,Ltd
|
||
** --------------------------------------------------------------------------
|
||
** R E V I S I O N H I S T O R Y
|
||
** --------------------------------------------------------------------------
|
||
** Date Ver Author Description
|
||
|
||
** -20230602- --V1.0-- --mingyea--- --修改--
|
||
|
||
** #########################################################################*/
|
||
#ifndef I2C_
|
||
#define I2C_
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- I N C L U D E F I L E S
|
||
----------------------------------------------------------------------------*/
|
||
#include "common_types.h"
|
||
#include "error.h"
|
||
#include "i2c_cfg.h"
|
||
#include "cpu.h"
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- D E F I N E S / M A C R O S
|
||
----------------------------------------------------------------------------*/
|
||
#define I2C_CMD_NULL 0u /* 空闲 */
|
||
#define I2C_CMD_READ 1u /* I2C读操作 */
|
||
#define I2C_CMD_WRITE 2u /* I2C写操作 */
|
||
|
||
#define I2C_STATE_IDLE 0u
|
||
#define I2C_STATE_START_BIT 1u
|
||
#define I2C_STATE_SEND_ADDR 2u
|
||
#define I2C_STATE_WRITE 3u
|
||
#define I2C_STATE_READ 4u
|
||
#define I2C_STATE_STOP_BIT 5u
|
||
|
||
#define I2C_SUB_STATE_ADDR_HIGH 0u
|
||
#define I2C_SUB_STATE_ADDR_LOW 1u
|
||
|
||
#define I2C_CMD_RESULT_INIT 0u
|
||
#define I2C_CMD_RESULT_FAILED 1u
|
||
#define I2C_CMD_RESULT_OK 2u
|
||
|
||
#define I2C_RESULT_INIT 0u
|
||
#define I2C_RESULT_OK 1u
|
||
#define I2C_RESULT_FAILED_TIMEOUT 2u
|
||
#define I2C_RESULT_FAILED_NACK 3u
|
||
#define I2C_RESULT_FAILE_TOHER 4u
|
||
|
||
#define I2C_JUDGE_ACK 0u
|
||
#define I2C_JUDGE_NACK 1u
|
||
|
||
#define I2C_ADDR_7BIT 0u
|
||
#define I2C_ADDR_10BIT 1u
|
||
|
||
#define I2C_RE_INIT_WHEN_FAULT //当I2C出现故障时,强制重新初始
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- T Y P E D E F I N I T I O N S
|
||
----------------------------------------------------------------------------*/
|
||
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- G L O B A L V A R I A B L E S
|
||
- only configuration table allowed here,variables are not allowed!
|
||
----------------------------------------------------------------------------*/
|
||
extern u16 i2c_snd_recv_temp;
|
||
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- C O N S T A N T S
|
||
----------------------------------------------------------------------------*/
|
||
|
||
/*---------------------------------------------------------------------------
|
||
- F U N C T I O N P R O T O T Y P E
|
||
----------------------------------------------------------------------------*/
|
||
void i2c_init(void);
|
||
void i2c_task(void);
|
||
|
||
|
||
void i2c_re_init_para(void);
|
||
|
||
uint8_t i2c_send_block(u8 *p_buf, i2c_len_type len,i2c_len_type *p_real_len);
|
||
uint8_t i2c_recv_block(u8 *p_buf, i2c_len_type len,i2c_len_type *p_real_len);
|
||
|
||
void i2c_sel_slave_addr(u16 addr);
|
||
|
||
void i2c_send_block_successful_callback(void);
|
||
void i2c_recv_block_successful_callback(void);
|
||
|
||
|
||
void i2c_test(void);
|
||
|
||
|
||
#endif /* */
|