display.h
1 /* *************************************************************************************************
2  *
3  * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the
16  * distribution.
17  *
18  * Neither the name of Texas Instruments Incorporated nor the names of
19  * its contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * *************************************************************************************************
35  * Basic display functions.
36  * ************************************************************************************************/
37 
38 #ifndef DISPLAY_H
39 #define DISPLAY_H
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #define CLOCK_24HR (0)
46 #define CLOCK_AM_PM (1)
47 #define CLOCK_DISPLAY_SELECT (2)
48 
49 
50 /* *************************************************************************************************
51  * Global Variable section */
52 
54 typedef union {
55  struct {
56  /* Line1 + Line2 + Icons*/
57  uint16_t full_update : 1;
58  uint16_t partial_update : 1;
60  /* Line only */
61  uint16_t line1_full_update : 1;
62  uint16_t line2_full_update : 1;
64  /* Logic module data update flags */
65  uint16_t update_time : 1;
66  uint16_t update_stopwatch : 1;
67  uint16_t update_temperature : 1;
68  uint16_t update_battery_voltage : 1;
69  uint16_t update_date : 1;
70  uint16_t update_alarm : 1;
71  uint16_t update_acceleration : 1;
72  } flag;
73  uint16_t all_flags;
75 
76 extern volatile s_display_flags_t display;
77 
78 /* Constants defined in library */
79 extern const uint8_t lcd_font[];
80 extern const uint8_t *segments_lcdmem[];
81 extern const uint8_t segments_bitmask[];
82 extern const uint8_t itoa_conversion_table[][3];
83 
84 /* ************************************************************************************************* */
85 /* Defines section */
86 
87 /* Display function modes */
88 #define DISPLAY_LINE_UPDATE_FULL (BIT0)
89 #define DISPLAY_LINE_UPDATE_PARTIAL (BIT1)
90 #define DISPLAY_LINE_CLEAR (BIT2)
91 
92 /* Definitions for line view style */
93 #define DISPLAY_DEFAULT_VIEW (0u)
94 #define DISPLAY_ALTERNATIVE_VIEW (1u)
95 #define DISPLAY_ALTERNATIVE2_VIEW (2u)
96 
97 /* Definitions for line access */
98 #define LINE1 (1u)
99 #define LINE2 (2u)
100 
101 /* LCD display modes */
102 #define SEG_OFF (0u)
103 #define SEG_ON (1u)
104 #define SEG_ON_BLINK_ON (2u)
105 #define SEG_ON_BLINK_OFF (3u)
106 #define SEG_OFF_BLINK_OFF (4u)
107 
108 /* 7-segment character bit assignments */
109 #define SEG_A (BIT4)
110 #define SEG_B (BIT5)
111 #define SEG_C (BIT6)
112 #define SEG_D (BIT7)
113 #define SEG_E (BIT2)
114 #define SEG_F (BIT0)
115 #define SEG_G (BIT1)
116 
117 /* ------------------------------------------
118  * LCD symbols for easier access
119  *
120  * xxx_SEG_xxx = Seven-segment character (sequence 5-4-3-2-1-0)
121  * xxx_SYMB_xxx = Display symbol, e.g. "AM" for ante meridiem
122  * xxx_UNIT_xxx = Display unit, e.g. "km/h" for kilometers per hour
123  * xxx_ICON_xxx = Display icon, e.g. heart to indicate reception of heart rate data
124  * xxx_L1_xxx = Item is part of Line1 information
125  * xxx_L2_xxx = Item is part of Line2 information
126  */
127 
128 //* Symbols for Line1 */
129 #define LCD_SYMB_AM 0
130 #define LCD_SYMB_PM 1
131 #define LCD_SYMB_ARROW_UP 2
132 #define LCD_SYMB_ARROW_DOWN 3
133 #define LCD_SYMB_PERCENT 4
134 
135 /* Symbols for Line2 */
136 #define LCD_SYMB_TOTAL 5
137 #define LCD_SYMB_AVERAGE 6
138 #define LCD_SYMB_MAX 7
139 #define LCD_SYMB_BATTERY 8
140 
141 /* Units for Line1 */
142 #define LCD_UNIT_L1_FT 9
143 #define LCD_UNIT_L1_K 10
144 #define LCD_UNIT_L1_M 11
145 #define LCD_UNIT_L1_I 12
146 #define LCD_UNIT_L1_PER_S 13
147 #define LCD_UNIT_L1_PER_H 14
148 #define LCD_UNIT_L1_DEGREE 15
149 
150 /* Units for Line2 */
151 #define LCD_UNIT_L2_KCAL 16
152 #define LCD_UNIT_L2_KM 17
153 #define LCD_UNIT_L2_MI 18
154 
155 /* Icons */
156 #define LCD_ICON_HEART 19
157 #define LCD_ICON_STOPWATCH 20
158 #define LCD_ICON_RECORD 21
159 #define LCD_ICON_ALARM 22
160 #define LCD_ICON_BEEPER1 23
161 #define LCD_ICON_BEEPER2 24
162 #define LCD_ICON_BEEPER3 25
163 
164 /* Line1 7-segments */
165 #define LCD_SEG_L1_3 26
166 #define LCD_SEG_L1_2 27
167 #define LCD_SEG_L1_1 28
168 #define LCD_SEG_L1_0 29
169 #define LCD_SEG_L1_COL 30
170 #define LCD_SEG_L1_DP1 31
171 #define LCD_SEG_L1_DP0 32
172 
173 /* Line2 7-segments */
174 #define LCD_SEG_L2_5 33
175 #define LCD_SEG_L2_4 34
176 #define LCD_SEG_L2_3 35
177 #define LCD_SEG_L2_2 36
178 #define LCD_SEG_L2_1 37
179 #define LCD_SEG_L2_0 38
180 #define LCD_SEG_L2_COL1 39
181 #define LCD_SEG_L2_COL0 40
182 #define LCD_SEG_L2_DP 41
183 
184 /* Line1 7-segment arrays */
185 #define LCD_SEG_L1_3_0 70
186 #define LCD_SEG_L1_2_0 71
187 #define LCD_SEG_L1_1_0 72
188 #define LCD_SEG_L1_3_1 73
189 #define LCD_SEG_L1_3_2 74
190 
191 /* Line2 7-segment arrays */
192 #define LCD_SEG_L2_5_0 90
193 #define LCD_SEG_L2_4_0 91
194 #define LCD_SEG_L2_3_0 92
195 #define LCD_SEG_L2_2_0 93
196 #define LCD_SEG_L2_1_0 94
197 #define LCD_SEG_L2_5_2 95
198 #define LCD_SEG_L2_3_2 96
199 #define LCD_SEG_L2_5_4 97
200 #define LCD_SEG_L2_4_2 98
201 
202 /* LCD controller memory map */
203 #define LCD_MEM_1 ((uint8_t*)0x0A20)
204 #define LCD_MEM_2 ((uint8_t*)0x0A21)
205 #define LCD_MEM_3 ((uint8_t*)0x0A22)
206 #define LCD_MEM_4 ((uint8_t*)0x0A23)
207 #define LCD_MEM_5 ((uint8_t*)0x0A24)
208 #define LCD_MEM_6 ((uint8_t*)0x0A25)
209 #define LCD_MEM_7 ((uint8_t*)0x0A26)
210 #define LCD_MEM_8 ((uint8_t*)0x0A27)
211 #define LCD_MEM_9 ((uint8_t*)0x0A28)
212 #define LCD_MEM_10 ((uint8_t*)0x0A29)
213 #define LCD_MEM_11 ((uint8_t*)0x0A2A)
214 #define LCD_MEM_12 ((uint8_t*)0x0A2B)
215 
216 /* Memory assignment */
217 #define LCD_SEG_L1_0_MEM (LCD_MEM_6)
218 #define LCD_SEG_L1_1_MEM (LCD_MEM_4)
219 #define LCD_SEG_L1_2_MEM (LCD_MEM_3)
220 #define LCD_SEG_L1_3_MEM (LCD_MEM_2)
221 #define LCD_SEG_L1_COL_MEM (LCD_MEM_1)
222 #define LCD_SEG_L1_DP1_MEM (LCD_MEM_1)
223 #define LCD_SEG_L1_DP0_MEM (LCD_MEM_5)
224 #define LCD_SEG_L2_0_MEM (LCD_MEM_8)
225 #define LCD_SEG_L2_1_MEM (LCD_MEM_9)
226 #define LCD_SEG_L2_2_MEM (LCD_MEM_10)
227 #define LCD_SEG_L2_3_MEM (LCD_MEM_11)
228 #define LCD_SEG_L2_4_MEM (LCD_MEM_12)
229 #define LCD_SEG_L2_5_MEM (LCD_MEM_12)
230 #define LCD_SEG_L2_COL1_MEM (LCD_MEM_1)
231 #define LCD_SEG_L2_COL0_MEM (LCD_MEM_5)
232 #define LCD_SEG_L2_DP_MEM (LCD_MEM_9)
233 #define LCD_SYMB_AM_MEM (LCD_MEM_1)
234 #define LCD_SYMB_PM_MEM (LCD_MEM_1)
235 #define LCD_SYMB_ARROW_UP_MEM (LCD_MEM_1)
236 #define LCD_SYMB_ARROW_DOWN_MEM (LCD_MEM_1)
237 #define LCD_SYMB_PERCENT_MEM (LCD_MEM_5)
238 #define LCD_SYMB_TOTAL_MEM (LCD_MEM_11)
239 #define LCD_SYMB_AVERAGE_MEM (LCD_MEM_10)
240 #define LCD_SYMB_MAX_MEM (LCD_MEM_8)
241 #define LCD_SYMB_BATTERY_MEM (LCD_MEM_7)
242 #define LCD_UNIT_L1_FT_MEM (LCD_MEM_5)
243 #define LCD_UNIT_L1_K_MEM (LCD_MEM_5)
244 #define LCD_UNIT_L1_M_MEM (LCD_MEM_7)
245 #define LCD_UNIT_L1_I_MEM (LCD_MEM_7)
246 #define LCD_UNIT_L1_PER_S_MEM (LCD_MEM_5)
247 #define LCD_UNIT_L1_PER_H_MEM (LCD_MEM_7)
248 #define LCD_UNIT_L1_DEGREE_MEM (LCD_MEM_5)
249 #define LCD_UNIT_L2_KCAL_MEM (LCD_MEM_7)
250 #define LCD_UNIT_L2_KM_MEM (LCD_MEM_7)
251 #define LCD_UNIT_L2_MI_MEM (LCD_MEM_7)
252 #define LCD_ICON_HEART_MEM (LCD_MEM_2)
253 #define LCD_ICON_STOPWATCH_MEM (LCD_MEM_3)
254 #define LCD_ICON_RECORD_MEM (LCD_MEM_1)
255 #define LCD_ICON_ALARM_MEM (LCD_MEM_4)
256 #define LCD_ICON_BEEPER1_MEM (LCD_MEM_5)
257 #define LCD_ICON_BEEPER2_MEM (LCD_MEM_6)
258 #define LCD_ICON_BEEPER3_MEM (LCD_MEM_7)
259 
260 /* Bit masks for write access */
261 #define LCD_SEG_L1_0_MASK (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
262 #define LCD_SEG_L1_1_MASK (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
263 #define LCD_SEG_L1_2_MASK (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
264 #define LCD_SEG_L1_3_MASK (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
265 #define LCD_SEG_L1_COL_MASK (BIT5)
266 #define LCD_SEG_L1_DP1_MASK (BIT6)
267 #define LCD_SEG_L1_DP0_MASK (BIT2)
268 #define LCD_SEG_L2_0_MASK (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
269 #define LCD_SEG_L2_1_MASK (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
270 #define LCD_SEG_L2_2_MASK (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
271 #define LCD_SEG_L2_3_MASK (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
272 #define LCD_SEG_L2_4_MASK (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
273 #define LCD_SEG_L2_5_MASK (BIT7)
274 #define LCD_SEG_L2_COL1_MASK (BIT4)
275 #define LCD_SEG_L2_COL0_MASK (BIT0)
276 #define LCD_SEG_L2_DP_MASK (BIT7)
277 #define LCD_SYMB_AM_MASK (BIT1+BIT0)
278 #define LCD_SYMB_PM_MASK (BIT0)
279 #define LCD_SYMB_ARROW_UP_MASK (BIT2)
280 #define LCD_SYMB_ARROW_DOWN_MASK (BIT3)
281 #define LCD_SYMB_PERCENT_MASK (BIT4)
282 #define LCD_SYMB_TOTAL_MASK (BIT7)
283 #define LCD_SYMB_AVERAGE_MASK (BIT7)
284 #define LCD_SYMB_MAX_MASK (BIT7)
285 #define LCD_SYMB_BATTERY_MASK (BIT7)
286 #define LCD_UNIT_L1_FT_MASK (BIT5)
287 #define LCD_UNIT_L1_K_MASK (BIT6)
288 #define LCD_UNIT_L1_M_MASK (BIT1)
289 #define LCD_UNIT_L1_I_MASK (BIT0)
290 #define LCD_UNIT_L1_PER_S_MASK (BIT7)
291 #define LCD_UNIT_L1_PER_H_MASK (BIT2)
292 #define LCD_UNIT_L1_DEGREE_MASK (BIT1)
293 #define LCD_UNIT_L2_KCAL_MASK (BIT4)
294 #define LCD_UNIT_L2_KM_MASK (BIT5)
295 #define LCD_UNIT_L2_MI_MASK (BIT6)
296 #define LCD_ICON_HEART_MASK (BIT3)
297 #define LCD_ICON_STOPWATCH_MASK (BIT3)
298 #define LCD_ICON_RECORD_MASK (BIT7)
299 #define LCD_ICON_ALARM_MASK (BIT3)
300 #define LCD_ICON_BEEPER1_MASK (BIT3)
301 #define LCD_ICON_BEEPER2_MASK (BIT3)
302 #define LCD_ICON_BEEPER3_MASK (BIT3)
303 
304 
305 /* *************************************************************************************************
306  * API section
307  */
308 
309 /* Physical LCD memory write */
310 /* *************************************************************************************************
311  * @fn write_segment
312  * @brief Write to one or multiple LCD segments
313  * @param lcdmem Pointer to LCD byte memory
314  * bits Segments to address
315  * bitmask Bitmask for particular display item
316  * mode On, off or blink segments
317  * @return
318  * ************************************************************************************************/
319 void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state);
320 
321 /* Display init / clear */
322 /* *************************************************************************************************
323  * @fn lcd_init
324  * @brief Erase LCD memory. Init LCD peripheral.
325  * @param none
326  * @return none
327  * ************************************************************************************************/
328 void lcd_init(void);
329 
330 /* *************************************************************************************************
331  * @fn clear_display
332  * @brief Erase LINE1 and LINE2 segments. Keep icons.
333  * @param none
334  * @return none
335  * ************************************************************************************************/
336 void clear_display(void);
337 
338 /* *************************************************************************************************
339  * @fn clear_display_all
340  * @brief Erase LINE1 and LINE2 segments. Clear also function-specific content.
341  * @param none
342  * @return none
343  * ************************************************************************************************/
344 void clear_display_all(void);
345 
346 /* *************************************************************************************************
347  * @fn clear_line
348  * @brief Erase segments of a given line.
349  * @param uint8_t line LINE1, LINE2
350  * @return none
351  * ************************************************************************************************/
352 void clear_line(uint8_t line);
353 
354 /* Blinking function */
355 /* *************************************************************************************************
356  * @fn start_blink
357  * @brief Start blinking.
358  * @param none
359  * @return none
360  * ************************************************************************************************/
361 void start_blink(void);
362 
363 /* *************************************************************************************************
364  * @fn stop_blink
365  * @brief Stop blinking.
366  * @param none
367  * @return none
368  * ************************************************************************************************/
369 void stop_blink(void);
370 
371 /* *************************************************************************************************
372  * @fn stop_blink
373  * @brief Clear blinking memory.
374  * @param none
375  * @return none
376  * ************************************************************************************************/
377 void clear_blink_mem(void);
378 
379 /* *************************************************************************************************
380  * @fn set_blink_rate
381  * @brief Set blink rate register bits.
382  * @param none
383  * @return none
384  * ************************************************************************************************/
385 void set_blink_rate(uint8_t bits);
386 
387 /* Character / symbol draw functions */
388 /* *************************************************************************************************
389  * @fn display_char
390  * @brief Write to 7-segment characters.
391  * @param uint8_t segment A valid LCD segment
392  * uint8_t chr Character to display
393  * uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK
394  * @return none
395  * ************************************************************************************************/
396 void display_char(uint8_t segment, char chr, uint8_t mode);
397 
398 /* *************************************************************************************************
399  * @FN display_chars
400  * @brief Write to consecutive 7-segment characters.
401  * @param uint8_t segments LCD segment array
402  * uint8_t * str Pointer to a string
403  * uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK
404  * @return none
405  * ************************************************************************************************/
406 void display_chars(uint8_t segments, char *str, uint8_t mode);
407 
408 /* *************************************************************************************************
409  * @fn display_symbol
410  * @brief Switch symbol on or off on LCD.
411  * @param uint8_t symbol A valid LCD symbol (index 0..42)
412  * uint8_t state SEG_ON, SEG_OFF, SEG_BLINK
413  * @return none
414  * ************************************************************************************************/
415 void display_symbol(uint8_t symbol, uint8_t mode);
416 
417 /* Set_value display functions */
418 /* *************************************************************************************************
419  * @fn display_value1
420  * @brief Generic decimal display routine. Used exclusively by set_value function.
421  * @param uint8_t segments LCD segments where value is displayed
422  * uint32_t value Integer value to be displayed
423  * uint8_t digits Number of digits to convert
424  * uint8_t blanks Number of leadings blanks in itoa result string
425  * @return none
426  * ************************************************************************************************/
427 void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode);
428 
429 /* Integer to string conversion */
430 /* *************************************************************************************************
431  * @fn itoa
432  * @brief Generic integer to array routine. Converts integer n to string.
433  * Default conversion result has leading zeros, e.g. "00123"
434  * Option to convert leading '0' into whitespace (blanks)
435  * @param uint32_t n integer to convert
436  * uint8_t digits number of digits
437  * uint8_t blanks fill up result string with number of whitespaces instead of leading zeros
438  * @return uint8_t string
439  * ************************************************************************************************/
440 char *itoa(uint32_t n, uint8_t digits, uint8_t blanks);
441 
442 /* Segment index helper function */
443 /* *************************************************************************************************
444  * @fn switch_seg
445  * @brief Returns index of 7-segment character. Required for display routines that can draw
446  * information on both lines.
447  * @param uint8_t line LINE1, LINE2
448  * uint8_t index1 Index of LINE1
449  * uint8_t index2 Index of LINE2
450  * @return uint8
451  * ************************************************************************************************/
452 uint8_t switch_seg(uint8_t line, uint8_t index1, uint8_t index2);
453 
454 /* *************************************************************************************************
455  * @fn display_all_off
456  * @brief Sets everything of on the display
457  * @param none
458  * @return none
459  * ************************************************************************************************/
460 void display_all_off(void);
461 
462 #ifdef __cplusplus
463 }
464 #endif
465 
466 #endif /* DISPLAY_H */
uint16_t all_flags
Shortcut to all display flags (for reset)
Definition: display.h:73
Set of display flags.
Definition: display.h:54