2011-05-11 21:18:46 +00:00
|
|
|
#include <display.h>
|
|
|
|
#include <sysdefs.h>
|
|
|
|
#include "lpc134x.h"
|
|
|
|
#include "gpio/gpio.h"
|
2011-06-13 19:06:09 +00:00
|
|
|
#include "basic/basic.h"
|
2011-05-11 21:18:46 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Utility routines to manage nokia display */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
uint8_t lcdBuffer[RESX*RESY_B];
|
2011-05-22 15:48:02 +00:00
|
|
|
int inverted = 0;
|
2011-05-20 23:12:09 +00:00
|
|
|
|
2011-06-13 22:16:14 +00:00
|
|
|
#define CS RB_LCD_CS
|
|
|
|
#define SCK RB_SPI_SCK
|
|
|
|
#define SDA RB_SPI_MOSI
|
|
|
|
#define RST RB_LCD_RST
|
2011-05-11 21:18:46 +00:00
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdWrite(uint8_t cd, uint8_t data)
|
2011-05-11 21:18:46 +00:00
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
gpioSetDir(SDA, 1);
|
|
|
|
gpioSetValue(SCK, 0);
|
|
|
|
//delayms(0);
|
|
|
|
gpioSetValue(CS, 0);
|
|
|
|
//delayms(0);
|
|
|
|
|
|
|
|
gpioSetValue(SDA, cd);
|
|
|
|
//delayms(0);
|
|
|
|
gpioSetValue(SCK, 1);
|
|
|
|
//delayms(0);
|
|
|
|
|
|
|
|
for(i=0; i<8; i++){
|
|
|
|
gpioSetValue(SCK, 0);
|
|
|
|
//delayms(0);
|
|
|
|
if( data & 0x80 )
|
|
|
|
gpioSetValue(SDA, 1);
|
|
|
|
else
|
|
|
|
gpioSetValue(SDA, 0);
|
|
|
|
data <<= 1;
|
|
|
|
gpioSetValue(SCK, 1);
|
|
|
|
//delayms(1);
|
|
|
|
}
|
|
|
|
gpioSetValue(CS, 0);
|
|
|
|
//delayms(0);
|
|
|
|
}
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdRead(uint8_t data)
|
2011-05-11 21:18:46 +00:00
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
gpioSetDir(SDA, 1);
|
|
|
|
gpioSetValue(SCK, 0);
|
|
|
|
delayms(1);
|
|
|
|
gpioSetValue(CS, 0);
|
|
|
|
delayms(1);
|
|
|
|
|
|
|
|
gpioSetValue(SDA, 0);
|
|
|
|
delayms(1);
|
|
|
|
gpioSetValue(SCK, 1);
|
|
|
|
delayms(1);
|
|
|
|
|
|
|
|
for(i=0; i<8; i++){
|
|
|
|
gpioSetValue(SCK, 0);
|
|
|
|
delayms(1);
|
|
|
|
if( data & 0x80 )
|
|
|
|
gpioSetValue(SDA, 1);
|
|
|
|
else
|
|
|
|
gpioSetValue(SDA, 0);
|
|
|
|
data <<= 1;
|
|
|
|
gpioSetValue(SCK, 1);
|
|
|
|
delayms(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gpioSetDir(SDA, 0);
|
|
|
|
for(i=0; i<8; i++){
|
|
|
|
gpioSetValue(SCK, 0);
|
|
|
|
delayms(1);
|
|
|
|
gpioSetValue(SCK, 1);
|
|
|
|
delayms(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gpioSetValue(CS, 0);
|
|
|
|
delayms(1);
|
|
|
|
}
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdInit(void)
|
2011-05-11 21:18:46 +00:00
|
|
|
{
|
2011-06-12 20:54:41 +00:00
|
|
|
//IOCON_SWCLK_PIO0_10 = 0x51;
|
2011-05-11 21:18:46 +00:00
|
|
|
gpioSetValue(RST, 1);
|
|
|
|
gpioSetValue(CS, 1);
|
|
|
|
|
|
|
|
gpioSetDir(RST, 1);
|
|
|
|
gpioSetDir(CS, 1);
|
|
|
|
gpioSetDir(SCK, 1);
|
|
|
|
|
|
|
|
|
|
|
|
delayms(100);
|
|
|
|
gpioSetValue(RST, 0);
|
|
|
|
delayms(100);
|
|
|
|
gpioSetValue(RST, 1);
|
|
|
|
delayms(100);
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdWrite(0,0xE2);
|
2011-05-11 21:18:46 +00:00
|
|
|
delayms(5);
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdWrite(0,0xAF);
|
|
|
|
lcdWrite(0,0xA4);
|
|
|
|
lcdWrite(0,0x2F);
|
|
|
|
lcdWrite(0,0xB0);
|
|
|
|
lcdWrite(0,0x10);
|
|
|
|
lcdWrite(0,0x00);
|
2011-05-11 21:18:46 +00:00
|
|
|
|
|
|
|
uint16_t i;
|
|
|
|
for(i=0; i<100; i++)
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdWrite(1,0x00);
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdFill(char f){
|
2011-05-11 21:18:46 +00:00
|
|
|
int x;
|
2011-05-20 23:12:09 +00:00
|
|
|
for(x=0;x<RESX*RESY_B;x++) {
|
|
|
|
lcdBuffer[x]=f;
|
|
|
|
}
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
|
|
|
|
2011-06-13 17:55:51 +00:00
|
|
|
void lcdSetPixel(char x, char y, bool f){
|
|
|
|
char y_byte = (RESY-(y+1)) / 8;
|
|
|
|
char y_off = (RESY-(y+1)) % 8;
|
|
|
|
char byte = lcdBuffer[y_byte*RESX+(RESX-x)%RESX];
|
|
|
|
if (f) {
|
|
|
|
byte |= (1 << y_off);
|
|
|
|
} else {
|
|
|
|
byte &= ~(1 << y_off);
|
|
|
|
}
|
|
|
|
lcdBuffer[y_byte*RESX+(RESX-x)%RESX] = byte;
|
|
|
|
}
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdDisplay(uint32_t shift)
|
2011-05-11 21:18:46 +00:00
|
|
|
{
|
2011-05-20 23:12:09 +00:00
|
|
|
lcdWrite(0,0xB0);
|
|
|
|
lcdWrite(0,0x10);
|
|
|
|
lcdWrite(0,0x00);
|
2011-05-11 21:18:46 +00:00
|
|
|
uint16_t i,page;
|
2011-05-20 23:12:09 +00:00
|
|
|
for(page=0; page<RESY_B;page++) {
|
|
|
|
for(i=0; i<RESX; i++) {
|
2011-05-22 15:48:02 +00:00
|
|
|
if (inverted) {
|
|
|
|
lcdWrite(1,~lcdBuffer[page*RESX+((i+shift)%RESX)]);
|
|
|
|
} else {
|
|
|
|
lcdWrite(1,lcdBuffer[page*RESX+((i+shift)%RESX)]);
|
|
|
|
}
|
2011-05-20 23:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
2011-05-22 15:48:02 +00:00
|
|
|
|
|
|
|
void lcdInvert(void) {
|
|
|
|
inverted = ~inverted;
|
|
|
|
}
|
|
|
|
|