|
|
@@ -24,8 +24,8 @@ static struct button* head_handle = NULL;
|
|
|
|
|
|
/**
|
|
|
* @brief Initializes the button struct handle.
|
|
|
- * @param handle: the button handle strcut.
|
|
|
- * @param pin_level: read the pin of the connet button level.
|
|
|
+ * @param handle: the button handle struct.
|
|
|
+ * @param pin_level: read the pin of the connected button level.
|
|
|
* @param active_level: pin pressed level.
|
|
|
* @retval None
|
|
|
*/
|
|
|
@@ -40,7 +40,7 @@ void button_init(struct button* handle, uint8_t(*pin_level)(void), uint8_t activ
|
|
|
|
|
|
/**
|
|
|
* @brief Attach the button event callback function.
|
|
|
- * @param handle: the button handle strcut.
|
|
|
+ * @param handle: the button handle struct.
|
|
|
* @param event: trigger event type.
|
|
|
* @param cb: callback function.
|
|
|
* @retval None
|
|
|
@@ -52,7 +52,7 @@ void button_attach(struct button* handle, PressEvent event, BtnCallback cb)
|
|
|
|
|
|
/**
|
|
|
* @brief Inquire the button event happen.
|
|
|
- * @param handle: the button handle strcut.
|
|
|
+ * @param handle: the button handle struct.
|
|
|
* @retval button event.
|
|
|
*/
|
|
|
PressEvent get_button_event(struct button* handle)
|
|
|
@@ -62,10 +62,10 @@ PressEvent get_button_event(struct button* handle)
|
|
|
|
|
|
/**
|
|
|
* @brief button driver core function, driver state machine.
|
|
|
- * @param handle: the button handle strcut.
|
|
|
+ * @param handle: the button handle struct.
|
|
|
* @retval None
|
|
|
*/
|
|
|
-void button_handler(struct button* handle)
|
|
|
+static void button_handler(struct button* handle)
|
|
|
{
|
|
|
uint8_t read_gpio_level = handle->hal_button_Level();
|
|
|
|
|
|
@@ -88,7 +88,7 @@ void button_handler(struct button* handle)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // leved not change ,counter reset.
|
|
|
+ // level not change ,counter reset.
|
|
|
handle->debounce_cnt = 0;
|
|
|
}
|
|
|
|
|
|
@@ -169,9 +169,9 @@ void button_handler(struct button* handle)
|
|
|
handle->state = 0;
|
|
|
}
|
|
|
}
|
|
|
- else if(handle->ticks > SHORT_TICKS)
|
|
|
+ else if(handle->ticks > SHORT_TICKS) // SHORT_TICKS < press down hold time < LONG_TICKS
|
|
|
{
|
|
|
- handle->state = 0;
|
|
|
+ handle->state = 1;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -192,12 +192,16 @@ void button_handler(struct button* handle)
|
|
|
handle->state = 0;
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ handle->state = 0; /* reset */
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Start the button work, add the handle into work list.
|
|
|
- * @param handle: target handle strcut.
|
|
|
+ * @param handle: target handle struct.
|
|
|
* @retval 0: succeed. -1: already exist.
|
|
|
*/
|
|
|
int button_start(struct button* handle)
|
|
|
@@ -222,7 +226,7 @@ int button_start(struct button* handle)
|
|
|
|
|
|
/**
|
|
|
* @brief Stop the button work, remove the handle off work list.
|
|
|
- * @param handle: target handle strcut.
|
|
|
+ * @param handle: target handle struct.
|
|
|
* @retval None
|
|
|
*/
|
|
|
void button_stop(struct button* handle)
|