#include "lcd.h"
#include "defines.h"
//***************************************************************
// Function: clearLCD
// Description: LCD clear screen
// Parameters: -
// Return value: -
//***************************************************************
void clearLCD(){
if(fpClearLCD)
{
setCursor(0,0);
(*fpClearLCD)();
f
setCursor(0,0);
}
}
//***************************************************************
// Function: draw
// Description: send a byte to LCD
// Parameters: value: value to be sent to LCD via SPI
// Return value: -
//***************************************************************
void draw(unsigned char value)
{
spi(value);
}
unsigned char lcdXpos; // x cursor position for LCD
unsigned char lcdYpos; // y cursor position for LCD
unsigned int fgColor; // foreground color for LCD (xRGB)
unsigned int bgColor; // background color for LCD (xRGB)
//***************************************************************
// Function: getCursor
// Description: returns current virtual cursor position of LCD
// Parameters: *y: pointer to current y position
// *x: pointer to current x position
// Return value: -
//***************************************************************
void getCursor(unsigned char *y, unsigned char *x)
{
*x = lcdXpos;
*y = lcdYpos;
}
//***************************************************************
// Function: setCursor
// Description: set virtual cursor position of LCD
// Parameters: y: y position
// x: x position
// Return value: -
//***************************************************************
void setCursor(unsigned char y, unsigned char x)
{
lcdXpos = x;
lcdYpos = y;
if(fpCursor)
{
(*fpCursor)(y, x);
}
}
//***************************************************************
// Function: lcdColor
// Description: set colors for LCD output
// Parameters: fc: forground color
// bc: background color
// Return value: -
//***************************************************************
void lcdColor(unsigned int fc, unsigned int bc)
{
fgColor = fc;
bgColor = bc;
}
//***************************************************************
// Function: displayFlashText
// Description: show a text stored in flash on LCD
// Parameters: *c: pointer to text string
// Return value: -
//**************************************************************
/*
void displayFlashText( char *c)
{
flash unsigned char *pFont;
unsigned char i, j;
unsigned char x, y, value, mask;
getCursor(&y, &x);
while(*c)
{
window_LM15(x, y, x+7, y+13);
x += 8;
P_LCD_CD = 0;
P_LCD_CS = 0;
pFont = &charMap[((unsigned int)(*c) - 32) * 14];
for(i = 0; i < 14; i++)
{struct menuitem Date;
value = *pFont;
mask = 0x80;
for(j = 0; j < 8; j++)
{
if(value & mask)
{
draw(fgColor >> 8);
draw(fgColor & 0xFF);
}
else
{
draw(bgColor >> 8);
draw(bgColor & 0xFF);
}
mask >>= 1;
}
pFont++;
}
P_LCD_CS = 1;
c++;
}
}*/
//***************************************************************
// Function: lcdChar
// Description: show a character stored in RAM on LCD
// Parameters: c: character
// Return value: -
//***************************************************************
void lcdChar(char c)
{
flash unsigned char *pFont;
unsigned char i, j;
unsigned char x, y, value, mask;
getCursor(&y, &x);
window_LM15(x, y, x+7, y+13);
x += 8;
P_LCD_CD = 0;
P_LCD_CS = 0;
pFont = &charMap[((unsigned int)(c) - 32) * 14];
for(i = 0; i < 14; i++)
{
value = *pFont;
mask = 0x80;
for(j = 0; j < 8; j++)
{
if(value & mask)
{
draw(fgColor >> 8);
draw(fgColor & 0xFF);
}
else
{
draw(bgColor >> 8);
draw(bgColor & 0xFF);
}
mask >>= 1;
}
pFont++;
}
P_LCD_CS = 1;
setCursor(y, x);
}
//***************************************************************
// Function: lcdText
// Description: show a text stored in RAM on LCD
// Parameters: *c: pointer to text string
// Return value: -
//***************************************************************
void lcdText(char *c)
{
while(*c)
{
lcdChar(*c);
c++;
}
}
//***************************************************************
// Function: setPixel
// Description: draws a pixel on LCD
// Parameters: x: x coordinate
// y: y coordinate
// Return value: -
//***************************************************************
void setPixel(unsigned char x, unsigned char y)
{
setCursor(y, x);
P_LCD_CD = 0;
P_LCD_CS = 0;
draw(fgColor >> 8);
draw(fgColor & 0xFF);
P_LCD_CS = 1;
}
//***************************************************************
// Function: lcdLine
// Description: draws a line on LCD
// Parameters: xstart: x start coordinate
// ystart: y start coordinate
// xend: x end coordinate
// yend: y end coordinate
// Return value: -
//***************************************************************
void lcdLine(int xstart, int ystart, int xend, int yend)
{
int x, y, t, dist, xerr, yerr, dx, dy, incx, incy;
/* Entfernung in beiden Dimensionen berechnen */
dx = xend - xstart;
dy = yend - ystart;
/* Vorzeichen des Inkrements bestimmen */
if(dx<0)
{
incx = -1;
dx = -dx;
}
else
incx = dx ? 1 : 0;
if(dy < 0)
{
incy = -1;
dy = -dy;
}
else
incy = dy ? 1 : 0;
/* feststellen, welche Entfernung größer ist */
dist = (dx > dy)?dx:dy;
/* Initialisierungen vor Schleifenbeginn */
x = xstart;
y = ystart;
xerr = yerr = (dist) >> 1; //dx;
// yerr = dist >> 1; //dy1;
/* Pixel berechnen */
for(t = 0; t < dist; ++t)
{
setPixel(x, y);
xerr += dx;
yerr += dy;
if(xerr >= dist)
{
xerr -= dist;
x += incx;
}
if(yerr >= dist)
{
yerr -= dist;
y += incy;
}
}
setPixel(xend, yend);
}