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
lcd128lib.h@4:1bd241d1fad0, 2014-05-26 (annotated)
- Committer:
- medvdv
- Date:
- Mon May 26 20:14:58 2014 +0000
- Revision:
- 4:1bd241d1fad0
- Parent:
- 3:c0e409cda493
- Child:
- 5:ff31feb7d966
comments updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
medvdv | 0:6ac8f630d9a0 | 1 | // |
medvdv | 0:6ac8f630d9a0 | 2 | // MBED Application Board |
medvdv | 0:6ac8f630d9a0 | 3 | // Lightweight C12832 LCD library |
medvdv | 0:6ac8f630d9a0 | 4 | // 2014, Alexander Medvedev, @medvdv |
medvdv | 0:6ac8f630d9a0 | 5 | // |
medvdv | 0:6ac8f630d9a0 | 6 | |
medvdv | 0:6ac8f630d9a0 | 7 | // |
medvdv | 0:6ac8f630d9a0 | 8 | // BC12832 LCD |
medvdv | 0:6ac8f630d9a0 | 9 | // Base geometry: 128 x 32 px |
medvdv | 0:6ac8f630d9a0 | 10 | // X - [0..127] pixels |
medvdv | 0:6ac8f630d9a0 | 11 | // Y - [0..3] 8 bit rows |
medvdv | 0:6ac8f630d9a0 | 12 | // 512 byte total buffer size |
medvdv | 0:6ac8f630d9a0 | 13 | // |
medvdv | 0:6ac8f630d9a0 | 14 | |
medvdv | 3:c0e409cda493 | 15 | #define LCD_X 128 // In pixels |
medvdv | 3:c0e409cda493 | 16 | #define LCD_Y 4 // In rows by 8 pixels each |
medvdv | 3:c0e409cda493 | 17 | #define LCD_SIZE 512 // In bytes, = LCD_X*LCD_Y |
medvdv | 1:17443d6d2740 | 18 | |
medvdv | 0:6ac8f630d9a0 | 19 | // |
medvdv | 0:6ac8f630d9a0 | 20 | // Proportional font |
medvdv | 0:6ac8f630d9a0 | 21 | // |
medvdv | 0:6ac8f630d9a0 | 22 | |
medvdv | 0:6ac8f630d9a0 | 23 | typedef struct { |
medvdv | 0:6ac8f630d9a0 | 24 | char first_code, glyphs_total; |
medvdv | 0:6ac8f630d9a0 | 25 | const char* widths; |
medvdv | 0:6ac8f630d9a0 | 26 | const char** glyphs; |
medvdv | 0:6ac8f630d9a0 | 27 | } lcd128font; |
medvdv | 0:6ac8f630d9a0 | 28 | |
medvdv | 1:17443d6d2740 | 29 | // |
medvdv | 1:17443d6d2740 | 30 | // Progress bar shape |
medvdv | 1:17443d6d2740 | 31 | // Drawed as BFFF...FFUU...UUUE |
medvdv | 1:17443d6d2740 | 32 | // B - Begin one |
medvdv | 1:17443d6d2740 | 33 | // F - Filled zone |
medvdv | 1:17443d6d2740 | 34 | // U - Empty zone |
medvdv | 1:17443d6d2740 | 35 | // E - End one |
medvdv | 1:17443d6d2740 | 36 | // |
medvdv | 1:17443d6d2740 | 37 | |
medvdv | 1:17443d6d2740 | 38 | #define LCD_BAR_B 0x1c |
medvdv | 1:17443d6d2740 | 39 | #define LCD_BAR_F 0x3e |
medvdv | 1:17443d6d2740 | 40 | #define LCD_BAR_U 0x22 |
medvdv | 1:17443d6d2740 | 41 | #define LCD_BAR_E 0x1c |
medvdv | 1:17443d6d2740 | 42 | |
medvdv | 1:17443d6d2740 | 43 | // |
medvdv | 0:6ac8f630d9a0 | 44 | // lcd128 class |
medvdv | 0:6ac8f630d9a0 | 45 | // |
medvdv | 0:6ac8f630d9a0 | 46 | |
medvdv | 0:6ac8f630d9a0 | 47 | class lcd128 { |
medvdv | 0:6ac8f630d9a0 | 48 | |
medvdv | 0:6ac8f630d9a0 | 49 | // Interface with lcd |
medvdv | 0:6ac8f630d9a0 | 50 | SPI spi; |
medvdv | 0:6ac8f630d9a0 | 51 | DigitalOut rst, cs, a0; |
medvdv | 0:6ac8f630d9a0 | 52 | |
medvdv | 0:6ac8f630d9a0 | 53 | // Current font |
medvdv | 0:6ac8f630d9a0 | 54 | lcd128font font; |
medvdv | 0:6ac8f630d9a0 | 55 | |
medvdv | 1:17443d6d2740 | 56 | // Write options |
medvdv | 0:6ac8f630d9a0 | 57 | bool invert; |
medvdv | 0:6ac8f630d9a0 | 58 | bool bold; |
medvdv | 1:17443d6d2740 | 59 | bool underline; |
medvdv | 0:6ac8f630d9a0 | 60 | |
medvdv | 0:6ac8f630d9a0 | 61 | // buffer |
medvdv | 0:6ac8f630d9a0 | 62 | char buffer[LCD_SIZE]; |
medvdv | 0:6ac8f630d9a0 | 63 | |
medvdv | 0:6ac8f630d9a0 | 64 | // Cursor position |
medvdv | 0:6ac8f630d9a0 | 65 | int X, Y; |
medvdv | 0:6ac8f630d9a0 | 66 | |
medvdv | 4:1bd241d1fad0 | 67 | // SPI writer with data / command |
medvdv | 0:6ac8f630d9a0 | 68 | void write(char byte, bool cmd = false); |
medvdv | 0:6ac8f630d9a0 | 69 | |
medvdv | 0:6ac8f630d9a0 | 70 | public: |
medvdv | 0:6ac8f630d9a0 | 71 | |
medvdv | 0:6ac8f630d9a0 | 72 | // Supply LCD connected pin's here for your design |
medvdv | 0:6ac8f630d9a0 | 73 | lcd128(PinName mosi= p5, PinName sclk = p7, PinName a0 = p8, PinName cs = p11, PinName rst = p6); |
medvdv | 0:6ac8f630d9a0 | 74 | |
medvdv | 0:6ac8f630d9a0 | 75 | // LCD control |
medvdv | 0:6ac8f630d9a0 | 76 | void Reset(); // Reset LCD, configure defaults |
medvdv | 0:6ac8f630d9a0 | 77 | void Power(bool power = true); // Power off / on |
medvdv | 0:6ac8f630d9a0 | 78 | void InverseMode(bool inverse = true); // Invert LCD off / on |
medvdv | 0:6ac8f630d9a0 | 79 | |
medvdv | 0:6ac8f630d9a0 | 80 | // Buffer -> LCD |
medvdv | 4:1bd241d1fad0 | 81 | void Update(); // Update LCD from buffer, actually shows drawed |
medvdv | 3:c0e409cda493 | 82 | void Clear(int row = -1); // Clear all buffer or one concrete row |
medvdv | 0:6ac8f630d9a0 | 83 | |
medvdv | 0:6ac8f630d9a0 | 84 | // Write mode |
medvdv | 0:6ac8f630d9a0 | 85 | void Invert(bool invert = true); // Switch inverting of chars |
medvdv | 0:6ac8f630d9a0 | 86 | void Bold(bool bold = true); // Switch bold mode (repeat each char row twice) |
medvdv | 1:17443d6d2740 | 87 | void Underline(bool underline = true); // Switch underline mode (last pixel of row always on) |
medvdv | 0:6ac8f630d9a0 | 88 | |
medvdv | 0:6ac8f630d9a0 | 89 | // Cursor |
medvdv | 0:6ac8f630d9a0 | 90 | void XY(int x = 0, int y = 0); // Change write position X in pixels, Y in rows |
medvdv | 0:6ac8f630d9a0 | 91 | |
medvdv | 4:1bd241d1fad0 | 92 | // Vertical 8bit pixel row |
medvdv | 0:6ac8f630d9a0 | 93 | void Write(char byte); // One 8bit row |
medvdv | 0:6ac8f630d9a0 | 94 | void Write(char byte, int count); // One 8bit row * 'count' times |
medvdv | 0:6ac8f630d9a0 | 95 | void Write(char* data, int size); // 'size' 8bit rows |
medvdv | 0:6ac8f630d9a0 | 96 | void Write2(char* data, int size); // Bold: 'size' 8bit rows * 2 |
medvdv | 0:6ac8f630d9a0 | 97 | |
medvdv | 0:6ac8f630d9a0 | 98 | // Character drawing |
medvdv | 0:6ac8f630d9a0 | 99 | void Character(char chr); // Draw one font character (with invert and bold opt-s) |
medvdv | 0:6ac8f630d9a0 | 100 | // ! automaticaly does next line if char is wider then space left |
medvdv | 0:6ac8f630d9a0 | 101 | int CharacterWidth(char chr); // Calculate one character width (with bold opt-n) |
medvdv | 0:6ac8f630d9a0 | 102 | |
medvdv | 0:6ac8f630d9a0 | 103 | // String drawing |
medvdv | 0:6ac8f630d9a0 | 104 | void String(char* str); // Draw string proportionally |
medvdv | 0:6ac8f630d9a0 | 105 | int StringWidth(char* str); // Calculate string width in px |
medvdv | 0:6ac8f630d9a0 | 106 | |
medvdv | 1:17443d6d2740 | 107 | // Higher level drawers |
medvdv | 3:c0e409cda493 | 108 | void Row(int Y, char* str = ""); // Clear one text row and draw string on it (left aligned) |
medvdv | 3:c0e409cda493 | 109 | void RowCenter(int Y, char* str = ""); // Clear one text row and draw string on it (center aligned) |
medvdv | 1:17443d6d2740 | 110 | void Bar(int width, float fill = 0.0); // Progress bar - one row, width pixels, fill - 0.0..1.0 |
medvdv | 0:6ac8f630d9a0 | 111 | }; |