Contiki 2.5
lcd.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in
12  * the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of the copyright holders nor the names of
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 /**
31  * \file
32  *
33  * \brief
34  * This file provides Raven LCD support.
35  *
36  * \author
37  * Mike Vidales mavida404@gmail.com
38  *
39  */
40 
41 #ifndef __LCD_H__
42 #define __LCD_H__
43 
44 #include <avr/io.h>
45 #include <avr/interrupt.h>
46 #include <avr/pgmspace.h>
47 
48 #include <stdint.h>
49 #include <stdbool.h>
50 #include <stdlib.h>
51 #include <stdio.h>
52 #include <string.h>
53 
54 
55 #define LCD_SYMBOL_FISRT 0
56 #define LCD_SYMBOL_COUNT 34
57 
58 /* Duplicate usage of segments */
59 #define LCD_SYMBOL_ARR_UP LCD_SYMBOL_ENV_OP
60 #define LCD_SYMBOL_ARR_DN LCD_SYMBOL_ENV_CL
61 
62 #define LCD_CLCK_FRQ 32768
63 
64 /** @name Constant defines for making seg_map[] table */
65 /** @{ */
66 /*
67  - a -
68  f b
69  |-g-|
70  e c
71  - d -
72 */
73 #define NUM_LCD_SYMBOL_A 0x01
74 #define NUM_LCD_SYMBOL_B 0x02
75 #define NUM_LCD_SYMBOL_C 0x04
76 #define NUM_LCD_SYMBOL_D 0x08
77 #define NUM_LCD_SYMBOL_E 0x10
78 #define NUM_LCD_SYMBOL_F 0x20
79 #define NUM_LCD_SYMBOL_G 0x40
80 /** @} */
81 
82 /** @name Constant defines for indexing seg_map[] table */
83 /** @{ */
84 #define LCD_SEV_SEG_INDEX_0 (0)
85 #define LCD_SEV_SEG_INDEX_1 (1)
86 #define LCD_SEV_SEG_INDEX_2 (2)
87 #define LCD_SEV_SEG_INDEX_3 (3)
88 #define LCD_SEV_SEG_INDEX_4 (4)
89 #define LCD_SEV_SEG_INDEX_5 (5)
90 #define LCD_SEV_SEG_INDEX_6 (6)
91 #define LCD_SEV_SEG_INDEX_7 (7)
92 #define LCD_SEV_SEG_INDEX_8 (8)
93 #define LCD_SEV_SEG_INDEX_9 (9)
94 #define LCD_SEV_SEG_INDEX_A (10)
95 #define LCD_SEV_SEG_INDEX_B (11)
96 #define LCD_SEV_SEG_INDEX_C (12)
97 #define LCD_SEV_SEG_INDEX_D (13)
98 #define LCD_SEV_SEG_INDEX_E (14)
99 #define LCD_SEV_SEG_INDEX_F (15)
100 #define LCD_SEV_SEG_INDEX_SPACE (16)
101 #define LCD_SEV_SEG_INDEX_MINUS (17)
102 /** @} */
103 
104 #define lcd_symbol_set_all() lcd_symbol_set_group(0, sizeof(lcd_symbol_chart))
105 #define lcd_symbol_clr_all() lcd_symbol_clr_group(0, sizeof(lcd_symbol_chart))
106 
107 typedef enum {
108  LCD_NUM_PADDING_ZERO,
109  LCD_NUM_PADDING_SPACE
110 } lcd_padding_t;
111 
112 typedef enum {
113 /* name = (bit_number << bit_number_offset) | mem_offset*/
114  /* Raven */
115  LCD_SYMBOL_RAVEN = (7<<5) | 3,
116 
117  /* Audio */
118  LCD_SYMBOL_BELL = (2<<5) | 17,
119  LCD_SYMBOL_TONE = (6<<5) | 17,
120  LCD_SYMBOL_MIC = (3<<5) | 3,
121  LCD_SYMBOL_SPEAKER = (2<<5) | 18,
122 
123  /* Status */
124  LCD_SYMBOL_KEY = (3<<5) | 2,
125  LCD_SYMBOL_ATT = (7<<5) | 2,
126 
127  /* Time */
128  LCD_SYMBOL_SUN = (6<<5) | 13,
129  LCD_SYMBOL_MOON = (6<<5) | 3,
130  LCD_SYMBOL_AM = (2<<5) | 15,
131  LCD_SYMBOL_PM = (6<<5) | 15,
132 
133  /* Radio commuication status */
134  LCD_SYMBOL_RX = (6<<5) | 18,
135  LCD_SYMBOL_TX = (5<<5) | 13,
136  LCD_SYMBOL_IP = (7<<5) | 13,
137  LCD_SYMBOL_PAN = (7<<5) | 18,
138  LCD_SYMBOL_ZLINK = (5<<5) | 8,
139  LCD_SYMBOL_ZIGBEE = (5<<5) | 3,
140 
141  /* Antenna status */
142  LCD_SYMBOL_ANT_FOOT= (5<<5) | 18,
143  LCD_SYMBOL_ANT_SIG1= (3<<5) | 0,
144  LCD_SYMBOL_ANT_SIG2= (7<<5) | 0,
145  LCD_SYMBOL_ANT_SIG3= (3<<5) | 1,
146  LCD_SYMBOL_ANT_DIS = (7<<5) | 1,
147 
148  /* Battery status */
149  LCD_SYMBOL_BAT_CONT= (4<<5) | 18,
150  LCD_SYMBOL_BAT_CAP1= (4<<5) | 3,
151  LCD_SYMBOL_BAT_CAP2= (4<<5) | 8,
152  LCD_SYMBOL_BAT_CAP3= (4<<5) | 13,
153 
154  /* Envelope status */
155  LCD_SYMBOL_ENV_OP = (6<<5) | 8,
156  LCD_SYMBOL_ENV_CL = (0<<5) | 4,
157  LCD_SYMBOL_ENV_MAIN= (2<<5) | 4,
158 
159  /* Temperature */
160  LCD_SYMBOL_C = (6<<5) | 16,
161  LCD_SYMBOL_F = (2<<5) | 16,
162 
163  /* Numeric */
164  LCD_SYMBOL_MINUS = (7<<5) | 8,
165  LCD_SYMBOL_DOT = (4<<5) | 4,
166  LCD_SYMBOL_COL = (6<<5) | 4,
167 } lcd_symbol_t;
168 
169 typedef enum {
170  LCD_WAVE_DEFAULT = 0,
171  LCD_WAVE_LOW_POWER = 1
172 } lcd_wave_t;
173 
174 typedef enum {
175  LCD_BUFFER_ON = 0,
176  LCD_BUFFER_OFF = 1
177 } lcd_buffer_t;
178 
179 typedef enum {
180  LCD_BLANKING_OFF = 0,
181  LCD_BLANKING_ON = 1
182 } lcd_blanking_t;
183 
184 typedef enum {
185  LCD_CLOCK_SYSTEM = 0,
186  LCD_CLOCK_EXTERN = 1
187 } lcd_clock_t;
188 
189 typedef enum {
190  LCD_BIAS_THIRD = 0,
191  LCD_BIAS_HALF = 1
192 } lcd_bias_t;
193 
194 typedef enum {
195  LCD_PRESCL_16 = 0x0,
196  LCD_PRESCL_64 = 0x1,
197  LCD_PRESCL_128 = 0x2,
198  LCD_PRESCL_256 = 0x3,
199  LCD_PRESCL_512 = 0x4,
200  LCD_PRESCL_1024 = 0x5,
201  LCD_PRESCL_2048 = 0x6,
202  LCD_PRESCL_4096 = 0x7,
203 } lcd_prescl_t;
204 
205 typedef enum {
206  LCD_DIV_1 = 0,
207  LCD_DIV_2 = 1,
208  LCD_DIV_3 = 2,
209  LCD_DIV_4 = 3,
210  LCD_DIV_5 = 4,
211  LCD_DIV_6 = 5,
212  LCD_DIV_7 = 6,
213  LCD_DIV_8 = 7
214 } lcd_div_t;
215 
216 /** Bit LCDDC2:0 and LCMDT */
217 typedef enum {
218  LCD_DRIVE_300 = 0x0,
219  LCD_DRIVE_70 = 0x2,
220  LCD_DRIVE_150 = 0x4,
221  LCD_DRIVE_450 = 0x6,
222  LCD_DRIVE_575 = 0x8,
223  LCD_DRIVE_850 = 0xA,
224  LCD_DRIVE_1150 = 0xC,
225  LCD_DRIVE_HALF = 0xE,
226  LCD_DRIVE_FULL = 0xF
227 } lcd_drive_t;
228 
229 typedef enum {
230  LCD_CONTRAST_2_60 = 0x0,
231  LCD_CONTRAST_2_65 = 0x1,
232  LCD_CONTRAST_2_70 = 0x2,
233  LCD_CONTRAST_2_75 = 0x3,
234  LCD_CONTRAST_2_80 = 0x4,
235  LCD_CONTRAST_2_85 = 0x5,
236  LCD_CONTRAST_2_90 = 0x6,
237  LCD_CONTRAST_2_95 = 0x7,
238  LCD_CONTRAST_3_00 = 0x8,
239  LCD_CONTRAST_3_05 = 0x9,
240  LCD_CONTRAST_3_10 = 0xA,
241  LCD_CONTRAST_3_15 = 0xB,
242  LCD_CONTRAST_3_20 = 0xC,
243  LCD_CONTRAST_3_25 = 0xD,
244  LCD_CONTRAST_3_30 = 0xE,
245  LCD_CONTRAST_3_35 = 0xF
246 } lcd_contrast_t;
247 
248 typedef struct {
249  union {
250  struct {
251  unsigned int blanking: 1;
252  unsigned int : 1;
253  unsigned int buffer : 1;
254  unsigned int : 3;
255  unsigned int wave : 1;
256  unsigned int : 1;
257  };
258  uint8_t lcdcra;
259  };
260  union {
261  struct {
262  unsigned int : 6;
263  unsigned int bias : 1;
264  unsigned int clock : 1;
265  };
266  uint8_t lcdcrb;
267  };
268  union {
269  struct {
270  unsigned int div : 3;
271  unsigned int : 1;
272  unsigned int prescl : 3;
273  unsigned int : 1;
274  };
275  uint8_t lcdfrr;
276  };
277  union {
278  struct {
279  unsigned int contrast: 4;
280  unsigned int drive : 4;
281  };
282  uint8_t lcdccr;
283  };
284 } lcd_config_t;
285 
286 /*========================= PUBLIC VARIABLES =========================*/
287 
288 
289 /*========================= PUBLIC FUNCTIONS =========================*/
290 
291 /** Initialization and configuration of the LCD controller
292  *
293  * Example:
294  * \code
295  *
296  * Configuring LCD with Extern clock (TOSC, 32.768kHz)
297  * 32786 Hz 32786 Hz
298  * frame_rate = ------------------ = ------------- = 32 Hz
299  * 8 * .prescl * .div 8 * 16 * 8
300  *
301  * lcd_config_t lcd_config = {
302  * .wave = LCD_WAVE_LOW_POWER,
303  * .buffer = LCD_BUFFER_ON,
304  * .blanking = LCD_BLANKING_OFF,
305  * .clock = LCD_CLOCK_EXTERN,
306  * .bias = LCD_BIAS_HALF,
307  * .prescl = LCD_PRESCL_16,
308  * .div = LCD_DIV_8,
309  * .drive = LCD_DRIVE_450,
310  * .contrast = LCD_CONTRAST_3_30
311  * };
312  *
313  * lcd_init(lcd_config);
314  * \endcode
315 */
316 int lcd_init(void);
317 void lcd_deinit(void);
318 uint8_t itobcd(uint8_t inNumber);
319 
320 /** @name Numeric functions */
321 /** @{ */
322 int lcd_num_puthex(uint16_t numb, lcd_padding_t padding);
323 int lcd_num_putdec(int numb, lcd_padding_t padding);
324 int lcd_num_clr(void);
325 void lcd_single_print_dig(uint8_t numb, uint8_t pos);
326 /** @} */
327 
328 /** @name Text functions */
329 /** @{ */
330 int lcd_puts(const char* s);
331 int lcd_puts_P(const char *s);
332 int lcd_puta(size_t length, const uint8_t *s);
333 int lcd_putchar(unsigned char c);
334 /** @} */
335 
336 /** @name Symbol functions */
337 /** @{ */
338 void lcd_symbol_set(lcd_symbol_t symbol);
339 void lcd_symbol_set_group(int start, int count);
340 void lcd_symbol_clr(lcd_symbol_t symbol);
341 void lcd_symbol_clr_group(int start, int count);
342 /** @} */
343 
344 /** @name LED Functions */
345 /** @{ */
346 void led_on(void);
347 void led_off(void);
348 /** @} */
349 
350 #endif /* __LCD_H__ */
351