| 
    XFusion API v1.3.0
    
   | 
 
xf_template 编程风格模板。 更多...

结构体 | |
| struct | _xf_templ_struct_t | 
| 结构体示例。  更多... | |
宏定义 | |
| #define | XF_TEMPLATE_HELP_STR "xf_template v0.1" | 
| 关于格式化程序。   | |
| #define | XF_TEMPLATE_HELP_STR_SPLICING "test" XF_TEMPLATE_HELP_STR "abc123" | 
| #define | XF_TEMPLATE_DEFINE (1) | 
| #define | XF_TEMPLATE_MACROS_ADD(_a, _b) ((_a) + (_b)) | 
| 带参宏: [Macros].   | |
| #define | XF_TEMPLATE_MACROS_NO_RETURN(_a, _b) | 
| 无需返回参数的宏。   | |
| #define | XF_TEMPLATE_MACROS_HAS_RETURN(_x) | 
| 需要返回参数的宏。   | |
| #define | XF_TEMPL_PRINTF(_fmt, ...) | 
| 关于条件编译。   | |
| #define | UNUSED(_x) ((void)(_x)) | 
类型定义 | |
| typedef enum _xf_templ_enum_t | xf_templ_enum_t | 
| 类型定义: [Typedefs].   | |
| typedef int | xf_templ_int_t | 
| typedef struct _xf_templ_struct_t | xf_templ_struct_t | 
| 结构体示例。   | |
枚举 | |
| enum | _xf_templ_enum_t {  XF_TEMPL_ENUM_0 = 0x00 , XF_TEMPL_ENUM_1 , XF_TEMPL_ENUM_2 , XF_TEMPL_ENUM_MAX , XF_TEMPL_ENUM_DEFAULT = XF_TEMPL_ENUM_1 }  | 
| 类型定义: [Typedefs].  更多... | |
函数 | |
| static xf_templ_int_t | _xf_template_func (xf_templ_struct_t *p_struct, int32_t *p_out) | 
| 静态函数原型: [Static Prototypes].   | |
| void | a_function_of_very_many_parameters (uint32_t a_parameter_with_a_very_long_name, uint32_t another_parameter_with_a_very_long_name, uint32_t a_parameter_with_a_very_long_name_too, uint32_t a_parameter_with_a_very_long_name_that_is_really_long) | 
| 一个演示函数参数换行的示例。   | |
| void | xf_main (void) | 
| 全局函数定义: [Global Functions].   | |
| xf_templ_err_t | xf_template_init (void) | 
| 一个初始化函数。   | |
变量 | |
| static const char *const | TAG = "xf_main" | 
| 静态变量: [Static Variables].   | |
| static xf_templ_int_t | s_data = 0 | 
| static xf_templ_struct_t | s_struct = {0} | 
| static void * | p_a_pointer = NULL | 
| int | g_xf_templ_global_data1_in_head = 0 | 
| 全局变量: [Global Variables].   | |
| int | g_xf_templ_global_data2_no_in_head = 0 | 
xf_template 编程风格模板。
每行字数限制
建议每行**少于 80 个字符**,这样在 vscode 中分两栏也可以看全部代码。 123456789012345678901234567890123456789012345678901234567890123456789012345678 代码正文最长不要超过 120 字符。
注释
2.1 中文与英文、数字之间根据需要加空格。 例如:
缩进
代码中使用 4 个空格作为缩进,不要使用 TAB。
行尾
不要在行尾尾随空格。
大括号
只有函数定义的左大括号必须换行,在函数中的左大括号不需要换行(K&R风格)。
在文件 xf_template_source_detail.c 中定义.
| #define XF_TEMPLATE_HELP_STR "xf_template v0.1" | 
关于格式化程序。
基于 esp-idf 的格式化风格修改。
一些说明。
如: /* ==================== [Includes] ========================================== / / ==================== [Defines] =========================================== */
注意: 1.1 内容标识中,从开头到'['(不含)共有 24 个字符。 /* ==================== 1.2 内容标识中,从开头到末尾共有 80 个字符,编程时尽量不要超过内容标识的长度。 1.3 如需更改 "[]" 内的内容,请增删 ']' 右侧的 '=',使总长度维持 80 字符。 1.4 内容标识的顺序**不建议更改**。
/**
头文件: [Includes].
在这里放头文件,通常顺序是:
#include "xf_template_header_detail.h";#include <stdio.h>;#include <sys/time.h>;#include "xf_log.h"、#include "xf_spi.h";宏定义(无参宏): [Defines].
在文件 xf_template_source_detail.c 第 152 行定义.
| #define XF_TEMPLATE_HELP_STR_SPLICING "test" XF_TEMPLATE_HELP_STR "abc123" | 
在文件 xf_template_source_detail.c 第 153 行定义.
| #define XF_TEMPLATE_DEFINE (1) | 
在文件 xf_template_source_detail.c 第 154 行定义.
| #define XF_TEMPLATE_MACROS_ADD | ( | _a, | |
| _b | |||
| ) | ((_a) + (_b)) | 
带参宏: [Macros].
带参宏示例。
在文件 xf_template_source_detail.c 第 291 行定义.
| #define XF_TEMPLATE_MACROS_NO_RETURN | ( | _a, | |
| _b | |||
| ) | 
无需返回参数的宏。
在文件 xf_template_source_detail.c 第 299 行定义.
| #define XF_TEMPLATE_MACROS_HAS_RETURN | ( | _x | ) | 
需要返回参数的宏。
在文件 xf_template_source_detail.c 第 310 行定义.
| #define XF_TEMPL_PRINTF | ( | _fmt, | |
| ... | |||
| ) | 
关于条件编译。
#else 后追加相应的的条件(如:!defined(xf_log_printf)), 在 #endif 后标注 #if 的信息(如:defined(xf_log_printf))。在文件 xf_template_source_detail.c 第 329 行定义.
| #define UNUSED | ( | _x | ) | ((void)(_x)) | 
未使用的变量
在文件 xf_template_source_detail.c 第 333 行定义.
| typedef enum _xf_templ_enum_t xf_templ_enum_t | 
类型定义: [Typedefs].
类型定义的类型**必须**以_t为结尾。前缀xf_表示是在 xf_hal 中定义的。
枚举类型示例。
| typedef int xf_templ_int_t | 
"!<"表示当前的注释的说明对象是前面的代码, 没有的话默认都是说明后面的代码。
在文件 xf_template_source_detail.c 第 183 行定义.
| typedef struct _xf_templ_struct_t xf_templ_struct_t | 
结构体示例。
_xf_templ_struct_t。 当然用 xf_templ_struct_s 也可以。 | enum _xf_templ_enum_t | 
类型定义: [Typedefs].
类型定义的类型**必须**以_t为结尾。前缀xf_表示是在 xf_hal 中定义的。
枚举类型示例。
| 枚举值 | |
|---|---|
| XF_TEMPL_ENUM_0 | 枚举值 0,第一个枚举值要求手动赋值  | 
| XF_TEMPL_ENUM_1 | 枚举值 1  | 
| XF_TEMPL_ENUM_2 | 枚举值 2  | 
| XF_TEMPL_ENUM_MAX | 枚举值最大值  | 
| XF_TEMPL_ENUM_DEFAULT | 枚举值默认值  | 
在文件 xf_template_source_detail.c 第 173 行定义.
      
  | 
  static | 
静态函数原型: [Static Prototypes].
一个静态函数。(说明注释)
| p_struct | 输入一个的结构体。 参数默认都是输入,可以不标记[in], | |
| [out] | p_out | 指向用于传出数据的指针(会改变原本的变量)。 需要传出的参数注释时添加[out]。 | 
< goto 通常用作出错后处理。
单字节变量通常只能用作循环变量。
< 记录返回值
< 注意 label 前面要有单下划线
在文件 xf_template_source_detail.c 第 422 行定义.
| void a_function_of_very_many_parameters | ( | uint32_t | a_parameter_with_a_very_long_name, | 
| uint32_t | another_parameter_with_a_very_long_name, | ||
| uint32_t | a_parameter_with_a_very_long_name_too, | ||
| uint32_t | a_parameter_with_a_very_long_name_that_is_really_long | ||
| ) | 
一个演示函数参数换行的示例。
| a_parameter_with_a_very_long_name | 无用参数。 | 
| another_parameter_with_a_very_long_name | 无用参数。 | 
| a_parameter_with_a_very_long_name_too | 无用参数。 | 
| a_parameter_with_a_very_long_name_that_is_really_long | 无用参数。 | 
在文件 xf_template_source_detail.c 第 454 行定义.
| void xf_main | ( | void | ) | 
全局函数定义: [Global Functions].
主函数。 正常情况下此行空白:函数之间需要有一个空行作为分隔
< 用于接收 _xf_template_func 的传出
< 防止警告
分支语句哪怕只有一句也必须加花括号。
判断语句中,如果一行不足以放下判断语句, 分行时需要将逻辑符号放在新行的开头。 此时最好还是用变量表达判断语句。
常量在前可以避免不必要的逻辑错误。 如 if (XF_TEMPL_FAIL = ret) 时编译会报错。
对于返回值为 void 的函数, return;可有可无,文件风格统一即可。
在文件 xf_template_source_detail.c 第 346 行定义.
| xf_templ_err_t xf_template_init | ( | void | ) | 
      
  | 
  static | 
静态变量: [Static Variables].
s_前缀标识静态变量。p_前缀标识。可以与s_组合使用(sp_),表示静态指针类型。 日志标签 在文件 xf_template_source_detail.c 第 259 行定义.
      
  | 
  static | 
一个全局静态数据
在文件 xf_template_source_detail.c 第 260 行定义.
      
  | 
  static | 
一个结构体
在文件 xf_template_source_detail.c 第 261 行定义.
      
  | 
  static | 
一个指针
在文件 xf_template_source_detail.c 第 262 行定义.
| int g_xf_templ_global_data1_in_head = 0 | 
全局变量: [Global Variables].
g_前缀标识全局变量。在文件 xf_template_source_detail.c 第 275 行定义.
| int g_xf_templ_global_data2_no_in_head = 0 | 
没有在头文件中声明的全局变量
在文件 xf_template_source_detail.c 第 276 行定义.