// PCD8544 (Nokia cellphone LCD) driver for LCDInfo
#define PLUGINGUID "{FA2DF5D2-8333-42e6-9547-795076498BF9}"
#define PLUGINNAME "PCD8544 (Nokia LCD) v0.2 alpha"
#include "..\sdk\component.h"
#include "..\sdk\plugin.h"
#include "..\sdk\displaydriver.h"
#include "..\sdk\configure.h"
#include <windows.h>
#include "WinIo.h"
#include "ks0108font.h"
#include "configuration.h"
class Plugin : public IPlugin
{
virtual void __stdcall onCreate(void)
{
// do startup stuff here
}
virtual void __stdcall onDestroy(void)
{
// do things needed before destroying plugin
}
};
class PCD8544 : public IDisplayDriver
{
public:
virtual bool __stdcall initialize(void)
{
int BASE = readSettingInt("PORT");
int sclk_pin = readSettingInt("SCLK_PIN");
int sda_pin = readSettingInt("SDA_PIN");
int dc_pin = readSettingInt("DC_PIN");
int cs_pin = readSettingInt("CS_PIN");
int reset_pin = readSettingInt("RESET_PIN");
int power_pin = readSettingInt("POWER_PIN");
width = readSettingInt("WIDTH");
height = readSettingInt("HEIGHT");
width = ( width==0 ) ? 84 : width;
height = ( height==0 ) ? 48 : height;
buffersize = width * ((height%8==0) ? height/8 : height/8+1);
delay = 0;
DATA = (BASE==0) ? 0x378 : BASE;
//CONTROL = DATA + 2;
sclk = ( sclk_pin==0 ) ? 2 : sclk_pin;
sda = ( sda_pin==0 ) ? 3 : sda_pin;
dc = ( dc_pin==0 ) ? 6 : dc_pin;
cs = ( cs_pin==0 ) ? 5 : cs_pin;
reset = ( reset_pin==0 ) ? 4 : reset_pin;
power = ( power_pin==0 ) ? 7 : power_pin;
driverinfo.XPixels = width;
driverinfo.YPixels = height;
driverinfo.XChars = width/6;
driverinfo.YChars = height/8;
gfxbuffer = new unsigned char[buffersize];
txtbuffer = new unsigned char[buffersize];
SetPins();
InitializeWinIo();
InitLCD();
clearText();
clearGraph();
return true;
}
virtual void __stdcall unInitialize(void)
{
SetPortVal(DATA, 0, 1); // Power OFF
ShutdownWinIo();
delete gfxbuffer;
delete txtbuffer;
}
virtual int __stdcall configure(void)
{
// launch configuration dialog here if needed
int ret = DialogBox(GetModuleHandle("pcd8544_driver.dll"), MAKEINTRESOURCE(IDD_CONFIGURATION),
NULL, ConfigurationDlgProc);
if(ret == -1)
{
MessageBox(NULL, "Failed loading configuration dialog!", "Error", MB_OK | MB_ICONINFORMATION);
}
return 0;
}
virtual DriverInfo __stdcall getDriverInfo(void)
{
return driverinfo;
}
virtual void __stdcall clearText(void)
{
unsigned char col, page;
ZeroMemory(txtbuffer, buffersize); // clear text buffer
// write only graphics layer to lcd
for(page=0;page<6;page++)
{
SetYAddress(page);
SetXAddress(0);
for(col=0;col<width;col++)
{
WriteData(gfxbuffer[page*width+col]);
}
}
}
virtual void __stdcall clearGraph(void)
{
unsigned char col, page;
ZeroMemory(gfxbuffer, buffersize); // clear graphics buffer
// write only text layer to lcd
for(page=0;page<6;page++)
{
SetYAddress(page);
SetXAddress(0);
for(col=0;col<width;col++)
{
WriteData(txtbuffer[page*width+col]);
}
}
}
virtual void __stdcall writeText(char *string, int x, int y)
{
unsigned int n, i, bufpos;
SetXAddress(x*6);
SetYAddress(y);
for (n = 0;n < strlen(string);n++)
{
for(i=0;i<5;i++)
{
bufpos = y*width+x*6+n*6+i;
txtbuffer[bufpos] = font5x7[((*(string+n)-32))*5+i]; // save font data to text buffer
WriteData(txtbuffer[bufpos] | gfxbuffer[bufpos]); // overlay graphics and text
}
WriteData(gfxbuffer[bufpos+1]);
}
}
virtual void __stdcall writeGraphics(unsigned char *LcdData[], int x, int y, int sizex, int sizey)
{
unsigned char i, col, page, lcdbyte;
int ystartlcd, ysizelcd;
ystartlcd = y/8;
if((y+sizey)%8 == 0) ysizelcd = (sizey >> 3);
else ysizelcd = (sizey >> 3) + 1;
for(page=ystartlcd;page<ystartlcd+ysizelcd;page++)
{
SetYAddress(page);
SetXAddress(x);
for(col=x;col<x+sizex;col++)
{
lcdbyte = 0;
for(i=7;i>0;i--)
{
lcdbyte |= (*LcdData)[page*width*8 + i*width + col] & 1;
lcdbyte <<= 1;
}
lcdbyte |= (*LcdData)[page*width*8 + col] & 1;
gfxbuffer[page*84+col] = lcdbyte;
lcdbyte |= txtbuffer[page*width+col];
WriteData(lcdbyte);
}
}
}
private:
DriverInfo driverinfo;
int DATA;
int CONTROL;
int delay;
int buffersize;
int width;
int height;
unsigned char *gfxbuffer;
unsigned char *txtbuffer;
int sclk, sda, dc, cs, reset, power;
int SCLK_HI, SCLK_LO, SDA_HI, SDA_LO, DC_HI, DC_LO, CS_HI, CS_LO, RESET_HI, RESET_LO, POWER_HI, POWER_LO;
/*
#define SCLK 1
#define SI 2
#define RES 4
#define CE 8
#define DC 16
#define POWER 32
*/
#define PIN2HI 1;
#define PIN2LO 0;
#define PIN3HI 2;
#define PIN3LO 0;
#define PIN4HI 4;
#define PIN4LO 0;
#define PIN5HI 8;
#define PIN5LO 0;
#define PIN6HI 16;
#define PIN6LO 0;
#define PIN7HI 32;
#define PIN7LO 0;
#define PIN8HI 64;
#define PIN8LO 0;
#define PIN9HI 128;
#define PIN9LO 0;
void SetPins(void)
{
switch (sclk)
{
case 2: SCLK_HI = PIN2HI; SCLK_LO = PIN2LO; break;
case 3: SCLK_HI = PIN3HI; SCLK_LO = PIN3LO; break;
case 4: SCLK_HI = PIN4HI; SCLK_LO = PIN4LO; break;
case 5: SCLK_HI = PIN5HI; SCLK_LO = PIN5LO; break;
case 6: SCLK_HI = PIN6HI; SCLK_LO = PIN6LO; break;
case 7: SCLK_HI = PIN7HI; SCLK_LO = PIN7LO; break;
case 8: SCLK_HI = PIN8HI; SCLK_LO = PIN8LO; break;
case 9: SCLK_HI = PIN9HI; SCLK_LO = PIN9LO; break;
}
switch (sda)
{
case 2: SDA_HI = PIN2HI; SDA_LO = PIN2LO; break;
case 3: SDA_HI = PIN3HI; SDA_LO = PIN3LO; break;
case 4: SDA_HI = PIN4HI; SDA_LO = PIN4LO; break;
case 5: SDA_HI = PIN5HI; SDA_LO = PIN5LO; break;
case 6: SDA_HI = PIN6HI; SDA_LO = PIN6LO; break;
case 7: SDA_HI = PIN7HI; SDA_LO = PIN7LO; break;
case 8: SDA_HI = PIN8HI; SDA_LO = PIN8LO; break;
case 9: SDA_HI = PIN9HI; SDA_LO = PIN9LO; break;
}
switch (dc)
{
case 2: DC_HI = PIN2HI; DC_LO = PIN2LO; break;
case 3: DC_HI = PIN3HI; DC_LO = PIN3LO; break;
case 4: DC_HI = PIN4HI; DC_LO = PIN4LO; break;
case 5: DC_HI = PIN5HI; DC_LO = PIN5LO; break;
case 6: DC_HI = PIN6HI; DC_LO = PIN6LO; break;
case 7: DC_HI = PIN7HI; DC_LO = PIN7LO; break;
case 8: DC_HI = PIN8HI; DC_LO = PIN8LO; break;
case 9: DC_HI = PIN9HI; DC_LO = PIN9LO; break;
}
switch (cs)
{
case 2: CS_HI = PIN2HI; CS_LO = PIN2LO; break;
case 3: CS_HI = PIN3HI; CS_LO = PIN3LO; break;
case 4: CS_HI = PIN4HI; CS_LO = PIN4LO; break;
case 5: CS_HI = PIN5HI; CS_LO = PIN5LO; break;
case 6: CS_HI = PIN6HI; CS_LO = PIN6LO; break;
case 7: CS_HI = PIN7HI; CS_LO = PIN7LO; break;
case 8: CS_HI = PIN8HI; CS_LO = PIN8LO; break;
case 9: CS_HI = PIN9HI; CS_LO = PIN9LO; break;
}
switch (reset)
{
case 2: RESET_HI = PIN2HI; RESET_LO = PIN2LO; break;
case 3: RESET_HI = PIN3HI; RESET_LO = PIN3LO; break;
case 4: RESET_HI = PIN4HI; RESET_LO = PIN4LO; break;
case 5: RESET_HI = PIN5HI; RESET_LO = PIN5LO; break;
case 6: RESET_HI = PIN6HI; RESET_LO = PIN6LO; break;
case 7: RESET_HI = PIN7HI; RESET_LO = PIN7LO; break;
case 8: RESET_HI = PIN8HI; RESET_LO = PIN8LO; break;
case 9: RESET_HI = PIN9HI; RESET_LO = PIN9LO; break;
}
switch (power)
{
case 2: POWER_HI = PIN2HI; POWER_LO = PIN2LO; break;
case 3: POWER_HI = PIN3HI; POWER_LO = PIN3LO; break;
case 4: POWER_HI = PIN4HI; POWER_LO = PIN4LO; break;
case 5: POWER_HI = PIN5HI; POWER_LO = PIN5LO; break;
case 6: POWER_HI = PIN6HI; POWER_LO = PIN6LO; break;
case 7: POWER_HI = PIN7HI; POWER