/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32f4xx_it.c * @brief Interrupt Service Routines. ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ //float test_trmp = 0.0; extern bool update_temp; extern bool flash_flag; //extern uint32_t time_to_upd_flash; /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ extern DMA_HandleTypeDef hdma_spi1_tx; extern SPI_HandleTypeDef hspi2; extern TIM_HandleTypeDef htim2; extern TIM_HandleTypeDef htim3; /* USER CODE BEGIN EV */ extern uint8_t btnCnt_en; extern btn_status_t BTN_flag; extern uint8_t motor_timeCnt; extern uint8_t run_flag; extern SCREEN_Buf disp_buf; extern uint32_t SleepTickCnt; extern bool Sleep_status; // sound--------- extern uint8_t sound_flag; extern uint16_t vol_timeline; extern uint16_t vol_timeCnt; // bounce and systick-------------- uint16_t sysTickCnt = 0; uint16_t bounce_sysTickCnt = 0; //static uint8_t press_time = 0; bool finish = false; /* USER CODE END EV */ /******************************************************************************/ /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** * @brief This function handles Memory management fault. */ void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** * @brief This function handles Pre-fetch fault, memory access fault. */ void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** * @brief This function handles Undefined instruction or illegal state. */ void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** * @brief This function handles System service call via SWI instruction. */ void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ /* USER CODE BEGIN SVCall_IRQn 1 */ /* USER CODE END SVCall_IRQn 1 */ } /** * @brief This function handles Debug monitor. */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ /* USER CODE BEGIN DebugMonitor_IRQn 1 */ /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles Pendable request for system service. */ void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ /* USER CODE BEGIN PendSV_IRQn 1 */ /* USER CODE END PendSV_IRQn 1 */ } /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ //static uint16_t test_trmp_counter = 0; static uint16_t temp_upd_counter = 0; // if (time_to_upd_flash != 0){ // if (time_to_upd_flash == 1){ // flash_flag = true; // } // time_to_upd_flash--; // } temp_upd_counter++; if (temp_upd_counter>=250){ temp_upd_counter = 0; update_temp = true; } // test_trmp_counter++; // if (test_trmp_counter>=100){ // test_trmp_counter = 0; // test_trmp += 0.1; // if (test_trmp >= 5.0){ // test_trmp = 0.0; // } // } if(sound_flag == 1){ if(vol_timeCnt >= vol_timeline){ sound_flag = 2; vol_timeCnt = 0; } else vol_timeCnt++; } if(disp_buf.motor_status == MOTOR_RUN){ sysTickCnt++; if(sysTickCnt >=1000){ sysTickCnt = 0; if(run_flag) motor_timeCnt++; if(disp_buf.disp_runtime_sec == 0){ if(disp_buf.disp_runtime_min == 0){ disp_buf.disp_runtime_min = disp_buf.runtime_min; disp_buf.disp_runtime_sec = disp_buf.runtime_sec; finish = true; BTN_flag = BTN_PRESS; disp_buf.disp_status = HOME_START; } else{ disp_buf.disp_runtime_sec = 59; disp_buf.disp_runtime_min--; } } else disp_buf.disp_runtime_sec--; } } if (SleepTickCnt != 0){ SleepTickCnt --; } // if(disp_buf.screen_timeout){ // if(Sleep_status == false){ // SleepTickCnt++; // if(SleepTickCnt >= SLEEP_TIME){ // Sleep_status = true; // SleepTickCnt = 0; // } // } // } #if 0 if(btnCnt_en) bounce_sysTickCnt++; #else bounce_sysTickCnt++; #endif if(bounce_sysTickCnt > 150){ bounce_sysTickCnt = 0; btnCnt_en = 0; #if 1 static bool btn_pressed = false; //static uint8_t btn_press_time = 0; if(HAL_GPIO_ReadPin(BTN_GPIO_Port, BTN_Pin) == GPIO_PIN_RESET){ ////////////TODO GPIO_PIN_RESET //if (btn_press_time < 1){ // btn_press_time++; //} else { if (btn_pressed == false){ Sound_Set_Func(disp_buf.buz_status, disp_buf.buzzer_volume, VOLTIMELINE); BTN_flag = BTN_PRESS; btn_pressed = true; } //} } else { //btn_press_time = 0; btn_pressed = false; } #else if(HAL_GPIO_ReadPin(BTN_GPIO_Port, BTN_Pin) == GPIO_PIN_RESET) { press_time++; } else { if (press_time != 0) { if (press_time > LONG_PRESS_TIME_X_150MS) { BTN_flag = BTN_LONG_PRESS; } else { BTN_flag = BTN_PRESS; } } press_time = 0; } #endif } if(disp_buf.motor_status == MOTOR_RUN){ if(!run_flag){ motor_timeCnt = 0; run_flag = 1; } else{ RunMotorCycle(disp_buf.pattern, disp_buf.rpm); } } else if (disp_buf.motor_status == MOTOR_PAUSE) { run_flag = false; Motor_Set_Func(PAUSE, 0); } else { Motor_Set_Func(PAUSE, 0); motor_timeCnt = 0; run_flag = false; //Init_DISP_Para(); } /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ /* STM32F4xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32f4xx.s). */ /******************************************************************************/ /** * @brief This function handles EXTI line0 interrupt. */ void EXTI0_IRQHandler(void) { /* USER CODE BEGIN EXTI0_IRQn 0 */ /* USER CODE END EXTI0_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(T_IRQ_Pin); /* USER CODE BEGIN EXTI0_IRQn 1 */ /* USER CODE END EXTI0_IRQn 1 */ } /** * @brief This function handles EXTI line[9:5] interrupts. */ void EXTI9_5_IRQHandler(void) { /* USER CODE BEGIN EXTI9_5_IRQn 0 */ /* USER CODE END EXTI9_5_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(BTN_Pin); /* USER CODE BEGIN EXTI9_5_IRQn 1 */ /* USER CODE END EXTI9_5_IRQn 1 */ } /** * @brief This function handles TIM2 global interrupt. */ void TIM2_IRQHandler(void) { /* USER CODE BEGIN TIM2_IRQn 0 */ /* USER CODE END TIM2_IRQn 0 */ HAL_TIM_IRQHandler(&htim2); /* USER CODE BEGIN TIM2_IRQn 1 */ /* USER CODE END TIM2_IRQn 1 */ } /** * @brief This function handles TIM3 global interrupt. */ void TIM3_IRQHandler(void) { /* USER CODE BEGIN TIM3_IRQn 0 */ /* USER CODE END TIM3_IRQn 0 */ HAL_TIM_IRQHandler(&htim3); /* USER CODE BEGIN TIM3_IRQn 1 */ /* USER CODE END TIM3_IRQn 1 */ } /** * @brief This function handles SPI2 global interrupt. */ void SPI2_IRQHandler(void) { /* USER CODE BEGIN SPI2_IRQn 0 */ /* USER CODE END SPI2_IRQn 0 */ HAL_SPI_IRQHandler(&hspi2); /* USER CODE BEGIN SPI2_IRQn 1 */ /* USER CODE END SPI2_IRQn 1 */ } /** * @brief This function handles DMA2 stream3 global interrupt. */ void DMA2_Stream3_IRQHandler(void) { /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */ /* USER CODE END DMA2_Stream3_IRQn 0 */ HAL_DMA_IRQHandler(&hdma_spi1_tx); /* USER CODE BEGIN DMA2_Stream3_IRQn 1 */ /* USER CODE END DMA2_Stream3_IRQn 1 */ } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */