1 /*---------------------------------------------------------------------------*\
2 
3   FILE........: sm1000_leds_switches.h
4   AUTHOR......: David Rowe
5   DATE CREATED: 18 July 2014
6 
7   Functions for controlling LEDs and reading switches on SM1000.
8 
9 \*---------------------------------------------------------------------------*/
10 
11 /*
12   Copyright (C) 2014 David Rowe
13 
14   All rights reserved.
15 
16   This program is free software; you can redistribute it and/or modify
17   it under the terms of the GNU Lesser General Public License version 2.1, as
18   published by the Free Software Foundation.  This program is
19   distributed in the hope that it will be useful, but WITHOUT ANY
20   WARRANTY; without even the implied warranty of MERCHANTABILITY or
21   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
22   License for more details.
23 
24   You should have received a copy of the GNU Lesser General Public License
25   along with this program; if not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #ifndef __LEDS_SWITCHES__
29 #define __LEDS_SWITCHES__
30 
31 #include <stdint.h>
32 
33 void sm1000_leds_switches_init(void);
34 
35 #define	LED_ON	1	/*!< Turn LED on */
36 #define LED_OFF	0	/*!< Turn LED off */
37 #define LED_INV	-1	/*!< Invert LED state */
38 
39 void led_pwr(int state);
40 void led_ptt(int state);
41 void led_rt(int state);
42 void led_err(int state);
43 void not_cptt(int state);
44 
45 int switch_ptt(void);
46 int switch_select(void);
47 int switch_back(void);
48 int ext_ptt(void);
49 
50 #define DEBOUNCE_DELAY 50 /*!< Delay to wait while switch bounces */
51 
52 #define SW_STEADY   0   /*!< Switch is in steady-state */
53 #define SW_DEBOUNCE 1   /*!< Switch is being debounced */
54 
55 /*! Switch debounce and logic handling */
56 struct switch_t {
57     /*! Debounce/hold timer */
58     uint32_t    timer;
59     /*! Current/debounced observed switch state */
60     uint8_t     sw;
61     /*! Raw observed switch state (during debounce) */
62     uint8_t     raw;
63     /*! Last steady-state switch state */
64     uint8_t     last;
65     /*! Debouncer state */
66     uint8_t     state;
67 };
68 
69 /*! Update the state of a switch */
70 void switch_update(struct switch_t* const sw, uint8_t state);
71 
72 /*! Acknowledge the current state of the switch */
73 void switch_ack(struct switch_t* const sw);
74 
75 /*! Return how long the switch has been pressed in ticks. */
76 uint32_t switch_pressed(const struct switch_t* const sw);
77 
78 /*! Return non-zero if the switch has been released. */
79 int switch_released(const struct switch_t* const sw);
80 
81 /*! Count the tick timers on the switches. */
82 void switch_tick(struct switch_t* const sw);
83 
84 void ColorfulRingOfDeath(int code);
85 
86 #endif
87