Commit d662e59b authored by Raptor Engineering Development Team's avatar Raptor Engineering Development Team
Browse files

Debounce button presses in software

parent b7b0adb9
......@@ -32,6 +32,8 @@ static struct k_thread kestrel_service_thread_data;
#define KESTREL_IDLE_THREAD_PRIORITY K_PRIO_PREEMPT(CONFIG_NUM_PREEMPT_PRIORITIES - 1)
#define BUTTON_PRESS_DEBOUNCE_DELAY_MS 200
static void kestrel_init_thread(void)
{
kestrel_init();
......@@ -60,6 +62,8 @@ static void kestrel_service_thread(void)
void host_power_button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
static uint64_t last_press = 0;
int want_power_on = 0;
int want_power_off = 0;
......@@ -78,16 +82,23 @@ void host_power_button_pressed(const struct device *dev, struct gpio_callback *c
// Re-activate interupts on exiting critical section
irq_unlock(key);
if ((k_uptime_get() - last_press) > BUTTON_PRESS_DEBOUNCE_DELAY_MS) {
// The debounce delay has passed since last press, handle request
if (want_power_on) {
power_on_host();
}
else if (want_power_off) {
power_off_chassis();
}
}
last_press = k_uptime_get();
}
void host_reset_button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
static uint64_t last_press = 0;
// Deactivate interrupts on entering critical section
int key = irq_lock();
......@@ -97,7 +108,12 @@ void host_reset_button_pressed(const struct device *dev, struct gpio_callback *c
// Re-activate interupts on exiting critical section
irq_unlock(key);
if ((k_uptime_get() - last_press) > BUTTON_PRESS_DEBOUNCE_DELAY_MS) {
// The debounce delay has passed since last press, handle request
LOG_WRN("[FIXME] Reset button pressed, but not implemented!");
}
last_press = k_uptime_get();
}
static int configure_gpios(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment