Lightweight proportional text library for C12832 LCD. Easy to modify, fast, robust and compact. Nice font, good for text driven menus, messages, etc. Fell free to use and modify in any projects.
Documentation will be here later.
Usage sample:
Import programapp-board-lcd128
Sample usage of lightweight C12832 LCD library
Diff: lcd128lib.h
- Revision:
- 0:6ac8f630d9a0
- Child:
- 1:17443d6d2740
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcd128lib.h Sat Feb 01 13:13:37 2014 +0000 @@ -0,0 +1,92 @@ +// +// MBED Application Board +// Lightweight C12832 LCD library +// 2014, Alexander Medvedev, @medvdv +// + +// +// BC12832 LCD +// Base geometry: 128 x 32 px +// X - [0..127] pixels +// Y - [0..3] 8 bit rows +// 512 byte total buffer size +// + +#define LCD_X 128 +#define LCD_Y 4 +#define LCD_SIZE 512 + +// +// Proportional font +// + +typedef struct { + char first_code, glyphs_total; + const char* widths; + const char** glyphs; +} lcd128font; + +// +// lcd128 class +// + +class lcd128 { + + // Interface with lcd + SPI spi; + DigitalOut rst, cs, a0; + + // Current font + lcd128font font; + + bool invert; + bool bold; + + // buffer + char buffer[LCD_SIZE]; + + // Cursor position + + int X, Y; + + // Generic SPI writer + void write(char byte, bool cmd = false); + + public: + + // Supply LCD connected pin's here for your design + lcd128(PinName mosi= p5, PinName sclk = p7, PinName a0 = p8, PinName cs = p11, PinName rst = p6); + + // LCD control + void Reset(); // Reset LCD, configure defaults + void Power(bool power = true); // Power off / on + void InverseMode(bool inverse = true); // Invert LCD off / on + + // Buffer -> LCD + void Update(); // Update LCD from buffer, shows all actually + void Clear(int row = -1); // Clear all buffer or one row + + // Write mode + void Invert(bool invert = true); // Switch inverting of chars + void Bold(bool bold = true); // Switch bold mode (repeat each char row twice) + + // Cursor + void XY(int x = 0, int y = 0); // Change write position X in pixels, Y in rows + + // Row write + void Write(char byte); // One 8bit row + void Write(char byte, int count); // One 8bit row * 'count' times + void Write(char* data, int size); // 'size' 8bit rows + void Write2(char* data, int size); // Bold: 'size' 8bit rows * 2 + + // Character drawing + void Character(char chr); // Draw one font character (with invert and bold opt-s) + // ! automaticaly does next line if char is wider then space left + int CharacterWidth(char chr); // Calculate one character width (with bold opt-n) + + // String drawing + void String(char* str); // Draw string proportionally + int StringWidth(char* str); // Calculate string width in px + + void Row(int Y, char* str = ""); // Clear one text row and draw string on it +};