修复Yoda条件(常量右置)与函数定义括号同行

- net_select.c/net_socket.c 共 62 处 Yoda 条件改为常量在右(规范 6.3.1)

- 11 个文件 58 处函数定义左大括号由换行改为与右括号同行(规范 4.4.2)
This commit is contained in:
2026-09-01 16:57:34 +08:00
parent bb76cfd779
commit 02c10fa5ef
13 changed files with 111 additions and 169 deletions
+18 -36
View File
@@ -65,8 +65,7 @@ static void tpafe5160_read_channels(uint8_t count, int16_t *buf);
* 2. 确保 RD 为高、CONVST 为低
* 3. 等待 BUSY 释放(转换空闲)
*/
int tpafe5160_init(void)
{
int tpafe5160_init(void) {
/* 设置默认过采样:无过采样 (OS[2:0] = 000) */
tpafe5160_set_os(TPAFE5160_OS_NONE);
@@ -91,8 +90,7 @@ int tpafe5160_init(void)
* 限定条件:GPIO 已初始化
* 函数说明:通过 OS[2:0] 引脚设置过采样率,在下一次 BUSY 下降沿锁存生效
*/
void tpafe5160_set_os(tpafe5160_os_t os)
{
void tpafe5160_set_os(tpafe5160_os_t os) {
TPAFE5160_OS0(os & 0x01); /* OS0 = bit0 */
TPAFE5160_OS1((os >> 1) & 0x01); /* OS1 = bit1 */
TPAFE5160_OS2((os >> 2) & 0x01); /* OS2 = bit2 */
@@ -105,8 +103,7 @@ void tpafe5160_set_os(tpafe5160_os_t os)
* 限定条件:GPIO 已初始化
* 函数说明:产生 CONVST 脉冲上升沿,启动全部8通道同步采样与转换
*/
void tpafe5160_start_conv(void)
{
void tpafe5160_start_conv(void) {
TPAFE5160_CONVST_PULSE();
}
@@ -117,8 +114,7 @@ void tpafe5160_start_conv(void)
* 限定条件:已调用 tpafe5160_start_conv()
* 函数说明:轮询 BUSY 引脚等待下降沿
*/
int tpafe5160_wait_busy(uint32_t timeout_ms)
{
int tpafe5160_wait_busy(uint32_t timeout_ms) {
uint32_t tick_start = HAL_GetTick();
/* 等待 BUSY 释放(低电平表示空闲) */
@@ -138,8 +134,7 @@ int tpafe5160_wait_busy(uint32_t timeout_ms)
* 限定条件:GPIO 已初始化
* 函数说明:读取 BUSY 引脚电平
*/
uint8_t tpafe5160_is_busy(void)
{
uint8_t tpafe5160_is_busy(void) {
return (TPAFE5160_BUSY_READ() == GPIO_PIN_SET) ? 1 : 0;
}
@@ -152,8 +147,7 @@ uint8_t tpafe5160_is_busy(void)
* 2. 连续8次拉低RD读取各通道数据
* 3. 通过 FRSTDATA 验证第一通道
*/
int tpafe5160_read_all(int16_t *buf)
{
int tpafe5160_read_all(int16_t *buf) {
int ret = 0;
/* 启动转换 */
@@ -180,8 +174,7 @@ int tpafe5160_read_all(int16_t *buf)
* 限定条件:GPIO 已初始化
* 函数说明:启动转换并等待完成后,连续读取至指定通道
*/
int tpafe5160_read_channel(uint8_t channel, int16_t *value)
{
int tpafe5160_read_channel(uint8_t channel, int16_t *value) {
int ret = 0;
int16_t buf[TPAFE5160_CH_NUM] = {0};
@@ -207,8 +200,7 @@ int tpafe5160_read_channel(uint8_t channel, int16_t *value)
* ±10V量程时 LSB = 20V / 65536 ≈ 305.18μV
* 硬件 RANGE 引脚接 GND,默认 ±5V 量程
*/
float tpafe5160_to_voltage(int16_t raw)
{
float tpafe5160_to_voltage(int16_t raw) {
/* RANGE 接 GND → ±5V 量程,满量程 10V */
return (float)raw * (10.0f / 65536.0f);
}
@@ -220,8 +212,7 @@ float tpafe5160_to_voltage(int16_t raw)
* 限定条件:RD 为低或 CS 与 RD 已拉低
* 函数说明:读取 GPIOG->IDR 低16位,对应 DB[15:0]
*/
uint16_t tpafe5160_read_bus(void)
{
uint16_t tpafe5160_read_bus(void) {
return TPAFE5160_READ_BUS();
}
@@ -241,8 +232,7 @@ uint16_t tpafe5160_read_bus(void)
* t14 数据建立 ≤ 21ns → 数据在 RD 下降沿后 21ns 内有效
* 5 个 NOP (~30ns) 覆盖建立时间
*/
static void tpafe5160_read_channels(uint8_t count, int16_t *buf)
{
static void tpafe5160_read_channels(uint8_t count, int16_t *buf) {
uint8_t i;
for (i = 0; i < count; i++) {
@@ -272,8 +262,7 @@ static volatile uint8_t s_buf_sel = 0; /* 0 = 写 B / 读 A, 1 = 写 A / 读 B
* 限定条件:CubeMX 已完成 GPIO 和 NVIC 配置
* 函数说明:正常启动流程无需调用,仅在 irq_disable() 后需要重新使能时使用
*/
void tpafe5160_irq_enable(void)
{
void tpafe5160_irq_enable(void) {
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
@@ -284,8 +273,7 @@ void tpafe5160_irq_enable(void)
* 限定条件:已调用 tpafe5160_irq_enable()
* 函数说明:仅禁用 NVIC 中断,GPIO 配置保持 CubeMX 设定
*/
void tpafe5160_irq_disable(void)
{
void tpafe5160_irq_disable(void) {
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
}
@@ -296,8 +284,7 @@ void tpafe5160_irq_disable(void)
* 限定条件:已调用 tpafe5160_irq_enable()
* 函数说明:产生 CONVST 脉冲,转换完成后由 EXTI 中断自动读取 8 通道数据
*/
void tpafe5160_start_conv_irq(void)
{
void tpafe5160_start_conv_irq(void) {
s_ready = 0;
TPAFE5160_CONVST_PULSE();
}
@@ -309,8 +296,7 @@ void tpafe5160_start_conv_irq(void)
* 限定条件:中断模式已启用
* 函数说明:在 EXTI 回调中置位,主循环读取后需调用 tpafe5160_clear_ready() 清除
*/
uint8_t tpafe5160_data_ready(void)
{
uint8_t tpafe5160_data_ready(void) {
return s_ready;
}
@@ -321,8 +307,7 @@ uint8_t tpafe5160_data_ready(void)
* 限定条件:中断模式已启用
* 函数说明:主循环处理完数据后调用
*/
void tpafe5160_clear_ready(void)
{
void tpafe5160_clear_ready(void) {
s_ready = 0;
}
@@ -333,8 +318,7 @@ void tpafe5160_clear_ready(void)
* 限定条件:tpafe5160_data_ready() 返回 1 时调用
* 函数说明:双缓冲切换,ISR 写另一个缓冲区,主循环安全读取当前缓冲区
*/
const int16_t* tpafe5160_get_buf(void)
{
const int16_t* tpafe5160_get_buf(void) {
return (s_buf_sel == 0) ? s_buf_a : s_buf_b;
}
@@ -345,13 +329,11 @@ const int16_t* tpafe5160_get_buf(void)
* 限定条件:BUSY EXTI 已使能
* 函数说明:转换完成后自动读取 8 通道数据到缓冲区,耗时约 0.5µs (168MHz)
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
tpafe5160_exti_handler(GPIO_Pin);
}
void tpafe5160_exti_handler(uint16_t GPIO_Pin)
{
void tpafe5160_exti_handler(uint16_t GPIO_Pin) {
if (GPIO_Pin != TP_BUSY_Pin) {
return;
}