2011-05-11 21:18:46 +00:00
|
|
|
#include <display.h>
|
|
|
|
#include <sysdefs.h>
|
|
|
|
#include "lpc134x.h"
|
|
|
|
#include "gpio/gpio.h"
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
Approximates a 1 millisecond delay using "nop". This is less
|
|
|
|
accurate than a dedicated timer, but is useful in certain situations.
|
|
|
|
|
|
|
|
The number of ticks to delay depends on the optimisation level set
|
|
|
|
when compiling (-O). Depending on the compiler settings, one of the
|
|
|
|
two defined values for 'delay' should be used.
|
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
|
|
|
void delayms(uint32_t ms)
|
|
|
|
{
|
|
|
|
uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45); // Release Mode (-Os)
|
|
|
|
// uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120); // Debug Mode (No optimisations)
|
|
|
|
|
|
|
|
while (delay > 0)
|
|
|
|
{
|
|
|
|
__asm volatile ("nop");
|
|
|
|
delay--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* 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
|
|
|
|
|
|
|
/*
|
|
|
|
//TODO FIXME why doenst that work ?
|
|
|
|
#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
|
|
|
|
|
|
|
#define CS 2,1
|
2011-06-12 20:54:41 +00:00
|
|
|
#define SCK 2,11
|
|
|
|
//#define SCK 2,8
|
2011-05-11 21:18:46 +00:00
|
|
|
#define SDA 0,9
|
2011-06-12 20:54:41 +00:00
|
|
|
//#define SDA 2,8
|
2011-05-11 21:18:46 +00:00
|
|
|
#define RST 2,2
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|