而在开发板的配置文件里
有下面的代码
- /**
- * @brief Configures Button GPIO and EXTI Line.
- * @param Button: Specifies the Button to be configured.
- * This parameter should be: BUTTON_USER
- * @param ButtonMode: Specifies Button mode.
- * This parameter can be one of following parameters:
- * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
- * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
- * generation capability
- * @retval None
- */
- void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
-
- /* Enable the BUTTON Clock */
- BUTTONx_GPIO_CLK_ENABLE(Button);
-
- if(ButtonMode == BUTTON_MODE_GPIO)
- {
- /* Configure Button pin as input */
- GPIO_InitStruct.Pin = BUTTON_PIN[Button];
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
- }
-
- if(ButtonMode == BUTTON_MODE_EXTI)
- {
- /* Configure Button pin as input with External interrupt */
- GPIO_InitStruct.Pin = BUTTON_PIN[Button];
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
- HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
-
- /* Enable and set Button EXTI Interrupt to the lowest priority */
- HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
- HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
- }
- }
我们可以根据主函数传递进来的内容知道,传递进来的是按键的位置以及按键的配置功能为中断类
|