light text library for 5110 nokia lcd * easy to modify * proportional font, bold / inverse modes * easy to add / change fonts * fixed rows for fast update
Library finished! :-) If you use 5110 and need fast menus - try this library. No overhead - small and robust, optimized for this display type only, fast update. Nice looking font. Power management. Displays from 5110 and 3110 are cheap as dirt :-)
Diff: medvdv5110.cpp
- Revision:
- 2:65df20ffef51
- Parent:
- 1:cce4622d70f6
- Child:
- 4:82917c164f2b
diff -r cce4622d70f6 -r 65df20ffef51 medvdv5110.cpp --- a/medvdv5110.cpp Tue Sep 25 16:03:34 2012 +0000 +++ b/medvdv5110.cpp Fri Dec 07 21:41:54 2012 +0000 @@ -1,12 +1,14 @@ // // 5110 LCD Driver -// (c) 2012 medvdv.com +// (c) 2012 @medvdv // Alexander Medvedev // #include "mbed.h" #include "medvdv5110.h" +// Nice proportional font with 8px height + const char lcd_font8p_widths[] = { 2, 1, 3, 5, 5, 5, 5, 1, 2, 2, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 6, 5, 6, 5, 6, 5, 5, 5, 5, 5, 5, 5, 5, 3, @@ -110,13 +112,12 @@ (const char[]){ 0x00, 0x7F }, (const char[]){ 0x00, 0x41, 0x36, 0x08 }, (const char[]){ 0x08, 0x04, 0x08, 0x10, 0x08 }, - (const char[]) { - 0x2A, 0x55, 0x2A, 0x55 - } + (const char[]){ 0x2A, 0x55, 0x2A, 0x55 } }; -// Internals +// lcd5110 - Internals +// Generic SPI writer void lcd5110::write(char data, bool cmd) { sce -> write(0); @@ -125,8 +126,9 @@ sce -> write(1); } -// Public +// lcd5110 - Public +// Supply LCD pin's here lcd5110::lcd5110(PinName mosi, PinName sclk, PinName dc, PinName sce, PinName rst) { spi = new SPI(mosi, NC, sclk); @@ -138,6 +140,7 @@ this -> sce = new DigitalOut(sce); this -> dc = new DigitalOut(dc); + // Setup default font font.first_code = 32; font.glyphs_total = 128 - 32; font.widths = lcd_font8p_widths; @@ -145,18 +148,23 @@ invert = false; bold = false; + + contrast = DEFAULT_CONTRAST; } +// Start inverting chars void lcd5110::Invert(bool invert) { this -> invert = invert; } +// Start bold mode (repeat twice wide) void lcd5110::Bold(bool bold) { this -> bold = bold; } +// Reset LCD, configure defaults and contrast void lcd5110::Reset() { rst -> write(0); @@ -171,6 +179,7 @@ XY(); } +// Change contrast void lcd5110::Contrast(char contrast) { this -> contrast = contrast; @@ -179,23 +188,22 @@ write(0x20, true); } -void lcd5110::Init() -{ - contrast = DEFAULT_CONTRAST; - Reset(); -} - +// LCD power off void lcd5110::PowerOff() { // TBD } +// Clear - fill all by 8bit line 'pattern' void lcd5110::Clear(char pattern) { Write(pattern,504); XY(); } +// Change current output position +// X in pixels [0..83] +// Y in rows [0..5] void lcd5110::XY(int x, int y) { if (x<0) x=0; @@ -210,6 +218,8 @@ write( 0x40 | (y & 0x3f), true); } +// Write one 8bit row +// with inversion and XY update void lcd5110::Write(char byte) { write(invert?(~byte):byte, false); @@ -219,11 +229,13 @@ } } +// Write array of 8bit rows void lcd5110::Write(char* data, int size) { for(int i=0; i<size; i++) Write(data[i]); } +// Write array of 8bit rows, twice each void lcd5110::Write2(char* data, int size) { for(int i=0; i<size; i++) { @@ -232,11 +244,13 @@ } } +// Write 8bit row 'count' times void lcd5110::Write(char byte, int count) { for(int i=0; i<count; i++) Write(byte); } +// Draw one font character void lcd5110::Character(char chr) { if( chr < font.first_code ) return; @@ -265,6 +279,8 @@ } } +// Calculate width of concrete character +// accounts bold setting int lcd5110::CharacterWidth(char chr) { if( chr < font.first_code ) return 0; @@ -278,11 +294,13 @@ return font.widths[chr] + 1; } +// Write string void lcd5110::String(char* str) { while(*str) Character(*str++); } +// Predict string width int lcd5110::StringWidth(char* str) { int width = 0; @@ -292,6 +310,8 @@ return width; } +// Clear one line, +// then write string from it's begin void lcd5110::Row(int Y, char* str) { XY(0, Y); @@ -300,6 +320,7 @@ String(str); } +// Remove pin objects's lcd5110::~lcd5110() { delete spi;