2011-07-21 18:01:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-05-11 21:18:46 +00:00
|
|
|
#include <display.h>
|
|
|
|
#include <sysdefs.h>
|
|
|
|
#include "lpc134x.h"
|
2011-06-15 14:17:42 +00:00
|
|
|
#include "core/ssp/ssp.h"
|
2011-05-11 21:18:46 +00:00
|
|
|
#include "gpio/gpio.h"
|
2011-06-13 19:06:09 +00:00
|
|
|
#include "basic/basic.h"
|
2011-06-27 08:43:46 +00:00
|
|
|
#include "usb/usbmsc.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-07-09 21:23:33 +00:00
|
|
|
int lcd_layout = 0;
|
2011-07-12 23:13:19 +00:00
|
|
|
uint32_t intstatus; // Caches USB interrupt state
|
|
|
|
// (need to disable MSC while displaying)
|
2011-05-20 23:12:09 +00:00
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
#define TYPE_CMD 0
|
|
|
|
#define TYPE_DATA 1
|
|
|
|
|
|
|
|
static void select() {
|
2011-07-10 13:32:20 +00:00
|
|
|
#if CFG_USBMSC
|
2011-06-27 08:43:46 +00:00
|
|
|
if(usbMSCenabled){
|
|
|
|
intstatus=USB_DEVINTEN;
|
|
|
|
USB_DEVINTEN=0;
|
|
|
|
};
|
2011-07-10 13:32:20 +00:00
|
|
|
#endif
|
2011-06-15 14:17:42 +00:00
|
|
|
/* the LCD requires 9-Bit frames */
|
|
|
|
uint32_t configReg = ( SSP_SSP0CR0_DSS_9BIT // Data size = 9-bit
|
|
|
|
| SSP_SSP0CR0_FRF_SPI // Frame format = SPI
|
|
|
|
| SSP_SSP0CR0_SCR_8); // Serial clock rate = 8
|
|
|
|
SSP_SSP0CR0 = configReg;
|
|
|
|
gpioSetValue(RB_LCD_CS, 0);
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
static void deselect() {
|
|
|
|
gpioSetValue(RB_LCD_CS, 1);
|
|
|
|
/* reset the bus to 8-Bit frames that everyone else uses */
|
|
|
|
uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT // Data size = 8-bit
|
|
|
|
| SSP_SSP0CR0_FRF_SPI // Frame format = SPI
|
|
|
|
| SSP_SSP0CR0_SCR_8); // Serial clock rate = 8
|
|
|
|
SSP_SSP0CR0 = configReg;
|
2011-07-10 13:32:20 +00:00
|
|
|
#if CFG_USBMSC
|
2011-06-27 08:43:46 +00:00
|
|
|
if(usbMSCenabled){
|
|
|
|
USB_DEVINTEN=intstatus;
|
|
|
|
};
|
2011-07-10 13:32:20 +00:00
|
|
|
#endif
|
2011-06-15 14:17:42 +00:00
|
|
|
}
|
2011-05-11 21:18:46 +00:00
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
static void lcdWrite(uint8_t cd, uint8_t data) {
|
|
|
|
uint16_t frame = 0x0;
|
|
|
|
|
|
|
|
frame = cd << 8;
|
|
|
|
frame |= data;
|
2011-05-11 21:18:46 +00:00
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
while ((SSP_SSP0SR & (SSP_SSP0SR_TNF_NOTFULL | SSP_SSP0SR_BSY_BUSY)) != SSP_SSP0SR_TNF_NOTFULL);
|
|
|
|
SSP_SSP0DR = frame;
|
|
|
|
while ((SSP_SSP0SR & (SSP_SSP0SR_BSY_BUSY|SSP_SSP0SR_RNE_NOTEMPTY)) != SSP_SSP0SR_RNE_NOTEMPTY);
|
|
|
|
/* clear the FIFO */
|
|
|
|
frame = SSP_SSP0DR;
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
void lcdInit(void) {
|
|
|
|
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
|
|
|
|
|
|
|
|
gpioSetValue(RB_LCD_CS, 1);
|
|
|
|
gpioSetValue(RB_LCD_RST, 1);
|
|
|
|
|
|
|
|
gpioSetDir(RB_LCD_CS, gpioDirection_Output);
|
|
|
|
gpioSetDir(RB_LCD_RST, gpioDirection_Output);
|
|
|
|
|
2011-05-11 21:18:46 +00:00
|
|
|
delayms(100);
|
2011-06-15 14:17:42 +00:00
|
|
|
gpioSetValue(RB_LCD_RST, 0);
|
2011-05-11 21:18:46 +00:00
|
|
|
delayms(100);
|
2011-06-15 14:17:42 +00:00
|
|
|
gpioSetValue(RB_LCD_RST, 1);
|
2011-05-11 21:18:46 +00:00
|
|
|
delayms(100);
|
|
|
|
|
2011-06-15 14:17:42 +00:00
|
|
|
select();
|
|
|
|
|
|
|
|
lcdWrite(TYPE_CMD,0xE2);
|
2011-05-11 21:18:46 +00:00
|
|
|
delayms(5);
|
2011-06-15 14:17:42 +00:00
|
|
|
lcdWrite(TYPE_CMD,0xAF);
|
|
|
|
lcdWrite(TYPE_CMD,0xA4);
|
|
|
|
lcdWrite(TYPE_CMD,0x2F);
|
|
|
|
lcdWrite(TYPE_CMD,0xB0);
|
|
|
|
lcdWrite(TYPE_CMD,0x10);
|
|
|
|
lcdWrite(TYPE_CMD,0x00);
|
2011-05-11 21:18:46 +00:00
|
|
|
|
|
|
|
uint16_t i;
|
|
|
|
for(i=0; i<100; i++)
|
2011-06-15 14:17:42 +00:00
|
|
|
lcdWrite(TYPE_DATA,0x00);
|
|
|
|
|
|
|
|
deselect();
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 23:12:09 +00:00
|
|
|
void lcdFill(char f){
|
2011-06-15 14:17:42 +00:00
|
|
|
int x;
|
|
|
|
for(x=0;x<RESX*RESY_B;x++) {
|
|
|
|
lcdBuffer[x]=f;
|
|
|
|
}
|
2011-05-11 21:18:46 +00:00
|
|
|
};
|
|
|
|
|
2011-07-17 10:14:49 +00:00
|
|
|
void lcdSafeSetPixel(char x, char y, bool f){
|
2011-07-17 10:32:19 +00:00
|
|
|
if (x>=0 && x<RESX && y>=0 && y < RESY)
|
2011-07-17 10:14:49 +00:00
|
|
|
lcdSetPixel(x, y, f);
|
|
|
|
}
|
|
|
|
|
2011-06-13 17:55:51 +00:00
|
|
|
void lcdSetPixel(char x, char y, bool f){
|
2011-07-17 10:14:49 +00:00
|
|
|
if (x<0 || x> RESX || y<0 || y > RESY)
|
|
|
|
return;
|
2011-06-15 14:17:42 +00:00
|
|
|
char y_byte = (RESY-(y+1)) / 8;
|
|
|
|
char y_off = (RESY-(y+1)) % 8;
|
|
|
|
char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))];
|
|
|
|
if (f) {
|
|
|
|
byte |= (1 << y_off);
|
|
|
|
} else {
|
|
|
|
byte &= ~(1 << y_off);
|
|
|
|
}
|
|
|
|
lcdBuffer[y_byte*RESX+(RESX-(x+1))] = byte;
|
2011-06-13 17:55:51 +00:00
|
|
|
}
|
2011-06-14 00:20:15 +00:00
|
|
|
|
|
|
|
bool lcdGetPixel(char x, char y){
|
2011-06-15 14:17:42 +00:00
|
|
|
char y_byte = (RESY-(y+1)) / 8;
|
|
|
|
char y_off = (RESY-(y+1)) % 8;
|
|
|
|
char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))];
|
|
|
|
return byte & (1 << y_off);
|
2011-06-14 00:20:15 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 20:09:31 +00:00
|
|
|
void lcdDisplay(void) {
|
2011-07-09 21:23:33 +00:00
|
|
|
char byte;
|
2011-06-15 14:17:42 +00:00
|
|
|
select();
|
|
|
|
|
|
|
|
lcdWrite(TYPE_CMD,0xB0);
|
|
|
|
lcdWrite(TYPE_CMD,0x10);
|
|
|
|
lcdWrite(TYPE_CMD,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-07-09 21:23:33 +00:00
|
|
|
if (lcd_layout & LCD_MIRRORX)
|
2011-07-18 20:09:31 +00:00
|
|
|
byte=lcdBuffer[page*RESX+RESX-1-(i)];
|
2011-07-09 21:23:33 +00:00
|
|
|
else
|
2011-07-18 20:09:31 +00:00
|
|
|
byte=lcdBuffer[page*RESX+(i)];
|
2011-07-09 21:23:33 +00:00
|
|
|
|
|
|
|
if (lcd_layout & LCD_INVERTED)
|
|
|
|
byte=~byte;
|
|
|
|
|
|
|
|
lcdWrite(TYPE_DATA,byte);
|
2011-05-20 23:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 14:17:42 +00:00
|
|
|
|
|
|
|
deselect();
|
2011-05-11 21:18:46 +00:00
|
|
|
}
|
2011-05-22 15:48:02 +00:00
|
|
|
|
2011-07-09 21:23:33 +00:00
|
|
|
inline void lcdInvert(void) {
|
|
|
|
lcdToggleFlag(LCD_INVERTED);
|
2011-05-22 15:48:02 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 21:23:33 +00:00
|
|
|
void lcdToggleFlag(int flag) {
|
|
|
|
lcd_layout=lcd_layout ^ flag;
|
|
|
|
}
|
2011-07-19 00:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void lcdShiftH(bool right, bool wrap) {
|
|
|
|
uint8_t tmp;
|
|
|
|
for (int yb = 0; yb<RESY_B; yb++) {
|
|
|
|
if (right) {
|
|
|
|
tmp = lcdBuffer[yb*RESX];
|
|
|
|
memmove(lcdBuffer + yb*RESX,lcdBuffer + yb*RESX+1 ,RESX-1);
|
|
|
|
if (wrap) lcdBuffer[yb*RESX+(RESX-1)] = tmp;
|
|
|
|
} else {
|
|
|
|
tmp = lcdBuffer[yb*RESX+(RESX-1)];
|
|
|
|
memmove(lcdBuffer + yb*RESX+1,lcdBuffer + yb*RESX ,RESX-1);
|
|
|
|
if (wrap) lcdBuffer[yb*RESX] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdShiftV8(bool up, bool wrap) {
|
|
|
|
uint8_t tmp[RESX];
|
|
|
|
if (up) {
|
|
|
|
if (wrap) memmove(tmp, lcdBuffer, RESX);
|
|
|
|
memmove(lcdBuffer,lcdBuffer+RESX ,RESX*(RESY_B-1));
|
|
|
|
if (wrap) memmove(lcdBuffer+RESX*(RESY_B-1),tmp,RESX);
|
|
|
|
} else {
|
|
|
|
if (wrap) memmove(tmp, lcdBuffer+RESX*(RESY_B-1), RESX);
|
|
|
|
memmove(lcdBuffer+RESX,lcdBuffer ,RESX*(RESY_B-1));
|
|
|
|
if (wrap) memmove(lcdBuffer,tmp,RESX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdShiftV(bool up, bool wrap) {
|
|
|
|
uint8_t tmp[RESX];
|
|
|
|
if (up) {
|
|
|
|
if (wrap) memmove(tmp,lcdBuffer+((RESY_B-1)*RESX),RESX);
|
|
|
|
for (int x = 0; x<RESX; x++){
|
|
|
|
for (int y = RESY_B-1; y > 0; y--){
|
|
|
|
lcdBuffer[x+(y*RESX)] = (lcdBuffer[x+(y*RESX)] << 1) |( lcdBuffer[x+((y-1)*RESX)] >> 7);
|
|
|
|
}
|
|
|
|
if (wrap) lcdBuffer[x] = ( lcdBuffer[x] << 1) | ((tmp[x]>>3)&1);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (wrap) memmove(tmp,lcdBuffer,RESX);
|
|
|
|
for (int x = 0; x<RESX; x++){
|
|
|
|
for (int y = 0; y < (RESY_B-1); y++){
|
|
|
|
lcdBuffer[x+(y*RESX)] = (lcdBuffer[x+(y*RESX)] >> 1) |( lcdBuffer[x+((y+1)*RESX)] << 7);
|
|
|
|
}
|
|
|
|
if (wrap) lcdBuffer[x+((RESY_B-1)*RESX)] = ( lcdBuffer[x+((RESY_B-1)*RESX)] >> 1) | ((tmp[x]<<3)&8);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcdShift(int x, int y, bool wrap) {
|
2011-07-21 18:01:49 +00:00
|
|
|
bool dir=true;
|
2011-07-19 00:43:15 +00:00
|
|
|
|
2011-07-21 18:01:49 +00:00
|
|
|
if(x<0){
|
|
|
|
dir=false;
|
|
|
|
x=-x;
|
|
|
|
};
|
|
|
|
|
|
|
|
while(x-->0)
|
|
|
|
lcdShiftH(dir, wrap);
|
|
|
|
|
|
|
|
if(y<0){
|
|
|
|
dir=false;
|
|
|
|
y=-y;
|
|
|
|
}else{
|
|
|
|
dir=true;
|
|
|
|
};
|
|
|
|
|
|
|
|
while(y>=8){
|
|
|
|
y-=8;
|
|
|
|
lcdShiftV8(dir, wrap);
|
|
|
|
};
|
|
|
|
|
|
|
|
while(y-->0)
|
2011-07-19 00:43:15 +00:00
|
|
|
lcdShiftV(dir, wrap);
|
|
|
|
}
|