Contiki 2.6

lcd.c

00001 /*
00002  * Copyright (c) 2006, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * Author  : Adam Dunkels
00032  */
00033 
00034 #include "lcd.h"
00035 #include "hal_lcd.h"
00036 
00037 #define WITH_LCD 1
00038 
00039 #define Y_MAX 9
00040 #define X_MAX 15
00041 static int xpos, ypos;
00042 
00043 #define X_CHAR_SIZE 8
00044 #define Y_CHAR_SIZE 9
00045 
00046 #define SCROLL_AREA LCD_MAX_SCROLL_AREA
00047 /*---------------------------------------------------------------------------*/
00048 void
00049 lcd_init(void)
00050 {
00051   if(WITH_LCD) {
00052     halLcdInit();
00053     halLcdActive();
00054     halLcdBackLightInit();
00055     halLcdSetBackLight(8);
00056     lcd_clear();
00057   }
00058 }
00059 /*---------------------------------------------------------------------------*/
00060 void
00061 lcd_clear(void)
00062 {
00063   if(WITH_LCD) {
00064     halLcdClearScreen();
00065     xpos = ypos = 0;
00066   }
00067 }
00068 /*---------------------------------------------------------------------------*/
00069 void
00070 lcd_set_pixel(int x, int y, int intensity)
00071 {
00072   if(WITH_LCD) {
00073     halLcdPixel(x, y, intensity);
00074   }
00075 }
00076 /*---------------------------------------------------------------------------*/
00077 static void
00078 inc_y(void)
00079 {
00080   if(WITH_LCD) {
00081     ypos++;
00082     xpos = 0;
00083   }
00084 }
00085 /*---------------------------------------------------------------------------*/
00086 void
00087 lcd_write_char(char c)
00088 {
00089   char string[2];
00090 
00091   if(WITH_LCD) {
00092     if(c == '\n') {
00093       inc_y();
00094     } else {
00095       string[0] = c;
00096       string[1] = 0;
00097 
00098       if(ypos == Y_MAX) {
00099         lcd_clear();
00100         ypos = xpos = 0;
00101       }
00102 
00103       halLcdPrintXY(string, xpos * X_CHAR_SIZE, ypos * Y_CHAR_SIZE, 0);
00104 
00105       if(xpos == X_MAX) {
00106         inc_y();
00107       } else {
00108         xpos++;
00109       }
00110     }
00111   }
00112 }
00113 /*---------------------------------------------------------------------------*/
00114 void
00115 lcd_draw_line(int x0, int y0, int x1, int y1)
00116 {
00117   if(WITH_LCD) {
00118     halLcdLine(x0, y0, x1, y1, 3);
00119   }
00120 }
00121 /*---------------------------------------------------------------------------*/
00122 void
00123 lcd_draw_vertical_line(int pixels)
00124 {
00125   if(WITH_LCD) {
00126     if(pixels > SCROLL_AREA) {
00127       pixels = SCROLL_AREA;
00128     }
00129     lcd_draw_line(LCD_MAX_X, LCD_MAX_Y - pixels, LCD_MAX_X, LCD_MAX_Y);
00130   }
00131 }
00132 /*---------------------------------------------------------------------------*/
00133 void
00134 lcd_scroll_x(void)
00135 {
00136   if(WITH_LCD) {
00137     halLcdHScroll(LCD_MAX_Y - SCROLL_AREA, LCD_MAX_Y);
00138     halLcdLine(LCD_MAX_X, LCD_MAX_Y - SCROLL_AREA, LCD_MAX_X, LCD_MAX_Y, 0);
00139   }
00140 }
00141 /*---------------------------------------------------------------------------*/