Contiki 3.x
lcd.c
1 /*
2  * Copyright (c) 2006, 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
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * Author : Adam Dunkels
32  */
33 
34 #include "lcd.h"
35 #include "hal_lcd.h"
36 
37 #define WITH_LCD 0
38 
39 #define Y_MAX 9
40 #define X_MAX 15
41 static int xpos, ypos;
42 
43 #define X_CHAR_SIZE 8
44 #define Y_CHAR_SIZE 9
45 
46 #define SCROLL_AREA LCD_MAX_SCROLL_AREA
47 /*---------------------------------------------------------------------------*/
48 void
49 lcd_init(void)
50 {
51  if(WITH_LCD) {
52  halLcdInit();
53  halLcdActive();
54  halLcdBackLightInit();
55  halLcdSetBackLight(8);
56  lcd_clear();
57  }
58 }
59 /*---------------------------------------------------------------------------*/
60 void
61 lcd_clear(void)
62 {
63  if(WITH_LCD) {
64  halLcdClearScreen();
65  xpos = ypos = 0;
66  }
67 }
68 /*---------------------------------------------------------------------------*/
69 void
70 lcd_set_pixel(int x, int y, int intensity)
71 {
72  if(WITH_LCD) {
73  halLcdPixel(x, y, intensity);
74  }
75 }
76 /*---------------------------------------------------------------------------*/
77 static void
78 inc_y(void)
79 {
80  if(WITH_LCD) {
81  ypos++;
82  xpos = 0;
83  }
84 }
85 /*---------------------------------------------------------------------------*/
86 void
87 lcd_write_char(char c)
88 {
89  char string[2];
90 
91  if(WITH_LCD) {
92  if(c == '\n') {
93  inc_y();
94  } else {
95  string[0] = c;
96  string[1] = 0;
97 
98  if(ypos == Y_MAX) {
99  lcd_clear();
100  ypos = xpos = 0;
101  }
102 
103  halLcdPrintXY(string, xpos * X_CHAR_SIZE, ypos * Y_CHAR_SIZE, 0);
104 
105  if(xpos == X_MAX) {
106  inc_y();
107  } else {
108  xpos++;
109  }
110  }
111  }
112 }
113 /*---------------------------------------------------------------------------*/
114 void
115 lcd_draw_line(int x0, int y0, int x1, int y1)
116 {
117  if(WITH_LCD) {
118  halLcdLine(x0, y0, x1, y1, 3);
119  }
120 }
121 /*---------------------------------------------------------------------------*/
122 void
123 lcd_draw_vertical_line(int pixels)
124 {
125  if(WITH_LCD) {
126  if(pixels > SCROLL_AREA) {
127  pixels = SCROLL_AREA;
128  }
129  lcd_draw_line(LCD_MAX_X, LCD_MAX_Y - pixels, LCD_MAX_X, LCD_MAX_Y);
130  }
131 }
132 /*---------------------------------------------------------------------------*/
133 void
134 lcd_scroll_x(void)
135 {
136  if(WITH_LCD) {
137  halLcdHScroll(LCD_MAX_Y - SCROLL_AREA, LCD_MAX_Y);
138  halLcdLine(LCD_MAX_X, LCD_MAX_Y - SCROLL_AREA, LCD_MAX_X, LCD_MAX_Y, 0);
139  }
140 }
141 /*---------------------------------------------------------------------------*/
int lcd_init(void)
This function will initialize the proper settings for the LCD driver.
Definition: lcd.c:277