添加三个按键模块仅需要增加以下代码:
typedef enum _MAZDRV_KEY_
{
MAZDRV_KEY0 = 0,
MAZDRV_KEY1,
MAZDRV_KEY2,
MAZDRV_KEY_MAX,
} MAZDRV_KEY;
void MAZ_Drv_key0_handle(void);
void MAZ_Drv_key1_handle(void);
void MAZ_Drv_key2_handle(void);
static MAZDRV_KEY_CTRL g_mazdrv_key_ctrl[MAZDRV_KEY_MAX] =
{
[MAZDRV_KEY0] =
{
.port = MAZDRV_GPIO_PORTC,
.pin = MAZDRV_GPIO_PIN1,
.polarity = MAZDRV_KEY_POLARITY_LOW,
.mode = MAZDRV_KEY_INTERRUPT,
.handle = MAZ_Drv_key0_handle,
},
[MAZDRV_KEY1] =
{
.port = MAZDRV_GPIO_PORTC,
.pin = MAZDRV_GPIO_PIN13,
.polarity = MAZDRV_KEY_POLARITY_LOW,
.mode = MAZDRV_KEY_INTERRUPT,
.handle = MAZ_Drv_key1_handle,
},
[MAZDRV_KEY2] =
{
.port = MAZDRV_GPIO_PORTA,
.pin = MAZDRV_GPIO_PIN0,
.polarity = MAZDRV_KEY_POLARITY_HIGH,
.mode = MAZDRV_KEY_INTERRUPT,
.handle = MAZ_Drv_key2_handle,
},
};
/* Interrupt handler */
void MAZ_Drv_key0_handle(void)
{
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_1) != 0x00u)
{
MAZ_Drv_led_set_status(MAZDRV_LED0, MAZDRV_LED_STATUS_TOGGLE);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
}
}
void MAZ_Drv_key1_handle(void)
{
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != 0x00u)
{
MAZ_Drv_led_set_status(MAZDRV_LED1, MAZDRV_LED_STATUS_TOGGLE);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13);
}
}
void MAZ_Drv_key2_handle(void)
{
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_0) != 0x00u)
{
MAZ_Drv_led_set_status(MAZDRV_LED0, MAZDRV_LED_STATUS_TOGGLE);
MAZ_Drv_led_set_status(MAZDRV_LED1, MAZDRV_LED_STATUS_TOGGLE);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
}
}
|