This includes all known improvements from other people's spins on the Nokia library, including Alistair Popple's fix to the very poor contrast on newer LCD 6100 displays.
Fork of NokiaLCD by
Diff: NokiaLCD.cpp
- Revision:
- 4:0a17a8a82c4c
- Parent:
- 3:ea0c085881f3
--- a/NokiaLCD.cpp Tue Mar 05 18:52:17 2013 +0000 +++ b/NokiaLCD.cpp Sun Jan 26 23:10:31 2014 +0000 @@ -10,9 +10,9 @@ #define NOKIALCD_COLS 16 #define NOKIALCD_WIDTH 130 #define NOKIALCD_HEIGHT 132 -#define NOKIALCD_FREQUENCY 5000000 +#define NOKIALCD_FREQUENCY 1000000 -NokiaLCD::NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type) +NokiaLCD::NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type, int contrast) : _spi(mosi, NC, sclk) , _rst(rst) , _cs(cs) { @@ -23,11 +23,13 @@ _column = 0; _foreground = 0x00FFFFFF; _background = 0x00000000; + _rows = NOKIALCD_ROWS; + _columns = NOKIALCD_COLS; - reset(); + //reset(contrast); } -void NokiaLCD::reset() { +void NokiaLCD::reset(int contrast) { // setup the SPI interface and bring display out of reset _cs = 1; @@ -43,7 +45,7 @@ switch (_type) { case LCD6100: command(0xCA); // display control - data(0); + data(0xC); data(32); data(0); command(0xBB); @@ -53,14 +55,14 @@ command(0x20); // power control data(0x0F); command(0xA7); // invert display - command(0x81); // Voltage control - data(39); // contrast setting: 0..63 - data(3); // resistance ratio - wait_ms(1); - command(0xBC); + command(0xBC); // data control data(0); data(1); data(4); + command(0x81); // Voltage control + data(contrast);// contrast setting: 0..63 + data(3); // 3 resistance ratio + wait_ms(10); // allow power supply to stabilize command(0xAF); // turn on the display break; @@ -77,7 +79,7 @@ data(0x0F); command(0xA7); // invert display command(0x81); // Voltage control - data(39); // contrast setting: 0..63 + data(contrast);// contrast setting: 0..63 data(3); // resistance ratio wait_ms(1); command(0xBC); @@ -94,7 +96,7 @@ command(0x36); // madctl data(0x60); // vertical RAM, flip x command(0x25); // setcon - data(0x30);// contrast 0x30 + data(contrast);// contrast 0x30 wait_ms(2); command(0x29);//DISPON command(0x03);//BSTRON @@ -337,6 +339,249 @@ _cs = 1; } +void NokiaLCD::circle(int x0, int y0, int r, int colour) { + int draw_x0, draw_y0; + int draw_x1, draw_y1; + int draw_x2, draw_y2; + int draw_x3, draw_y3; + int draw_x4, draw_y4; + int draw_x5, draw_y5; + int draw_x6, draw_y6; + int draw_x7, draw_y7; + int xx, yy; + int di; + + _cs = 0; + _window(x0, y0, 1, 1); + + if(r == 0) /* no radius */ + { + return; + } + + draw_x0 = draw_x1 = x0; + draw_y0 = draw_y1 = y0 + r; + if(draw_y0 < NOKIALCD_HEIGHT) + { + _window(draw_x0, draw_y0, 1, 1); + _putp(colour); /* 90 degree */ + } + + draw_x2 = draw_x3 = x0; + draw_y2 = draw_y3 = y0 - r; + if(draw_y2 >= 0) + { + _window(draw_x2, draw_y2, 1, 1); + _putp(colour); /* 270 degree */ + } + + draw_x4 = draw_x6 = x0 + r; + draw_y4 = draw_y6 = y0; + if(draw_x4 < NOKIALCD_WIDTH) + { + _window(draw_x4, draw_y4, 1, 1); + _putp(colour); /* 0 degree */ + } + + draw_x5 = draw_x7 = x0 - r; + draw_y5 = draw_y7 = y0; + if(draw_x5>=0) + { + _window(draw_x5, draw_y5, 1, 1); + _putp(colour); /* 90 degree */ /* 180 degree */ + } + + if(r == 1) + { + return; + } + + di = 3 - 2*r; + xx = 0; + yy = r; + while(xx < yy) + { + + if(di < 0) + { + di += 4*xx + 6; + } + else + { + di += 4*(xx - yy) + 10; + yy--; + draw_y0--; + draw_y1--; + draw_y2++; + draw_y3++; + draw_x4--; + draw_x5++; + draw_x6--; + draw_x7++; + } + xx++; + draw_x0++; + draw_x1--; + draw_x2++; + draw_x3--; + draw_y4++; + draw_y5++; + draw_y6--; + draw_y7--; + + if( (draw_x0 <= NOKIALCD_WIDTH) && (draw_y0>=0) ) + { + _window(draw_x0, draw_y0, 1, 1); + _putp(colour); + } + + if( (draw_x1 >= 0) && (draw_y1 >= 0) ) + { + _window(draw_x1, draw_y1, 1, 1); + _putp(colour); + } + + if( (draw_x2 <= NOKIALCD_WIDTH) && (draw_y2 <= NOKIALCD_HEIGHT) ) + { + _window(draw_x2, draw_y2, 1, 1); + _putp(colour); + } + + if( (draw_x3 >=0 ) && (draw_y3 <= NOKIALCD_HEIGHT) ) + { + _window(draw_x3, draw_y3, 1, 1); + _putp(colour); + } + + if( (draw_x4 <= /*OLED_DISPLAY_HEIGHT*/NOKIALCD_WIDTH) && (draw_y4 >= 0) ) + { + _window(draw_x4, draw_y4, 1, 1); + _putp(colour); + } + + if( (draw_x5 >= 0) && (draw_y5 >= 0) ) + { + _window(draw_x5, draw_y5, 1, 1); + _putp(colour); + } + if( (draw_x6 <= NOKIALCD_WIDTH) && (draw_y6 <= NOKIALCD_HEIGHT) ) + { + _window(draw_x6, draw_y6, 1, 1); + _putp(colour); + } + if( (draw_x7 >= 0) && (draw_y7 <= NOKIALCD_HEIGHT) ) + { + _window(draw_x7, draw_y7, 1, 1); + _putp(colour); + } + } + _cs = 1; + return; +} + +void NokiaLCD::line(int x0, int y0, int x1, int y1, int colour) { + int dx = 0, dy = 0; + int dx_sym = 0, dy_sym = 0; + int dx_x2 = 0, dy_x2 = 0; + int di = 0; + + _cs = 0; // Chipselect the LCD. + + dx = x1-x0; + dy = y1-y0; + + + if(dx == 0) /* vertical line */ + { + for(int y=y0; y<y1; y++){ + _window(x0, y, 1, 1); + _putp(colour); + } + return; + } + + if(dx > 0) + { + dx_sym = 1; + } + else + { + dx_sym = -1; + } + + + if(dy == 0) /* horizontal line */ + { + for(int x=x0; x<x1; x++){ + _window(x, y0, 1, 1); + _putp(colour); + } + return; + } + + + if(dy > 0) + { + dy_sym = 1; + } + else + { + dy_sym = -1; + } + + dx = dx_sym*dx; + dy = dy_sym*dy; + + dx_x2 = dx*2; + dy_x2 = dy*2; + + if(dx >= dy) + { + di = dy_x2 - dx; + while(x0 != x1) + { + + _window(x0, y0, 1, 1); + _putp(colour); + x0 += dx_sym; + if(di<0) + { + di += dy_x2; + } + else + { + di += dy_x2 - dx_x2; + y0 += dy_sym; + } + } + _window(x0, y0, 1, 1); + _putp(colour); + } + else + { + di = dx_x2 - dy; + while(y0 != y1) + { + _window(x0, y0, 1, 1); + _putp(colour); + y0 += dy_sym; + if(di < 0) + { + di += dx_x2; + } + else + { + di += dx_x2 - dy_x2; + x0 += dx_sym; + } + } + _window(x0, y0, 1, 1); + _putp(colour); + } + _cs = 1; + return; +} + void NokiaLCD::blit(int x, int y, int width, int height, const int* colour) { _cs = 0; _window(x, y, width, height);