add button test at the board startup, part 2

This commit is contained in:
2025-03-08 14:43:54 +02:00
parent 82a3907d8a
commit 0b8a55a9e2
4 changed files with 20 additions and 6 deletions

View File

@@ -53,7 +53,7 @@ void ((*executors[])(void)) = {
external_temp_show_fahrenheit
};
int current_executor_id = 0;
size_t current_executor_id = 0;
/* USER CODE END PV */
@@ -174,14 +174,13 @@ int main(void)
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
// switch mode for SW5 (alternative advancing method)
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI8_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI8_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

View File

@@ -41,7 +41,7 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
extern int current_executor_id;
extern size_t current_executor_id;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -214,4 +214,18 @@ void EXTI0_IRQHandler(void)
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}
void EXTI9_5_IRQHandler(void)
{
GPIOD->ODR = 0x1000;
current_executor_id += 1;
current_executor_id %= 2;
for (int i = 900000; i > 0; i--) asm("nop");
GPIOD->ODR = 0x0000;
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);
}
/* USER CODE END 1 */