switched LCD code from manual SPI to builtin

This commit is contained in:
bsx 2011-06-15 16:17:42 +02:00
parent 2b40528b88
commit 152f7ade21
3 changed files with 80 additions and 116 deletions

View File

@ -28,8 +28,8 @@ OBJS += $(TARGET)_handlers.o LPC1xxx_startup.o
LDLIBS = -lm LDLIBS = -lm
LDLIBS += -Lmodules -lmodules LDLIBS += -Lmodules -lmodules
LDLIBS += -Lfilesystem -lfat LDLIBS += -Lfilesystem -lfat
LDLIBS += -Lcore -lcore
LDLIBS += -Llcd -llcd LDLIBS += -Llcd -llcd
LDLIBS += -Lcore -lcore
OCFLAGS = --strip-unneeded OCFLAGS = --strip-unneeded
LD_PATH = lpc1xxx LD_PATH = lpc1xxx

View File

@ -1,6 +1,7 @@
#include <display.h> #include <display.h>
#include <sysdefs.h> #include <sysdefs.h>
#include "lpc134x.h" #include "lpc134x.h"
#include "core/ssp/ssp.h"
#include "gpio/gpio.h" #include "gpio/gpio.h"
#include "basic/basic.h" #include "basic/basic.h"
@ -11,152 +12,117 @@
uint8_t lcdBuffer[RESX*RESY_B]; uint8_t lcdBuffer[RESX*RESY_B];
int inverted = 0; int inverted = 0;
#define CS RB_LCD_CS #define TYPE_CMD 0
#define SCK RB_SPI_SCK #define TYPE_DATA 1
#define SDA RB_SPI_MOSI
#define RST RB_LCD_RST
void lcdWrite(uint8_t cd, uint8_t data) static void select() {
{ /* the LCD requires 9-Bit frames */
uint8_t i; uint32_t configReg = ( SSP_SSP0CR0_DSS_9BIT // Data size = 9-bit
| SSP_SSP0CR0_FRF_SPI // Frame format = SPI
gpioSetDir(SDA, 1); | SSP_SSP0CR0_SCR_8); // Serial clock rate = 8
gpioSetValue(SCK, 0); SSP_SSP0CR0 = configReg;
//delayms(0); gpioSetValue(RB_LCD_CS, 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);
} }
void lcdRead(uint8_t data) static void deselect() {
{ gpioSetValue(RB_LCD_CS, 1);
uint8_t i; /* reset the bus to 8-Bit frames that everyone else uses */
uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT // Data size = 8-bit
gpioSetDir(SDA, 1); | SSP_SSP0CR0_FRF_SPI // Frame format = SPI
gpioSetValue(SCK, 0); | SSP_SSP0CR0_SCR_8); // Serial clock rate = 8
delayms(1); SSP_SSP0CR0 = configReg;
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);
} }
void lcdInit(void) static void lcdWrite(uint8_t cd, uint8_t data) {
{ uint16_t frame = 0x0;
//IOCON_SWCLK_PIO0_10 = 0x51;
gpioSetValue(RST, 1);
gpioSetValue(CS, 1);
gpioSetDir(RST, 1); frame = cd << 8;
gpioSetDir(CS, 1); frame |= data;
gpioSetDir(SCK, 1);
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;
}
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);
delayms(100); delayms(100);
gpioSetValue(RST, 0); gpioSetValue(RB_LCD_RST, 0);
delayms(100); delayms(100);
gpioSetValue(RST, 1); gpioSetValue(RB_LCD_RST, 1);
delayms(100); delayms(100);
lcdWrite(0,0xE2); select();
lcdWrite(TYPE_CMD,0xE2);
delayms(5); delayms(5);
lcdWrite(0,0xAF); lcdWrite(TYPE_CMD,0xAF);
lcdWrite(0,0xA4); lcdWrite(TYPE_CMD,0xA4);
lcdWrite(0,0x2F); lcdWrite(TYPE_CMD,0x2F);
lcdWrite(0,0xB0); lcdWrite(TYPE_CMD,0xB0);
lcdWrite(0,0x10); lcdWrite(TYPE_CMD,0x10);
lcdWrite(0,0x00); lcdWrite(TYPE_CMD,0x00);
uint16_t i; uint16_t i;
for(i=0; i<100; i++) for(i=0; i<100; i++)
lcdWrite(1,0x00); lcdWrite(TYPE_DATA,0x00);
deselect();
} }
void lcdFill(char f){ void lcdFill(char f){
int x; int x;
for(x=0;x<RESX*RESY_B;x++) { for(x=0;x<RESX*RESY_B;x++) {
lcdBuffer[x]=f; lcdBuffer[x]=f;
} }
}; };
void lcdSetPixel(char x, char y, bool f){ void lcdSetPixel(char x, char y, bool f){
char y_byte = (RESY-(y+1)) / 8; char y_byte = (RESY-(y+1)) / 8;
char y_off = (RESY-(y+1)) % 8; char y_off = (RESY-(y+1)) % 8;
char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))]; char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))];
if (f) { if (f) {
byte |= (1 << y_off); byte |= (1 << y_off);
} else { } else {
byte &= ~(1 << y_off); byte &= ~(1 << y_off);
} }
lcdBuffer[y_byte*RESX+(RESX-(x+1))] = byte; lcdBuffer[y_byte*RESX+(RESX-(x+1))] = byte;
} }
bool lcdGetPixel(char x, char y){ bool lcdGetPixel(char x, char y){
char y_byte = (RESY-(y+1)) / 8; char y_byte = (RESY-(y+1)) / 8;
char y_off = (RESY-(y+1)) % 8; char y_off = (RESY-(y+1)) % 8;
char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))]; char byte = lcdBuffer[y_byte*RESX+(RESX-(x+1))];
return byte & (1 << y_off); return byte & (1 << y_off);
} }
void lcdDisplay(uint32_t shift) void lcdDisplay(uint32_t shift) {
{ select();
lcdWrite(0,0xB0);
lcdWrite(0,0x10); lcdWrite(TYPE_CMD,0xB0);
lcdWrite(0,0x00); lcdWrite(TYPE_CMD,0x10);
lcdWrite(TYPE_CMD,0x00);
uint16_t i,page; uint16_t i,page;
for(page=0; page<RESY_B;page++) { for(page=0; page<RESY_B;page++) {
for(i=0; i<RESX; i++) { for(i=0; i<RESX; i++) {
if (inverted) { if (inverted) {
lcdWrite(1,~lcdBuffer[page*RESX+((i+shift)%RESX)]); lcdWrite(TYPE_DATA,~lcdBuffer[page*RESX+((i+shift)%RESX)]);
} else { } else {
lcdWrite(1,lcdBuffer[page*RESX+((i+shift)%RESX)]); lcdWrite(TYPE_DATA,lcdBuffer[page*RESX+((i+shift)%RESX)]);
} }
} }
} }
deselect();
} }
void lcdInvert(void) { void lcdInvert(void) {

View File

@ -17,8 +17,6 @@
/* Display buffer */ /* Display buffer */
extern uint8_t lcdBuffer[RESX*RESY_B]; extern uint8_t lcdBuffer[RESX*RESY_B];
void lcdWrite(uint8_t cd, uint8_t data);
void lcdRead(uint8_t data);
void lcdInit(void); void lcdInit(void);
void lcdFill(char f); void lcdFill(char f);
void lcdDisplay(uint32_t shift); void lcdDisplay(uint32_t shift);