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 :-)
medvdv5110.cpp@5:c37e5454bdb2, 2014-01-31 (annotated)
- Committer:
- medvdv
- Date:
- Fri Jan 31 20:25:57 2014 +0000
- Revision:
- 5:c37e5454bdb2
- Parent:
- 4:82917c164f2b
Added Power On/Off; Added Inverse Mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
medvdv | 0:0a6619901f2e | 1 | // |
medvdv | 0:0a6619901f2e | 2 | // 5110 LCD Driver |
medvdv | 4:82917c164f2b | 3 | // (c) 2012 @medvdv - Alexander Medvedev |
medvdv | 0:0a6619901f2e | 4 | // |
medvdv | 0:0a6619901f2e | 5 | |
medvdv | 0:0a6619901f2e | 6 | #include "mbed.h" |
medvdv | 0:0a6619901f2e | 7 | #include "medvdv5110.h" |
medvdv | 0:0a6619901f2e | 8 | |
medvdv | 2:65df20ffef51 | 9 | // Nice proportional font with 8px height |
medvdv | 2:65df20ffef51 | 10 | |
medvdv | 1:cce4622d70f6 | 11 | const char lcd_font8p_widths[] = { |
medvdv | 1:cce4622d70f6 | 12 | 2, 1, 3, 5, 5, 5, 5, 1, 2, 2, 5, 5, 4, |
medvdv | 1:cce4622d70f6 | 13 | 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, |
medvdv | 0:0a6619901f2e | 14 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
medvdv | 1:cce4622d70f6 | 15 | 1, 3, 4, 1, 5, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 2, 4, 5, 4 |
medvdv | 1:cce4622d70f6 | 16 | }; |
medvdv | 0:0a6619901f2e | 17 | |
medvdv | 0:0a6619901f2e | 18 | const char* lcd_font8p[] = { |
medvdv | 1:cce4622d70f6 | 19 | (const char[]){ 0x00, 0x00 }, |
medvdv | 1:cce4622d70f6 | 20 | (const char[]){ 0x2F }, |
medvdv | 1:cce4622d70f6 | 21 | (const char[]){ 0x03, 0x00, 0x03 }, |
medvdv | 1:cce4622d70f6 | 22 | (const char[]){ 0x14, 0x3E, 0x14, 0x3E, 0x14 }, |
medvdv | 1:cce4622d70f6 | 23 | (const char[]){ 0x24, 0x6A, 0x3E, 0x2B, 0x12 }, |
medvdv | 1:cce4622d70f6 | 24 | (const char[]){ 0x22, 0x10, 0x08, 0x04, 0x22 }, |
medvdv | 1:cce4622d70f6 | 25 | (const char[]){ 0x14, 0x2A, 0x2A, 0x14, 0x20 }, |
medvdv | 1:cce4622d70f6 | 26 | (const char[]){ 0x03 }, |
medvdv | 1:cce4622d70f6 | 27 | (const char[]){ 0x1E, 0x21 }, |
medvdv | 1:cce4622d70f6 | 28 | (const char[]){ 0x21, 0x1E }, |
medvdv | 1:cce4622d70f6 | 29 | (const char[]){ 0x14, 0x08, 0x3E, 0x08, 0x14 }, |
medvdv | 1:cce4622d70f6 | 30 | (const char[]){ 0x08, 0x08, 0x3E, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 31 | (const char[]){ 0x00, 0x80, 0x70, 0x30 }, |
medvdv | 1:cce4622d70f6 | 32 | (const char[]){ 0x08, 0x08, 0x08, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 33 | (const char[]){ 0x00, 0x00, 0x30, 0x30, 0x00 }, |
medvdv | 1:cce4622d70f6 | 34 | (const char[]){ 0x20, 0x10, 0x08, 0x04, 0x02 }, |
medvdv | 1:cce4622d70f6 | 35 | (const char[]){ 0x1E, 0x31, 0x2D, 0x23, 0x1E }, |
medvdv | 1:cce4622d70f6 | 36 | (const char[]){ 0x00, 0x00, 0x02, 0x3F, 0x00 }, |
medvdv | 1:cce4622d70f6 | 37 | (const char[]){ 0x22, 0x31, 0x29, 0x25, 0x22 }, |
medvdv | 1:cce4622d70f6 | 38 | (const char[]){ 0x12, 0x21, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 39 | (const char[]){ 0x18, 0x14, 0x12, 0x3F, 0x10 }, |
medvdv | 1:cce4622d70f6 | 40 | (const char[]){ 0x17, 0x25, 0x25, 0x25, 0x19 }, |
medvdv | 1:cce4622d70f6 | 41 | (const char[]){ 0x1E, 0x25, 0x25, 0x25, 0x18 }, |
medvdv | 1:cce4622d70f6 | 42 | (const char[]){ 0x01, 0x01, 0x39, 0x05, 0x03 }, |
medvdv | 1:cce4622d70f6 | 43 | (const char[]){ 0x1A, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 44 | (const char[]){ 0x06, 0x29, 0x29, 0x29, 0x1E }, |
medvdv | 1:cce4622d70f6 | 45 | (const char[]){ 0x00, 0x00, 0x36, 0x36 }, |
medvdv | 1:cce4622d70f6 | 46 | (const char[]){ 0x00, 0x80, 0x76, 0x36 }, |
medvdv | 1:cce4622d70f6 | 47 | (const char[]){ 0x08, 0x08, 0x14, 0x14, 0x22, 0x22 }, |
medvdv | 1:cce4622d70f6 | 48 | (const char[]){ 0x14, 0x14, 0x14, 0x14, 0x14 }, |
medvdv | 1:cce4622d70f6 | 49 | (const char[]){ 0x22, 0x22, 0x14, 0x14, 0x08, 0x08 }, |
medvdv | 1:cce4622d70f6 | 50 | (const char[]){ 0x02, 0x01, 0x29, 0x05, 0x02 }, |
medvdv | 1:cce4622d70f6 | 51 | (const char[]){ 0x3E, 0x41, 0x5D, 0x55, 0x5E, 0x20 }, |
medvdv | 1:cce4622d70f6 | 52 | (const char[]){ 0x3E, 0x09, 0x09, 0x09, 0x3E }, |
medvdv | 1:cce4622d70f6 | 53 | (const char[]){ 0x3F, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 54 | (const char[]){ 0x1E, 0x21, 0x21, 0x21, 0x12 }, |
medvdv | 1:cce4622d70f6 | 55 | (const char[]){ 0x3F, 0x21, 0x21, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 56 | (const char[]){ 0x3F, 0x25, 0x25, 0x25, 0x21 }, |
medvdv | 1:cce4622d70f6 | 57 | (const char[]){ 0x3F, 0x05, 0x05, 0x05, 0x01 }, |
medvdv | 1:cce4622d70f6 | 58 | (const char[]){ 0x1E, 0x21, 0x21, 0x29, 0x1A }, |
medvdv | 1:cce4622d70f6 | 59 | (const char[]){ 0x3F, 0x04, 0x04, 0x04, 0x3F }, |
medvdv | 1:cce4622d70f6 | 60 | (const char[]){ 0x21, 0x3F, 0x21 }, |
medvdv | 1:cce4622d70f6 | 61 | (const char[]){ 0x18, 0x20, 0x21, 0x1F, 0x01 }, |
medvdv | 1:cce4622d70f6 | 62 | (const char[]){ 0x3F, 0x04, 0x04, 0x0A, 0x31 }, |
medvdv | 1:cce4622d70f6 | 63 | (const char[]){ 0x3F, 0x20, 0x20, 0x20, 0x20 }, |
medvdv | 1:cce4622d70f6 | 64 | (const char[]){ 0x3F, 0x02, 0x04, 0x02, 0x3F }, |
medvdv | 1:cce4622d70f6 | 65 | (const char[]){ 0x3F, 0x02, 0x04, 0x08, 0x3F }, |
medvdv | 1:cce4622d70f6 | 66 | (const char[]){ 0x1E, 0x21, 0x21, 0x21, 0x1E }, |
medvdv | 1:cce4622d70f6 | 67 | (const char[]){ 0x3F, 0x09, 0x09, 0x09, 0x06 }, |
medvdv | 1:cce4622d70f6 | 68 | (const char[]){ 0x1E, 0x21, 0x29, 0x31, 0x3E }, |
medvdv | 1:cce4622d70f6 | 69 | (const char[]){ 0x3F, 0x09, 0x09, 0x19, 0x26 }, |
medvdv | 1:cce4622d70f6 | 70 | (const char[]){ 0x12, 0x25, 0x25, 0x25, 0x1A }, |
medvdv | 1:cce4622d70f6 | 71 | (const char[]){ 0x01, 0x01, 0x3F, 0x01, 0x01 }, |
medvdv | 1:cce4622d70f6 | 72 | (const char[]){ 0x1F, 0x20, 0x20, 0x20, 0x1F }, |
medvdv | 1:cce4622d70f6 | 73 | (const char[]){ 0x03, 0x0C, 0x30, 0x0C, 0x03 }, |
medvdv | 1:cce4622d70f6 | 74 | (const char[]){ 0x1F, 0x20, 0x18, 0x20, 0x1F }, |
medvdv | 1:cce4622d70f6 | 75 | (const char[]){ 0x21, 0x12, 0x0C, 0x12, 0x21 }, |
medvdv | 1:cce4622d70f6 | 76 | (const char[]){ 0x03, 0x04, 0x38, 0x04, 0x03 }, |
medvdv | 1:cce4622d70f6 | 77 | (const char[]){ 0x31, 0x29, 0x25, 0x23, 0x21 }, |
medvdv | 1:cce4622d70f6 | 78 | (const char[]){ 0x00, 0x3F, 0x21, 0x21 }, |
medvdv | 1:cce4622d70f6 | 79 | (const char[]){ 0x02, 0x04, 0x08, 0x10, 0x20 }, |
medvdv | 1:cce4622d70f6 | 80 | (const char[]){ 0x00, 0x00, 0x21, 0x21, 0x3F }, |
medvdv | 1:cce4622d70f6 | 81 | (const char[]){ 0x04, 0x02, 0x01, 0x02, 0x04 }, |
medvdv | 1:cce4622d70f6 | 82 | (const char[]){ 0x20, 0x20, 0x20, 0x20, 0x20 }, |
medvdv | 1:cce4622d70f6 | 83 | (const char[]){ 0x00, 0x01, 0x03, 0x04 }, |
medvdv | 1:cce4622d70f6 | 84 | (const char[]){ 0x10, 0x2A, 0x2A, 0x3C }, |
medvdv | 1:cce4622d70f6 | 85 | (const char[]){ 0x3F, 0x24, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 86 | (const char[]){ 0x1C, 0x22, 0x22, 0x14 }, |
medvdv | 1:cce4622d70f6 | 87 | (const char[]){ 0x1C, 0x22, 0x24, 0x3F }, |
medvdv | 1:cce4622d70f6 | 88 | (const char[]){ 0x1C, 0x2A, 0x2A, 0x2C }, |
medvdv | 1:cce4622d70f6 | 89 | (const char[]){ 0x3E, 0x09, 0x01, 0x02 }, |
medvdv | 1:cce4622d70f6 | 90 | (const char[]){ 0x0C, 0x52, 0x4A, 0x3C }, |
medvdv | 1:cce4622d70f6 | 91 | (const char[]){ 0x3F, 0x04, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 92 | (const char[]){ 0x3D }, |
medvdv | 1:cce4622d70f6 | 93 | (const char[]){ 0x40, 0x40, 0x3D }, |
medvdv | 1:cce4622d70f6 | 94 | (const char[]){ 0x3F, 0x08, 0x0C, 0x32 }, |
medvdv | 1:cce4622d70f6 | 95 | (const char[]){ 0x3F }, |
medvdv | 1:cce4622d70f6 | 96 | (const char[]){ 0x3C, 0x02, 0x3C, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 97 | (const char[]){ 0x3C, 0x02, 0x02, 0x3C }, |
medvdv | 1:cce4622d70f6 | 98 | (const char[]){ 0x1C, 0x22, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 99 | (const char[]){ 0x7E, 0x22, 0x22, 0x1C }, |
medvdv | 1:cce4622d70f6 | 100 | (const char[]){ 0x1C, 0x22, 0x22, 0x7E }, |
medvdv | 1:cce4622d70f6 | 101 | (const char[]){ 0x02, 0x3C, 0x02, 0x02 }, |
medvdv | 1:cce4622d70f6 | 102 | (const char[]){ 0x24, 0x2A, 0x2A, 0x12 }, |
medvdv | 1:cce4622d70f6 | 103 | (const char[]){ 0x02, 0x1F, 0x22, 0x22 }, |
medvdv | 1:cce4622d70f6 | 104 | (const char[]){ 0x1E, 0x20, 0x20, 0x3E }, |
medvdv | 1:cce4622d70f6 | 105 | (const char[]){ 0x06, 0x18, 0x20, 0x3C, 0x02 }, |
medvdv | 1:cce4622d70f6 | 106 | (const char[]){ 0x1E, 0x20, 0x1C, 0x20, 0x1E }, |
medvdv | 1:cce4622d70f6 | 107 | (const char[]){ 0x22, 0x14, 0x08, 0x14, 0x22 }, |
medvdv | 1:cce4622d70f6 | 108 | (const char[]){ 0x0E, 0x50, 0x50, 0x3E }, |
medvdv | 1:cce4622d70f6 | 109 | (const char[]){ 0x22, 0x32, 0x2A, 0x26 }, |
medvdv | 1:cce4622d70f6 | 110 | (const char[]){ 0x00, 0x08, 0x36, 0x41 }, |
medvdv | 1:cce4622d70f6 | 111 | (const char[]){ 0x00, 0x7F }, |
medvdv | 1:cce4622d70f6 | 112 | (const char[]){ 0x00, 0x41, 0x36, 0x08 }, |
medvdv | 1:cce4622d70f6 | 113 | (const char[]){ 0x08, 0x04, 0x08, 0x10, 0x08 }, |
medvdv | 2:65df20ffef51 | 114 | (const char[]){ 0x2A, 0x55, 0x2A, 0x55 } |
medvdv | 1:cce4622d70f6 | 115 | }; |
medvdv | 0:0a6619901f2e | 116 | |
medvdv | 2:65df20ffef51 | 117 | // lcd5110 - Internals |
medvdv | 0:0a6619901f2e | 118 | |
medvdv | 2:65df20ffef51 | 119 | // Generic SPI writer |
medvdv | 0:0a6619901f2e | 120 | void lcd5110::write(char data, bool cmd) |
medvdv | 0:0a6619901f2e | 121 | { |
medvdv | 0:0a6619901f2e | 122 | sce -> write(0); |
medvdv | 0:0a6619901f2e | 123 | dc -> write(cmd ? 0:1); |
medvdv | 1:cce4622d70f6 | 124 | spi -> write(data); |
medvdv | 0:0a6619901f2e | 125 | sce -> write(1); |
medvdv | 0:0a6619901f2e | 126 | } |
medvdv | 0:0a6619901f2e | 127 | |
medvdv | 2:65df20ffef51 | 128 | // lcd5110 - Public |
medvdv | 0:0a6619901f2e | 129 | |
medvdv | 2:65df20ffef51 | 130 | // Supply LCD pin's here |
medvdv | 0:0a6619901f2e | 131 | lcd5110::lcd5110(PinName mosi, PinName sclk, PinName dc, PinName sce, PinName rst) |
medvdv | 0:0a6619901f2e | 132 | { |
medvdv | 0:0a6619901f2e | 133 | spi = new SPI(mosi, NC, sclk); |
medvdv | 1:cce4622d70f6 | 134 | |
medvdv | 0:0a6619901f2e | 135 | spi -> format(8, 1); |
medvdv | 0:0a6619901f2e | 136 | spi -> frequency(4000000); |
medvdv | 1:cce4622d70f6 | 137 | |
medvdv | 0:0a6619901f2e | 138 | this -> rst = new DigitalOut(rst); |
medvdv | 0:0a6619901f2e | 139 | this -> sce = new DigitalOut(sce); |
medvdv | 0:0a6619901f2e | 140 | this -> dc = new DigitalOut(dc); |
medvdv | 1:cce4622d70f6 | 141 | |
medvdv | 2:65df20ffef51 | 142 | // Setup default font |
medvdv | 0:0a6619901f2e | 143 | font.first_code = 32; |
medvdv | 0:0a6619901f2e | 144 | font.glyphs_total = 128 - 32; |
medvdv | 0:0a6619901f2e | 145 | font.widths = lcd_font8p_widths; |
medvdv | 0:0a6619901f2e | 146 | font.glyphs = lcd_font8p; |
medvdv | 1:cce4622d70f6 | 147 | |
medvdv | 0:0a6619901f2e | 148 | invert = false; |
medvdv | 0:0a6619901f2e | 149 | bold = false; |
medvdv | 2:65df20ffef51 | 150 | |
medvdv | 2:65df20ffef51 | 151 | contrast = DEFAULT_CONTRAST; |
medvdv | 0:0a6619901f2e | 152 | } |
medvdv | 0:0a6619901f2e | 153 | |
medvdv | 2:65df20ffef51 | 154 | // Start inverting chars |
medvdv | 0:0a6619901f2e | 155 | void lcd5110::Invert(bool invert) |
medvdv | 0:0a6619901f2e | 156 | { |
medvdv | 0:0a6619901f2e | 157 | this -> invert = invert; |
medvdv | 0:0a6619901f2e | 158 | } |
medvdv | 0:0a6619901f2e | 159 | |
medvdv | 2:65df20ffef51 | 160 | // Start bold mode (repeat twice wide) |
medvdv | 0:0a6619901f2e | 161 | void lcd5110::Bold(bool bold) |
medvdv | 0:0a6619901f2e | 162 | { |
medvdv | 0:0a6619901f2e | 163 | this -> bold = bold; |
medvdv | 0:0a6619901f2e | 164 | } |
medvdv | 0:0a6619901f2e | 165 | |
medvdv | 2:65df20ffef51 | 166 | // Reset LCD, configure defaults and contrast |
medvdv | 0:0a6619901f2e | 167 | void lcd5110::Reset() |
medvdv | 0:0a6619901f2e | 168 | { |
medvdv | 0:0a6619901f2e | 169 | rst -> write(0); |
medvdv | 0:0a6619901f2e | 170 | wait_ms(100); |
medvdv | 0:0a6619901f2e | 171 | rst -> write(1); |
medvdv | 0:0a6619901f2e | 172 | write(0x21, true); |
medvdv | 0:0a6619901f2e | 173 | write(0x80 + contrast, true); |
medvdv | 0:0a6619901f2e | 174 | write(0x04, true); |
medvdv | 0:0a6619901f2e | 175 | write(0x14, true); |
medvdv | 0:0a6619901f2e | 176 | write(0x20, true); |
medvdv | 0:0a6619901f2e | 177 | write(0x0C, true); |
medvdv | 0:0a6619901f2e | 178 | XY(); |
medvdv | 1:cce4622d70f6 | 179 | } |
medvdv | 1:cce4622d70f6 | 180 | |
medvdv | 2:65df20ffef51 | 181 | // Change contrast |
medvdv | 0:0a6619901f2e | 182 | void lcd5110::Contrast(char contrast) |
medvdv | 0:0a6619901f2e | 183 | { |
medvdv | 0:0a6619901f2e | 184 | this -> contrast = contrast; |
medvdv | 0:0a6619901f2e | 185 | write(0x21, true); |
medvdv | 0:0a6619901f2e | 186 | write(0x80 + contrast, true); |
medvdv | 0:0a6619901f2e | 187 | write(0x20, true); |
medvdv | 0:0a6619901f2e | 188 | } |
medvdv | 0:0a6619901f2e | 189 | |
medvdv | 2:65df20ffef51 | 190 | // LCD power off |
medvdv | 5:c37e5454bdb2 | 191 | void lcd5110::Power(bool power) |
medvdv | 0:0a6619901f2e | 192 | { |
medvdv | 5:c37e5454bdb2 | 193 | if(!power) write(0x24, true); |
medvdv | 5:c37e5454bdb2 | 194 | else write(0x20, true); |
medvdv | 5:c37e5454bdb2 | 195 | } |
medvdv | 5:c37e5454bdb2 | 196 | |
medvdv | 5:c37e5454bdb2 | 197 | void lcd5110::InverseMode(bool invert) |
medvdv | 5:c37e5454bdb2 | 198 | { |
medvdv | 5:c37e5454bdb2 | 199 | if(invert) write(0x0d, true); |
medvdv | 5:c37e5454bdb2 | 200 | else write(0x08, true); |
medvdv | 0:0a6619901f2e | 201 | } |
medvdv | 0:0a6619901f2e | 202 | |
medvdv | 2:65df20ffef51 | 203 | // Clear - fill all by 8bit line 'pattern' |
medvdv | 0:0a6619901f2e | 204 | void lcd5110::Clear(char pattern) |
medvdv | 0:0a6619901f2e | 205 | { |
medvdv | 0:0a6619901f2e | 206 | Write(pattern,504); |
medvdv | 0:0a6619901f2e | 207 | XY(); |
medvdv | 0:0a6619901f2e | 208 | } |
medvdv | 0:0a6619901f2e | 209 | |
medvdv | 2:65df20ffef51 | 210 | // Change current output position |
medvdv | 2:65df20ffef51 | 211 | // X in pixels [0..83] |
medvdv | 2:65df20ffef51 | 212 | // Y in rows [0..5] |
medvdv | 0:0a6619901f2e | 213 | void lcd5110::XY(int x, int y) |
medvdv | 0:0a6619901f2e | 214 | { |
medvdv | 0:0a6619901f2e | 215 | if (x<0) x=0; |
medvdv | 0:0a6619901f2e | 216 | if (x>83) x=83; |
medvdv | 0:0a6619901f2e | 217 | if (y<0) y=0; |
medvdv | 0:0a6619901f2e | 218 | if (y>5) y=5; |
medvdv | 1:cce4622d70f6 | 219 | |
medvdv | 1:cce4622d70f6 | 220 | X = x; |
medvdv | 0:0a6619901f2e | 221 | Y = y; |
medvdv | 1:cce4622d70f6 | 222 | |
medvdv | 0:0a6619901f2e | 223 | write( 0x80 | (x & 0x3f), true); |
medvdv | 0:0a6619901f2e | 224 | write( 0x40 | (y & 0x3f), true); |
medvdv | 0:0a6619901f2e | 225 | } |
medvdv | 1:cce4622d70f6 | 226 | |
medvdv | 2:65df20ffef51 | 227 | // Write one 8bit row |
medvdv | 2:65df20ffef51 | 228 | // with inversion and XY update |
medvdv | 0:0a6619901f2e | 229 | void lcd5110::Write(char byte) |
medvdv | 1:cce4622d70f6 | 230 | { |
medvdv | 0:0a6619901f2e | 231 | write(invert?(~byte):byte, false); |
medvdv | 1:cce4622d70f6 | 232 | if (++X > 83) { |
medvdv | 1:cce4622d70f6 | 233 | X=0; |
medvdv | 1:cce4622d70f6 | 234 | if (++Y > 5) Y=0; |
medvdv | 0:0a6619901f2e | 235 | } |
medvdv | 0:0a6619901f2e | 236 | } |
medvdv | 0:0a6619901f2e | 237 | |
medvdv | 2:65df20ffef51 | 238 | // Write array of 8bit rows |
medvdv | 0:0a6619901f2e | 239 | void lcd5110::Write(char* data, int size) |
medvdv | 0:0a6619901f2e | 240 | { |
medvdv | 0:0a6619901f2e | 241 | for(int i=0; i<size; i++) Write(data[i]); |
medvdv | 0:0a6619901f2e | 242 | } |
medvdv | 0:0a6619901f2e | 243 | |
medvdv | 2:65df20ffef51 | 244 | // Write array of 8bit rows, twice each |
medvdv | 0:0a6619901f2e | 245 | void lcd5110::Write2(char* data, int size) |
medvdv | 0:0a6619901f2e | 246 | { |
medvdv | 1:cce4622d70f6 | 247 | for(int i=0; i<size; i++) { |
medvdv | 1:cce4622d70f6 | 248 | Write(data[i]); |
medvdv | 1:cce4622d70f6 | 249 | Write(data[i]); |
medvdv | 1:cce4622d70f6 | 250 | } |
medvdv | 0:0a6619901f2e | 251 | } |
medvdv | 1:cce4622d70f6 | 252 | |
medvdv | 2:65df20ffef51 | 253 | // Write 8bit row 'count' times |
medvdv | 0:0a6619901f2e | 254 | void lcd5110::Write(char byte, int count) |
medvdv | 0:0a6619901f2e | 255 | { |
medvdv | 0:0a6619901f2e | 256 | for(int i=0; i<count; i++) Write(byte); |
medvdv | 0:0a6619901f2e | 257 | } |
medvdv | 1:cce4622d70f6 | 258 | |
medvdv | 4:82917c164f2b | 259 | // Draw one proportional font character |
medvdv | 4:82917c164f2b | 260 | // Jump to next line if empty space is not enought |
medvdv | 0:0a6619901f2e | 261 | void lcd5110::Character(char chr) |
medvdv | 0:0a6619901f2e | 262 | { |
medvdv | 0:0a6619901f2e | 263 | if( chr < font.first_code ) return; |
medvdv | 0:0a6619901f2e | 264 | if( chr > font.first_code + font.glyphs_total - 1 ) return; |
medvdv | 1:cce4622d70f6 | 265 | |
medvdv | 0:0a6619901f2e | 266 | chr -= font.first_code; |
medvdv | 1:cce4622d70f6 | 267 | |
medvdv | 0:0a6619901f2e | 268 | int width = font.widths[chr]; |
medvdv | 1:cce4622d70f6 | 269 | |
medvdv | 0:0a6619901f2e | 270 | if (bold) width*=2; |
medvdv | 1:cce4622d70f6 | 271 | |
medvdv | 0:0a6619901f2e | 272 | if ((X + width) > 83) { |
medvdv | 0:0a6619901f2e | 273 | if (++Y > 5) Y = 0; |
medvdv | 0:0a6619901f2e | 274 | XY(0,Y); |
medvdv | 0:0a6619901f2e | 275 | } |
medvdv | 1:cce4622d70f6 | 276 | |
medvdv | 0:0a6619901f2e | 277 | if (bold) { |
medvdv | 0:0a6619901f2e | 278 | Write2( (char*) font.glyphs[chr], (int) font.widths[chr] ); |
medvdv | 1:cce4622d70f6 | 279 | if (X != 0) { |
medvdv | 1:cce4622d70f6 | 280 | Write( 0 ); |
medvdv | 1:cce4622d70f6 | 281 | Write( 0 ); |
medvdv | 1:cce4622d70f6 | 282 | } |
medvdv | 0:0a6619901f2e | 283 | } else { |
medvdv | 0:0a6619901f2e | 284 | Write( (char*) font.glyphs[chr], (int) font.widths[chr] ); |
medvdv | 0:0a6619901f2e | 285 | if (X != 0) Write( 0 ); |
medvdv | 0:0a6619901f2e | 286 | } |
medvdv | 0:0a6619901f2e | 287 | } |
medvdv | 0:0a6619901f2e | 288 | |
medvdv | 2:65df20ffef51 | 289 | // Calculate width of concrete character |
medvdv | 4:82917c164f2b | 290 | // takes into account bold setting |
medvdv | 0:0a6619901f2e | 291 | int lcd5110::CharacterWidth(char chr) |
medvdv | 0:0a6619901f2e | 292 | { |
medvdv | 0:0a6619901f2e | 293 | if( chr < font.first_code ) return 0; |
medvdv | 0:0a6619901f2e | 294 | if( chr > font.first_code + font.glyphs_total - 1 ) return 0; |
medvdv | 1:cce4622d70f6 | 295 | |
medvdv | 0:0a6619901f2e | 296 | chr -= font.first_code; |
medvdv | 1:cce4622d70f6 | 297 | |
medvdv | 1:cce4622d70f6 | 298 | if (bold) |
medvdv | 0:0a6619901f2e | 299 | return 2 * (font.widths[chr] + 1); |
medvdv | 0:0a6619901f2e | 300 | else |
medvdv | 0:0a6619901f2e | 301 | return font.widths[chr] + 1; |
medvdv | 0:0a6619901f2e | 302 | } |
medvdv | 0:0a6619901f2e | 303 | |
medvdv | 2:65df20ffef51 | 304 | // Write string |
medvdv | 0:0a6619901f2e | 305 | void lcd5110::String(char* str) |
medvdv | 0:0a6619901f2e | 306 | { |
medvdv | 0:0a6619901f2e | 307 | while(*str) Character(*str++); |
medvdv | 0:0a6619901f2e | 308 | } |
medvdv | 0:0a6619901f2e | 309 | |
medvdv | 2:65df20ffef51 | 310 | // Predict string width |
medvdv | 0:0a6619901f2e | 311 | int lcd5110::StringWidth(char* str) |
medvdv | 0:0a6619901f2e | 312 | { |
medvdv | 0:0a6619901f2e | 313 | int width = 0; |
medvdv | 1:cce4622d70f6 | 314 | |
medvdv | 0:0a6619901f2e | 315 | while(*str) width += CharacterWidth(*str++); |
medvdv | 1:cce4622d70f6 | 316 | |
medvdv | 0:0a6619901f2e | 317 | return width; |
medvdv | 0:0a6619901f2e | 318 | } |
medvdv | 0:0a6619901f2e | 319 | |
medvdv | 2:65df20ffef51 | 320 | // Clear one line, |
medvdv | 2:65df20ffef51 | 321 | // then write string from it's begin |
medvdv | 0:0a6619901f2e | 322 | void lcd5110::Row(int Y, char* str) |
medvdv | 0:0a6619901f2e | 323 | { |
medvdv | 0:0a6619901f2e | 324 | XY(0, Y); |
medvdv | 0:0a6619901f2e | 325 | Write((char) 0, 84); |
medvdv | 0:0a6619901f2e | 326 | XY(0, Y); |
medvdv | 1:cce4622d70f6 | 327 | String(str); |
medvdv | 0:0a6619901f2e | 328 | } |
medvdv | 0:0a6619901f2e | 329 | |
medvdv | 2:65df20ffef51 | 330 | // Remove pin objects's |
medvdv | 0:0a6619901f2e | 331 | lcd5110::~lcd5110() |
medvdv | 0:0a6619901f2e | 332 | { |
medvdv | 0:0a6619901f2e | 333 | delete spi; |
medvdv | 1:cce4622d70f6 | 334 | |
medvdv | 0:0a6619901f2e | 335 | delete rst; |
medvdv | 0:0a6619901f2e | 336 | delete sce; |
medvdv | 1:cce4622d70f6 | 337 | delete dc; |
medvdv | 0:0a6619901f2e | 338 | } |
medvdv | 0:0a6619901f2e | 339 | |
medvdv | 0:0a6619901f2e | 340 | |
medvdv | 0:0a6619901f2e | 341 | |
medvdv | 0:0a6619901f2e | 342 |