sm1000_leds_switches: Re-locate switch debounce code.
authorsjlongland <sjlongland@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 24 Sep 2015 08:12:00 +0000 (08:12 +0000)
committersjlongland <sjlongland@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 24 Sep 2015 08:12:00 +0000 (08:12 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2362 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/inc/sm1000_leds_switches.h
codec2-dev/stm32/src/sm1000_leds_switches.c
codec2-dev/stm32/src/sm1000_main.c

index b98f74df6629ec1ffc2770aa3f8ef687c9b894cd..a7fadd4f1b9bb5e609343ad0599fab7b9de34e1a 100644 (file)
@@ -41,6 +41,35 @@ int switch_select(void);
 int switch_back(void);
 int ext_ptt(void);
 
+/*! Switch debounce and logic handling */
+struct switch_t {
+    /*! Debounce/hold timer */
+    uint32_t    timer;
+    /*! Current/debounced observed switch state */
+    uint8_t     sw;
+    /*! Raw observed switch state (during debounce) */
+    uint8_t     raw;
+    /*! Last steady-state switch state */
+    uint8_t     last;
+    /*! Debouncer state */
+    uint8_t     state;
+};
+
+/*! Update the state of a switch */
+void switch_update(struct switch_t* const sw, uint8_t state);
+
+/*! Acknowledge the current state of the switch */
+void switch_ack(struct switch_t* const sw);
+
+/*! Return how long the switch has been pressed in ticks. */
+uint32_t switch_pressed(const struct switch_t* const sw);
+
+/*! Return non-zero if the switch has been released. */
+int switch_released(const struct switch_t* const sw);
+
+/*! Count the tick timers on the switches. */
+void switch_tick(struct switch_t* const sw);
+
 void ColorfulRingOfDeath(int code);
 
 #endif
index aa633711fc218a5c2712bfffa449b2bee054d3d3..b08d533384095181ca874fed74dac83a104c9a77 100644 (file)
@@ -158,3 +158,64 @@ void HardFault_Handler(void) { ColorfulRingOfDeath(1); }
 void MemManage_Handler(void) { ColorfulRingOfDeath(2); }
 void BusFault_Handler(void)  { ColorfulRingOfDeath(3); }
 void UsageFault_Handler(void){ ColorfulRingOfDeath(4); }
+
+
+static void switch_tick(struct switch_t* const sw)
+{
+    if (sw->sw != sw->raw) {
+        /* State transition, reset timer */
+        if (sw->state == SW_STEADY)
+            sw->last = sw->sw;
+        sw->state = SW_DEBOUNCE;
+        sw->timer = DEBOUNCE_DELAY;
+        sw->sw = sw->raw;
+    } else if (sw->state == SW_DEBOUNCE) {
+        if (sw->timer > 0) {
+            /* Steady so far, keep waiting */
+            sw->timer--;
+        } else {
+            /* Steady state reached */
+            sw->state = SW_STEADY;
+        }
+    } else if (sw->sw) {
+        /* Hold state.  Yes this will wrap, but who cares? */
+        sw->timer++;
+    }
+}
+
+void switch_update(struct switch_t* const sw, uint8_t state)
+{
+    sw->raw = state;
+    if (sw->raw == sw->sw)
+        return;
+
+    if (sw->state == SW_STEADY)
+        sw->last = sw->sw;
+    sw->timer = DEBOUNCE_DELAY;
+    sw->sw = sw->raw;
+    sw->state = SW_DEBOUNCE;
+}
+
+uint32_t switch_pressed(const struct switch_t* const sw)
+{
+    if ((sw->state == SW_STEADY) && sw->sw)
+        return sw->timer;
+    return 0;
+}
+
+int switch_released(const struct switch_t* const sw)
+{
+    if (sw->state != SW_STEADY)
+        return 0;
+    if (!sw->last)
+        return 0;
+    if (sw->sw)
+        return 0;
+    return 1;
+}
+
+void switch_ack(struct switch_t* const sw)
+{
+    if (sw->state == SW_STEADY)
+        sw->last = sw->sw;
+}
index 8b7f983b3babc98ed9e339a2088791b2b6dfbdd4..22c183e48baa97fde4d21e66cb451bd46c7776df 100644 (file)
 #define SW_STEADY   0   /*!< Switch is in steady-state */
 #define SW_DEBOUNCE 1   /*!< Switch is being debounced */
 
-/*! Switch debounce and logic handling */
-struct switch_t {
-    /*! Debounce/hold timer */
-    uint32_t    timer;
-    /*! Current/debounced observed switch state */
-    uint8_t     sw;
-    /*! Raw observed switch state (during debounce) */
-    uint8_t     raw;
-    /*! Last steady-state switch state */
-    uint8_t     last;
-    /*! Debouncer state */
-    uint8_t     state;
-};
-
 struct switch_t sw_select;  /*!< Switch driver for SELECT button */
 struct switch_t sw_back;    /*!< Switch driver for BACK button */
 struct switch_t sw_ptt;     /*!< Switch driver for PTT buttons */
 
-/*!
- * Count the tick timers on the switches.
- */
-static void switch_tick(struct switch_t* const sw);
-
-/*!
- * Update the state of a switch
- */
-static void switch_update(struct switch_t* const sw, uint8_t state);
-
-/*! Return how long the switch has been pressed in ticks. */
-static uint32_t switch_pressed(const struct switch_t* const sw);
-
-/*! Return non-zero if the switch has been released. */
-static int switch_released(const struct switch_t* const sw);
-
-/*! Acknowledge the current state of the switch */
-static void switch_ack(struct switch_t* const sw);
-
 unsigned int announceTicker = 0;
 
 /*!
@@ -329,63 +296,3 @@ void SysTick_Handler(void)
         announceTicker--;
     }
 }
-
-static void switch_tick(struct switch_t* const sw)
-{
-    if (sw->sw != sw->raw) {
-        /* State transition, reset timer */
-        if (sw->state == SW_STEADY)
-            sw->last = sw->sw;
-        sw->state = SW_DEBOUNCE;
-        sw->timer = DEBOUNCE_DELAY;
-        sw->sw = sw->raw;
-    } else if (sw->state == SW_DEBOUNCE) {
-        if (sw->timer > 0) {
-            /* Steady so far, keep waiting */
-            sw->timer--;
-        } else {
-            /* Steady state reached */
-            sw->state = SW_STEADY;
-        }
-    } else if (sw->sw) {
-        /* Hold state.  Yes this will wrap, but who cares? */
-        sw->timer++;
-    }
-}
-
-static void switch_update(struct switch_t* const sw, uint8_t state)
-{
-    sw->raw = state;
-    if (sw->raw == sw->sw)
-        return;
-
-    if (sw->state == SW_STEADY)
-        sw->last = sw->sw;
-    sw->timer = DEBOUNCE_DELAY;
-    sw->sw = sw->raw;
-    sw->state = SW_DEBOUNCE;
-}
-
-static uint32_t switch_pressed(const struct switch_t* const sw)
-{
-    if ((sw->state == SW_STEADY) && sw->sw)
-        return sw->timer;
-    return 0;
-}
-
-static int switch_released(const struct switch_t* const sw)
-{
-    if (sw->state != SW_STEADY)
-        return 0;
-    if (!sw->last)
-        return 0;
-    if (sw->sw)
-        return 0;
-    return 1;
-}
-
-static void switch_ack(struct switch_t* const sw)
-{
-    if (sw->state == SW_STEADY)
-        sw->last = sw->sw;
-}