123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #ifndef __I2C_SLAVE_SIMULATE_H__
- #define __I2C_SLAVE_SIMULATE_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "define.h"
- #include "nrf_drv_gpiote.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- //IO操作函数
- #define I2C_SDA_HIGH nrf_gpio_pin_write(I2C_SLAVE_SDA, 1);
- #define I2C_SDA_LOW nrf_gpio_pin_write(I2C_SLAVE_SDA, 0);
- #define READ_I2C_SDA nrf_gpio_pin_read(I2C_SLAVE_SDA) //输入SDA
- #define READ_I2C_SCL nrf_gpio_pin_read(I2C_SLAVE_SCL) //输入SCL
- typedef enum{
- I2C_SLAVE_START,
- I2C_SLAVE_ADDR,
- I2C_SLAVE_ACK,
- I2C_SLAVE_NACK,
- I2C_SLAVE_WRITE,
- I2C_SLAVE_READ,
- I2C_SLAVE_STOP
- }i2c_slave_stat;
- typedef struct{
- i2c_slave_stat i2c_stat;
- int bit_idx;
- uint8_t addr;
- uint8_t reg_addr;
- bool is_wr;
- int wr_len;
- uint8_t *wr_data;
- int rd_len;
- uint8_t *rd_data;
- int idx;
- bool scl_stat;
- bool sda_start;
- bool sda_end;
- }i2c_slave_work;
-
- #define I2C_SLAVE_WORK_DEFAULT_CONFIG \
- { \
- .i2c_stat=I2C_SLAVE_STOP, \
- .bit_idx=0, \
- .addr=0, \
- .reg_addr=0, \
- .is_wr=true, \
- .wr_len=0, \
- .wr_data=NULL, \
- .rd_len=0, \
- .rd_data=NULL, \
- .idx=0, \
- .scl_stat=true, \
- .sda_start=true, \
- .sda_end=true, \
- }
- typedef void (*i2c_data_func)(i2c_slave_work *slave_work);
- void set_i2c_slave_addr(uint8_t addr);
- void set_i2c_slave_data_func(i2c_data_func func);
- #ifdef __cplusplus
- }
- #endif
- #endif //__I2C_SLAVE_SIMULATE_H__
|