altos/telelco-v3.0: Add contrast setting
[fw/altos] / src / drivers / ao_lco.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_LCO_H_
20 #define _AO_LCO_H_
21
22 #include <ao_lco_func.h>
23
24 #ifndef AO_LCO_DRAG
25 #define AO_LCO_DRAG     1
26 #endif
27
28 #define DEBUG   1
29
30 #if DEBUG
31 extern uint8_t  ao_lco_debug;
32 #define PRINTD(...) do { if (!ao_lco_debug) break; printf ("\r%5lu %s: ", (unsigned long) ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } while(0)
33 #else
34 #define PRINTD(...) 
35 #endif
36
37 #if AO_LCO_DRAG
38 extern uint8_t  ao_lco_drag_race;       /* true when drag race mode enabled */
39 #endif
40
41 extern uint8_t  ao_lco_pad;             /* Currently selected pad */
42 extern int16_t  ao_lco_box;             /* Currently selected box */
43
44 extern uint8_t  ao_lco_armed;           /* armed mode active */
45 extern uint8_t  ao_lco_firing;          /* fire button pressed */
46
47 extern struct ao_pad_query      ao_pad_query;   /* Last received QUERY from pad */
48
49 #ifdef AO_LCO_DRAG_RACE_BOX
50 #define AO_LCO_BOX_DRAG         0               /* Box number to enable drag race mode (old LCO bits) */
51 #define AO_LCO_BOX_FIRST        AO_LCO_BOX_DRAG
52 #else
53 #define AO_LCO_LCO_VOLTAGE      0               /* Box number to show LCO voltage */
54 # ifdef AO_LCO_HAS_CONTRAST
55 #  define AO_LCO_CONTRAST       -1
56 #  define AO_LCO_BOX_FIRST      AO_LCO_CONTRAST
57 # else
58 #  define AO_LCO_BOX_FIRST      AO_LCO_LCO_VOLTAGE
59 # endif
60 #endif
61 #define AO_LCO_PAD_VOLTAGE      0               /* Pad number to show box voltage */
62
63 static inline bool
64 ao_lco_box_pseudo(int16_t box)
65 {
66         switch (box) {
67 #ifdef AO_LCO_LCO_VOLTAGE
68         case AO_LCO_LCO_VOLTAGE:
69                 return true;
70 #endif
71 #ifdef AO_LCO_DRAG_RACE_BOX
72         case AO_LCO_BOX_DRAG:
73                 return true;
74 #endif
75 #ifdef AO_LCO_CONTRAST
76         case AO_LCO_CONTRAST:
77                 return true;
78 #endif
79         default:
80                 return false;
81         }
82 }
83
84 extern int16_t  ao_lco_min_box, ao_lco_max_box;
85
86 #define AO_LCO_MASK_SIZE(n)     (((n) + 7) >> 3)
87 #define AO_LCO_MASK_ID(n)       ((n) >> 3)
88 #define AO_LCO_MASK_SHIFT(n)    ((n) & 7)
89
90 extern uint8_t  ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
91
92 /*
93  * Shared functions
94  */
95
96 void
97 ao_lco_igniter_status(void);
98
99 void
100 ao_lco_update(void);
101
102 uint8_t
103 ao_lco_pad_present(int16_t box, uint8_t pad);
104
105 uint8_t
106 ao_lco_pad_first(int16_t box);
107
108 void
109 ao_lco_set_pad(uint8_t new_pad);
110
111 void
112 ao_lco_step_pad(int8_t dir);
113
114 void
115 ao_lco_set_box(int16_t new_box);
116
117 void
118 ao_lco_step_box(int8_t dir);
119
120 void
121 ao_lco_set_armed(uint8_t armed);
122
123 void
124 ao_lco_set_firing(uint8_t firing);
125
126 void
127 ao_lco_pretend(void);
128
129 void
130 ao_lco_toggle_drag(void);
131
132 void
133 ao_lco_search(void);
134
135 void
136 ao_lco_monitor(void);
137
138 extern uint8_t                  ao_lco_drag_beep_count;
139
140 /* enable drag race mode */
141 void
142 ao_lco_drag_enable(void);
143
144 /* disable drag race mode */
145 void
146 ao_lco_drag_disable(void);
147
148 /* Handle drag beeps, return new delay */
149 AO_TICK_TYPE
150 ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
151
152 /* Check if it's time to beep during drag race. Return new delay */
153 AO_TICK_TYPE
154 ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
155
156 /* Request 'beeps' additional drag race beeps */
157 void
158 ao_lco_drag_add_beeps(uint8_t beeps);
159
160 /* task function for beeping while arm is active */
161 void
162 ao_lco_arm_warn(void);
163
164 /*
165  * Provided by the hw-specific driver code
166  */
167
168 void
169 ao_lco_show_pad(uint8_t pad);
170
171 void
172 ao_lco_show_box(int16_t box);
173
174 void
175 ao_lco_show(void);
176
177 void
178 ao_lco_init(void);
179
180 uint8_t
181 ao_lco_box_present(int16_t box);
182
183 #ifdef AO_LCO_HAS_CONTRAST
184 void
185 ao_lco_set_contrast(int16_t contrast);
186
187 int16_t
188 ao_lco_get_contrast(void);
189 #endif
190
191 #ifdef AO_LCO_SEARCH_API
192
193 void
194 ao_lco_search_start(void);
195
196 void
197 ao_lco_search_box_check(int16_t box);
198
199 void
200 ao_lco_search_box_present(int16_t box);
201
202 void
203 ao_lco_search_done(void);
204
205 #endif /* AO_LCO_SEARCH_API */
206
207 #endif /* _AO_LCO_H_ */