From e82c7554c89e13e683ee17b0c4954b4a691f6606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=86=AFSir?= Date: Fri, 3 May 2024 03:32:48 +0800 Subject: [PATCH] Add HAL_UARTEx_RxEventCallback & HAL_RTCEx_RTCEventCallback --- Firmware/Core/Inc/main.h | 3 +++ Firmware/Core/Src/main.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Firmware/Core/Inc/main.h b/Firmware/Core/Inc/main.h index ca633a1..e5b9dfd 100644 --- a/Firmware/Core/Inc/main.h +++ b/Firmware/Core/Inc/main.h @@ -36,6 +36,8 @@ extern "C" { #include "menu.h" #include "key.h" #include "led.h" +#include "command.h" +#include "cJSON.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ @@ -46,6 +48,7 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ extern uint8_t sdMountFlag; +extern uint8_t keyVal; /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ diff --git a/Firmware/Core/Src/main.c b/Firmware/Core/Src/main.c index f494fd9..715ee42 100644 --- a/Firmware/Core/Src/main.c +++ b/Firmware/Core/Src/main.c @@ -53,6 +53,8 @@ /* USER CODE BEGIN PV */ uint8_t sdMountFlag = 0; +uint8_t cmdBuffer[120]; +uint8_t keyVal = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -107,6 +109,8 @@ int main(void) MX_SPI1_Init(); /* USER CODE BEGIN 2 */ WS_TFT_Init(); + HAL_UARTEx_ReceiveToIdle_DMA(&huart1,cmdBuffer, sizeof(cmdBuffer)); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT); printf("System Init OK!\r\n"); Staring_Menu(); /* USER CODE END 2 */ @@ -114,6 +118,7 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { + user_Menu(); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ @@ -170,7 +175,29 @@ void SystemClock_Config(void) } /* USER CODE BEGIN 4 */ - +//串口中断回调函数 +void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){ + if(huart->Instance == USART1){ + command_Process(cmdBuffer,Size); + memset(cmdBuffer,0, sizeof(cmdBuffer)); + HAL_UARTEx_ReceiveToIdle_DMA(&huart1,cmdBuffer, sizeof(cmdBuffer)); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT); + } +} +//Second event callback +void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc){ + static RTC_DateTypeDef sDate = {0,0,0,0}; + HAL_RTC_GetDate(hrtc,&hrtc->DateToUpdate,RTC_FORMAT_BIN); + if(sDate.Year != hrtc->DateToUpdate.Year || sDate.Month != + hrtc->DateToUpdate.Month || sDate.Date != hrtc->DateToUpdate.Date){ + HAL_RTCEx_BKUPWrite(hrtc,RTC_BKP_DR2,hrtc->DateToUpdate.Year); + HAL_RTCEx_BKUPWrite(hrtc,RTC_BKP_DR3,hrtc->DateToUpdate.Month); + HAL_RTCEx_BKUPWrite(hrtc,RTC_BKP_DR4,hrtc->DateToUpdate.Date); + sDate.Year = hrtc->DateToUpdate.Year ; + sDate.Month = hrtc->DateToUpdate.Month ; + sDate.Date = hrtc->DateToUpdate.Date; + } +} /* USER CODE END 4 */ /**