前言
好的规范的代码给一种赏心悦目的感觉而糟糕的代码则给人的一种烦躁厌恶的感觉。这是会影响个人心情的同时也会影响代码维护效率。同时好的代码规范也可以减少不必要的错误的发生。
代码规则
1. 变量和参数使用完整的数据类型
GPIO_InitTypeDef GPIO_InitStruct;
2. 定义常量的表达式用括号括起来
#define GPIO_PIN_13 ((uint16_t)0x2000U) /* Pin 13 selected */
3. 大写名称,用于标识核心寄存器、外围寄存器和CPU指令
4. 用于标识函数名和中断函数的驼峰命名法名称
函数注释规范
@brief:函数的简要说明;@param:参数说明;@return:返回值说明;最后是函数的详细说明
比如:
/**
* @brief Enable Interrupt in NVIC Interrupt Controller
* @param IRQn interrupt number that specifies the interrupt
* @return none.
* Enable the specified interrupt in the NVIC Interrupt Controller.
* Other settings of the interrupt such as priority are not affected.
*/