From 1dc8622f53eb69371de95867283b58b7dbf9b68a Mon Sep 17 00:00:00 2001 From: NeoZeng Date: Sat, 19 Nov 2022 15:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81=EF=BC=8C=E5=B0=86?= =?UTF-8?q?=E8=80=81=E6=97=A7=E7=9A=84struct=5Ftypedef=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=E6=96=B0=E7=9A=84stdint-gcc.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 6 ++- bsp/bsp_buzzer.h | 5 +- bsp/bsp_can.h | 2 +- bsp/bsp_led.h | 3 +- bsp/bsp_usart.h | 2 +- bsp/struct_typedef.h | 5 +- modules/led_light/led_task.c | 91 ++++++++++++++++----------------- modules/led_light/led_task.h | 24 ++++----- modules/motor/HT04.h | 2 +- modules/motor/LK9025.h | 2 +- modules/referee/crc.h | 12 ++--- modules/referee/referee.c | 20 +------- modules/referee/referee.h | 4 +- modules/remote/remote_control.h | 2 +- 14 files changed, 77 insertions(+), 103 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4d64b69..5c3bbaf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,8 @@ { "files.associations": { - "memory.h": "c" + "memory.h": "c", + "stdint-gcc.h": "c", + "led_task.h": "c", + "stdint.h": "c" }, - "C_Cpp.errorSquiggles": "Disabled" } \ No newline at end of file diff --git a/bsp/bsp_buzzer.h b/bsp/bsp_buzzer.h index c238343..900f913 100644 --- a/bsp/bsp_buzzer.h +++ b/bsp/bsp_buzzer.h @@ -1,10 +1,11 @@ #ifndef BSP_BUZZER_H #define BSP_BUZZER_H -#include "struct_typedef.h" +#include +#include void buzzer_init(); -extern void buzzer_on(uint16_t psc, uint16_t pwm,uint8_t level); +extern void buzzer_on(uint16_t psc, uint16_t pwm, uint8_t level); extern void buzzer_off(void); #endif diff --git a/bsp/bsp_can.h b/bsp/bsp_can.h index e6faf21..a14ff09 100644 --- a/bsp/bsp_can.h +++ b/bsp/bsp_can.h @@ -1,7 +1,7 @@ #ifndef BSP_CAN_H #define BSP_CAN_H -#include "struct_typedef.h" +#include #include "can.h" #define MX_REGISTER_DEVICE_CNT 12 // maximum number of device can be registered to CAN service diff --git a/bsp/bsp_led.h b/bsp/bsp_led.h index 2e96943..01805fc 100644 --- a/bsp/bsp_led.h +++ b/bsp/bsp_led.h @@ -1,8 +1,7 @@ #ifndef BSP_LED_H #define BSP_LED_H -#include "struct_typedef.h" - +#include void LED_init(); extern void aRGB_led_show(uint32_t aRGB); diff --git a/bsp/bsp_usart.h b/bsp/bsp_usart.h index c70b925..9e8ff29 100644 --- a/bsp/bsp_usart.h +++ b/bsp/bsp_usart.h @@ -1,7 +1,7 @@ #ifndef BSP_RC_H #define BSP_RC_H -#include "struct_typedef.h" +#include #include "main.h" #define DEVICE_USART_CNT 3 // C板至多分配3个串口 diff --git a/bsp/struct_typedef.h b/bsp/struct_typedef.h index e80ba2b..18c8e71 100644 --- a/bsp/struct_typedef.h +++ b/bsp/struct_typedef.h @@ -22,10 +22,7 @@ typedef unsigned int uint32_t; typedef unsigned long long uint64_t; typedef unsigned char bool_t; -typedef float fp32; +typedef float float; typedef double fp64; #endif - - - diff --git a/modules/led_light/led_task.c b/modules/led_light/led_task.c index 978986a..6f6ea1a 100644 --- a/modules/led_light/led_task.c +++ b/modules/led_light/led_task.c @@ -2,7 +2,7 @@ ****************************(C) COPYRIGHT 2019 DJI**************************** * @file led_trigger_task.c/h * @brief led RGB show.led RGB灯效。 - * @note + * @note * @history * Version Date Author Modification * V1.0.0 Nov-11-2019 RM 1. rgb led @@ -19,62 +19,59 @@ #include "cmsis_os.h" #include "main.h" - -#define RGB_FLOW_COLOR_CHANGE_TIME 1000 -#define RGB_FLOW_COLOR_LENGHT 6 -//blue-> green(dark)-> red -> blue(dark) -> green(dark) -> red(dark) -> blue -//蓝 -> 绿(灭) -> 红 -> 蓝(灭) -> 绿 -> 红(灭) -> 蓝 +#define RGB_FLOW_COLOR_CHANGE_TIME 1000 +#define RGB_FLOW_COLOR_LENGHT 6 +// blue-> green(dark)-> red -> blue(dark) -> green(dark) -> red(dark) -> blue +// 蓝 -> 绿(灭) -> 红 -> 蓝(灭) -> 绿 -> 红(灭) -> 蓝 uint32_t RGB_flow_color[RGB_FLOW_COLOR_LENGHT + 1] = {0xFF0000FF, 0x0000FF00, 0xFFFF0000, 0x000000FF, 0xFF00FF00, 0x00FF0000, 0xFF0000FF}; /** - * @brief led rgb task - * @param[in] pvParameters: NULL - * @retval none - */ + * @brief led rgb task + * @param[in] pvParameters: NULL + * @retval none + */ /** - * @brief led RGB任务 - * @param[in] pvParameters: NULL - * @retval none - */ + * @brief led RGB任务 + * @param[in] pvParameters: NULL + * @retval none + */ void led_RGB_flow_task() { - uint16_t i, j; - fp32 delta_alpha, delta_red, delta_green, delta_blue; - fp32 alpha,red,green,blue; - uint32_t aRGB; + uint16_t i, j; + float delta_alpha, delta_red, delta_green, delta_blue; + float alpha, red, green, blue; + uint32_t aRGB; - while(1) + while (1) + { + + for (i = 0; i < RGB_FLOW_COLOR_LENGHT; i++) { + alpha = (RGB_flow_color[i] & 0xFF000000) >> 24; + red = ((RGB_flow_color[i] & 0x00FF0000) >> 16); + green = ((RGB_flow_color[i] & 0x0000FF00) >> 8); + blue = ((RGB_flow_color[i] & 0x000000FF) >> 0); - for(i = 0; i < RGB_FLOW_COLOR_LENGHT; i++) - { - alpha = (RGB_flow_color[i] & 0xFF000000) >> 24; - red = ((RGB_flow_color[i] & 0x00FF0000) >> 16); - green = ((RGB_flow_color[i] & 0x0000FF00) >> 8); - blue = ((RGB_flow_color[i] & 0x000000FF) >> 0); + delta_alpha = (float)((RGB_flow_color[i + 1] & 0xFF000000) >> 24) - (float)((RGB_flow_color[i] & 0xFF000000) >> 24); + delta_red = (float)((RGB_flow_color[i + 1] & 0x00FF0000) >> 16) - (float)((RGB_flow_color[i] & 0x00FF0000) >> 16); + delta_green = (float)((RGB_flow_color[i + 1] & 0x0000FF00) >> 8) - (float)((RGB_flow_color[i] & 0x0000FF00) >> 8); + delta_blue = (float)((RGB_flow_color[i + 1] & 0x000000FF) >> 0) - (float)((RGB_flow_color[i] & 0x000000FF) >> 0); - delta_alpha = (fp32)((RGB_flow_color[i + 1] & 0xFF000000) >> 24) - (fp32)((RGB_flow_color[i] & 0xFF000000) >> 24); - delta_red = (fp32)((RGB_flow_color[i + 1] & 0x00FF0000) >> 16) - (fp32)((RGB_flow_color[i] & 0x00FF0000) >> 16); - delta_green = (fp32)((RGB_flow_color[i + 1] & 0x0000FF00) >> 8) - (fp32)((RGB_flow_color[i] & 0x0000FF00) >> 8); - delta_blue = (fp32)((RGB_flow_color[i + 1] & 0x000000FF) >> 0) - (fp32)((RGB_flow_color[i] & 0x000000FF) >> 0); + delta_alpha /= RGB_FLOW_COLOR_CHANGE_TIME; + delta_red /= RGB_FLOW_COLOR_CHANGE_TIME; + delta_green /= RGB_FLOW_COLOR_CHANGE_TIME; + delta_blue /= RGB_FLOW_COLOR_CHANGE_TIME; + for (j = 0; j < RGB_FLOW_COLOR_CHANGE_TIME; j++) + { + alpha += delta_alpha; + red += delta_red; + green += delta_green; + blue += delta_blue; - delta_alpha /= RGB_FLOW_COLOR_CHANGE_TIME; - delta_red /= RGB_FLOW_COLOR_CHANGE_TIME; - delta_green /= RGB_FLOW_COLOR_CHANGE_TIME; - delta_blue /= RGB_FLOW_COLOR_CHANGE_TIME; - for(j = 0; j < RGB_FLOW_COLOR_CHANGE_TIME; j++) - { - alpha += delta_alpha; - red += delta_red; - green += delta_green; - blue += delta_blue; - - aRGB = ((uint32_t)(alpha)) << 24 | ((uint32_t)(red)) << 16 | ((uint32_t)(green)) << 8 | ((uint32_t)(blue)) << 0; - aRGB_led_show(aRGB); - osDelay(1); - } - } + aRGB = ((uint32_t)(alpha)) << 24 | ((uint32_t)(red)) << 16 | ((uint32_t)(green)) << 8 | ((uint32_t)(blue)) << 0; + aRGB_led_show(aRGB); + osDelay(1); + } } + } } - - diff --git a/modules/led_light/led_task.h b/modules/led_light/led_task.h index a8325c7..512f65c 100644 --- a/modules/led_light/led_task.h +++ b/modules/led_light/led_task.h @@ -2,7 +2,7 @@ ****************************(C) COPYRIGHT 2019 DJI**************************** * @file led_trigger_task.c/h * @brief led RGB show.led RGB��Ч�� - * @note + * @note * @history * Version Date Author Modification * V1.0.0 Nov-11-2019 RM 1. rgb led @@ -17,22 +17,18 @@ #ifndef LED_TRIGGER_TASK_H #define LED_TRIGGER_TASK_H - -#include "struct_typedef.h" +#include /** - * @brief led rgb task - * @param[in] pvParameters: NULL - * @retval none - */ + * @brief led rgb task + * @param[in] pvParameters: NULL + * @retval none + */ /** - * @brief led RGB���� - * @param[in] pvParameters: NULL - * @retval none - */ + * @brief led RGB���� + * @param[in] pvParameters: NULL + * @retval none + */ extern void led_RGB_flow_task(); #endif - - - diff --git a/modules/motor/HT04.h b/modules/motor/HT04.h index 5da5f1f..296a651 100644 --- a/modules/motor/HT04.h +++ b/modules/motor/HT04.h @@ -1,7 +1,7 @@ #ifndef HT04_H #define HT04_H -#include "struct_typedef.h" +#include #include "bsp_can.h" #include "controller.h" diff --git a/modules/motor/LK9025.h b/modules/motor/LK9025.h index e3092fc..4d5be8e 100644 --- a/modules/motor/LK9025.h +++ b/modules/motor/LK9025.h @@ -1,7 +1,7 @@ #ifndef LK9025_H #define LK9025_H -#include "struct_typedef.h" +#include #include "bsp_can.h" #include "controller.h" diff --git a/modules/referee/crc.h b/modules/referee/crc.h index 1a53543..e97535a 100644 --- a/modules/referee/crc.h +++ b/modules/referee/crc.h @@ -1,18 +1,18 @@ #ifndef __CRC_H_ #define __CRC_H_ -#include "struct_typedef.h" +#include #define TRUE 1 #define FALSE 0 // CRC8 -void Append_CRC8_Check_Sum( uint8_t *pchMessage, uint16_t dwLength); -uint32_t Verify_CRC8_Check_Sum( uint8_t *pchMessage, uint16_t dwLength); -uint8_t Get_CRC8_Check_Sum( uint8_t *pchMessage, uint16_t dwLength, uint8_t ucCRC8 ); +void Append_CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength); +uint32_t Verify_CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength); +uint8_t Get_CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength, uint8_t ucCRC8); // CRC16 -void Append_CRC16_Check_Sum(uint8_t * pchMessage,uint32_t dwLength); +void Append_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength); uint32_t Verify_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength); -uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC); +uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength, uint16_t wCRC); #endif diff --git a/modules/referee/referee.c b/modules/referee/referee.c index df38ea4..6e75f30 100644 --- a/modules/referee/referee.c +++ b/modules/referee/referee.c @@ -13,7 +13,6 @@ usart_instance referee_usart_instance; /**************裁判系统数据******************/ referee_info_t referee_info; -bool_t Judge_Data_TF = FALSE; //裁判数据是否可用,辅助函数调用 uint8_t Judge_Self_ID; //当前机器人的ID uint16_t Judge_SelfClient_ID; //发送者机器人对应的客户端ID @@ -21,7 +20,7 @@ uint16_t Judge_SelfClient_ID; //发送者机器人对应的客户端ID static void ReceiveCallback() { - Judge_Data_TF=Judge_Read_Data(referee_usart_instance.recv_buff); + Judge_Read_Data(referee_usart_instance.recv_buff); } void referee_init(UART_HandleTypeDef *referee_usart_handle) @@ -39,9 +38,8 @@ void referee_init(UART_HandleTypeDef *referee_usart_handle) * @retval 是否对正误判断做处理 * @attention 在此判断帧头和CRC校验,无误再写入数据,不重复判断帧头 */ -bool_t Judge_Read_Data(uint8_t *ReadFromUsart) +void Judge_Read_Data(uint8_t *ReadFromUsart) { - bool_t retval_tf = FALSE; //数据正确与否标志,每次调用读取裁判系统数据函数都先默认为错误 uint16_t judge_length; //统计一帧数据长度 // referee_info.CmdID = 0; //数据命令码解析 //空数据包,则不作任何处理 @@ -64,7 +62,6 @@ bool_t Judge_Read_Data(uint8_t *ReadFromUsart) //帧尾CRC16校验 if (Verify_CRC16_Check_Sum(ReadFromUsart, judge_length) == TRUE) { - retval_tf = TRUE; //都校验过了则说明数据可用 // 2个8位拼成16位int referee_info.CmdID = (ReadFromUsart[6] << 8 | ReadFromUsart[5]); //解析数据命令码,将数据拷贝到相应结构体中(注意拷贝数据的长度) @@ -129,21 +126,8 @@ bool_t Judge_Read_Data(uint8_t *ReadFromUsart) } } - - return retval_tf; //返回此次接收到的数据是否时有效的 } - -/** - * @brief 数据是否可用 - * @param void - * @retval TRUE可用 FALSE不可用 - * @attention 在裁判读取函数中实时改变返回值 - */ -bool_t JUDGE_sGetDataState(void) -{ - return Judge_Data_TF; -} /** * @brief 读取瞬时功率 * @param void diff --git a/modules/referee/referee.h b/modules/referee/referee.h index 57d9b04..c93d30f 100644 --- a/modules/referee/referee.h +++ b/modules/referee/referee.h @@ -342,9 +342,7 @@ typedef struct extern referee_info_t referee_info; void referee_init(UART_HandleTypeDef *referee_usart_handle); -bool_t Judge_Read_Data(uint8_t *ReadFromUsart); - -bool_t JUDGE_sGetDataState(void); +void Judge_Read_Data(uint8_t *ReadFromUsart); float JUDGE_fGetChassisPower(void); #endif // !REFEREE_H diff --git a/modules/remote/remote_control.h b/modules/remote/remote_control.h index f0cdc23..6235c02 100644 --- a/modules/remote/remote_control.h +++ b/modules/remote/remote_control.h @@ -13,7 +13,7 @@ #ifndef REMOTE_CONTROL_H #define REMOTE_CONTROL_H -#include "struct_typedef.h" +#include #include "main.h" #define RC_CH_VALUE_MIN ((uint16_t)364)