From 123869efc4bc527c70e89db97de9db23df9b4419 Mon Sep 17 00:00:00 2001 From: qiuxin Date: Mon, 26 May 2025 17:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BD=8D=E6=9C=BAIO=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?OK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Inc/main.h | 12 +- Core/Src/freertos.c | 276 ++++++++++++------------------ Core/Src/main.c | 52 +++--- Core/Src/stm32f4xx_it.c | 2 +- User/application/inc/TCA6416.h | 7 + User/application/src/TCA6416.c | 128 ++++++++++++++ User/application/src/tcpserverc.c | 8 +- User/board/src/leds.c | 140 +++++++-------- 8 files changed, 350 insertions(+), 275 deletions(-) diff --git a/Core/Inc/main.h b/Core/Inc/main.h index d02e0b8..14f8dc8 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -121,12 +121,12 @@ extern "C" #define EC11_A_GPIO_Port GPIOE #define EC11_B_Pin GPIO_PIN_11 #define EC11_B_GPIO_Port GPIOE -#define LED2_R_Pin GPIO_PIN_12 -#define LED2_R_GPIO_Port GPIOE -#define LED2_G_Pin GPIO_PIN_13 -#define LED2_G_GPIO_Port GPIOE -#define LED2_Y_Pin GPIO_PIN_14 -#define LED2_Y_GPIO_Port GPIOE +// #define LED2_R_Pin GPIO_PIN_12 +// #define LED2_R_GPIO_Port GPIOE +// #define LED2_G_Pin GPIO_PIN_13 +// #define LED2_G_GPIO_Port GPIOE +// #define LED2_Y_Pin GPIO_PIN_14 +// #define LED2_Y_GPIO_Port GPIOE #define ENCODE_Z_Pin GPIO_PIN_14 #define ENCODE_Z_GPIO_Port GPIOB #define BLE2_TX_Pin GPIO_PIN_8 diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 9116183..5fcce1b 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -94,10 +94,14 @@ volatile uint8_t tca6416_port0_status = 0; // 第一个TCA6416的Port0状态 volatile uint8_t tca6416_port1_status = 0; // 第一个TCA6416的Port1状态 volatile uint8_t tca6416_port2_status = 0; // 第二个TCA6416的Port0状态 volatile uint8_t tca6416_port3_status = 0; // 第二个TCA6416的Port1状态 +volatile uint8_t tca6416_port4_status = 0; // 第三个TCA6416的Port0状态 +volatile uint8_t tca6416_port5_status = 0; // 第三个TCA6416的Port1状态 // 添加TCA6416测试相关的调试变量 volatile uint8_t tca6416_test_step = 0; // 当前测试步骤 volatile uint8_t tca6416_init_result = 0xFF; // 初始化结果 +volatile uint8_t tca6416_init2_result = 0xFF; // 第二个芯片初始化结果 +volatile uint8_t tca6416_init3_result = 0xFF; // 第三个芯片初始化结果 volatile uint8_t tca6416_write_data = 0; // 写入的数据 volatile uint8_t tca6416_read_data = 0; // 读取的数据 volatile uint8_t tca6416_error_count = 0; // 错误计数 @@ -574,69 +578,10 @@ void start_usart6_dma_test_task(void const *argument) } -/* USER CODE BEGIN Header_start_tca6416_task */ -/** - * @brief Function implementing the tca6416_task thread. - * @param argument: Not used - * @retval None - */ -/* USER CODE END Header_start_tca6416_task */ -void start_tca6416_task(void const *argument) -{ - /* USER CODE BEGIN start_tca6416_task */ - uint8_t port0_data, port1_data; - - // 初始化第一个TCA6416 - if(TCA6416_Init() != 0) - { - Error_Handler(); - } - - // 初始化第二个TCA6416 - if(TCA6416_Init2() != 0) - { - Error_Handler(); - } - - // 设置两个芯片的所有端口为输入 - if(TCA6416_SetPortDirection(0, 0xFF) != 0) Error_Handler(); - if(TCA6416_SetPortDirection(1, 0xFF) != 0) Error_Handler(); - if(TCA6416_SetPortDirection2(0, 0xFF) != 0) Error_Handler(); - if(TCA6416_SetPortDirection2(1, 0xFF) != 0) Error_Handler(); - - for(;;) - { - // 读取第一个芯片的输入状态 - if(TCA6416_ReadPort(0, &port0_data) == 0) - { - tca6416_port0_status = port0_data; - } - if(TCA6416_ReadPort(1, &port1_data) == 0) - { - tca6416_port1_status = port1_data; - } - - // 读取第二个芯片的输入状态 - if(TCA6416_ReadPort2(0, &port0_data) == 0) - { - tca6416_port2_status = port0_data; - } - if(TCA6416_ReadPort2(1, &port1_data) == 0) - { - tca6416_port3_status = port1_data; - } - - osDelay(100); // 100ms读取一次 - } - /* USER CODE END start_tca6416_task */ -} - void test_tca6416_task(void const *argument) { /* USER CODE BEGIN test_tca6416_task */ uint8_t ret = 0; - uint8_t test_patterns[] = {0x00, 0xFF, 0xAA, 0x55, 0x0F, 0xF0, 0x5A, 0xA5}; - uint8_t pattern_index = 0; uint8_t addr_scan_result[8] = {0}; // 存储地址扫描结果 // 等待系统稳定 @@ -653,7 +598,7 @@ void test_tca6416_task(void const *argument) osDelay(10); } - // 步骤1: 初始化TCA6416 + // 步骤1: 初始化第一个TCA6416芯片 tca6416_test_step = 1; tca6416_init_result = TCA6416_Init(); @@ -667,141 +612,134 @@ void test_tca6416_task(void const *argument) } } - // 初始化成功,继续测试 - osDelay(50); + // 步骤2: 初始化第二个TCA6416芯片(地址0x21) + tca6416_test_step = 2; + tca6416_init2_result = TCA6416_Init2(); + + if(tca6416_init2_result != 0) + { + tca6416_error_count++; + // 继续执行,不阻塞 + } + + // 步骤3: 初始化第三个TCA6416芯片(地址0x20,第二条总线) + tca6416_test_step = 3; + tca6416_init3_result = TCA6416_Init3(); + + if(tca6416_init3_result != 0) + { + tca6416_error_count++; + // 继续执行,不阻塞 + } + + // 步骤4: 配置第一个芯片所有IO为输出模式并置高电平 + tca6416_test_step = 4; + + // 设置Port0和Port1为输出(0=输出,1=输入) + ret = TCA6416_SetPortDirection(0, 0x00); // Port0全部设为输出 + if(ret != 0) + { + tca6416_error_count++; + tca6416_i2c_ack_status = ret; + } + osDelay(10); + + ret = TCA6416_SetPortDirection(1, 0x00); // Port1全部设为输出 + if(ret != 0) + { + tca6416_error_count++; + tca6416_i2c_ack_status = ret; + } + osDelay(10); + + // 将第一个芯片所有IO置为高电平 + ret = TCA6416_WritePort(0, 0xFF); + if(ret == 0) tca6416_port0_status = 0xFF; + osDelay(10); + + ret = TCA6416_WritePort(1, 0xFF); + if(ret == 0) tca6416_port1_status = 0xFF; + osDelay(10); + + // 步骤5: 配置第二、三个芯片所有IO为输入模式 + tca6416_test_step = 5; + + // 第二个芯片设为输入 + if(tca6416_init2_result == 0) + { + TCA6416_SetPortDirection2(0, 0xFF); // Port0全部设为输入 + osDelay(10); + TCA6416_SetPortDirection2(1, 0xFF); // Port1全部设为输入 + osDelay(10); + } + + // 第三个芯片设为输入 + if(tca6416_init3_result == 0) + { + TCA6416_SetPortDirection3(0, 0xFF); // Port0全部设为输入 + osDelay(10); + TCA6416_SetPortDirection3(1, 0xFF); // Port1全部设为输入 + osDelay(10); + } + + // 步骤6: 循环检测所有芯片状态 + tca6416_test_step = 6; for(;;) { - // 步骤2: 设置Port0为输出,Port1为输入 - tca6416_test_step = 2; - tca6416_port0_dir = 0x00; // 0=输出 - tca6416_port1_dir = 0xFF; // 1=输入 - - ret = TCA6416_SetPortDirection(0, tca6416_port0_dir); - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } + // 刷新第一个芯片的输出状态 + TCA6416_WritePort(0, 0xFF); + osDelay(10); + TCA6416_WritePort(1, 0xFF); osDelay(10); - ret = TCA6416_SetPortDirection(1, tca6416_port1_dir); - if(ret != 0) + // 读取第一个芯片状态 + if(TCA6416_ReadPort(0, &tca6416_read_data) == 0) { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - osDelay(10); - - // 步骤3: 写入测试模式到Port0 - tca6416_test_step = 3; - tca6416_test_pattern = test_patterns[pattern_index]; - tca6416_write_data = tca6416_test_pattern; - - ret = TCA6416_WritePort(0, tca6416_write_data); - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - osDelay(10); - - // 步骤4: 读取Port0的值(验证写入) - tca6416_test_step = 4; - ret = TCA6416_ReadPort(0, &tca6416_read_data); - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - else - { - // 更新状态变量 tca6416_port0_status = tca6416_read_data; } osDelay(10); - // 步骤5: 读取Port1的输入状态 - tca6416_test_step = 5; - ret = TCA6416_ReadPort(1, &tca6416_read_data); - if(ret != 0) + if(TCA6416_ReadPort(1, &tca6416_read_data) == 0) { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - else - { - // 更新状态变量 tca6416_port1_status = tca6416_read_data; } osDelay(10); - // 步骤6: 测试单个引脚操作 - tca6416_test_step = 6; - for(uint8_t pin = 0; pin < 8; pin++) + // 读取第二个芯片状态(如果初始化成功) + if(tca6416_init2_result == 0) { - // 设置单个引脚为高 - ret = TCA6416_WritePin(0, pin, 1); - if(ret != 0) + if(TCA6416_ReadPort2(0, &tca6416_read_data) == 0) { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; + tca6416_port2_status = tca6416_read_data; } - osDelay(5); + osDelay(10); - // 读取验证 - uint8_t pin_state = 0; - ret = TCA6416_ReadPin(0, pin, &pin_state); - if(ret != 0) + if(TCA6416_ReadPort2(1, &tca6416_read_data) == 0) { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; + tca6416_port3_status = tca6416_read_data; } - osDelay(5); + osDelay(10); + } + + // 读取第三个芯片状态(如果初始化成功) + if(tca6416_init3_result == 0) + { + if(TCA6416_ReadPort3(0, &tca6416_read_data) == 0) + { + tca6416_port4_status = tca6416_read_data; + } + osDelay(10); - // 设置单个引脚为低 - ret = TCA6416_WritePin(0, pin, 0); - if(ret != 0) + if(TCA6416_ReadPort3(1, &tca6416_read_data) == 0) { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; + tca6416_port5_status = tca6416_read_data; } - osDelay(5); + osDelay(10); } - // 步骤7: 测试极性反转功能 - tca6416_test_step = 7; - ret = TCA6416_SetPortPolarity(0, 0xFF); // 反转所有位 - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - osDelay(10); - - // 读取并验证极性反转效果 - ret = TCA6416_ReadPort(0, &tca6416_read_data); - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - osDelay(10); - - // 恢复正常极性 - ret = TCA6416_SetPortPolarity(0, 0x00); - if(ret != 0) - { - tca6416_error_count++; - tca6416_i2c_ack_status = ret; - } - osDelay(10); - - // 切换到下一个测试模式 - pattern_index = (pattern_index + 1) % (sizeof(test_patterns) / sizeof(test_patterns[0])); - - // 延时后继续下一轮测试 - osDelay(500); + // 总延时1秒后重复 + osDelay(800); } /* USER CODE END test_tca6416_task */ } \ No newline at end of file diff --git a/Core/Src/main.c b/Core/Src/main.c index a1438de..da1d465 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -336,32 +336,32 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) } } -void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) -{ - if (GPIO_Pin == EC11_KEY_Pin) - { - if (ec11_data.confirm_key_flag == 0) - { - ec11_data.confirm_key_flag = 1; - } - else if (ec11_data.confirm_key_flag == 1) - { - ec11_data.confirm_key_flag = 2; - } - else if (ec11_data.confirm_key_flag == 2) - { - ec11_data.confirm_key_flag = 3; - } - } - if (GPIO_Pin == HART2_OCD_Pin) - { - HAL_GPIO_TogglePin(LED2_R_GPIO_Port, LED2_R_Pin); - } - if (GPIO_Pin == HART1_OCD_Pin) - { - HAL_GPIO_TogglePin(LED2_Y_GPIO_Port, LED2_Y_Pin); - } -} +//void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +//{ +// if (GPIO_Pin == EC11_KEY_Pin) +// { +// if (ec11_data.confirm_key_flag == 0) +// { +// ec11_data.confirm_key_flag = 1; +// } +// else if (ec11_data.confirm_key_flag == 1) +// { +// ec11_data.confirm_key_flag = 2; +// } +// else if (ec11_data.confirm_key_flag == 2) +// { +// ec11_data.confirm_key_flag = 3; +// } +// } +// if (GPIO_Pin == HART2_OCD_Pin) +// { +// //HAL_GPIO_TogglePin(LED2_R_GPIO_Port, LED2_R_Pin); +// } +// if (GPIO_Pin == HART1_OCD_Pin) +// { +// //HAL_GPIO_TogglePin(LED2_Y_GPIO_Port, LED2_Y_Pin); +// } +//} /* USER CODE END 4 */ /** diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 18e2efa..897b452 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -453,7 +453,7 @@ void ETH_IRQHandler(void) /* USER CODE END ETH_IRQn 0 */ HAL_ETH_IRQHandler(&heth); /* USER CODE BEGIN ETH_IRQn 1 */ - HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin); + //HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin); /* USER CODE END ETH_IRQn 1 */ } diff --git a/User/application/inc/TCA6416.h b/User/application/inc/TCA6416.h index 3b1d03f..7ea8028 100644 --- a/User/application/inc/TCA6416.h +++ b/User/application/inc/TCA6416.h @@ -17,6 +17,8 @@ /* TCA6416 I2C地址 */ #define TCA6416_ADDR 0x20 // 第一个芯片地址 (A0=A1=A2=GND) #define TCA6416_ADDR2 0x21 // 第二个芯片地址 (A0=1, A1=A2=GND) +#define TCA6416_ADDR3 0x20 // 第三个芯片地址 (与第二个芯片共用总线,地址0x20) + /* 寄存器地址定义 */ #define TCA6416_INPUT_PORT0 0x00 // 输入端口0 @@ -67,14 +69,19 @@ void TCA6416_GPIO_Init(void); uint8_t TCA6416_Init(void); uint8_t TCA6416_Init2(void); // 第二个芯片的初始化函数 +uint8_t TCA6416_Init3(void); // 第三个芯片的初始化函数 uint8_t TCA6416_WritePort(uint8_t port, uint8_t data); uint8_t TCA6416_WritePort2(uint8_t port, uint8_t data); // 第二个芯片的写端口函数 +uint8_t TCA6416_WritePort3(uint8_t port, uint8_t data); // 第三个芯片的写端口函数 uint8_t TCA6416_ReadPort(uint8_t port, uint8_t *data); uint8_t TCA6416_ReadPort2(uint8_t port, uint8_t *data); // 第二个芯片的读端口函数 +uint8_t TCA6416_ReadPort3(uint8_t port, uint8_t *data); // 第三个芯片的读端口函数 uint8_t TCA6416_SetPortDirection(uint8_t port, uint8_t direction); uint8_t TCA6416_SetPortDirection2(uint8_t port, uint8_t direction); // 第二个芯片的设置方向函数 +uint8_t TCA6416_SetPortDirection3(uint8_t port, uint8_t direction); // 第三个芯片的设置方向函数 uint8_t TCA6416_SetPortPolarity(uint8_t port, uint8_t polarity); uint8_t TCA6416_SetPortPolarity2(uint8_t port, uint8_t polarity); // 第二个芯片的设置极性函数 +uint8_t TCA6416_SetPortPolarity3(uint8_t port, uint8_t polarity); // 第三个芯片的设置极性函数 uint8_t TCA6416_WritePin(uint8_t port, uint8_t pin, uint8_t state); uint8_t TCA6416_ReadPin(uint8_t port, uint8_t pin, uint8_t *state); diff --git a/User/application/src/TCA6416.c b/User/application/src/TCA6416.c index b65a238..17d245e 100644 --- a/User/application/src/TCA6416.c +++ b/User/application/src/TCA6416.c @@ -541,4 +541,132 @@ uint8_t TCA6416_SetPortPolarity2(uint8_t port, uint8_t polarity) return 0; } +/* 第三个芯片的操作函数(使用第二个芯片的I2C总线,但地址为TCA6416_ADDR3) */ + +/** + * @brief 初始化第三个TCA6416 + * @retval 0:成功 1:失败 + */ +uint8_t TCA6416_Init3(void) +{ + // GPIO已在TCA6416_GPIO_Init()中初始化 + + // 增加延时以确保设备稳定 + HAL_Delay(10); + + // 默认将所有引脚设置为输入 + if(TCA6416_SetPortDirection3(0, 0xFF) != 0) return 1; + if(TCA6416_SetPortDirection3(1, 0xFF) != 0) return 1; + + // 设置默认输出值为0 + if(TCA6416_WritePort3(0, 0x00) != 0) return 1; + if(TCA6416_WritePort3(1, 0x00) != 0) return 1; + + // 设置默认极性(非反转) + if(TCA6416_SetPortPolarity3(0, 0x00) != 0) return 1; + if(TCA6416_SetPortPolarity3(1, 0x00) != 0) return 1; + + return 0; +} + +/** + * @brief 向第三个TCA6416的端口写入数据 + * @param port: 端口号(0或1) + * @param data: 要写入的数据 + * @retval 0:成功 1:失败 + */ +uint8_t TCA6416_WritePort3(uint8_t port, uint8_t data) +{ + uint8_t reg_addr = (port == 0) ? TCA6416_OUTPUT_PORT0 : TCA6416_OUTPUT_PORT1; + + I2C_Start2(); + I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(reg_addr); // 寄存器地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(data); // 数据 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_Stop2(); + return 0; +} + +/** + * @brief 从第三个TCA6416的端口读取数据 + * @param port: 端口号(0或1) + * @param data: 存储读取数据的指针 + * @retval 0:成功 1:失败 + */ +uint8_t TCA6416_ReadPort3(uint8_t port, uint8_t *data) +{ + uint8_t reg_addr = (port == 0) ? TCA6416_INPUT_PORT0 : TCA6416_INPUT_PORT1; + + I2C_Start2(); + I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(reg_addr); // 寄存器地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_Start2(); + I2C_SendByte2((TCA6416_ADDR3 << 1) | 0x01); // 读地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + *data = I2C_ReadByte2(); // 读取数据 + I2C_NAck2(); + + I2C_Stop2(); + return 0; +} + +/** + * @brief 设置第三个TCA6416的端口方向 + * @param port: 端口号(0或1) + * @param direction: 0 = 输出, 1 = 输入 + * @retval 0:成功 1:失败 + */ +uint8_t TCA6416_SetPortDirection3(uint8_t port, uint8_t direction) +{ + uint8_t reg_addr = (port == 0) ? TCA6416_CONFIG_PORT0 : TCA6416_CONFIG_PORT1; + + I2C_Start2(); + I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(reg_addr); // 寄存器地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(direction); // 方向设置 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_Stop2(); + return 0; +} + +/** + * @brief 设置第三个TCA6416的端口极性 + * @param port: 端口号(0或1) + * @param polarity: 0 = 非反转, 1 = 反转 + * @retval 0:成功 1:失败 + */ +uint8_t TCA6416_SetPortPolarity3(uint8_t port, uint8_t polarity) +{ + uint8_t reg_addr = (port == 0) ? TCA6416_POL_INV_PORT0 : TCA6416_POL_INV_PORT1; + + I2C_Start2(); + I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(reg_addr); // 寄存器地址 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_SendByte2(polarity); // 极性设置 + if(I2C_WaitAck2()) { I2C_Stop2(); return 1; } + + I2C_Stop2(); + return 0; +} + diff --git a/User/application/src/tcpserverc.c b/User/application/src/tcpserverc.c index 4ef10d4..875e44b 100644 --- a/User/application/src/tcpserverc.c +++ b/User/application/src/tcpserverc.c @@ -399,9 +399,11 @@ uint16_t handle_type_87(const uint8_t *body, uint16_t body_len, uint8_t *tx) // 报文类型 tx[8] = reply_type; - // 填充TCA6416引脚状态到第9-10字节 - tx[9] = tca6416_port2_status; // 第二个TCA6416的Port0状态 - tx[10] = tca6416_port3_status; // 第二个TCA6416的Port1状态 + // 填充地址为0x21的TCA6416芯片状态到第9-10字节 + // tx[9] = tca6416_port2_status; // 第二个TCA6416的Port0状态(地址0x21)外部端口8-15 + // tx[10] = tca6416_port3_status; // 第二个TCA6416的Port1状态(地址0x21)外部端口0-7 + tx[9] = tca6416_port3_status; // 第二个TCA6416的Port0状态(地址0x21)外部端口0-7 + tx[10] = tca6416_port2_status; // 第二个TCA6416的Port1状态(地址0x21)外部端口8-15 // 填充AD7124原始数据到tx[11]~tx[75],每通道4字节,MSB格式 extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX]; diff --git a/User/board/src/leds.c b/User/board/src/leds.c index de277fb..0423393 100644 --- a/User/board/src/leds.c +++ b/User/board/src/leds.c @@ -9,32 +9,32 @@ unsigned char tim_led_state = 0; * * @param io LED灯的枚举值,表示需要打开的LED灯。 */ -void leds_on(leds_e io) -{ - switch (io) - { - case LEDS2_RED: - HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); - break; - case LEDS2_GREEN: - HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); - break; - case LEDS2_YELLOW: - HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); - break; - case LEDS3_RED: - HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); - break; - case LEDS3_GREEN: - HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); - break; - case LEDS3_YELLOW: - HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); - break; - default: - break; - } -} +//void leds_on(leds_e io) +//{ +// switch (io) +// { +// case LEDS2_RED: +// HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); +// break; +// case LEDS2_GREEN: +// HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); +// break; +// case LEDS2_YELLOW: +// HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); +// break; +// case LEDS3_RED: +// HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); +// break; +// case LEDS3_GREEN: +// HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); +// break; +// case LEDS3_YELLOW: +// HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); +// break; +// default: +// break; +// } +//} /** * @brief 关闭指定的LED灯 @@ -43,32 +43,32 @@ void leds_on(leds_e io) * * @param io LED灯的枚举值 */ -void leds_off(leds_e io) -{ - switch (io) - { - case LEDS2_RED: - HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); - break; - case LEDS2_GREEN: - HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); - break; - case LEDS2_YELLOW: - HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); - break; - case LEDS3_RED: - HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); - break; - case LEDS3_GREEN: - HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); - break; - case LEDS3_YELLOW: - HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); - break; - default: - break; - } -} +//void leds_off(leds_e io) +//{ +// switch (io) +// { +// case LEDS2_RED: +// HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); +// break; +// case LEDS2_GREEN: +// HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); +// break; +// case LEDS2_YELLOW: +// HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); +// break; +// case LEDS3_RED: +// HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); +// break; +// case LEDS3_GREEN: +// HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); +// break; +// case LEDS3_YELLOW: +// HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); +// break; +// default: +// break; +// } +//} /** * @brief 打开所有LED灯 @@ -78,30 +78,30 @@ void leds_off(leds_e io) * 通过将指定GPIO端口和引脚上的电平设置为低电平(GPIO_PIN_RESET), * 从而打开相应的LED灯。 */ -void leds_on_all(void) -{ - HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); -} +//void leds_on_all(void) +//{ +// HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); +// HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); +// HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); +// HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); +// HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); +// HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); +//} /** * @brief 关闭所有LED灯 * * 该函数用于将所有LED灯关闭。 */ -void leds_off_all(void) -{ - HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); -} +//void leds_off_all(void) +//{ +// HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); +// HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); +// HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); +// HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); +// HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); +// HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); +//} // void lan8720_reset(void) // {