OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LPC1768_GCC_RedSuite/] [src/] [LCD/] [lcd.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//   +--+       
3
//   | ++----+   
4
//   +-++    |  
5
//     |     |  
6
//   +-+--+  |   
7
//   | +--+--+  
8
//   +----+    Copyright (c) 2009 Code Red Technologies Ltd. 
9
//
10
// lcd.c contains various routines to plot to the LCD display on the RDB1768
11
// development board.
12
//
13
// Software License Agreement
14
// 
15
// The software is owned by Code Red Technologies and/or its suppliers, and is 
16
// protected under applicable copyright laws.  All rights are reserved.  Any 
17
// use in violation of the foregoing restrictions may subject the user to criminal 
18
// sanctions under applicable laws, as well as to civil liability for the breach 
19
// of the terms and conditions of this license.
20
// 
21
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
22
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
23
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
24
// USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
25
// TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
26
// CODE RED TECHNOLOGIES LTD. 
27
 
28
#include "lcd_commands.h"
29
#include "lcd.h"
30
#include "lcd_driver.h"
31
#include "font.h"
32
 
33
#include <stdlib.h>             // to provice abs() function
34
 
35
// Routine to draw a filled rectangle to the LCD.
36
// Two corners of rectangle are at (xmin,ymin) and (xmax,ymax).
37
// The Rectangle is filled with the RGB565 color specified
38
void LCD_FilledRect(int xmin,int xmax,int ymin,int ymax,int color)
39
{
40
    int i;
41
 
42
    // Specify to LCD controller coordinates we are writing to...
43
    LCDdriver_WriteCom(DD_CASET);       // Set the column address
44
    LCDdriver_WriteData(xmin);          // min address
45
    LCDdriver_WriteData(xmax);          // max address
46
    LCDdriver_WriteCom(DD_RASET);       // Set the row address
47
    LCDdriver_WriteData(ymin + 1);      // min address
48
    LCDdriver_WriteData(ymax + 1);      // max address
49
    LCDdriver_WriteCom(DD_RAMWR);       // RAM Write command
50
 
51
    // Plot the color data to the LCD buffer
52
    for(i = ((xmax - xmin + 1) * (ymax - ymin + 1)); i > 0; i--)
53
    {
54
        LCDdriver_WriteData(color >> 8);        // top 8 bits of RGB565 color
55
        LCDdriver_WriteData(color);                     // bottom 8 bits of RGB565 color
56
    }
57
}
58
 
59
// Routine to draw an unfilled rectangle to the LCD.
60
// Two corners of rectangle are at (xmin,ymin) and (xmax,ymax).
61
// The Rectangle is drawn in the RGB565 color specified
62
void LCD_Rect(int xmin,int xmax,int ymin,int ymax,int color)
63
{
64
        // Draw 4 lines of rectange as 4 filled rectanges, each of 1 pixel wide
65
        LCD_FilledRect(xmin,xmin,ymin,ymax,color);
66
        LCD_FilledRect(xmax,xmax,ymin,ymax,color);
67
        LCD_FilledRect(xmin,xmax,ymin,ymin,color);
68
        LCD_FilledRect(xmin,xmax,ymax,ymax,color);
69
}
70
 
71
 
72
 
73
// Plot a point on the screen in the 6:5:6 color format
74
void LCD_PlotPoint(int x,int y,int color)
75
{
76
    LCDdriver_WriteCom(DD_CASET);       // Set the column address 
77
    LCDdriver_WriteData(x);                     // min address
78
    LCDdriver_WriteData(x);                     // max address
79
    LCDdriver_WriteCom(DD_RASET);       // Set the row address
80
    LCDdriver_WriteData(y + 1);         // min address
81
    LCDdriver_WriteData(y + 1);         // max address
82
    LCDdriver_WriteCom(DD_RAMWR);       // RAM Write command
83
    LCDdriver_WriteData(color >> 8);    // top 8 bits of RGB565 color
84
    LCDdriver_WriteData(color);                 // top 8 bits of RGB565 color
85
}
86
 
87
// Routine to draw a filled circle to the LCD.
88
// The centre of the circle is at (x0,y0) and the circle has the 
89
// specifed radius. The circle is filled with the RGB565 color 
90
// The circle is drawn using the "Midpoint circle algorithm", 
91
// also known as "Bresenham's circle algorithm". In order to fill
92
// the circle, the algorithm has been modifed to draw a line between
93
// each two points, rather than plotting the two points individually.
94
void LCD_FilledCircle (int x0, int y0, int radius, int color)
95
{
96
  int f = 1 - radius;
97
  int ddF_x = 1;
98
  int ddF_y = -2 * radius;
99
  int x = 0;
100
  int y = radius;
101
 
102
  LCD_FilledRect(x0, x0 ,y0 - radius,y0 + radius, color);
103
  LCD_FilledRect(x0 - radius, x0 + radius ,y0,y0, color);
104
 
105
  while(x < y)
106
  {
107
    if(f >= 0)
108
    {
109
      y--;
110
      ddF_y += 2;
111
      f += ddF_y;
112
    }
113
    x++;
114
    ddF_x += 2;
115
    f += ddF_x;
116
 
117
    LCD_FilledRect(x0-x, x0+x ,y0 +y, y0 + y, color);
118
    LCD_FilledRect(x0-x, x0+x ,y0 - y, y0 - y, color);
119
    LCD_FilledRect(x0-y, x0+y ,y0 + x, y0 + x, color);
120
    LCD_FilledRect(x0-y, x0+y ,y0 - x, y0 - x, color);
121
  }
122
}
123
 
124
// Routine to draw an unfilled circle to the LCD.
125
// The centre of the circle is at (x0,y0) and the circle has the 
126
// specifed radius. The circle is drawn in the RGB565 color 
127
// The circle is drawn using the "Midpoint circle algorithm", 
128
// also known as "Bresenham's circle algorithm". 
129
void LCD_Circle (int x0, int y0, int radius, int color)
130
{
131
  int f = 1 - radius;
132
  int ddF_x = 1;
133
  int ddF_y = -2 * radius;
134
  int x = 0;
135
  int y = radius;
136
 
137
  LCD_PlotPoint(x0, y0 + radius, color);
138
  LCD_PlotPoint(x0, y0 - radius, color);
139
  LCD_PlotPoint(x0 + radius, y0, color);
140
  LCD_PlotPoint(x0 - radius, y0, color);
141
 
142
  while(x < y)
143
  {
144
    if(f >= 0)
145
    {
146
      y--;
147
      ddF_y += 2;
148
      f += ddF_y;
149
    }
150
    x++;
151
    ddF_x += 2;
152
    f += ddF_x;
153
    LCD_PlotPoint(x0 + x, y0 + y, color);
154
    LCD_PlotPoint(x0 - x, y0 + y, color);
155
    LCD_PlotPoint(x0 + x, y0 - y, color);
156
    LCD_PlotPoint(x0 - x, y0 - y, color);
157
    LCD_PlotPoint(x0 + y, y0 + x, color);
158
    LCD_PlotPoint(x0 - y, y0 + x, color);
159
    LCD_PlotPoint(x0 + y, y0 - x, color);
160
    LCD_PlotPoint(x0 - y, y0 - x, color);
161
  }
162
}
163
 
164
// Routine to draw a line in the RGB565 color to the LCD.
165
// The line is drawn from (xmin,ymin) to (xmax,ymax).
166
// The algorithm used to draw the line is "Bresenham's line
167
// algorithm". 
168
#define SWAP(a, b)  a ^= b; b ^= a; a ^= b; 
169
 
170
void LCD_Line (int xmin,int xmax,int ymin,int ymax,int color)
171
{
172
   int Dx = xmax - xmin;
173
   int Dy = ymax - ymin;
174
   int steep = (abs(Dy) >= abs(Dx));
175
   if (steep) {
176
       SWAP(xmin, ymin);
177
       SWAP(xmax, ymax);
178
       // recompute Dx, Dy after swap
179
       Dx = xmax - xmin;
180
       Dy = ymax - ymin;
181
   }
182
   int xstep = 1;
183
   if (Dx < 0) {
184
       xstep = -1;
185
       Dx = -Dx;
186
   }
187
   int ystep = 1;
188
   if (Dy < 0) {
189
       ystep = -1;
190
       Dy = -Dy;
191
   }
192
   int TwoDy = 2*Dy;
193
   int TwoDyTwoDx = TwoDy - 2*Dx; // 2*Dy - 2*Dx
194
   int E = TwoDy - Dx; //2*Dy - Dx
195
   int y = ymin;
196
   int xDraw, yDraw;
197
   int x;
198
   for (x = xmin; x != xmax; x += xstep) {
199
       if (steep) {
200
           xDraw = y;
201
           yDraw = x;
202
       } else {
203
           xDraw = x;
204
           yDraw = y;
205
       }
206
       // plot
207
       LCD_PlotPoint(xDraw, yDraw, color);
208
       // next
209
       if (E > 0) {
210
           E += TwoDyTwoDx; //E += 2*Dy - 2*Dx;
211
           y = y + ystep;
212
       } else {
213
           E += TwoDy; //E += 2*Dy;
214
       }
215
   }
216
}
217
 
218
// Routine to clear the LCD.
219
// Implemented by drawing a black rectangle across the whole screen
220
void LCD_ClearScreen(void)
221
{
222
        LCD_FilledRect (0,LCD_MAX_X,0 , LCD_MAX_Y, COLOR_BLACK);
223
}
224
 
225
 
226
 
227
// Routine to write a single character to screen in the font pointed
228
// to by pBitMap.  This routine is intended to be used via the 
229
// LCD_PrintChar() and LCD_PrintString() routines, rather than called
230
// directly from user code.
231
void LCD_WriteBitMap8x15(int x, int y, int height, int width, unsigned char *pBitMap, int color)
232
{
233
        int xmax = x + width - 1;       // start at zero
234
        int ymax = y + height - 1;      // start at zero
235
        int iRow, iCol;
236
        unsigned char ucRowData;
237
 
238
    LCDdriver_WriteCom(DD_CASET);       // Column address set
239
    LCDdriver_WriteData(x);             // Start column
240
    LCDdriver_WriteData(xmax);          // End column
241
    LCDdriver_WriteCom(DD_RASET);       // Row address set
242
    LCDdriver_WriteData(y);             // Start row
243
    LCDdriver_WriteData(ymax);          // End row
244
    LCDdriver_WriteCom(DD_RAMWR);       // Memory write
245
 
246
 
247
    for(iRow=0;iRow<height;iRow++)
248
    {
249
        ucRowData = *pBitMap++;
250
 
251
        for(iCol=0;iCol<width;iCol++)
252
        {
253
 
254
                // Look at each input bitmap bit
255
                // and write as a black-pixel or
256
                // a color-pixel.
257
 
258
                if(ucRowData & 0x80)  // 'color pixel'
259
                {
260
                LCDdriver_WriteData(color >> 8);
261
                LCDdriver_WriteData(color);
262
                }
263
                else                            // black pixel
264
                {
265
                        LCDdriver_WriteData(0x00);
266
                LCDdriver_WriteData(0x00);
267
                }
268
 
269
                ucRowData = ucRowData<<1;
270
        }
271
    }
272
 
273
}
274
 
275
 
276
// Prints the character 'c' to the LCD in the appropriate color.
277
void LCD_PrintChar(int x, int y, unsigned char c, int color )
278
{
279
    const unsigned char index = font_index_table[c];
280
    const unsigned int offset = index * 15;
281
    unsigned char *pData = (unsigned char *)&font_data_table[offset];
282
 
283
    LCD_WriteBitMap8x15(x, y, 15, 8, pData, color);
284
}
285
 
286
// Prints the string to the LCD in the appropriate color.
287
void LCD_PrintString(int x, int y, char *pcString, int iStrLen, int color)
288
{
289
    unsigned char index;
290
    unsigned int offset;
291
    unsigned char *pData;
292
    unsigned char c;
293
        int i;
294
 
295
        for(i=0;i<iStrLen;i++)
296
        {
297
                c = pcString[i];
298
                if(c==0)
299
                        break;
300
                index = font_index_table[c];
301
            offset = index * 15;
302
            pData = (unsigned char *)&font_data_table[offset];
303
 
304
            LCD_WriteBitMap8x15(x, y, 15, 8, pData, color);
305
            x += 8;
306
        }
307
 
308
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.