feat: 完成控制代码编写
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
/*********************************************************************************************************************
|
||||
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
||||
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
||||
*
|
||||
* 本文件是CH32V307VCT6 开源库的一部分
|
||||
*
|
||||
* CH32V307VCT6 开源库 是免费软件
|
||||
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU通用公共许可证)的条款
|
||||
* 即 GPL 的第3版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
||||
*
|
||||
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
||||
* 甚至没有隐含的适销性或适合特定用途的保证
|
||||
* 更多细节请参见 GPL
|
||||
*
|
||||
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
||||
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
||||
*
|
||||
* 额外注明:
|
||||
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
||||
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
||||
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
||||
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
||||
*
|
||||
* 文件名称 zf_driver_soft_iic
|
||||
* 公司名称 成都逐飞科技有限公司
|
||||
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
|
||||
* 开发环境 MounRiver Studio V1.8.1
|
||||
* 适用平台 CH32V307VCT6
|
||||
* 店铺链接 https://seekfree.taobao.com/
|
||||
*
|
||||
* 修改记录
|
||||
* 日期 作者 备注
|
||||
* 2022-09-15 大W first version
|
||||
********************************************************************************************************************/
|
||||
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
||||
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
||||
*
|
||||
* 本文件是CH32V307VCT6 开源库的一部分
|
||||
*
|
||||
* CH32V307VCT6 开源库 是免费软件
|
||||
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU通用公共许可证)的条款
|
||||
* 即 GPL 的第3版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
||||
*
|
||||
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
||||
* 甚至没有隐含的适销性或适合特定用途的保证
|
||||
* 更多细节请参见 GPL
|
||||
*
|
||||
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
||||
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
||||
*
|
||||
* 额外注明:
|
||||
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
||||
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
||||
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
||||
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
||||
*
|
||||
* 文件名称 zf_driver_soft_iic
|
||||
* 公司名称 成都逐飞科技有限公司
|
||||
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
|
||||
* 开发环境 MounRiver Studio V1.8.1
|
||||
* 适用平台 CH32V307VCT6
|
||||
* 店铺链接 https://seekfree.taobao.com/
|
||||
*
|
||||
* 修改记录
|
||||
* 日期 作者 备注
|
||||
* 2022-09-15 大W first version
|
||||
********************************************************************************************************************/
|
||||
|
||||
#include "zf_common_debug.h"
|
||||
|
||||
#include "zf_driver_soft_iic.h"
|
||||
|
||||
#define SOFT_IIC_SDA_IO_SWITCH (0) // 是否需要 SDA 进行 I/O 切换 0-不需要 1-需要
|
||||
#define SOFT_IIC_SDA_IO_SWITCH (0) // 是否需要 SDA 进行 I/O 切换 0-不需要 1-需要
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
// 函数简介 软件 IIC 延时
|
||||
@@ -46,12 +46,12 @@
|
||||
// 使用示例 soft_iic_delay(1);
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
//static void soft_iic_delay (vuint32 delay)
|
||||
// static void soft_iic_delay (vuint32 delay)
|
||||
//{
|
||||
// volatile uint32 count = delay;
|
||||
// while(count --);
|
||||
//}
|
||||
#define soft_iic_delay(x) for(uint32 i = x; i--; )
|
||||
#define soft_iic_delay(x) for (uint32 i = x; i--;)
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
// 函数简介 软件 IIC START 信号
|
||||
@@ -60,16 +60,16 @@
|
||||
// 使用示例 soft_iic_start(soft_iic_obj);
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static void soft_iic_start (soft_iic_info_struct *soft_iic_obj)
|
||||
static void soft_iic_start(soft_iic_info_struct *soft_iic_obj)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 高电平
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 高电平
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平
|
||||
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 先拉低
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 先拉低
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 再拉低
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 再拉低
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
@@ -79,16 +79,16 @@ static void soft_iic_start (soft_iic_info_struct *soft_iic_obj)
|
||||
// 使用示例 soft_iic_stop(soft_iic_obj);
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static void soft_iic_stop (soft_iic_info_struct *soft_iic_obj)
|
||||
static void soft_iic_stop(soft_iic_info_struct *soft_iic_obj)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 先拉高
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 先拉高
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 再拉高
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 再拉高
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
}
|
||||
|
||||
@@ -100,25 +100,22 @@ static void soft_iic_stop (soft_iic_info_struct *soft_iic_obj)
|
||||
// 使用示例 soft_iic_send_ack(soft_iic_obj, 1);
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static void soft_iic_send_ack (soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
static void soft_iic_send_ack(soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
|
||||
if(ack)
|
||||
{
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 拉高
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 拉低
|
||||
if (ack) {
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 拉高
|
||||
} else {
|
||||
gpio_low(soft_iic_obj->sda_pin); // SDA 拉低
|
||||
}
|
||||
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 拉高
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 拉高
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
@@ -128,25 +125,24 @@ static void soft_iic_send_ack (soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
// 使用示例 soft_iic_wait_ack(soft_iic_obj);
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static uint8 soft_iic_wait_ack (soft_iic_info_struct *soft_iic_obj)
|
||||
static uint8 soft_iic_wait_ack(soft_iic_info_struct *soft_iic_obj)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 temp = 0;
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平 释放 SDA
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平 释放 SDA
|
||||
#if SOFT_IIC_SDA_IO_SWITCH
|
||||
gpio_set_dir(soft_iic_obj->sda_pin, GPI, GPI_FLOATING_IN);
|
||||
#endif
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 高电平
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 高电平
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
|
||||
if(gpio_get_level((gpio_pin_enum)soft_iic_obj->sda_pin))
|
||||
{
|
||||
if (gpio_get_level((gpio_pin_enum)soft_iic_obj->sda_pin)) {
|
||||
temp = 1;
|
||||
}
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
#if SOFT_IIC_SDA_IO_SWITCH
|
||||
gpio_set_dir(soft_iic_obj->sda_pin, GPO, GPO_OPEN_DTAIN);
|
||||
#endif
|
||||
@@ -162,22 +158,21 @@ static uint8 soft_iic_wait_ack (soft_iic_info_struct *soft_iic_obj)
|
||||
// 返回参数 uint8 ACK 状态
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static uint8 soft_iic_send_data (soft_iic_info_struct *soft_iic_obj, const uint8 data)
|
||||
static uint8 soft_iic_send_data(soft_iic_info_struct *soft_iic_obj, const uint8 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 temp = 0x80;
|
||||
while(temp)
|
||||
{
|
||||
// gpio_set_level(soft_iic_obj->sda_pin, data & temp);
|
||||
while (temp) {
|
||||
// gpio_set_level(soft_iic_obj->sda_pin, data & temp);
|
||||
((data & temp) ? (gpio_high(soft_iic_obj->sda_pin)) : (gpio_low(soft_iic_obj->sda_pin)));
|
||||
temp >>= 1;
|
||||
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
}
|
||||
return ((soft_iic_wait_ack(soft_iic_obj) == 1) ? 0 : 1 );
|
||||
return ((soft_iic_wait_ack(soft_iic_obj) == 1) ? 0 : 1);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
@@ -187,27 +182,26 @@ static uint8 soft_iic_send_data (soft_iic_info_struct *soft_iic_obj, const uint8
|
||||
// 返回参数 uint8 数据
|
||||
// 备注信息 内部调用
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
static uint8 soft_iic_read_data (soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
static uint8 soft_iic_read_data(soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 data = 0x00;
|
||||
uint8 temp = 8;
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平 释放 SDA
|
||||
gpio_high(soft_iic_obj->sda_pin); // SDA 高电平 释放 SDA
|
||||
#if SOFT_IIC_SDA_IO_SWITCH
|
||||
gpio_set_dir(soft_iic_obj->sda_pin, GPI, GPI_FLOATING_IN);
|
||||
#endif
|
||||
|
||||
while(temp --)
|
||||
{
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
while (temp--) {
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 拉低
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
gpio_high(soft_iic_obj->scl_pin); // SCL 拉高
|
||||
soft_iic_delay(soft_iic_obj->delay);
|
||||
data = ((data << 1) | gpio_get_level((gpio_pin_enum)soft_iic_obj->sda_pin));
|
||||
}
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
gpio_low(soft_iic_obj->scl_pin); // SCL 低电平
|
||||
#if SOFT_IIC_SDA_IO_SWITCH
|
||||
gpio_set_dir(soft_iic_obj->sda_pin, GPO, GPO_OPEN_DTAIN);
|
||||
#endif
|
||||
@@ -220,11 +214,11 @@ static uint8 soft_iic_read_data (soft_iic_info_struct *soft_iic_obj, uint8 ack)
|
||||
// 函数简介 软件 IIC 接口写 8bit 数据
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 data 要写入的数据
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_8bit_register(soft_iic_obj, 0x01);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_8bit (soft_iic_info_struct *soft_iic_obj, const uint8 data)
|
||||
void soft_iic_write_8bit(soft_iic_info_struct *soft_iic_obj, const uint8 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
@@ -238,19 +232,18 @@ void soft_iic_write_8bit (soft_iic_info_struct *soft_iic_obj, const uint8 data)
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 *data 数据存放缓冲区
|
||||
// 参数说明 len 缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_8bit_array(soft_iic_obj, data, 6);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_8bit_array (soft_iic_info_struct *soft_iic_obj, const uint8 *data, uint32 len)
|
||||
void soft_iic_write_8bit_array(soft_iic_info_struct *soft_iic_obj, const uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
while(len --)
|
||||
{
|
||||
soft_iic_send_data(soft_iic_obj, *data ++);
|
||||
while (len--) {
|
||||
soft_iic_send_data(soft_iic_obj, *data++);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -259,11 +252,11 @@ void soft_iic_write_8bit_array (soft_iic_info_struct *soft_iic_obj, const uint8
|
||||
// 函数简介 软件 IIC 接口器写 16bit 数据
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 data 要写入的数据
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_16bit(soft_iic_obj, 0x0101);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_16bit (soft_iic_info_struct *soft_iic_obj, const uint16 data)
|
||||
void soft_iic_write_16bit(soft_iic_info_struct *soft_iic_obj, const uint16 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
@@ -278,20 +271,19 @@ void soft_iic_write_16bit (soft_iic_info_struct *soft_iic_obj, const uint16 data
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 *data 数据存放缓冲区
|
||||
// 参数说明 len 缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_16bit_array(soft_iic_obj, data, 6);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_16bit_array (soft_iic_info_struct *soft_iic_obj, const uint16 *data, uint32 len)
|
||||
void soft_iic_write_16bit_array(soft_iic_info_struct *soft_iic_obj, const uint16 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
while(len --)
|
||||
{
|
||||
while (len--) {
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)((*data & 0xFF00) >> 8));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*data ++ & 0x00FF));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*data++ & 0x00FF));
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -301,11 +293,11 @@ void soft_iic_write_16bit_array (soft_iic_info_struct *soft_iic_obj, const uint1
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 data 要写入的数据
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_8bit_register(soft_iic_obj, 0x01, 0x01);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_8bit_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 data)
|
||||
void soft_iic_write_8bit_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
@@ -321,20 +313,19 @@ void soft_iic_write_8bit_register (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 *data 数据存放缓冲区
|
||||
// 参数说明 len 缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_8bit_registers(soft_iic_obj, 0x01, data, 6);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 *data, uint32 len)
|
||||
void soft_iic_write_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
soft_iic_send_data(soft_iic_obj, register_name);
|
||||
while(len --)
|
||||
{
|
||||
soft_iic_send_data(soft_iic_obj, *data ++);
|
||||
while (len--) {
|
||||
soft_iic_send_data(soft_iic_obj, *data++);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -344,11 +335,11 @@ void soft_iic_write_8bit_registers (soft_iic_info_struct *soft_iic_obj, const ui
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 data 要写入的数据
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_16bit_register(soft_iic_obj, 0x0101, 0x0101);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_16bit_register (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 data)
|
||||
void soft_iic_write_16bit_register(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
@@ -366,11 +357,11 @@ void soft_iic_write_16bit_register (soft_iic_info_struct *soft_iic_obj, const ui
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 *data 数据存放缓冲区
|
||||
// 参数说明 len 缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_write_16bit_registers(soft_iic_obj, 0x0101, data, 6);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_write_16bit_registers (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 *data, uint32 len)
|
||||
void soft_iic_write_16bit_registers(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
@@ -378,10 +369,9 @@ void soft_iic_write_16bit_registers (soft_iic_info_struct *soft_iic_obj, const u
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)((register_name & 0xFF00) >> 8));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(register_name & 0x00FF));
|
||||
while(len--)
|
||||
{
|
||||
while (len--) {
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)((*data & 0xFF00) >> 8));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*data ++ & 0x00FF));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*data++ & 0x00FF));
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -391,9 +381,9 @@ void soft_iic_write_16bit_registers (soft_iic_info_struct *soft_iic_obj, const u
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 返回参数 uint8 返回读取的 8bit 数据
|
||||
// 使用示例 soft_iic_read_8bit(soft_iic_obj);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
uint8 soft_iic_read_8bit (soft_iic_info_struct *soft_iic_obj)
|
||||
uint8 soft_iic_read_8bit(soft_iic_info_struct *soft_iic_obj)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 temp = 0;
|
||||
@@ -410,19 +400,18 @@ uint8 soft_iic_read_8bit (soft_iic_info_struct *soft_iic_obj)
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 *data 要读取的数据的缓冲区指针
|
||||
// 参数说明 len 要读取的数据长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_read_8bit_array(soft_iic_obj, data, 8);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_read_8bit_array (soft_iic_info_struct *soft_iic_obj, uint8 *data, uint32 len)
|
||||
void soft_iic_read_8bit_array(soft_iic_info_struct *soft_iic_obj, uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(len --)
|
||||
{
|
||||
*data ++ = soft_iic_read_data(soft_iic_obj, len == 0);
|
||||
while (len--) {
|
||||
*data++ = soft_iic_read_data(soft_iic_obj, len == 0);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -433,16 +422,16 @@ void soft_iic_read_8bit_array (soft_iic_info_struct *soft_iic_obj, uint8 *data,
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 返回参数 uint16 返回读取的 16bit 数据
|
||||
// 使用示例 soft_iic_read_16bit(soft_iic_obj);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
uint16 soft_iic_read_16bit (soft_iic_info_struct *soft_iic_obj)
|
||||
uint16 soft_iic_read_16bit(soft_iic_info_struct *soft_iic_obj)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint16 temp = 0;
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
temp = soft_iic_read_data(soft_iic_obj, 0);
|
||||
temp = ((temp << 8)| soft_iic_read_data(soft_iic_obj, 1));
|
||||
temp = ((temp << 8) | soft_iic_read_data(soft_iic_obj, 1));
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
return temp;
|
||||
}
|
||||
@@ -452,21 +441,20 @@ uint16 soft_iic_read_16bit (soft_iic_info_struct *soft_iic_obj)
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 *data 要读取的数据的缓冲区指针
|
||||
// 参数说明 len 要读取的数据长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_read_16bit_array(soft_iic_obj, data, 8);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_read_16bit_array (soft_iic_info_struct *soft_iic_obj, uint16 *data, uint32 len)
|
||||
void soft_iic_read_16bit_array(soft_iic_info_struct *soft_iic_obj, uint16 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(len --)
|
||||
{
|
||||
while (len--) {
|
||||
*data = soft_iic_read_data(soft_iic_obj, 0);
|
||||
*data = ((*data << 8)| soft_iic_read_data(soft_iic_obj, len == 0));
|
||||
data ++;
|
||||
*data = ((*data << 8) | soft_iic_read_data(soft_iic_obj, len == 0));
|
||||
data++;
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -477,9 +465,9 @@ void soft_iic_read_16bit_array (soft_iic_info_struct *soft_iic_obj, uint16 *data
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 返回参数 uint8 返回读取的 8bit 数据
|
||||
// 使用示例 soft_iic_read_8bit_register(soft_iic_obj, 0x01);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
uint8 soft_iic_read_8bit_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name)
|
||||
uint8 soft_iic_read_8bit_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 temp = 0;
|
||||
@@ -499,11 +487,11 @@ uint8 soft_iic_read_8bit_register (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 *data 要读取的数据的缓冲区指针
|
||||
// 参数说明 len 要读取的数据长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_read_8bit_registers(soft_iic_obj, 0x01, data, 8);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_read_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 *data, uint32 len)
|
||||
void soft_iic_read_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
@@ -512,9 +500,8 @@ void soft_iic_read_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
soft_iic_send_data(soft_iic_obj, register_name);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(len --)
|
||||
{
|
||||
*data ++ = soft_iic_read_data(soft_iic_obj, len == 0);
|
||||
while (len--) {
|
||||
*data++ = soft_iic_read_data(soft_iic_obj, len == 0);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -525,9 +512,9 @@ void soft_iic_read_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 返回参数 uint16 返回读取的 16bit 数据
|
||||
// 使用示例 soft_iic_read_16bit_register(soft_iic_obj, 0x0101);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
uint16 soft_iic_read_16bit_register (soft_iic_info_struct *soft_iic_obj, const uint16 register_name)
|
||||
uint16 soft_iic_read_16bit_register(soft_iic_info_struct *soft_iic_obj, const uint16 register_name)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint16 temp = 0;
|
||||
@@ -538,7 +525,7 @@ uint16 soft_iic_read_16bit_register (soft_iic_info_struct *soft_iic_obj, const u
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
temp = soft_iic_read_data(soft_iic_obj, 0);
|
||||
temp = ((temp << 8)| soft_iic_read_data(soft_iic_obj, 1));
|
||||
temp = ((temp << 8) | soft_iic_read_data(soft_iic_obj, 1));
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
return temp;
|
||||
}
|
||||
@@ -549,11 +536,11 @@ uint16 soft_iic_read_16bit_register (soft_iic_info_struct *soft_iic_obj, const u
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 *data 要读取的数据的缓冲区指针
|
||||
// 参数说明 len 要读取的数据长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_read_16bit_registers(soft_iic_obj, 0x0101, data, 8);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_read_16bit_registers (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, uint16 *data, uint32 len)
|
||||
void soft_iic_read_16bit_registers(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, uint16 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
@@ -563,11 +550,10 @@ void soft_iic_read_16bit_registers (soft_iic_info_struct *soft_iic_obj, const ui
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(register_name & 0x00FF));
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(len --)
|
||||
{
|
||||
while (len--) {
|
||||
*data = soft_iic_read_data(soft_iic_obj, 0);
|
||||
*data = ((*data << 8)| soft_iic_read_data(soft_iic_obj, len == 0));
|
||||
data ++;
|
||||
*data = ((*data << 8) | soft_iic_read_data(soft_iic_obj, len == 0));
|
||||
data++;
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -579,29 +565,26 @@ void soft_iic_read_16bit_registers (soft_iic_info_struct *soft_iic_obj, const ui
|
||||
// 参数说明 write_len 发送缓冲区长度
|
||||
// 参数说明 *read_data 读取数据存放缓冲区
|
||||
// 参数说明 read_len 读取缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 iic_transfer_8bit_array(IIC_1, addr, data, 64, data, 64);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_transfer_8bit_array (soft_iic_info_struct *soft_iic_obj, const uint8 *write_data, uint32 write_len, uint8 *read_data, uint32 read_len)
|
||||
void soft_iic_transfer_8bit_array(soft_iic_info_struct *soft_iic_obj, const uint8 *write_data, uint32 write_len, uint8 *read_data, uint32 read_len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(write_data != NULL);
|
||||
zf_assert(read_data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
while(write_len --)
|
||||
{
|
||||
soft_iic_send_data(soft_iic_obj, *write_data ++);
|
||||
while (write_len--) {
|
||||
soft_iic_send_data(soft_iic_obj, *write_data++);
|
||||
}
|
||||
|
||||
if(read_len)
|
||||
{
|
||||
if (read_len) {
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(read_len --)
|
||||
{
|
||||
*read_data ++ = soft_iic_read_data(soft_iic_obj, read_len == 0);
|
||||
while (read_len--) {
|
||||
*read_data++ = soft_iic_read_data(soft_iic_obj, read_len == 0);
|
||||
}
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
@@ -614,31 +597,28 @@ void soft_iic_transfer_8bit_array (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 write_len 发送缓冲区长度
|
||||
// 参数说明 *read_data 读取数据存放缓冲区
|
||||
// 参数说明 read_len 读取缓冲区长度
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 iic_transfer_16bit_array(IIC_1, addr, data, 64, data, 64);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_transfer_16bit_array (soft_iic_info_struct *soft_iic_obj, const uint16 *write_data, uint32 write_len, uint16 *read_data, uint32 read_len)
|
||||
void soft_iic_transfer_16bit_array(soft_iic_info_struct *soft_iic_obj, const uint16 *write_data, uint32 write_len, uint16 *read_data, uint32 read_len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(write_data != NULL);
|
||||
zf_assert(read_data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
while(write_len--)
|
||||
{
|
||||
while (write_len--) {
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)((*write_data & 0xFF00) >> 8));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*write_data ++ & 0x00FF));
|
||||
soft_iic_send_data(soft_iic_obj, (uint8)(*write_data++ & 0x00FF));
|
||||
}
|
||||
if(read_len)
|
||||
{
|
||||
if (read_len) {
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while(read_len --)
|
||||
{
|
||||
while (read_len--) {
|
||||
*read_data = soft_iic_read_data(soft_iic_obj, 0);
|
||||
*read_data = ((*read_data << 8)| soft_iic_read_data(soft_iic_obj, read_len == 0));
|
||||
read_data ++;
|
||||
*read_data = ((*read_data << 8) | soft_iic_read_data(soft_iic_obj, read_len == 0));
|
||||
read_data++;
|
||||
}
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
@@ -649,11 +629,11 @@ void soft_iic_transfer_16bit_array (soft_iic_info_struct *soft_iic_obj, const ui
|
||||
// 参数说明 *soft_iic_obj 软件 IIC 指定信息 可以参照 zf_driver_soft_iic.h 里的格式看看
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 参数说明 data 要写入的数据
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_sccb_write_register(soft_iic_obj, 0x01, 0x01);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_sccb_write_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 data)
|
||||
void soft_iic_sccb_write_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 data)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
@@ -669,9 +649,9 @@ void soft_iic_sccb_write_register (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 register_name 传感器的寄存器地址
|
||||
// 返回参数 uint8 返回读取的 8bit 数据
|
||||
// 使用示例 soft_iic_sccb_read_register(soft_iic_obj, 0x01);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
uint8 soft_iic_sccb_read_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name)
|
||||
uint8 soft_iic_sccb_read_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
uint8 temp = 0;
|
||||
@@ -694,18 +674,46 @@ uint8 soft_iic_sccb_read_register (soft_iic_info_struct *soft_iic_obj, const uin
|
||||
// 参数说明 delay 软件 IIC 延时 就是时钟高电平时间 越短 IIC 速率越高
|
||||
// 参数说明 scl_pin 软件 IIC 时钟引脚 参照 zf_driver_gpio.h 内 gpio_pin_enum 枚举体定义
|
||||
// 参数说明 sda_pin 软件 IIC 数据引脚 参照 zf_driver_gpio.h 内 gpio_pin_enum 枚举体定义
|
||||
// 返回参数 void
|
||||
// 返回参数 void
|
||||
// 使用示例 soft_iic_init(&soft_iic_obj, addr, 100, B6, B7);
|
||||
// 备注信息
|
||||
// 备注信息
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void soft_iic_init (soft_iic_info_struct *soft_iic_obj, uint8 addr, uint32 delay, gpio_pin_enum scl_pin, gpio_pin_enum sda_pin)
|
||||
void soft_iic_init(soft_iic_info_struct *soft_iic_obj, uint8 addr, uint32 delay, gpio_pin_enum scl_pin, gpio_pin_enum sda_pin)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(scl_pin != sda_pin); // 醒醒! scl_pin 与 sda_pin 怎么能填同一个引脚?
|
||||
zf_assert(scl_pin != sda_pin); // 醒醒! scl_pin 与 sda_pin 怎么能填同一个引脚?
|
||||
soft_iic_obj->scl_pin = scl_pin;
|
||||
soft_iic_obj->sda_pin = sda_pin;
|
||||
soft_iic_obj->addr = addr;
|
||||
soft_iic_obj->delay = delay;
|
||||
gpio_init(scl_pin, GPO, GPIO_HIGH, GPO_PUSH_PULL); // 提取对应IO索引 AF功能编码
|
||||
gpio_init(sda_pin, GPO, GPIO_HIGH, GPO_OPEN_DTAIN); // 提取对应IO索引 AF功能编码
|
||||
soft_iic_obj->addr = addr;
|
||||
soft_iic_obj->delay = delay;
|
||||
gpio_init(scl_pin, GPO, GPIO_HIGH, GPO_PUSH_PULL); // 提取对应IO索引 AF功能编码
|
||||
gpio_init(sda_pin, GPO, GPIO_HIGH, GPO_OPEN_DTAIN); // 提取对应IO索引 AF功能编码
|
||||
}
|
||||
void eep_soft_iic_read_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name_h, const uint8 register_name_l, uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
soft_iic_send_data(soft_iic_obj, register_name_h);
|
||||
soft_iic_send_data(soft_iic_obj, register_name_l);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1 | 0x01);
|
||||
while (len--) {
|
||||
*data++ = soft_iic_read_data(soft_iic_obj, len == 0);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
void eep_soft_iic_write_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name_h, const uint8 register_name_l, const uint8 *data, uint32 len)
|
||||
{
|
||||
zf_assert(soft_iic_obj != NULL);
|
||||
zf_assert(data != NULL);
|
||||
soft_iic_start(soft_iic_obj);
|
||||
soft_iic_send_data(soft_iic_obj, soft_iic_obj->addr << 1);
|
||||
soft_iic_send_data(soft_iic_obj, register_name_h);
|
||||
soft_iic_send_data(soft_iic_obj, register_name_l);
|
||||
while (len--) {
|
||||
soft_iic_send_data(soft_iic_obj, *data++);
|
||||
}
|
||||
soft_iic_stop(soft_iic_obj);
|
||||
}
|
||||
@@ -1,83 +1,84 @@
|
||||
/*********************************************************************************************************************
|
||||
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
||||
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
||||
*
|
||||
* 本文件是CH32V307VCT6 开源库的一部分
|
||||
*
|
||||
* CH32V307VCT6 开源库 是免费软件
|
||||
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU通用公共许可证)的条款
|
||||
* 即 GPL 的第3版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
||||
*
|
||||
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
||||
* 甚至没有隐含的适销性或适合特定用途的保证
|
||||
* 更多细节请参见 GPL
|
||||
*
|
||||
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
||||
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
||||
*
|
||||
* 额外注明:
|
||||
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
||||
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
||||
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
||||
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
||||
*
|
||||
* 文件名称 zf_driver_soft_iic
|
||||
* 公司名称 成都逐飞科技有限公司
|
||||
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
|
||||
* 开发环境 MounRiver Studio V1.8.1
|
||||
* 适用平台 CH32V307VCT6
|
||||
* 店铺链接 https://seekfree.taobao.com/
|
||||
*
|
||||
* 修改记录
|
||||
* 日期 作者 备注
|
||||
* 2022-09-15 大W first version
|
||||
********************************************************************************************************************/
|
||||
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
||||
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
||||
*
|
||||
* 本文件是CH32V307VCT6 开源库的一部分
|
||||
*
|
||||
* CH32V307VCT6 开源库 是免费软件
|
||||
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU通用公共许可证)的条款
|
||||
* 即 GPL 的第3版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
||||
*
|
||||
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
||||
* 甚至没有隐含的适销性或适合特定用途的保证
|
||||
* 更多细节请参见 GPL
|
||||
*
|
||||
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
||||
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
||||
*
|
||||
* 额外注明:
|
||||
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
||||
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
||||
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
||||
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
||||
*
|
||||
* 文件名称 zf_driver_soft_iic
|
||||
* 公司名称 成都逐飞科技有限公司
|
||||
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
|
||||
* 开发环境 MounRiver Studio V1.8.1
|
||||
* 适用平台 CH32V307VCT6
|
||||
* 店铺链接 https://seekfree.taobao.com/
|
||||
*
|
||||
* 修改记录
|
||||
* 日期 作者 备注
|
||||
* 2022-09-15 大W first version
|
||||
********************************************************************************************************************/
|
||||
|
||||
#ifndef _zf_driver_soft_iic_h_
|
||||
#define _zf_driver_soft_iic_h_
|
||||
|
||||
|
||||
#include "zf_driver_gpio.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gpio_pin_enum scl_pin; // 用于记录对应的引脚编号
|
||||
gpio_pin_enum sda_pin; // 用于记录对应的引脚编号
|
||||
uint8 addr; // 器件地址 七位地址模式
|
||||
uint32 delay; // 模拟 IIC 软延时时长
|
||||
}soft_iic_info_struct;
|
||||
gpio_pin_enum scl_pin; // 用于记录对应的引脚编号
|
||||
gpio_pin_enum sda_pin; // 用于记录对应的引脚编号
|
||||
uint8 addr; // 器件地址 七位地址模式
|
||||
uint32 delay; // 模拟 IIC 软延时时长
|
||||
} soft_iic_info_struct;
|
||||
|
||||
void soft_iic_write_8bit (soft_iic_info_struct *soft_iic_obj, const uint8 data);
|
||||
void soft_iic_write_8bit_array (soft_iic_info_struct *soft_iic_obj, const uint8 *data, uint32 len);
|
||||
void soft_iic_write_8bit(soft_iic_info_struct *soft_iic_obj, const uint8 data);
|
||||
void soft_iic_write_8bit_array(soft_iic_info_struct *soft_iic_obj, const uint8 *data, uint32 len);
|
||||
|
||||
void soft_iic_write_16bit (soft_iic_info_struct *soft_iic_obj, const uint16 data);
|
||||
void soft_iic_write_16bit_array (soft_iic_info_struct *soft_iic_obj, const uint16 *data, uint32 len);
|
||||
void soft_iic_write_16bit(soft_iic_info_struct *soft_iic_obj, const uint16 data);
|
||||
void soft_iic_write_16bit_array(soft_iic_info_struct *soft_iic_obj, const uint16 *data, uint32 len);
|
||||
|
||||
void soft_iic_write_8bit_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 data);
|
||||
void soft_iic_write_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 *data, uint32 len);
|
||||
void soft_iic_write_8bit_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 data);
|
||||
void soft_iic_write_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, const uint8 *data, uint32 len);
|
||||
|
||||
void soft_iic_write_16bit_register (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 data);
|
||||
void soft_iic_write_16bit_registers (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 *data, uint32 len);
|
||||
void soft_iic_write_16bit_register(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 data);
|
||||
void soft_iic_write_16bit_registers(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, const uint16 *data, uint32 len);
|
||||
|
||||
uint8 soft_iic_read_8bit (soft_iic_info_struct *soft_iic_obj);
|
||||
void soft_iic_read_8bit_array (soft_iic_info_struct *soft_iic_obj, uint8 *data, uint32 len);
|
||||
uint8 soft_iic_read_8bit(soft_iic_info_struct *soft_iic_obj);
|
||||
void soft_iic_read_8bit_array(soft_iic_info_struct *soft_iic_obj, uint8 *data, uint32 len);
|
||||
|
||||
uint16 soft_iic_read_16bit (soft_iic_info_struct *soft_iic_obj);
|
||||
void soft_iic_read_16bit_array (soft_iic_info_struct *soft_iic_obj, uint16 *data, uint32 len);
|
||||
uint16 soft_iic_read_16bit(soft_iic_info_struct *soft_iic_obj);
|
||||
void soft_iic_read_16bit_array(soft_iic_info_struct *soft_iic_obj, uint16 *data, uint32 len);
|
||||
|
||||
uint8 soft_iic_read_8bit_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name);
|
||||
void soft_iic_read_8bit_registers (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 *data, uint32 len);
|
||||
uint8 soft_iic_read_8bit_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name);
|
||||
void soft_iic_read_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 *data, uint32 len);
|
||||
|
||||
uint16 soft_iic_read_16bit_register (soft_iic_info_struct *soft_iic_obj, const uint16 register_name);
|
||||
void soft_iic_read_16bit_registers (soft_iic_info_struct *soft_iic_obj, const uint16 register_name, uint16 *data, uint32 len);
|
||||
uint16 soft_iic_read_16bit_register(soft_iic_info_struct *soft_iic_obj, const uint16 register_name);
|
||||
void soft_iic_read_16bit_registers(soft_iic_info_struct *soft_iic_obj, const uint16 register_name, uint16 *data, uint32 len);
|
||||
|
||||
void soft_iic_transfer_8bit_array (soft_iic_info_struct *soft_iic_obj, const uint8 *write_data, uint32 write_len, uint8 *read_data, uint32 read_len);
|
||||
void soft_iic_transfer_16bit_array (soft_iic_info_struct *soft_iic_obj, const uint16 *write_data, uint32 write_len, uint16 *read_data, uint32 read_len);
|
||||
void soft_iic_transfer_8bit_array(soft_iic_info_struct *soft_iic_obj, const uint8 *write_data, uint32 write_len, uint8 *read_data, uint32 read_len);
|
||||
void soft_iic_transfer_16bit_array(soft_iic_info_struct *soft_iic_obj, const uint16 *write_data, uint32 write_len, uint16 *read_data, uint32 read_len);
|
||||
|
||||
void soft_iic_sccb_write_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 data);
|
||||
uint8 soft_iic_sccb_read_register (soft_iic_info_struct *soft_iic_obj, const uint8 register_name);
|
||||
void soft_iic_sccb_write_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name, uint8 data);
|
||||
uint8 soft_iic_sccb_read_register(soft_iic_info_struct *soft_iic_obj, const uint8 register_name);
|
||||
|
||||
void soft_iic_init (soft_iic_info_struct *soft_iic_obj, uint8 addr, uint32 delay, gpio_pin_enum scl_pin, gpio_pin_enum sda_pin);
|
||||
void soft_iic_init(soft_iic_info_struct *soft_iic_obj, uint8 addr, uint32 delay, gpio_pin_enum scl_pin, gpio_pin_enum sda_pin);
|
||||
|
||||
void eep_soft_iic_write_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name_h, const uint8 register_name_l, const uint8 *data, uint32 len);
|
||||
void eep_soft_iic_read_8bit_registers(soft_iic_info_struct *soft_iic_obj, const uint8 register_name_h, const uint8 register_name_l, uint8 *data, uint32 len);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user