Sdk 支持软件 IIC 和硬件 IIC,具体的驱动在 cpu/br23 目录下的 iic_hw.c、iic_soft.c 和 iic_eeprom_test.c
文件里,具体的函数接口如下:
- int soft_iic_init(soft_iic_dev iic)
初始化:
软件 IIC:
,通过全局结构体变量 soft_iic_cfg 配置 SCL,SDA,波特率等参数
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
0 成功, 非零 失败 - void soft_iic_uninit(soft_iic_dev iic)
反初始化软件 IIC
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
NULL - void soft_iic_suspend(soft_iic_dev iic)
挂起软件 IIC,使引脚不输出
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
NULL - void soft_iic_resume(soft_iic_dev iic)
恢复软件 IIC,重新占用引脚
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
NULL - void soft_iic_start(soft_iic_dev iic)
发送起始位
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
NULL - void soft_iic_stop(soft_iic_dev iic)
发送停止位
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
返回值:
NULL - u8 soft_iic_tx_byte(soft_iic_dev iic, u8 byte)
发送一个字节
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
u8 byte
被发送字节
返回值:
1 IIC 从机 ACK,0 IIC 从机 NACK - u8 soft_iic_rx_byte(soft_iic_dev iic, u8 ack)
接收一个字节
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
u8 ack
主机是否应答,1 ACK,0 NACK
返回值:
读取的字节 - int soft_iic_write_buf(soft_iic_dev iic, const void *buf, int len)
软件 IIC 写 buffer
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
const void *buf
发送缓冲区基地址
int len
缓冲区长度
返回值:
=0 返回实际发送长度,<0 失败
- int soft_iic_read_buf(soft_iic_dev iic, void *buf, int len)
软件 IIC 读 buffer
参数:
soft_iic_dev iic
iic 句柄,类型为 typedef 的 soft_iic_dev
void *buf
接收缓冲区基地址
int len
缓冲区长度
返回值:
=0 返回实际发送长度,<0 失败
硬件 IIC
- int hw_iic_init(hw_iic_dev iic)
初始化硬件 IIC,通过全局结构体变量 hw_iic_cfg 配置 SCL,SDA,波特率等参数
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
0 成功, 非零 失败 - void hw_iic_uninit(hw_iic_dev iic)
反初始化硬件 IIC
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
NULL - void hw_iic_suspend(hw_iic_dev iic)
挂起硬件 IIC,使引脚不输出数据
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
NULL - void hw_iic_resume(hw_iic_dev iic)
恢复硬件 IIC,重新占用引脚
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
NULL - void hw_iic_start(hw_iic_dev iic)
发送起始位
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
NULL - void hw_iic_stop(hw_iic_dev iic)
发送停止位
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
返回值:
NULL - u8 hw_iic_tx_byte(hw_iic_dev iic, u8 byte)
发送一个字节
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
u8 byte
被发送字节
返回值:
1 IIC 从机 ACK,0 IIC 从机 NACK - u8 hw_iic_rx_byte(hw_iic_dev iic, u8 ack)
接收一个字节
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
u8 ack
主机是否应答,1 ACK,0 NACK
返回值:
接收的字节 - int hw_iic_write_buf(hw_iic_dev iic, const void *buf, int len)
硬件 IIC 写 buffer
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
const void *buf
发送缓冲区基地址
int len
缓冲区长度
返回值:
=0 返回实际发送长度,<0 失败
- int hw_iic_read_buf(hw_iic_dev iic, void *buf, int len)
硬件 IIC 读 buffer
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
const void *buf
发送缓冲区基地址
int len
缓冲区长度
返回值:
=0 返回实际发送长度,<0 失败
- int hw_iic_set_baud(hw_iic_dev iic, u32 baud)
设置波特率
参数:
hw_iic_dev iic
iic 句柄,类型为 typedef 的 hw_iic_dev
u32 baud
波特率
返回值:
0 成功, 非零 失败