47d587bb046f9076564ac57186a374a1bc7cb378
[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 int8_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 # ifdef AO_LCO_HAS_CONTRAST
54 #  define AO_LCO_CONTRAST       -2
55 #  ifndef AO_LCO_BOX_FIRST
56 #   define AO_LCO_BOX_FIRST     AO_LCO_CONTRAST
57 #  endif
58 # endif
59 # ifdef AO_LCO_HAS_BACKLIGHT_UI
60 #  define AO_LCO_BACKLIGHT      -1
61 #  ifndef AO_LCO_BOX_FIRST
62 #   define AO_LCO_BOX_FIRST     AO_LCO_BACKLIGHT
63 #  endif
64 # endif
65 # if AO_LCO_HAS_LCO_INFO
66 #  define AO_LCO_LCO_INFO       0               /* Box number to show LCO info */
67 #  ifndef AO_LCO_BOX_FIRST
68 #   define AO_LCO_BOX_FIRST     AO_LCO_LCO_INFO
69 #  endif
70 # else
71 #  define AO_LCO_LCO_VOLTAGE    -1
72 #  ifndef AO_LCO_BOX_FIRST
73 #   define AO_LCO_BOX_FIRST     AO_LCO_LCO_VOLTAGE
74 #  endif
75 # endif
76 # ifndef AO_LCO_BOX_FIRST
77 #  define AO_LCO_BOX_FIRST      1
78 # endif
79 #endif
80
81 #ifdef AO_LCO_HAS_PAD_INFO
82 # define AO_LCO_PAD_INFO        0               /* Pad number to show box info */
83 # define AO_LCO_PAD_FIRST       AO_LCO_PAD_INFO
84 #else
85 # define AO_LCO_PAD_VOLTAGE     0               /* Pad number to show box voltage */
86 # define AO_LCO_PAD_RSSI        -1              /* Pad number to show box RSSI */
87 # define AO_LCO_PAD_FIRST       AO_LCO_PAD_RSSI
88 #endif
89
90 static inline bool
91 ao_lco_box_pseudo(int16_t box)
92 {
93         switch (box) {
94 #ifdef AO_LCO_LCO_VOLTAGE
95         case AO_LCO_LCO_VOLTAGE:
96                 return true;
97 #endif
98 #ifdef AO_LCO_DRAG_RACE_BOX
99         case AO_LCO_BOX_DRAG:
100                 return true;
101 #endif
102 #ifdef AO_LCO_CONTRAST
103         case AO_LCO_CONTRAST:
104                 return true;
105 #endif
106 #ifdef AO_LCO_BACKLIGHT
107         case AO_LCO_BACKLIGHT:
108                 return true;
109 #endif
110 #ifdef AO_LCO_LCO_INFO
111         case AO_LCO_LCO_INFO:
112                 return true;
113 #endif
114         default:
115                 return false;
116         }
117 }
118
119 static inline bool
120 ao_lco_pad_pseudo(int8_t pad)
121 {
122         switch (pad) {
123 #ifdef AO_LCO_PAD_VOLTAGE
124         case AO_LCO_PAD_VOLTAGE:
125                 return true;
126 #endif
127 #ifdef AO_LCO_PAD_RSSI
128         case AO_LCO_PAD_RSSI:
129                 return true;
130 #endif
131 #ifdef AO_LCO_PAD_INFO
132         case AO_LCO_PAD_INFO:
133                 return true;
134 #endif
135         default:
136                 return false;
137         }
138 }
139
140 extern int16_t  ao_lco_min_box, ao_lco_max_box;
141
142 #define AO_LCO_MASK_SIZE(n)     (((n) + 7) >> 3)
143 #define AO_LCO_MASK_ID(n)       ((n) >> 3)
144 #define AO_LCO_MASK_SHIFT(n)    ((n) & 7)
145
146 extern uint8_t  ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
147
148 #define AO_LCO_VALID_LAST       1
149 #define AO_LCO_VALID_EVER       2
150
151 extern uint8_t  ao_lco_valid[AO_PAD_MAX_BOXES];         /* AO_LCO_VALID bits per box */
152
153 /*
154  * Shared functions
155  */
156
157 void
158 ao_lco_igniter_status(void);
159
160 void
161 ao_lco_update(void);
162
163 uint8_t
164 ao_lco_pad_present(int16_t box, int8_t pad);
165
166 int8_t
167 ao_lco_pad_first(int16_t box);
168
169 void
170 ao_lco_set_pad(int8_t new_pad);
171
172 void
173 ao_lco_step_pad(int8_t dir);
174
175 void
176 ao_lco_set_box(int16_t new_box);
177
178 void
179 ao_lco_step_box(int8_t dir);
180
181 void
182 ao_lco_set_armed(uint8_t armed);
183
184 void
185 ao_lco_set_firing(uint8_t firing);
186
187 void
188 ao_lco_pretend(void);
189
190 void
191 ao_lco_toggle_drag(void);
192
193 void
194 ao_lco_search(void);
195
196 void
197 ao_lco_monitor(void);
198
199 extern int8_t                   ao_lco_drag_beep_count;
200
201 /* enable drag race mode */
202 void
203 ao_lco_drag_enable(void);
204
205 /* disable drag race mode */
206 void
207 ao_lco_drag_disable(void);
208
209 /* Handle drag beeps, return new delay */
210 AO_TICK_TYPE
211 ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
212
213 /* Check if it's time to beep during drag race. Return new delay */
214 AO_TICK_TYPE
215 ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
216
217 /* Request 'beeps' additional drag race beeps */
218 void
219 ao_lco_drag_add_beeps(int8_t beeps);
220
221 /* task function for beeping while arm is active */
222 void
223 ao_lco_arm_warn(void);
224
225 /*
226  * Provided by the hw-specific driver code
227  */
228
229 void
230 ao_lco_show_pad(int8_t pad);
231
232 void
233 ao_lco_show_box(int16_t box);
234
235 void
236 ao_lco_show(void);
237
238 void
239 ao_lco_init(void);
240
241 uint8_t
242 ao_lco_box_present(int16_t box);
243
244 #ifdef AO_LCO_HAS_CONTRAST
245 void
246 ao_lco_set_contrast(int32_t contrast);
247
248 int32_t
249 ao_lco_get_contrast(void);
250 #endif
251
252 #ifdef AO_LCO_HAS_BACKLIGHT
253 void
254 ao_lco_set_backlight(int32_t backlight);
255
256 int32_t
257 ao_lco_get_backlight(void);
258 #endif
259
260 #ifdef AO_LCO_SEARCH_API
261
262 void
263 ao_lco_search_start(void);
264
265 void
266 ao_lco_search_box_check(int16_t box);
267
268 void
269 ao_lco_search_box_present(int16_t box);
270
271 void
272 ao_lco_search_done(void);
273
274 #endif /* AO_LCO_SEARCH_API */
275
276 #endif /* _AO_LCO_H_ */