|
|
|
@ -10,11 +10,8 @@ uint8_t read_button_GPIO(uint8_t button_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case btn1_id:
|
|
|
|
case btn1_id:
|
|
|
|
return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
|
|
|
|
return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,19 +19,19 @@ uint8_t read_button_GPIO(uint8_t button_id)
|
|
|
|
int main()
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static uint8_t btn1_event_val;
|
|
|
|
static uint8_t btn1_event_val;
|
|
|
|
|
|
|
|
|
|
|
|
button_init(&btn1, read_button_GPIO, 0, btn1_id);
|
|
|
|
button_init(&btn1, read_button_GPIO, 0, btn1_id);
|
|
|
|
button_start(&btn1);
|
|
|
|
button_start(&btn1);
|
|
|
|
|
|
|
|
|
|
|
|
//make the timer invoking the button_ticks() interval 5ms.
|
|
|
|
//make the timer invoking the button_ticks() interval 5ms.
|
|
|
|
//This function is implemented by yourself.
|
|
|
|
//This function is implemented by yourself.
|
|
|
|
__timer_start(button_ticks, 0, 5);
|
|
|
|
__timer_start(button_ticks, 0, 5);
|
|
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(btn1_event_val != get_button_event(&btn1)) {
|
|
|
|
if(btn1_event_val != get_button_event(&btn1)) {
|
|
|
|
btn1_event_val = get_button_event(&btn1);
|
|
|
|
btn1_event_val = get_button_event(&btn1);
|
|
|
|
|
|
|
|
|
|
|
|
if(btn1_event_val == PRESS_DOWN) {
|
|
|
|
if(btn1_event_val == PRESS_DOWN) {
|
|
|
|
//do something
|
|
|
|
//do something
|
|
|
|
} else if(btn1_event_val == PRESS_UP) {
|
|
|
|
} else if(btn1_event_val == PRESS_UP) {
|
|
|
|
@ -45,4 +42,3 @@ int main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|