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