first commit

This commit is contained in:
2023-12-11 21:45:06 +08:00
commit eaa7cc0eea
180 changed files with 60911 additions and 0 deletions

View File

@@ -0,0 +1,167 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_clock
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#include "ch32v30x.h"
#include "zf_common_function.h"
#include "zf_common_interrupt.h"
#include "zf_common_clock.h"
uint32 system_clock = SYSTEM_CLOCK_144M; // 系统时钟信息
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 核心时钟恢复初始设置 内部调用
// 参数说明 void
// 返回参数 void
//-------------------------------------------------------------------------------------------------------------------
void clock_reset(void)
{
RCC->CTLR |= (uint32) 0x00000001; //使能HSI振荡器
RCC->CFGR0 &= (uint32) 0xF8FF0000;
RCC->CTLR &= (uint32) 0xFEF6FFFF;
RCC->CTLR &= (uint32) 0xFFFBFFFF;
RCC->CFGR0 &= (uint32) 0xFF80FFFF;
RCC->INTR = (uint32) 0x009F0000; // 禁用所有中断并清除挂起位
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 核心时钟设置
// 参数说明 clock 时钟频率 推荐使用 zf_common_clock.h 中 system_clock_enum 定义的选项
// 返回参数 void
//-------------------------------------------------------------------------------------------------------------------
void clock_set_freq(uint32 clock)
{
clock_reset();
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t) RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do {
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while ((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t) 0x01;
}
else
{
HSEStatus = (uint32_t) 0x00;
}
if (HSEStatus == (uint32_t) 0x01)
{
// /* Enable Prefetch Buffer */
// FLASH->ACTLR |= FLASH_ACTLR_PRFTBE; ((uint8_t)0x10)
//
// /* Flash 2 wait state */
// FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY); ((uint8_t)0x03)
// FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2; ((uint8_t)0x02)
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t) RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t) RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t) RCC_PPRE1_DIV1;
/* PLL configuration: PLLCLK = HSE * ? = ? MHz */
RCC->CFGR0 &= (uint32) ((uint32) ~(RCC_PLLSRC | RCC_PLLXTPRE
| RCC_PLLMULL));
if (clock == SYSTEM_CLOCK_144M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL18_EXTEN);
else if (clock == SYSTEM_CLOCK_120M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL15_EXTEN);
else if (clock == SYSTEM_CLOCK_96M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL12_EXTEN);
else if (clock == SYSTEM_CLOCK_72M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL9_EXTEN);
else if (clock == SYSTEM_CLOCK_48M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL6_EXTEN);
else if (clock == SYSTEM_CLOCK_24M)
RCC->CFGR0 |= (uint32) (RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE
| RCC_PLLMULL3_EXTEN);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t) ((uint32_t) ~(RCC_SW));
RCC->CFGR0 |= (uint32_t) RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
while(1);
// 外部晶振不稳定或缺失 时钟设置失败
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 核心时钟初始化
// 参数说明 clock 时钟频率 推荐使用 zf_common_clock.h 中 system_clock_enum 定义的选项
// 返回参数 void
// 使用示例 clock_init(SYSTEM_CLOCK_144M); // 初始化核心时钟为 144MHz
//-------------------------------------------------------------------------------------------------------------------
void clock_init(uint32 clock)
{
system_clock = clock; // 记录核心时钟频率
clock_reset();
clock_set_freq(clock);
interrupt_init();
}

View File

@@ -0,0 +1,61 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_clock
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_clock_h_
#define _zf_common_clock_h_
#include "ch32v30x.h"
#include "zf_common_typedef.h"
#define BOARD_XTAL_FREQ 8000000 // 晶振频率 如果自己用的不是这个频率就修改这里 UM 定义范围为 4-24Mhz
//#define XTAL_STARTUP_TIMEOUT 0x0800 // 晶振就绪等待超时时长
typedef enum
{
SYSTEM_CLOCK_XTAL = BOARD_XTAL_FREQ, // 使用晶振频率作为时钟频率
SYSTEM_CLOCK_24M = 24000000, // 24Mhz
SYSTEM_CLOCK_48M = 48000000, // 48Mhz
SYSTEM_CLOCK_72M = 72000000, // 72Mhz
SYSTEM_CLOCK_96M = 96000000, // 96Mhz
SYSTEM_CLOCK_120M = 120000000, // 120Mhz
SYSTEM_CLOCK_144M = 144000000, // 144Mhz
}system_clock_enum;
extern uint32 system_clock; // 全局变量 系统时钟信息
void clock_reset(void);
void clock_init (uint32 clock); // 核心时钟初始化
void clock_set_freq(uint32 clock); // 设置系统频率
#endif

View File

@@ -0,0 +1,471 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_debug
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#include "zf_driver_uart.h"
#include "zf_common_interrupt.h"
#include "zf_common_fifo.h"
#include "zf_common_debug.h"
#if DEBUG_UART_USE_INTERRUPT // 如果启用 debug uart 接收中断
uint8 debug_uart_buffer[DEBUG_RING_BUFFER_LEN]; // 数据存放数组
uint8 debug_uart_data;
#endif
fifo_struct debug_uart_fifo;
static debug_output_struct debug_output_info;
static volatile uint8 zf_debug_init_flag = 0;
static volatile uint8 zf_debug_assert_enable = 1;
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 软延时函数 在 120MHz 下是一秒多的时间 各单片机需要根据各自时钟试验
// 参数说明 pass 判断是否触发断言
// 参数说明 *file 文件名
// 参数说明 line 目标行数
// 返回参数 void
//-------------------------------------------------------------------------------------------------------------------
static void debug_delay (void)
{
vuint32 loop_1 = 0, loop_2 = 0;
for(loop_1 = 0; loop_1 <= 0xFF; loop_1 ++)
for(loop_2 = 0; loop_2 <= 0xFFFF; loop_2 ++)
__NOP();
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 保护处理 主要是防止断言后出现信号维持而导致硬件失控
// 参数说明 void
// 返回参数 void
// 使用示例 debug_protective_handler();
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void debug_protective_handler (void)
{
// 暂未更新
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 串口输出接口 此部分不允许用户更改
// 参数说明 *str 需要输出的字符串
// 返回参数 void
// 使用示例 debug_uart_str_output("Log message");
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void debug_uart_str_output (const char *str)
{
uart_write_string(DEBUG_UART_INDEX, str);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 输出接口
// 参数说明 *type log 类型
// 参数说明 *file 文件名
// 参数说明 line 目标行数
// 参数说明 *str 信息
// 返回参数 void
// 使用示例 debug_output("Log message", file, line, str);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void debug_output (char *type, char *file, int line, char *str)
{
char *file_str;
vuint16 i = 0, j = 0;
vint16 len_origin = 0;
vint16 show_len = 0;
vint16 show_line_index = 0;
len_origin = strlen(file);
char output_buffer[256];
char file_path_buffer[64];
if(debug_output_info.type_index)
{
debug_output_info.output_screen_clear();
}
if(zf_debug_init_flag)
{
if(debug_output_info.type_index)
{
// 需要分行将文件的路径和行数输出
// <不输出完整路径 只输出一级目录 例如 src/main.c>
// 输出 line : xxxx
debug_output_info.output_screen(0, show_line_index ++, type);
file_str = file;
len_origin = strlen(file);
show_len = (debug_output_info.display_x_max / debug_output_info.font_x_size);
while(*file_str++ != '\0');
// 只取一级目录 如果文件放在盘符根目录 或者 MDK 的工程根目录 就会直接输出当前目录
for(j = 0; (j < 2) && (len_origin >= 0); len_origin --) // 查找两个 '/'
{
file_str --;
if((*file_str == '/') || (*file_str == 0x5C))
{
j ++;
}
}
// 文件路径保存到数组中
if(len_origin >= 0)
{
file_str ++;
sprintf(output_buffer, "file: %s", file_str);
}
else
{
if(0 == j)
{
sprintf(output_buffer, "file: mdk/%s", file_str);
}
else
{
sprintf(output_buffer, "file: %s", file_str);
}
}
// 屏幕显示路径
for(i = 0; i < ((strlen(output_buffer) / show_len) + 1); i ++)
{
for(j = 0; j < show_len; j ++)
{
if(strlen(output_buffer) < (j + i * show_len))
{
break;
}
file_path_buffer[j] = output_buffer[j + i * show_len];
}
file_path_buffer[j] = '\0'; // 末尾添加\0
debug_output_info.output_screen(0, debug_output_info.font_y_size * show_line_index ++, file_path_buffer);
}
// 屏幕显示行号
sprintf(output_buffer, "line: %d", line);
debug_output_info.output_screen(0, debug_output_info.font_y_size * show_line_index ++, output_buffer);
// 屏幕显示 Log 如果有的话
if(NULL != str)
{
for(i = 0; i < ((strlen(str) / show_len) + 1); i ++)
{
for(j = 0; j < show_len; j ++)
{
if(strlen(str) < (j + i * show_len))
{
break;
}
file_path_buffer[j] = str[j + i * show_len];
}
file_path_buffer[j] = '\0'; // 末尾添加\0
debug_output_info.output_screen(0, debug_output_info.font_y_size * show_line_index ++, file_path_buffer);
}
}
}
else
{
char output_buffer[256];
memset(output_buffer, 0, 256);
debug_output_info.output_uart(type);
if(NULL != str)
{
sprintf(output_buffer, "\r\nfile %s line %d: %s.\r\n", file, line, str);
}
else
{
sprintf(output_buffer, "\r\nfile %s line %d.\r\n", file, line);
}
debug_output_info.output_uart(output_buffer);
}
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 调试串口发送缓冲区
// 参数说明 *buff 读出数据存放的数组指针
// 参数说明 len 需要发送的长度
// 返回参数 uint32 剩余未发送的长度
// 使用示例
// 备注信息 本函数需要开启 DEBUG_UART_USE_INTERRUPT 宏定义才可使用
//-------------------------------------------------------------------------------------------------------------------
uint32 debug_send_buffer(const uint8 *buff, uint32 len)
{
uart_write_buffer(DEBUG_UART_INDEX, buff, len);
return 0;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 读取 debug 环形缓冲区数据
// 参数说明 *buff 读出数据存放的数组指针
// 参数说明 len 需要读取的长度
// 返回参数 uint32 读出数据的实际长度
// 使用示例
// 备注信息 本函数需要开启 DEBUG_UART_USE_INTERRUPT 宏定义才可使用
//-------------------------------------------------------------------------------------------------------------------
uint32 debug_read_ring_buffer (uint8 *buff, uint32 len)
{
fifo_read_buffer(&debug_uart_fifo, buff, &len, FIFO_READ_AND_CLEAN);
return len;
}
#if DEBUG_UART_USE_INTERRUPT // 条件编译 只有在启用串口中断才编译
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 串口中断处理函数 isr.c 中对应串口中断服务函数调用
// 参数说明 void
// 返回参数 void
// 使用示例 debug_interrupr_handler();
// 备注信息 本函数需要开启 DEBUG_UART_USE_INTERRUPT 宏定义才可使用
// 并且本函数默认放置在 UART1 的串口接收中断处理处
//-------------------------------------------------------------------------------------------------------------------
void debug_interrupr_handler (void)
{
if(zf_debug_init_flag)
{
uart_query_byte(DEBUG_UART_INDEX, &debug_uart_data); // 读取串口数据
fifo_write_buffer(&debug_uart_fifo, &debug_uart_data, 1); // 存入 FIFO
}
}
#endif
//------------------------------------------------------------------------- // printf 重定向 此部分不允许用户更改
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 printf重定向
// 参数说明 void
// 返回参数 void
// @since v1.0
// 备注信息 重定向printf到DEBUG串口上
//-------------------------------------------------------------------------------------------------------------------
#if (1 == PRINTF_ENABLE)
int _write(int fd, char *buf, int size)
{
int i;
for(i=0; i<size; i++)
{
while (USART_GetFlagStatus((USART_TypeDef*)uart_index[DEBUG_UART_INDEX], USART_FLAG_TC) == RESET);
USART_SendData((USART_TypeDef*)uart_index[DEBUG_UART_INDEX], *buf++);
}
return size;
}
#endif
//------------------------------------------------------------------------- // printf 重定向 此部分不允许用户更改
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 启用断言
// 参数说明 void
// 返回参数 void
// 使用示例 debug_assert_enable();
// 备注信息 断言默认开启 建议开启断言
//-------------------------------------------------------------------------------------------------------------------
void debug_assert_enable (void)
{
zf_debug_assert_enable = 1;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 禁用断言
// 参数说明 void
// 返回参数 void
// 使用示例 debug_assert_disable();
// 备注信息 断言默认开启 不建议禁用断言
//-------------------------------------------------------------------------------------------------------------------
void debug_assert_disable (void)
{
zf_debug_assert_enable = 0;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 断言处理函数 此部分不允许用户更改
// 参数说明 pass 判断是否触发断言
// 参数说明 *file 文件名
// 参数说明 line 目标行数
// 返回参数 void
// 使用示例 zf_assert(0);
// 备注信息 这个函数不是直接调用的 此部分不允许用户更改
// 使用 zf_commmon_debug.h 中的 zf_assert(x) 接口
//-------------------------------------------------------------------------------------------------------------------
void debug_assert_handler (uint8 pass, char *file, int line)
{
do
{
if(pass || !zf_debug_assert_enable)
{
break;
}
static uint8 assert_nest_index = 0;
if(0 != assert_nest_index)
{
while(1);
}
assert_nest_index ++;
interrupt_global_disable();
debug_protective_handler();
while(1)
{
// 如果代码跳转到这里停住了
// 一般你的函数参数传递出错了
// 或者你自己调用的 zf_assert(x) 接口处报错了
// 如果调用了 debug_init 初始化了 log 输出
// 就在对应串口输出去查看是哪个文件的哪一行报错
// 如果没有初始化 debug
// 那就看看这个 file 的字符串值和 line 的行数
// 那代表报错的文件路径名称和对应报错行数
// 再去调试看看是为什么参数出错
debug_output("Assert error", file, line, NULL);
debug_delay();
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 调试信息处理函数 此部分不允许用户更改
// 参数说明 bool 判断是否触发断言
// 参数说明 *str 要输出的调试信息
// 参数说明 *file 文件名
// 参数说明 line 目标行数
// 返回参数 void
// 使用示例 zf_log(0, "Log Message");
// 备注信息 这个函数不是直接调用的 此部分不允许用户更改
// 使用 zf_commmon_debug.h 中的 zf_log(x, str) 接口
//-------------------------------------------------------------------------------------------------------------------
void debug_log_handler (uint8 pass, char *str, char *file, int line)
{
do
{
if(pass)
{
break;
}
if(zf_debug_init_flag)
{
debug_output("Log message", file, line, str);
// printf("Log message from %s line %d :\"%s\".\r\n", file, line, str);
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 输出绑定信息初始化 此部分不允许用户更改
// 参数说明 *info debug 输出的信息结构体
// 返回参数 void
// Sample usage: debug_output_struct_init(info);
//-------------------------------------------------------------------------------------------------------------------
void debug_output_struct_init (debug_output_struct *info)
{
info->type_index = 0;
info->display_x_max = 0xFFFF;
info->display_y_max = 0xFFFF;
info->font_x_size = 0xFF;
info->font_y_size = 0xFF;
info->output_uart = NULL;
info->output_screen = NULL;
info->output_screen_clear = NULL;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 输出绑定初始化 此部分不允许用户更改
// 参数说明 *info debug 输出的信息结构体
// 返回参数 void
// 使用示例 debug_output_init(info);
// 备注信息 这个函数一般不由用户调用
//-------------------------------------------------------------------------------------------------------------------
void debug_output_init (debug_output_struct *info)
{
debug_output_info.type_index = info->type_index;
debug_output_info.display_x_max = info->display_x_max;
debug_output_info.display_y_max = info->display_y_max;
debug_output_info.font_x_size = info->font_x_size;
debug_output_info.font_y_size = info->font_y_size;
debug_output_info.output_uart = info->output_uart;
debug_output_info.output_screen = info->output_screen;
debug_output_info.output_screen_clear = info->output_screen_clear;
zf_debug_init_flag = 1;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 debug 串口初始化 此部分不允许用户更改
// 参数说明 void
// 返回参数 void
// 使用示例 debug_init();
// 备注信息 开源库示例默认调用 但默认禁用中断接收
//-------------------------------------------------------------------------------------------------------------------
void debug_init (void)
{
debug_output_struct info;
debug_output_struct_init(&info);
info.output_uart = debug_uart_str_output;
debug_output_init(&info);
uart_init(
DEBUG_UART_INDEX, // 在 zf_common_debug.h 中查看对应值
DEBUG_UART_BAUDRATE, // 在 zf_common_debug.h 中查看对应值
DEBUG_UART_TX_PIN, // 在 zf_common_debug.h 中查看对应值
DEBUG_UART_RX_PIN); // 在 zf_common_debug.h 中查看对应值
#if DEBUG_UART_USE_INTERRUPT // 条件编译 只有在启用串口中断才编译
fifo_init(&debug_uart_fifo, FIFO_DATA_8BIT, debug_uart_buffer, DEBUG_RING_BUFFER_LEN);
uart_rx_interrupt(DEBUG_UART_INDEX, 1); // 使能对应串口接收中断
#endif
}

View File

@@ -0,0 +1,106 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_debug
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_debug_h_
#define _zf_common_debug_h_
#include "zf_common_typedef.h"
#define PRINTF_ENABLE (1) // 使能printf
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
#define DEBUG_UART_INDEX (UART_3) // 指定 debug uart 所使用的的串口
#define DEBUG_UART_BAUDRATE (115200) // 指定 debug uart 所使用的的串口波特率
#define DEBUG_UART_TX_PIN (UART3_MAP0_TX_B10 ) // 指定 debug uart 所使用的的串口引脚
#define DEBUG_UART_RX_PIN (UART3_MAP0_RX_B11 ) // 指定 debug uart 所使用的的串口引脚
#define DEBUG_UART_USE_INTERRUPT (1) // 是否启用 debug uart 接收中断
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 断言
// 参数说明 x 判断是否触发断言 0-触发断言 1-不触发断言
// 返回参数 void
// 使用示例 zf_assert(0);
// 备注信息 一般用于参数判断 zf_assert(0) 就断言报错
// 默认情况下会在 Debug UART 输出
// 但如果使用开源库内屏幕接口初始化了屏幕 则会在屏幕上显示
//-------------------------------------------------------------------------------------------------------------------
#define zf_assert(x) (debug_assert_handler((x), __FILE__, __LINE__))
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 Log 信息输出
// 参数说明 x 判断是否触发输出 0-触发输出 1-不触发输出
// 参数说明 *str 需要输出的 Log 信息
// 返回参数 void
// 使用示例 zf_log(0, "Error");
// 备注信息 调试信息输出 用来做一些报错或者警告之类的输出
// 默认情况下会在 Debug UART 输出
// 但如果使用开源库内屏幕接口初始化了屏幕 则会在屏幕上显示
//-------------------------------------------------------------------------------------------------------------------
#define zf_log(x, str) (debug_log_handler((x), (str), __FILE__, __LINE__))
typedef struct
{
uint16 type_index;
uint16 display_x_max;
uint16 display_y_max;
uint8 font_x_size;
uint8 font_y_size;
void (*output_uart) (const char *str);
void (*output_screen) (uint16 x, uint16 y, const char *str);
void (*output_screen_clear) (void);
}debug_output_struct;
uint32 debug_send_buffer(const uint8 *buff, uint32 len);
#if DEBUG_UART_USE_INTERRUPT // 如果启用 debug uart 接收中断
#define DEBUG_RING_BUFFER_LEN (64) // 定义环形缓冲区大小 默认 64byte
void debug_interrupr_handler (void);
#endif
uint32 debug_read_ring_buffer(uint8 *buff, uint32 len);
void debug_assert_enable (void);
void debug_assert_disable (void);
void debug_assert_handler (uint8 pass, char *file, int line);
void debug_log_handler (uint8 pass, char *str, char *file, int line);
void debug_output_struct_init (debug_output_struct *info);
void debug_output_init (debug_output_struct *info);
void debug_init (void);
#endif

View File

@@ -0,0 +1,554 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_fifo
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 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_common_fifo.h"
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 FIFO 头指针位移
// 参数说明 *fifo FIFO 对象指针
// 参数说明 offset 偏移量
// 返回参数 void
// 使用示例 fifo_head_offset(fifo, 1);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void fifo_head_offset (fifo_struct *fifo, uint32 offset)
{
fifo->head += offset;
while(fifo->max <= fifo->head) // 如果范围超过则减缓冲区大小 直到小于最大缓冲区大小
{
fifo->head -= fifo->max;
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 FIFO 尾指针位移
// 参数说明 *fifo FIFO 对象指针
// 参数说明 offset 偏移量
// 返回参数 void
// 使用示例 fifo_end_offset(fifo, 1);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void fifo_end_offset (fifo_struct *fifo, uint32 offset)
{
fifo->end += offset;
while(fifo->max <= fifo->end) // 如果范围超过则减缓冲区大小 直到小于最大缓冲区大小
{
fifo->end -= fifo->max;
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 FIFO 重置缓冲器
// 参数说明 *fifo FIFO 对象指针
// 返回参数 void
// 使用示例 fifo_clear(fifo);
// 备注信息 清空当前 FIFO 对象的内存
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_clear (fifo_struct *fifo)
{
zf_assert(fifo != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
do
{
if(FIFO_CLEAR & fifo->execution)
{
return_state = FIFO_CLEAR_UNDO;
break;
}
fifo->execution |= FIFO_CLEAR;
fifo->head = 0;
fifo->end = 0;
fifo->size = fifo->max;
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memset(fifo->buffer, 0, fifo->max);
break;
case FIFO_DATA_16BIT:
memset(fifo->buffer, 0, fifo->max * 2);
break;
case FIFO_DATA_32BIT:
memset(fifo->buffer, 0, fifo->max * 4);
break;
}
// memset(fifo->buffer, 0, fifo->max);
fifo->execution &= ~FIFO_CLEAR;
}while(0);
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 FIFO 查询当前数据个数
// 参数说明 *fifo FIFO 对象指针
// 返回参数 uint32 已使用长度
// 使用示例 uint32 len = fifo_used(fifo);
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
uint32 fifo_used (fifo_struct *fifo)
{
zf_assert(fifo != NULL);
return (fifo->max - fifo->size);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 向 FIFO 中写入数据
// 参数说明 *fifo FIFO 对象指针
// 参数说明 dat 数据
// 返回参数 fifo_state_enum 操作状态
// 使用示例 zf_log(fifo_write_element(&fifo, data) == FIFO_SUCCESS, "fifo_write_byte error");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_write_element (fifo_struct *fifo, uint32 dat)
{
zf_assert(fifo != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
do
{
if(FIFO_WRITE & fifo->execution)
{
return_state = FIFO_WRITE_UNDO;
break;
}
fifo->execution |= FIFO_WRITE;
if(1 <= fifo->size) // 剩余空间足够装下本次数据
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
((uint8 *)fifo->buffer)[fifo->head] = dat;
break;
case FIFO_DATA_16BIT:
((uint16 *)fifo->buffer)[fifo->head] = dat;
break;
case FIFO_DATA_32BIT:
((uint32 *)fifo->buffer)[fifo->head] = dat;
break;
}
fifo_head_offset(fifo, 1); // 头指针偏移
fifo->size -= 1; // 缓冲区剩余长度减小
}
else
{
return_state = FIFO_SPACE_NO_ENOUGH;
}
fifo->execution &= ~FIFO_WRITE;
}while(0);
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 向 FIFO 中写入数据
// 参数说明 *fifo FIFO 对象指针
// 参数说明 *dat 数据来源缓冲区指针
// 参数说明 length 需要写入的数据长度
// 返回参数 fifo_state_enum 操作状态
// 使用示例 zf_log(fifo_write_buffer(&fifo, data, 32) == FIFO_SUCCESS, "fifo_write_buffer error");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_write_buffer (fifo_struct *fifo, void *dat, uint32 length)
{
zf_assert(fifo != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
uint32 temp_length = 0;
do
{
if(NULL == dat)
{
return_state = FIFO_BUFFER_NULL;
break;
}
if(FIFO_WRITE & fifo->execution)
{
return_state = FIFO_WRITE_UNDO;
break;
}
fifo->execution |= FIFO_WRITE;
if(length <= fifo->size) // 剩余空间足够装下本次数据
{
temp_length = fifo->max - fifo->head; // 计算头指针距离缓冲区尾还有多少空间
if(length > temp_length) // 距离缓冲区尾长度不足写入数据 环形缓冲区分段操作
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(
&(((uint8 *)fifo->buffer)[fifo->head]),
dat, temp_length); // 拷贝第一段数据
fifo_head_offset(fifo, temp_length); // 头指针偏移
memcpy(
&(((uint8 *)fifo->buffer)[fifo->head]),
&(((uint8 *)dat)[temp_length]),
length - temp_length); // 拷贝第二段数据
fifo_head_offset(fifo, length - temp_length); // 头指针偏移
break;
case FIFO_DATA_16BIT:
memcpy(
&(((uint16 *)fifo->buffer)[fifo->head]),
dat, temp_length * 2); // 拷贝第一段数据
fifo_head_offset(fifo, temp_length); // 头指针偏移
memcpy(
&(((uint16 *)fifo->buffer)[fifo->head]),
&(((uint16 *)dat)[temp_length]),
(length - temp_length) * 2); // 拷贝第二段数据
fifo_head_offset(fifo, length - temp_length); // 头指针偏移
break;
case FIFO_DATA_32BIT:
memcpy(
&(((uint32 *)fifo->buffer)[fifo->head]),
dat, temp_length * 4); // 拷贝第一段数据
fifo_head_offset(fifo, temp_length); // 头指针偏移
memcpy(
&(((uint32 *)fifo->buffer)[fifo->head]),
&(((uint32 *)dat)[temp_length]),
(length - temp_length) * 4); // 拷贝第二段数据
fifo_head_offset(fifo, length - temp_length); // 头指针偏移
break;
}
}
else
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(
&(((uint8 *)fifo->buffer)[fifo->head]),
dat, length); // 一次完整写入
fifo_head_offset(fifo, length); // 头指针偏移
break;
case FIFO_DATA_16BIT:
memcpy(
&(((uint16 *)fifo->buffer)[fifo->head]),
dat, length * 2); // 一次完整写入
fifo_head_offset(fifo, length); // 头指针偏移
break;
case FIFO_DATA_32BIT:
memcpy(
&(((uint32 *)fifo->buffer)[fifo->head]),
dat, length * 4); // 一次完整写入
fifo_head_offset(fifo, length); // 头指针偏移
break;
}
// memcpy(&fifo->buffer[fifo->head], dat, length); // 一次完整写入
// fifo_head_offset(fifo, length); // 头指针偏移
}
fifo->size -= length; // 缓冲区剩余长度减小
}
else
{
return_state = FIFO_SPACE_NO_ENOUGH;
}
fifo->execution &= ~FIFO_WRITE;
}while(0);
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 从 FIFO 读取数据
// 参数说明 *fifo FIFO 对象指针
// 参数说明 *dat 目标缓冲区指针
// 参数说明 flag 是否变更 FIFO 状态 可选择是否清空读取的数据
// 返回参数 fifo_state_enum 操作状态
// 使用示例 zf_log(fifo_read_element(&fifo, data, FIFO_READ_ONLY) == FIFO_SUCCESS, "fifo_read_byte error");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_read_element (fifo_struct *fifo, void *dat, fifo_operation_enum flag)
{
zf_assert(fifo != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
do
{
if(NULL == dat)
{
return_state = FIFO_BUFFER_NULL;
break;
}
fifo->execution |= FIFO_READ;
if(1 > fifo_used(fifo))
{
return_state = FIFO_DATA_NO_ENOUGH; // 标志数据不够
}
switch(fifo->type)
{
case FIFO_DATA_8BIT:
*((uint8 *)dat) = ((uint8 *)fifo->buffer)[fifo->end];
break;
case FIFO_DATA_16BIT:
*((uint16 *)dat) = ((uint16 *)fifo->buffer)[fifo->end];
break;
case FIFO_DATA_32BIT:
*((uint32 *)dat) = ((uint32 *)fifo->buffer)[fifo->end];
break;
}
if(flag == FIFO_READ_AND_CLEAN) // 如果选择读取并更改 FIFO 状态
{
if(FIFO_CLEAR & fifo->execution)
{
return_state = FIFO_CLEAR_UNDO;
break;
}
fifo->execution |= FIFO_CLEAR;
fifo_end_offset(fifo, 1); // 移动 FIFO 头指针
fifo->size += 1;
fifo->execution &= ~FIFO_CLEAR;
}
}while(0);
fifo->execution &= FIFO_READ;
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 从 FIFO 读取数据
// 参数说明 *fifo FIFO 对象指针
// 参数说明 *dat 目标缓冲区指针
// 参数说明 *length 读取的数据长度 如果没有这么多数据这里会被修改
// 参数说明 flag 是否变更 FIFO 状态 可选择是否清空读取的数据
// 返回参数 fifo_state_enum 操作状态
// 使用示例 zf_log(fifo_read_buffer(&fifo, data, &length, FIFO_READ_ONLY) == FIFO_SUCCESS, "fifo_read_buffer error");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_read_buffer (fifo_struct *fifo, void *dat, uint32 *length, fifo_operation_enum flag)
{
zf_assert(fifo != NULL);
zf_assert(length != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
uint32 temp_length;
uint32 fifo_data_length;
do
{
if(NULL == dat)
{
return_state = FIFO_BUFFER_NULL;
break;
}
fifo->execution |= FIFO_READ;
fifo_data_length = fifo_used(fifo);
if(*length > fifo_data_length)
{
*length = fifo_data_length; // 纠正读取的长度
return_state = FIFO_DATA_NO_ENOUGH; // 标志数据不够
}
temp_length = fifo->max - fifo->end; // 计算尾指针距离缓冲区尾还有多少空间
if(*length <= temp_length) // 足够一次性读取完毕
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(dat, &(((uint8 *)fifo->buffer)[fifo->end]), *length);
break;
case FIFO_DATA_16BIT:
memcpy(dat, &(((uint16 *)fifo->buffer)[fifo->end]), *length * 2);
break;
case FIFO_DATA_32BIT:
memcpy(dat, &(((uint32 *)fifo->buffer)[fifo->end]), *length * 4);
break;
}
}
else
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(dat, &(((uint8 *)fifo->buffer)[fifo->end]), temp_length);
memcpy(&(((uint8 *)dat)[temp_length]), fifo->buffer, *length - temp_length);
break;
case FIFO_DATA_16BIT:
memcpy(dat, &(((uint16 *)fifo->buffer)[fifo->end]), temp_length * 2);
memcpy(&(((uint16 *)dat)[temp_length]), fifo->buffer, (*length - temp_length) * 2);
break;
case FIFO_DATA_32BIT:
memcpy(dat, &(((uint32 *)fifo->buffer)[fifo->end]), temp_length * 4);
memcpy(&(((uint32 *)dat)[temp_length]), fifo->buffer, (*length - temp_length) * 4);
break;
}
}
if(flag == FIFO_READ_AND_CLEAN) // 如果选择读取并更改 FIFO 状态
{
if(FIFO_CLEAR & fifo->execution)
{
return_state = FIFO_CLEAR_UNDO;
break;
}
fifo->execution |= FIFO_CLEAR;
fifo_end_offset(fifo, *length); // 移动 FIFO 头指针
fifo->size += *length;
fifo->execution &= ~FIFO_CLEAR;
}
}while(0);
fifo->execution &= FIFO_READ;
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 从 FIFO 尾部读取指定长度 buffer
// 参数说明 *fifo FIFO 对象指针
// 参数说明 *dat 目标缓冲区指针
// 参数说明 *length 读取的数据长度 如果没有这么多数据这里会被修改
// 参数说明 flag 是否变更 FIFO 状态 可选择是否清空读取的数据
// 返回参数 fifo_state_enum 操作状态
// 使用示例 zf_log(fifo_read_tail_buffer(&fifo, data, &length, FIFO_READ_ONLY) == FIFO_SUCCESS, "fifo_read_buffer error");
// 备注信息 如果使用 FIFO_READ_AND_CLEAN 操作 将会丢弃所有数据并清空整个 FIFO
// 如果使用 FIFO_READ_AND_CLEAN 操作 将会丢弃所有数据并清空整个 FIFO
// 如果使用 FIFO_READ_AND_CLEAN 操作 将会丢弃所有数据并清空整个 FIFO
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_read_tail_buffer (fifo_struct *fifo, void *dat, uint32 *length, fifo_operation_enum flag)
{
zf_assert(fifo != NULL);
zf_assert(length != NULL);
fifo_state_enum return_state = FIFO_SUCCESS;
uint32 temp_length;
uint32 fifo_data_length;
do
{
if(NULL == dat)
{
return_state = FIFO_BUFFER_NULL;
break;
}
fifo->execution |= FIFO_READ;
fifo_data_length = fifo_used(fifo);
if(*length > fifo_data_length)
{
*length = fifo_data_length; // 纠正读取的长度
return_state = FIFO_DATA_NO_ENOUGH; // 标志数据不够
}
if((fifo->head > fifo->end) || (fifo->head >= *length))
{
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(dat, &(((uint8 *)fifo->buffer)[fifo->head - *length]), *length);
break;
case FIFO_DATA_16BIT:
memcpy(dat, &(((uint16 *)fifo->buffer)[fifo->head - *length]), *length * 2);
break;
case FIFO_DATA_32BIT:
memcpy(dat, &(((uint32 *)fifo->buffer)[fifo->head - *length]), *length * 4);
break;
}
}
else
{
temp_length = *length - fifo->head; // 计算尾指针距离缓冲区尾还有多少空间
switch(fifo->type)
{
case FIFO_DATA_8BIT:
memcpy(dat, &(((uint8 *)fifo->buffer)[fifo->max - temp_length]), temp_length);
memcpy(&(((uint8 *)dat)[temp_length]), &(((uint8 *)fifo->buffer)[fifo->head - *length]), (*length - temp_length));
break;
case FIFO_DATA_16BIT:
memcpy(dat, &(((uint16 *)fifo->buffer)[fifo->max - temp_length]), temp_length * 2);
memcpy(&(((uint16 *)dat)[temp_length]), &(((uint16 *)fifo->buffer)[fifo->head - *length]), (*length - temp_length) * 2);
break;
case FIFO_DATA_32BIT:
memcpy(dat, &(((uint32 *)fifo->buffer)[fifo->max - temp_length]), temp_length * 4);
memcpy(&(((uint32 *)dat)[temp_length]), &(((uint32 *)fifo->buffer)[fifo->head - *length]), (*length - temp_length) * 4);
break;
}
}
if(flag == FIFO_READ_AND_CLEAN) // 如果选择读取并更改 FIFO 状态
{
if(FIFO_CLEAR & fifo->execution)
{
return_state = FIFO_CLEAR_UNDO;
break;
}
fifo->execution |= FIFO_CLEAR;
fifo_end_offset(fifo, (fifo->max - fifo->size));
fifo->size = fifo->max;
fifo->execution &= ~FIFO_CLEAR;
}
}while(0);
fifo->execution &= FIFO_READ;
return return_state;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 FIFO 初始化 挂载对应缓冲区
// 参数说明 *fifo FIFO 对象指针
// 参数说明 type FIFO 数据位数
// 参数说明 *buffer_addr 要挂载的缓冲区
// 参数说明 size 缓冲区大小
// 返回参数 fifo_state_enum 操作状态
// 使用示例 fifo_init(&user_fifo, user_buffer, 64);
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
fifo_state_enum fifo_init (fifo_struct *fifo, fifo_data_type_enum type, void *buffer_addr, uint32 size)
{
zf_assert(fifo != NULL);
fifo_state_enum return_value = FIFO_SUCCESS;
do
{
if(NULL == buffer_addr)
{
return_value = FIFO_BUFFER_NULL;
break;
}
fifo->buffer = buffer_addr;
fifo->execution = FIFO_IDLE;
fifo->type = type;
fifo->head = 0;
fifo->end = 0;
fifo->size = size;
fifo->max = size;
}while(0);
return return_value;
}

View File

@@ -0,0 +1,96 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_fifo
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_fifo_h_
#define _zf_common_fifo_h_
#include "zf_common_typedef.h"
typedef enum
{
FIFO_SUCCESS,
FIFO_WRITE_UNDO,
FIFO_CLEAR_UNDO,
FIFO_BUFFER_NULL,
FIFO_SPACE_NO_ENOUGH,
FIFO_DATA_NO_ENOUGH,
}fifo_state_enum;
typedef enum
{
FIFO_IDLE = 0x00,
FIFO_CLEAR = 0x01,
FIFO_WRITE = 0x02,
FIFO_READ = 0x04,
}fifo_execution_enum;
typedef enum
{
FIFO_READ_AND_CLEAN,
FIFO_READ_ONLY,
}fifo_operation_enum;
typedef enum
{
FIFO_DATA_8BIT,
FIFO_DATA_16BIT,
FIFO_DATA_32BIT,
}fifo_data_type_enum;
typedef struct
{
uint8 execution; // 执行步骤
fifo_data_type_enum type; // 数据类型
void *buffer; // 缓存指针
uint32 head; // 缓存头指针 总是指向空的缓存
uint32 end; // 缓存尾指针 总是指向非空缓存(缓存全空除外)
uint32 size; // 缓存剩余大小
uint32 max; // 缓存总大小
}fifo_struct;
fifo_state_enum fifo_clear (fifo_struct *fifo);
uint32 fifo_used (fifo_struct *fifo);
fifo_state_enum fifo_write_element (fifo_struct *fifo, uint32 dat);
fifo_state_enum fifo_write_buffer (fifo_struct *fifo, void *dat, uint32 length);
fifo_state_enum fifo_read_element (fifo_struct *fifo, void *dat, fifo_operation_enum flag);
fifo_state_enum fifo_read_buffer (fifo_struct *fifo, void *dat, uint32 *length, fifo_operation_enum flag);
fifo_state_enum fifo_read_tail_buffer (fifo_struct *fifo, void *dat, uint32 *length, fifo_operation_enum flag);
fifo_state_enum fifo_init (fifo_struct *fifo, fifo_data_type_enum type, void *buffer_addr, uint32 size);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_font
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_font_h_
#define _zf_common_font_h_
#include "zf_common_typedef.h"
//-------常用颜色----------
typedef enum
{
RGB565_WHITE = (0xFFFF), // 白色
RGB565_BLACK = (0x0000), // 黑色
RGB565_BLUE = (0x001F), // 蓝色
RGB565_PURPLE = (0xF81F), // 紫色
RGB565_PINK = (0xFE19), // 粉色
RGB565_RED = (0xF800), // 红色
RGB565_MAGENTA = (0xF81F), // 品红
RGB565_GREEN = (0x07E0), // 绿色
RGB565_CYAN = (0x07FF), // 青色
RGB565_YELLOW = (0xFFE0), // 黄色
RGB565_BROWN = (0xBC40), // 棕色
RGB565_GRAY = (0x8430), // 灰色
RGB565_39C5BB = (0x3616),
RGB565_66CCFF = (0x665F),
}rgb565_color_enum;
extern const uint8 ascii_font_8x16[][16];
extern const uint8 ascii_font_6x8[][6];
extern const uint8 chinese_test[8][16];
extern const uint8 oled_16x16_chinese[][16];
extern const uint8 gImage_seekfree_logo[38400];
#endif

View File

@@ -0,0 +1,907 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_function
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 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_common_function.h"
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 获取整型数的最大公约数 九章算术之更相减损术
// 参数说明 num1 数字1
// 参数说明 num2 数字2
// 返回参数 uint32 最大公约数
// 使用示例 return func_get_greatest_common_divisor(144, 36); // 获取 144 与 36 的最大公约数
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
uint32 func_get_greatest_common_divisor (uint32 num1, uint32 num2)
{
while(num1 != num2)
{
if(num1 > num2)
{
num1 = num1 - num2;
}
if(num1 < num2)
{
num2 = num2 - num1;
}
}
return num1;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 软件延时
// 参数说明 t 延时时间
// 返回参数 void
// 使用示例 func_soft_delay(100);
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_soft_delay (volatile long t)
{
while(t --);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 字符串转整形数字 数据范围是 [-32768,32767]
// 参数说明 *str 传入字符串 可带符号
// 返回参数 int32 转换后的数据
// 使用示例 int32 dat = func_str_to_int("-100");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
int32 func_str_to_int (char *str)
{
zf_assert(str != NULL);
uint8 sign = 0; // 标记符号 0-正数 1-负数
int32 temp = 0; // 临时计算变量
do
{
if(NULL == str)
{
break;
}
if('-' == *str) // 如果第一个字符是负号
{
sign = 1; // 标记负数
str ++;
}
else if('+' == *str) // 如果第一个字符是正号
{
str ++;
}
while(('0' <= *str) && ('9' >= *str)) // 确定这是个数字
{
temp = temp * 10 + ((uint8)(*str) - 0x30); // 计算数值
str ++;
}
if(sign)
{
temp = -temp;
}
}while(0);
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 整形数字转字符串 数据范围是 [-32768,32767]
// 参数说明 *str 字符串指针
// 参数说明 number 传入的数据
// 返回参数 void
// 使用示例 func_int_to_str(data_buffer, -300);
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_int_to_str (char *str, int32 number)
{
zf_assert(str != NULL);
uint8 data_temp[16]; // 缓冲区
uint8 bit = 0; // 数字位数
int32 number_temp = 0;
do
{
if(NULL == str)
{
break;
}
if(0 > number) // 负数
{
*str ++ = '-';
number = -number;
}
else if(0 == number) // 或者这是个 0
{
*str = '0';
break;
}
while(0 != number) // 循环直到数值归零
{
number_temp = number % 10;
data_temp[bit ++] = func_abs(number_temp); // 倒序将数值提取出来
number /= 10; // 削减被提取的个位数
}
while(0 != bit) // 提取的数字个数递减处理
{
*str ++ = (data_temp[bit - 1] + 0x30); // 将数字从倒序数组中倒序取出 变成正序放入字符串
bit --;
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 字符串转整形数字 数据范围是 [0,65535]
// 参数说明 *str 传入字符串 无符号
// 返回参数 uint32 转换后的数据
// 使用示例 uint32 dat = func_str_to_uint("100");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
uint32 func_str_to_uint (char *str)
{
zf_assert(str != NULL);
uint32 temp = 0; // 临时计算变量
do
{
if(NULL == str)
{
break;
}
while(('0' <= *str) && ('9' >= *str)) // 确定这是个数字
{
temp = temp * 10 + ((uint8)(*str) - 0x30); // 计算数值
str ++;
}
}while(0);
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 整形数字转字符串 数据范围是 [0,65535]
// 参数说明 *str 字符串指针
// 参数说明 number 传入的数据
// 返回参数 void
// 使用示例 func_uint_to_str(data_buffer, 300);
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_uint_to_str (char *str, uint32 number)
{
zf_assert(str != NULL);
int8 data_temp[16]; // 缓冲区
uint8 bit = 0; // 数字位数
do
{
if(NULL == str)
{
break;
}
if(0 == number) // 这是个 0
{
*str = '0';
break;
}
while(0 != number) // 循环直到数值归零
{
data_temp[bit ++] = (number % 10); // 倒序将数值提取出来
number /= 10; // 削减被提取的个位数
}
while(0 != bit) // 提取的数字个数递减处理
{
*str ++ = (data_temp[bit - 1] + 0x30); // 将数字从倒序数组中倒序取出 变成正序放入字符串
bit --;
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 字符串转浮点数 有效累计精度为小数点后六位
// 参数说明 *str 传入字符串 可带符号
// 返回参数 float 转换后的数据
// 使用示例 float dat = func_str_to_float("-100.2");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
float func_str_to_float (char *str)
{
zf_assert(str != NULL);
uint8 sign = 0; // 标记符号 0-正数 1-负数
float temp = 0.0; // 临时计算变量 整数部分
float temp_point = 0.0; // 临时计算变量 小数部分
float point_bit = 1; // 小数累计除数
do
{
if(NULL == str)
{
break;
}
if('-' == *str) // 负数
{
sign = 1; // 标记负数
str ++;
}
else if('+' == *str) // 如果第一个字符是正号
{
str ++;
}
// 提取整数部分
while(('0' <= *str) && ('9' >= *str)) // 确定这是个数字
{
temp = temp * 10 + ((uint8)(*str) - 0x30); // 将数值提取出来
str ++;
}
if('.' == *str)
{
str ++;
while(('0' <= *str) && ('9' >= *str) && point_bit < 1000000.0) // 确认这是个数字 并且精度控制还没到六位
{
temp_point = temp_point * 10 + ((uint8)(*str) - 0x30); // 提取小数部分数值
point_bit *= 10; // 计算这部分小数的除数
str ++;
}
temp_point /= point_bit; // 计算小数
}
temp += temp_point; // 将数值拼合
if(sign)
{
temp = -temp;
}
}while(0);
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 浮点数字转字符串
// 参数说明 *str 字符串指针
// 参数说明 number 传入的数据
// 参数说明 point_bit 小数点精度
// 返回参数 void
// 使用示例 func_float_to_str(data_buffer, 3.1415, 2); // 结果输出 data_buffer = "3.14"
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_float_to_str (char *str, float number, uint8 point_bit)
{
zf_assert(str != NULL);
int data_int = 0; // 整数部分
int data_float = 0.0; // 小数部分
int data_temp[8]; // 整数字符缓冲
int data_temp_point[6]; // 小数字符缓冲
uint8 bit = point_bit; // 转换精度位数
do
{
if(NULL == str)
{
break;
}
// 提取整数部分
data_int = (int)number; // 直接强制转换为 int
if(0 > number) // 判断源数据是正数还是负数
{
*str ++ = '-';
}
else if(0.0 == number) // 如果是个 0
{
*str ++ = '0';
*str ++ = '.';
*str = '0';
break;
}
// 提取小数部分
number = number - data_int; // 减去整数部分即可
while(bit --)
{
number = number * 10; // 将需要的小数位数提取到整数部分
}
data_float = (int)number; // 获取这部分数值
// 整数部分转为字符串
bit = 0;
do
{
data_temp[bit ++] = data_int % 10; // 将整数部分倒序写入字符缓冲区
data_int /= 10;
}while(0 != data_int);
while(0 != bit)
{
*str ++ = (func_abs(data_temp[bit - 1]) + 0x30); // 再倒序将倒序的数值写入字符串 得到正序数值
bit --;
}
// 小数部分转为字符串
if(point_bit != 0)
{
bit = 0;
*str ++ = '.';
if(0 == data_float)
{
*str = '0';
}
else
{
while(0 != point_bit) // 判断有效位数
{
data_temp_point[bit ++] = data_float % 10; // 倒序写入字符缓冲区
data_float /= 10;
point_bit --;
}
while(0 != bit)
{
*str ++ = (func_abs(data_temp_point[bit - 1]) + 0x30); // 再倒序将倒序的数值写入字符串 得到正序数值
bit --;
}
}
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 字符串转浮点数 有效累计精度为小数点后九位
// 参数说明 str 传入字符串 可带符号
// 返回参数 double 转换后的数据
// 使用示例 double dat = func_str_to_double("-100.2");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
double func_str_to_double (char *str)
{
zf_assert(str != NULL);
uint8 sign = 0; // 标记符号 0-正数 1-负数
double temp = 0.0; // 临时计算变量 整数部分
double temp_point = 0.0; // 临时计算变量 小数部分
double point_bit = 1; // 小数累计除数
do
{
if(NULL == str)
{
break;
}
if('-' == *str) // 负数
{
sign = 1; // 标记负数
str ++;
}
else if('+' == *str) // 如果第一个字符是正号
{
str ++;
}
// 提取整数部分
while(('0' <= *str) && ('9' >= *str)) // 确定这是个数字
{
temp = temp * 10 + ((uint8)(*str) - 0x30); // 将数值提取出来
str ++;
}
if('.' == *str)
{
str ++;
while(('0' <= *str) && ('9' >= *str) && point_bit < 1000000000.0) // 确认这是个数字 并且精度控制还没到九位
{
temp_point = temp_point * 10 + ((uint8)(*str) - 0x30); // 提取小数部分数值
point_bit *= 10; // 计算这部分小数的除数
str ++;
}
temp_point /= point_bit; // 计算小数
}
temp += temp_point; // 将数值拼合
if(sign)
{
temp = -temp;
}
}while(0);
return temp;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 浮点数字转字符串
// 参数说明 *str 字符串指针
// 参数说明 number 传入的数据
// 参数说明 point_bit 小数点精度
// 返回参数 void
// 使用示例 func_double_to_str(data_buffer, 3.1415, 2); // 结果输出 data_buffer = "3.14"
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_double_to_str (char *str, double number, uint8 point_bit)
{
zf_assert(str != NULL);
int data_int = 0; // 整数部分
int data_float = 0.0; // 小数部分
int data_temp[12]; // 整数字符缓冲
int data_temp_point[9]; // 小数字符缓冲
uint8 bit = point_bit; // 转换精度位数
do
{
if(NULL == str)
{
break;
}
// 提取整数部分
data_int = (int)number; // 直接强制转换为 int
if(0 > number) // 判断源数据是正数还是负数
{
*str ++ = '-';
}
else if(0.0 == number) // 如果是个 0
{
*str ++ = '0';
*str ++ = '.';
*str = '0';
break;
}
// 提取小数部分
number = number - data_int; // 减去整数部分即可
while(bit --)
{
number = number * 10; // 将需要的小数位数提取到整数部分
}
data_float = (int)number; // 获取这部分数值
// 整数部分转为字符串
bit = 0;
do
{
data_temp[bit ++] = data_int % 10; // 将整数部分倒序写入字符缓冲区
data_int /= 10;
}while(0 != data_int);
while(0 != bit)
{
*str ++ = (func_abs(data_temp[bit - 1]) + 0x30); // 再倒序将倒序的数值写入字符串 得到正序数值
bit --;
}
// 小数部分转为字符串
if(point_bit != 0)
{
bit = 0;
*str ++ = '.';
if(0 == data_float)
*str = '0';
else
{
while(0 != point_bit) // 判断有效位数
{
data_temp_point[bit ++] = data_float % 10; // 倒序写入字符缓冲区
data_float /= 10;
point_bit --;
}
while(0 != bit)
{
*str ++ = (func_abs(data_temp_point[bit - 1]) + 0x30); // 再倒序将倒序的数值写入字符串 得到正序数值
bit --;
}
}
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 字符串转 Hex
// 参数说明 str 传入字符串 无符号
// 返回参数 uint32 转换后的数据
// 使用示例 uint32 dat = func_str_to_hex("0x11");
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
uint32 func_str_to_hex (char *str)
{
zf_assert(str != NULL);
uint32 str_len = strlen(str); // 字符串长
uint32 result_data = 0; // 结果缓存
uint8 temp = 0; // 计算变量
uint8 flag = 0; // 标志位
do
{
if(NULL == str)
{
break;
}
if(flag)
{
if(('a' <= *str) && ('f' >= *str))
{
temp = (*str - 87);
}
else if(('A' <= *str) && ('F' >= *str))
{
temp = (*str - 55);
}
else if(('0' <= *str) && ('9' >= *str))
{
temp = (*str - 48);
}
else
{
break;
}
result_data = ((result_data << 4) | (temp & 0x0F));
}
else
{
// if(strncmp("0x", str, 2))
if((*str == '0') && (*(str + 1) == 'x'))
{
str ++;
flag = 1;
}
}
str ++;
}while(str_len --);
return result_data;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 Hex 转字符串
// 参数说明 *str 字符串指针
// 参数说明 number 传入的数据
// 返回参数 void
// 使用示例 func_hex_to_str(data_buffer, 0x11); // 结果输出 data_buffer = "0x11"
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
void func_hex_to_str (char *str, uint32 number)
{
zf_assert(str != NULL);
const char hex_index[16] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};
int8 data_temp[12]; // 缓冲区
uint8 bit = 0; // 数字位数
*str++ = '0';
*str++ = 'x';
do
{
if(NULL == str)
{
break;
}
if(0 == number) // 这是个 0
{
*str = '0';
break;
}
while(0 != number) // 循环直到数值归零
{
data_temp[bit ++] = (number & 0xF); // 倒序将数值提取出来
number >>= 4; // 削减被提取的个位数
}
while(0 != bit) // 提取的数字个数递减处理
{
*str ++ = hex_index[data_temp[bit - 1]]; // 将数字从倒序数组中倒序取出 变成正序放入字符串
bit --;
}
}while(0);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 数字转换为 ASCII 值
// 参数说明 dat 传入的数据
// 参数说明 *p 数据缓冲
// 参数说明 neg_type 数据类型
// 参数说明 radix 进制
// 返回参数 uint8 数据
// 使用示例 number_conversion_ascii((uint32)ival, vstr, 1, 10);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static uint8 number_conversion_ascii (uint32 dat, int8 *p, uint8 neg_type, uint8 radix)
{
int32 neg_dat;
uint32 pos_dat;
uint8 temp_data = 0;
uint8 valid_num = 0;
if(neg_type)
{
neg_dat = (int32)dat;
if(0 > neg_dat)
{
neg_dat = -neg_dat;
}
while(1)
{
*p = neg_dat%radix + '0';
neg_dat = neg_dat/radix;
valid_num ++;
if(!neg_dat)
{
break;
}
p ++;
}
}
else
{
pos_dat = dat;
while(1)
{
temp_data = pos_dat%radix;
if(10 <= temp_data)
{
temp_data += 'A'-10;
}
else
{
temp_data += '0';
}
*p = temp_data;
pos_dat = pos_dat/radix;
valid_num ++;
if(!pos_dat)
{
break;
}
p ++;
}
}
return valid_num;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 printf 显示转换
// 参数说明 *d_buff 缓冲区
// 参数说明 len 长度
// 返回参数 void
// 使用示例 printf_reverse_order(vstr, vlen);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
static void printf_reverse_order (int8 *d_buff, uint32 len)
{
uint32 i;
int8 temp_data;
for(i = 0; len / 2 > i; i ++)
{
temp_data = d_buff[len - 1 - i];
d_buff[len - 1 -i ] = d_buff[i];
d_buff[i] = temp_data;
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 sprintf 函数实现
// 参数说明 *buff 缓冲区
// 参数说明 *format 源字符串
// 参数说明 ... 可变参数列表
// 返回参数 uint32 处理后数据长
// 使用示例 zf_sprintf(buff, "Data : %d", 100);
// 备注信息 本函数在文件内部调用 用户不用关注 也不可修改
//-------------------------------------------------------------------------------------------------------------------
uint32 zf_sprintf (int8 *buff, const int8 *format, ...)
{
uint32 buff_len = 0;
va_list arg;
va_start(arg, format);
while (*format)
{
int8 ret = *format;
if ('%' == ret)
{
switch (*++ format)
{
case 'a':// 十六进制p计数法输出浮点数 暂未实现
{
}
break;
case 'c':// 一个字符
{
int8 ch = (int8)va_arg(arg, uint32);
*buff = ch;
buff ++;
buff_len ++;
}
break;
case 'd':
case 'i':// 有符号十进制整数
{
int8 vstr[33];
int32 ival = (int32)va_arg(arg, int32);
uint8 vlen = number_conversion_ascii((uint32)ival, vstr, 1, 10);
if(0 > ival)
{
vstr[vlen] = '-';
vlen ++;
}
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'f':// 浮点数,输出小数点后六位 不能指定输出精度
case 'F':// 浮点数,输出小数点后六位 不能指定输出精度
{
int8 vstr[33];
double ival = (double)va_arg(arg, double);
uint8 vlen = number_conversion_ascii((uint32)(int32)ival, vstr, 1, 10);
if(0 > ival)
{
vstr[vlen] = '-';
vlen ++;
}
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
ival = ((double)ival - (int32)ival)*1000000;
if(ival)
{
vlen = number_conversion_ascii((uint32)(int32)ival, vstr, 1, 10);
}
else
{
vstr[0] = vstr[1] = vstr[2] = vstr[3] = vstr[4] = vstr[5] = '0';
vlen = 6;
}
while(6 > vlen)
{
vstr[vlen] = '0';
vlen ++;
}
vstr[vlen] = '.';
vlen ++;
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'u':// 无符号十进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 10);
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'o':// 无符号八进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 8);
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'x':// 无符号十六进制整数
case 'X':// 无符号十六进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 16);
printf_reverse_order(vstr, vlen);
memcpy(buff, vstr, vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 's':// 字符串
{
int8 *pc = va_arg(arg, int8 *);
while (*pc)
{
*buff = *pc;
buff ++;
buff_len ++;
pc ++;
}
}
break;
case 'p':// 以16进制形式输出指针
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
//uint8 vlen = number_conversion_ascii(ival, vstr, 0, 16);
number_conversion_ascii(ival, vstr, 0, 16);
printf_reverse_order(vstr, 8);
memcpy(buff, vstr, 8);
buff += 8;
buff_len += 8;
}
break;
case '%':// 输出字符%
{
*buff = '%';
buff ++;
buff_len ++;
}
break;
default:
break;
}
}
else
{
*buff = (int8)(*format);
buff ++;
buff_len ++;
}
format ++;
}
va_end(arg);
return buff_len;
}

View File

@@ -0,0 +1,97 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_function
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 s 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_function_h_
#define _zf_common_function_h_
#include "zf_common_typedef.h"
//====================================================宏定义函数区====================================================
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 绝对值函数 数据范围是 [-32767,32767]
// 参数说明 dat 需要求绝对值的数
// 返回参数 int 返回绝对值
// 使用示例 dat = func_abs(dat); // 将dat变成正数
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
#define func_abs(x) ((x) >= 0 ? (x): -(x))
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 限幅 数据范围是 [-32768,32767]
// 参数说明 x 被限幅的数据
// 参数说明 y 限幅范围(数据会被限制在-y至+y之间)
// 返回参数 int 限幅之后的数据
// 使用示例 int dat = func_limit(500, 300); // 数据被限制在-300至+300之间 因此返回的结果是300
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
#define func_limit(x, y) ((x) > (y) ? (y) : ((x) < -(y) ? -(y) : (x)))
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 双边限幅 数据范围是 [-32768,32767]
// 参数说明 x 被限幅的数据
// 参数说明 a 限幅范围左边界
// 参数说明 b 限幅范围右边界
// 返回参数 int 限幅之后的数据
// 使用示例 int dat = func_limit_ab(500, -300, 400); //数据被限制在-300至+400之间 因此返回的结果是400
// 备注信息
//-------------------------------------------------------------------------------------------------------------------
#define func_limit_ab(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
//====================================================宏定义函数区====================================================
//=====================================================常规函数区=====================================================
uint32 func_get_greatest_common_divisor (uint32 num1, uint32 num2);
void func_soft_delay (volatile long t);
int32 func_str_to_int (char *str);
void func_int_to_str (char *str, int32 number);
uint32 func_str_to_uint (char *str);
void func_uint_to_str (char *str, uint32 number);
float func_str_to_float (char *str);
void func_float_to_str (char *str, float number, uint8 point_bit);
double func_str_to_double (char *str);
void func_double_to_str (char *str, double number, uint8 point_bit);
uint32 func_str_to_hex (char *str);
void func_hex_to_str (char *str, uint32 number);
uint32 zf_sprintf (int8 *buff, const int8 *format, ...);
//=====================================================常规函数区=====================================================
#endif

View File

@@ -0,0 +1,146 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_headfile
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef __HEADFILE_H
#define __HEADFILE_H
#include "stdio.h"
#include "stdint.h"
#include "string.h"
//===================================================芯片 SDK 底层===================================================
#include "ch32v30x_adc.h"
#include "ch32v30x_bkp.h"
#include "ch32v30x_can.h"
#include "ch32v30x_crc.h"
#include "ch32v30x_dac.h"
#include "ch32v30x_dbgmcu.h"
#include "ch32v30x_dma.h"
#include "ch32v30x_exti.h"
#include "ch32v30x_flash.h"
#include "ch32v30x_fsmc.h"
#include "ch32v30x_gpio.h"
#include "ch32v30x_i2c.h"
#include "ch32v30x_iwdg.h"
#include "ch32v30x_pwr.h"
#include "ch32v30x_rcc.h"
#include "ch32v30x_rtc.h"
#include "ch32v30x_sdio.h"
#include "ch32v30x_spi.h"
#include "ch32v30x_tim.h"
#include "ch32v30x_usart.h"
#include "ch32v30x_wwdg.h"
//===================================================芯片 SDK 底层===================================================
//====================================================开源库公共层====================================================
#include "zf_common_clock.h"
#include "zf_common_debug.h"
#include "zf_common_font.h"
#include "zf_common_function.h"
#include "zf_common_interrupt.h"
#include "zf_common_fifo.h"
#include "zf_common_typedef.h"
//====================================================开源库公共层====================================================
//===================================================芯片外设驱动层===================================================
#include "zf_driver_adc.h"
#include "zf_driver_delay.h"
#include "zf_driver_dvp.h"
#include "zf_driver_encoder.h"
#include "zf_driver_exti.h"
#include "zf_driver_flash.h"
#include "zf_driver_gpio.h"
//#include "zf_driver_iic.h"
#include "zf_driver_pit.h"
#include "zf_driver_pwm.h"
//#include "zf_driver_soft_iic.h"
//#include "zf_driver_soft_spi.h"
#include "zf_driver_spi.h"
#include "zf_driver_timer.h"
#include "zf_driver_uart.h"
#include "zf_driver_usb_cdc.h"
//===================================================芯片外设驱动层===================================================
//===================================================外接设备驱动层===================================================
#include "zf_device_camera.h"
#include "zf_device_icm20602.h"
#include "zf_device_ips114.h"
#include "zf_device_tft180.h"
#include "zf_device_ips200.h"
#include "zf_device_mt9v03x_dvp.h"
#include "zf_device_mpu6050.h"
#include "zf_device_type.h"
#include "zf_device_wireless_uart.h"
#include "zf_device_oled.h"
#include "zf_device_scc8660_dvp.h"
#include "zf_device_bluetooth_ch9141.h"
#include "zf_device_wireless_ch573.h"
#include "zf_device_wireless_uart.h"
#include "zf_device_virtual_oscilloscope.h"
#include "zf_device_w25q32.h"
#include "zf_device_k24c02.h"
#include "zf_device_aht20.h"
#include "zf_device_wifi_uart.h"
#include "zf_device_imu660ra.h"
#include "zf_device_imu963ra.h"
#include "zf_device_key.h"
#include "zf_device_gps_tau1201.h"
#include "zf_device_dl1a.h"
#include "zf_device_dm1xa.h"
#include "zf_device_wifi_spi.h"
#include "zf_device_detector.h"
#include "zf_device_dl1b.h"
//===================================================外接设备驱动层===================================================
//===================================================应用组件层===================================================
//===================================================应用组件层===================================================
//===================================================用户自定义文件===================================================
//===================================================用户自定义文件===================================================
#endif

View File

@@ -0,0 +1,135 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_interrupt
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#include "zf_common_interrupt.h"
static uint32 interrupt_nest_count = 0;
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 指定中断使能
// 参数说明 irqn 指定中断号 可查看 isr.c 对应中断服务函数的标注
// 返回参数 void
// 使用示例 interrupt_enable(UART1_IRQn);
//-------------------------------------------------------------------------------------------------------------------
void interrupt_enable (IRQn_Type irqn)
{
NVIC_EnableIRQ(irqn);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 指定中断屏蔽
// 参数说明 irqn 指定中断号 可查看 isr.c 对应中断服务函数的标注
// 返回参数 void
// 使用示例 interrupt_disable(UART1_IRQn);
//-------------------------------------------------------------------------------------------------------------------
void interrupt_disable (IRQn_Type irqn)
{
NVIC_DisableIRQ(irqn);
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 指定中断设置优先级
// 参数说明 irqn 指定中断号 可查看 isr.c 对应中断服务函数的标注
// 参数说明 priority bit7-bit5为抢占优先级bit4-bit0为次优先级值越低优先级越高
// 返回参数 void
// 使用示例 interrupt_enable(UART1_IRQn, (1<<5) | 2);
// 抢占优先级设置为1,次优先级设置为2
// 禁止调用ch32v30x_misc里面的函数
//-------------------------------------------------------------------------------------------------------------------
void interrupt_set_priority (IRQn_Type irqn, uint8 priority)
{
NVIC_SetPriority(irqn, priority);
}
////-------------------------------------------------------------------------------------------------------------------
//// @brief 中断组初始化 clock_init 内部调用
//// @param void
//// @return void
//// Sample usage: interrupt_init();
////-------------------------------------------------------------------------------------------------------------------
//void interrupt_init (void)
//{
// NVIC_PriorityGroupConfig(4);
//
//}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 全局中断使能
// 参数说明 void 还原的嵌套层 如果传入 0 则直接清空嵌套层数开启总中断
// 返回参数 void
// 使用示例 interrupt_global_enable();
//-------------------------------------------------------------------------------------------------------------------
void interrupt_global_enable (uint32 primask)
{
if(primask)
{
interrupt_nest_count --;
}
if(!interrupt_nest_count)
{
__enable_irq();
}
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 全局中断屏蔽
// 参数说明 void
// 返回参数 void
// 使用示例 interrupt_disable_all();
//-------------------------------------------------------------------------------------------------------------------
uint32 interrupt_global_disable (void)
{
if(!interrupt_nest_count)
{
__disable_irq();
}
interrupt_nest_count ++;
return interrupt_nest_count;
}
//-------------------------------------------------------------------------------------------------------------------
// 函数简介 中断初始化
// 参数说明 void
// 返回参数 void
// 使用示例 interrupt_init();
// 备注信息 会在 clock_init 内部调用
//-------------------------------------------------------------------------------------------------------------------
void interrupt_init (void)
{
interrupt_global_enable(0); //使能全局中断
}

View File

@@ -0,0 +1,51 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_interrupt
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_nvic_h
#define _zf_nvic_h
#include "ch32v30x.h"
#include "zf_common_typedef.h"
void interrupt_init (void);
void interrupt_global_enable (uint32 primask);
uint32 interrupt_global_disable (void);
void interrupt_enable (IRQn_Type irqn);
void interrupt_disable (IRQn_Type irqn);
void interrupt_set_priority (IRQn_Type irqn, uint8 priority);
#endif

View File

@@ -0,0 +1,82 @@
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技
*
* 本文件是CH32V307VCT6 开源库的一部分
*
* CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU 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_common_typedef
* 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/
*
* 修改记录
* 日期 作者 备注
* 2022-09-15 大W first version
********************************************************************************************************************/
#ifndef _zf_common_typedef_h_
#define _zf_common_typedef_h_
#include "stdio.h"
#include "stdint.h"
#include "stdbool.h"
#include "stdarg.h"
#include "string.h"
#include "stdlib.h"
//=================================================== 类型定义 ===================================================
//#define COMPATIBLE_WITH_OLDER_VERSIONS // 兼容旧版开源库接口
#define USE_ZF_TYPEDEF (1) // 是否启用类型定义申明
#if USE_ZF_TYPEDEF
// 数据类型声明
// 尽量使用 stdint.h 定义的类型名称 避免冲突 这里可以裁剪
typedef unsigned char uint8; // 无符号 8 bits
typedef unsigned short int uint16; // 无符号 16 bits
typedef unsigned int uint32; // 无符号 32 bits
typedef unsigned long long uint64; // 无符号 64 bits
typedef signed char int8; // 有符号 8 bits
typedef signed short int int16; // 有符号 16 bits
typedef signed int int32; // 有符号 32 bits
typedef signed long long int64; // 有符号 64 bits
typedef volatile uint8 vuint8; // 易变性修饰 无符号 8 bits
typedef volatile uint16 vuint16; // 易变性修饰 无符号 16 bits
typedef volatile uint32 vuint32; // 易变性修饰 无符号 32 bits
typedef volatile uint64 vuint64; // 易变性修饰 无符号 64 bits
typedef volatile int8 vint8; // 易变性修饰 有符号 8 bits
typedef volatile int16 vint16; // 易变性修饰 有符号 16 bits
typedef volatile int32 vint32; // 易变性修饰 有符号 32 bits
typedef volatile int64 vint64; // 易变性修饰 有符号 64 bits
#define ZF_ENABLE (1)
#define ZF_DISABLE (0)
#define ZF_TRUE (1)
#define ZF_FALSE (0)
#endif
//=================================================== 类型定义 ===================================================
#endif