NokiaLCD Library
NokiaLCD.cpp@0:740a742e0efa, 2011-02-27 (annotated)
- Committer:
- wjohnsto
- Date:
- Sun Feb 27 23:34:15 2011 +0000
- Revision:
- 0:740a742e0efa
Added the two patches for screen width and pixel function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wjohnsto | 0:740a742e0efa | 1 | /* mbed Nokia LCD Library |
wjohnsto | 0:740a742e0efa | 2 | * Copyright (c) 2007-2010, sford |
wjohnsto | 0:740a742e0efa | 3 | */ |
wjohnsto | 0:740a742e0efa | 4 | |
wjohnsto | 0:740a742e0efa | 5 | #include "NokiaLCD.h" |
wjohnsto | 0:740a742e0efa | 6 | |
wjohnsto | 0:740a742e0efa | 7 | #include "mbed.h" |
wjohnsto | 0:740a742e0efa | 8 | |
wjohnsto | 0:740a742e0efa | 9 | #define NOKIALCD_ROWS 16 |
wjohnsto | 0:740a742e0efa | 10 | #define NOKIALCD_COLS 16 |
wjohnsto | 0:740a742e0efa | 11 | #define NOKIALCD_WIDTH 132 |
wjohnsto | 0:740a742e0efa | 12 | #define NOKIALCD_HEIGHT 130 |
wjohnsto | 0:740a742e0efa | 13 | #define NOKIALCD_FREQUENCY 5000000 |
wjohnsto | 0:740a742e0efa | 14 | |
wjohnsto | 0:740a742e0efa | 15 | NokiaLCD::NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type) |
wjohnsto | 0:740a742e0efa | 16 | : _spi(mosi, NC, sclk) |
wjohnsto | 0:740a742e0efa | 17 | , _rst(rst) |
wjohnsto | 0:740a742e0efa | 18 | , _cs(cs) { |
wjohnsto | 0:740a742e0efa | 19 | |
wjohnsto | 0:740a742e0efa | 20 | _type = type; |
wjohnsto | 0:740a742e0efa | 21 | |
wjohnsto | 0:740a742e0efa | 22 | _row = 0; |
wjohnsto | 0:740a742e0efa | 23 | _column = 0; |
wjohnsto | 0:740a742e0efa | 24 | _foreground = 0x00FFFFFF; |
wjohnsto | 0:740a742e0efa | 25 | _background = 0x00000000; |
wjohnsto | 0:740a742e0efa | 26 | |
wjohnsto | 0:740a742e0efa | 27 | reset(); |
wjohnsto | 0:740a742e0efa | 28 | } |
wjohnsto | 0:740a742e0efa | 29 | |
wjohnsto | 0:740a742e0efa | 30 | void NokiaLCD::reset() { |
wjohnsto | 0:740a742e0efa | 31 | |
wjohnsto | 0:740a742e0efa | 32 | // setup the SPI interface and bring display out of reset |
wjohnsto | 0:740a742e0efa | 33 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 34 | _rst = 0; |
wjohnsto | 0:740a742e0efa | 35 | _spi.format(9); |
wjohnsto | 0:740a742e0efa | 36 | _spi.frequency(NOKIALCD_FREQUENCY); |
wjohnsto | 0:740a742e0efa | 37 | wait_ms(1); |
wjohnsto | 0:740a742e0efa | 38 | _rst = 1; |
wjohnsto | 0:740a742e0efa | 39 | wait_ms(1); |
wjohnsto | 0:740a742e0efa | 40 | |
wjohnsto | 0:740a742e0efa | 41 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 42 | |
wjohnsto | 0:740a742e0efa | 43 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 44 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 45 | command(0xCA); // display control |
wjohnsto | 0:740a742e0efa | 46 | data(0); |
wjohnsto | 0:740a742e0efa | 47 | data(32); |
wjohnsto | 0:740a742e0efa | 48 | data(0); |
wjohnsto | 0:740a742e0efa | 49 | command(0xBB); |
wjohnsto | 0:740a742e0efa | 50 | data(1); |
wjohnsto | 0:740a742e0efa | 51 | command(0xD1); // oscillator on |
wjohnsto | 0:740a742e0efa | 52 | command(0x94); // sleep out |
wjohnsto | 0:740a742e0efa | 53 | command(0x20); // power control |
wjohnsto | 0:740a742e0efa | 54 | data(0x0F); |
wjohnsto | 0:740a742e0efa | 55 | command(0xA7); // invert display |
wjohnsto | 0:740a742e0efa | 56 | command(0x81); // Voltage control |
wjohnsto | 0:740a742e0efa | 57 | data(39); // contrast setting: 0..63 |
wjohnsto | 0:740a742e0efa | 58 | data(3); // resistance ratio |
wjohnsto | 0:740a742e0efa | 59 | wait_ms(1); |
wjohnsto | 0:740a742e0efa | 60 | command(0xBC); |
wjohnsto | 0:740a742e0efa | 61 | data(0); |
wjohnsto | 0:740a742e0efa | 62 | data(1); |
wjohnsto | 0:740a742e0efa | 63 | data(4); |
wjohnsto | 0:740a742e0efa | 64 | command(0xAF); // turn on the display |
wjohnsto | 0:740a742e0efa | 65 | break; |
wjohnsto | 0:740a742e0efa | 66 | |
wjohnsto | 0:740a742e0efa | 67 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 68 | command(0xCA); // display control |
wjohnsto | 0:740a742e0efa | 69 | data(0); |
wjohnsto | 0:740a742e0efa | 70 | data(31); |
wjohnsto | 0:740a742e0efa | 71 | data(0); |
wjohnsto | 0:740a742e0efa | 72 | command(0xBB); |
wjohnsto | 0:740a742e0efa | 73 | data(1); |
wjohnsto | 0:740a742e0efa | 74 | command(0xD1); // oscillator on |
wjohnsto | 0:740a742e0efa | 75 | command(0x94); // sleep out |
wjohnsto | 0:740a742e0efa | 76 | command(0x20); // power control |
wjohnsto | 0:740a742e0efa | 77 | data(0x0F); |
wjohnsto | 0:740a742e0efa | 78 | command(0xA7); // invert display |
wjohnsto | 0:740a742e0efa | 79 | command(0x81); // Voltage control |
wjohnsto | 0:740a742e0efa | 80 | data(39); // contrast setting: 0..63 |
wjohnsto | 0:740a742e0efa | 81 | data(3); // resistance ratio |
wjohnsto | 0:740a742e0efa | 82 | wait_ms(1); |
wjohnsto | 0:740a742e0efa | 83 | command(0xBC); |
wjohnsto | 0:740a742e0efa | 84 | data(0); |
wjohnsto | 0:740a742e0efa | 85 | data(0); |
wjohnsto | 0:740a742e0efa | 86 | data(2); |
wjohnsto | 0:740a742e0efa | 87 | command(0xAF); // turn on the display |
wjohnsto | 0:740a742e0efa | 88 | break; |
wjohnsto | 0:740a742e0efa | 89 | |
wjohnsto | 0:740a742e0efa | 90 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 91 | command(0x11); // sleep out |
wjohnsto | 0:740a742e0efa | 92 | command(0x3A); // column mode |
wjohnsto | 0:740a742e0efa | 93 | data(0x05); |
wjohnsto | 0:740a742e0efa | 94 | command(0x36); // madctl |
wjohnsto | 0:740a742e0efa | 95 | data(0x60); // vertical RAM, flip x |
wjohnsto | 0:740a742e0efa | 96 | command(0x25); // setcon |
wjohnsto | 0:740a742e0efa | 97 | data(0x30);// contrast 0x30 |
wjohnsto | 0:740a742e0efa | 98 | wait_ms(2); |
wjohnsto | 0:740a742e0efa | 99 | command(0x29);//DISPON |
wjohnsto | 0:740a742e0efa | 100 | command(0x03);//BSTRON |
wjohnsto | 0:740a742e0efa | 101 | break; |
wjohnsto | 0:740a742e0efa | 102 | } |
wjohnsto | 0:740a742e0efa | 103 | |
wjohnsto | 0:740a742e0efa | 104 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 105 | |
wjohnsto | 0:740a742e0efa | 106 | cls(); |
wjohnsto | 0:740a742e0efa | 107 | } |
wjohnsto | 0:740a742e0efa | 108 | |
wjohnsto | 0:740a742e0efa | 109 | void NokiaLCD::command(int value) { |
wjohnsto | 0:740a742e0efa | 110 | _spi.write(value & 0xFF); |
wjohnsto | 0:740a742e0efa | 111 | } |
wjohnsto | 0:740a742e0efa | 112 | |
wjohnsto | 0:740a742e0efa | 113 | void NokiaLCD::data(int value) { |
wjohnsto | 0:740a742e0efa | 114 | _spi.write(value | 0x100); |
wjohnsto | 0:740a742e0efa | 115 | } |
wjohnsto | 0:740a742e0efa | 116 | |
wjohnsto | 0:740a742e0efa | 117 | void NokiaLCD::_window(int x, int y, int width, int height) { |
wjohnsto | 0:740a742e0efa | 118 | int x1 = x + 0; |
wjohnsto | 0:740a742e0efa | 119 | int y1 = y + 0; |
wjohnsto | 0:740a742e0efa | 120 | int x2 = x1 + width - 1; |
wjohnsto | 0:740a742e0efa | 121 | int y2 = y1 + height - 1; |
wjohnsto | 0:740a742e0efa | 122 | |
wjohnsto | 0:740a742e0efa | 123 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 124 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 125 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 126 | command(0x15); // column |
wjohnsto | 0:740a742e0efa | 127 | data(x1); |
wjohnsto | 0:740a742e0efa | 128 | data(x2); |
wjohnsto | 0:740a742e0efa | 129 | command(0x75); // row |
wjohnsto | 0:740a742e0efa | 130 | data(y1); |
wjohnsto | 0:740a742e0efa | 131 | data(y2); |
wjohnsto | 0:740a742e0efa | 132 | command(0x5C); // start write to ram |
wjohnsto | 0:740a742e0efa | 133 | break; |
wjohnsto | 0:740a742e0efa | 134 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 135 | command(0x2A); // column |
wjohnsto | 0:740a742e0efa | 136 | data(x1); |
wjohnsto | 0:740a742e0efa | 137 | data(x2); |
wjohnsto | 0:740a742e0efa | 138 | command(0x2B); // row |
wjohnsto | 0:740a742e0efa | 139 | data(y1); |
wjohnsto | 0:740a742e0efa | 140 | data(y2); |
wjohnsto | 0:740a742e0efa | 141 | command(0x2C); // start write to ram |
wjohnsto | 0:740a742e0efa | 142 | break; |
wjohnsto | 0:740a742e0efa | 143 | } |
wjohnsto | 0:740a742e0efa | 144 | } |
wjohnsto | 0:740a742e0efa | 145 | |
wjohnsto | 0:740a742e0efa | 146 | void NokiaLCD::_putp(int colour) { |
wjohnsto | 0:740a742e0efa | 147 | int gr = ((colour >> 20) & 0x0F) |
wjohnsto | 0:740a742e0efa | 148 | | ((colour >> 8 ) & 0xF0); |
wjohnsto | 0:740a742e0efa | 149 | int nb = ((colour >> 4 ) & 0x0F); |
wjohnsto | 0:740a742e0efa | 150 | data(nb); |
wjohnsto | 0:740a742e0efa | 151 | data(gr); |
wjohnsto | 0:740a742e0efa | 152 | } |
wjohnsto | 0:740a742e0efa | 153 | |
wjohnsto | 0:740a742e0efa | 154 | const unsigned char FONT8x8[97][8] = { |
wjohnsto | 0:740a742e0efa | 155 | 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char |
wjohnsto | 0:740a742e0efa | 156 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 |
wjohnsto | 0:740a742e0efa | 157 | 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! |
wjohnsto | 0:740a742e0efa | 158 | 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " |
wjohnsto | 0:740a742e0efa | 159 | 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # |
wjohnsto | 0:740a742e0efa | 160 | 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ |
wjohnsto | 0:740a742e0efa | 161 | 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % |
wjohnsto | 0:740a742e0efa | 162 | 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & |
wjohnsto | 0:740a742e0efa | 163 | 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' |
wjohnsto | 0:740a742e0efa | 164 | 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( |
wjohnsto | 0:740a742e0efa | 165 | 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) |
wjohnsto | 0:740a742e0efa | 166 | 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * |
wjohnsto | 0:740a742e0efa | 167 | 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + |
wjohnsto | 0:740a742e0efa | 168 | 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , |
wjohnsto | 0:740a742e0efa | 169 | 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - |
wjohnsto | 0:740a742e0efa | 170 | 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . |
wjohnsto | 0:740a742e0efa | 171 | 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) |
wjohnsto | 0:740a742e0efa | 172 | 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 |
wjohnsto | 0:740a742e0efa | 173 | 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 |
wjohnsto | 0:740a742e0efa | 174 | 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 |
wjohnsto | 0:740a742e0efa | 175 | 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 |
wjohnsto | 0:740a742e0efa | 176 | 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 |
wjohnsto | 0:740a742e0efa | 177 | 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 |
wjohnsto | 0:740a742e0efa | 178 | 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 |
wjohnsto | 0:740a742e0efa | 179 | 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 |
wjohnsto | 0:740a742e0efa | 180 | 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 |
wjohnsto | 0:740a742e0efa | 181 | 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 |
wjohnsto | 0:740a742e0efa | 182 | 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : |
wjohnsto | 0:740a742e0efa | 183 | 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; |
wjohnsto | 0:740a742e0efa | 184 | 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < |
wjohnsto | 0:740a742e0efa | 185 | 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = |
wjohnsto | 0:740a742e0efa | 186 | 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > |
wjohnsto | 0:740a742e0efa | 187 | 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? |
wjohnsto | 0:740a742e0efa | 188 | 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 |
wjohnsto | 0:740a742e0efa | 189 | 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A |
wjohnsto | 0:740a742e0efa | 190 | 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B |
wjohnsto | 0:740a742e0efa | 191 | 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C |
wjohnsto | 0:740a742e0efa | 192 | 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D |
wjohnsto | 0:740a742e0efa | 193 | 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E |
wjohnsto | 0:740a742e0efa | 194 | 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F |
wjohnsto | 0:740a742e0efa | 195 | 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G |
wjohnsto | 0:740a742e0efa | 196 | 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H |
wjohnsto | 0:740a742e0efa | 197 | 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I |
wjohnsto | 0:740a742e0efa | 198 | 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J |
wjohnsto | 0:740a742e0efa | 199 | 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K |
wjohnsto | 0:740a742e0efa | 200 | 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L |
wjohnsto | 0:740a742e0efa | 201 | 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M |
wjohnsto | 0:740a742e0efa | 202 | 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N |
wjohnsto | 0:740a742e0efa | 203 | 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O |
wjohnsto | 0:740a742e0efa | 204 | 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 |
wjohnsto | 0:740a742e0efa | 205 | 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q |
wjohnsto | 0:740a742e0efa | 206 | 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R |
wjohnsto | 0:740a742e0efa | 207 | 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S |
wjohnsto | 0:740a742e0efa | 208 | 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T |
wjohnsto | 0:740a742e0efa | 209 | 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U |
wjohnsto | 0:740a742e0efa | 210 | 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V |
wjohnsto | 0:740a742e0efa | 211 | 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W |
wjohnsto | 0:740a742e0efa | 212 | 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X |
wjohnsto | 0:740a742e0efa | 213 | 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y |
wjohnsto | 0:740a742e0efa | 214 | 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z |
wjohnsto | 0:740a742e0efa | 215 | 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ |
wjohnsto | 0:740a742e0efa | 216 | 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) |
wjohnsto | 0:740a742e0efa | 217 | 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] |
wjohnsto | 0:740a742e0efa | 218 | 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ |
wjohnsto | 0:740a742e0efa | 219 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ |
wjohnsto | 0:740a742e0efa | 220 | 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 |
wjohnsto | 0:740a742e0efa | 221 | 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a |
wjohnsto | 0:740a742e0efa | 222 | 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b |
wjohnsto | 0:740a742e0efa | 223 | 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c |
wjohnsto | 0:740a742e0efa | 224 | 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d |
wjohnsto | 0:740a742e0efa | 225 | 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e |
wjohnsto | 0:740a742e0efa | 226 | 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f |
wjohnsto | 0:740a742e0efa | 227 | 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g |
wjohnsto | 0:740a742e0efa | 228 | 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h |
wjohnsto | 0:740a742e0efa | 229 | 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i |
wjohnsto | 0:740a742e0efa | 230 | 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j |
wjohnsto | 0:740a742e0efa | 231 | 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k |
wjohnsto | 0:740a742e0efa | 232 | 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l |
wjohnsto | 0:740a742e0efa | 233 | 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m |
wjohnsto | 0:740a742e0efa | 234 | 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n |
wjohnsto | 0:740a742e0efa | 235 | 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o |
wjohnsto | 0:740a742e0efa | 236 | 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p |
wjohnsto | 0:740a742e0efa | 237 | 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q |
wjohnsto | 0:740a742e0efa | 238 | 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r |
wjohnsto | 0:740a742e0efa | 239 | 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s |
wjohnsto | 0:740a742e0efa | 240 | 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t |
wjohnsto | 0:740a742e0efa | 241 | 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u |
wjohnsto | 0:740a742e0efa | 242 | 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v |
wjohnsto | 0:740a742e0efa | 243 | 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w |
wjohnsto | 0:740a742e0efa | 244 | 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x |
wjohnsto | 0:740a742e0efa | 245 | 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y |
wjohnsto | 0:740a742e0efa | 246 | 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z |
wjohnsto | 0:740a742e0efa | 247 | 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { |
wjohnsto | 0:740a742e0efa | 248 | 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | |
wjohnsto | 0:740a742e0efa | 249 | 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } |
wjohnsto | 0:740a742e0efa | 250 | 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ |
wjohnsto | 0:740a742e0efa | 251 | 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00 |
wjohnsto | 0:740a742e0efa | 252 | }; // DEL |
wjohnsto | 0:740a742e0efa | 253 | |
wjohnsto | 0:740a742e0efa | 254 | void NokiaLCD::locate(int column, int row) { |
wjohnsto | 0:740a742e0efa | 255 | _column = column; |
wjohnsto | 0:740a742e0efa | 256 | _row = row; |
wjohnsto | 0:740a742e0efa | 257 | } |
wjohnsto | 0:740a742e0efa | 258 | |
wjohnsto | 0:740a742e0efa | 259 | void NokiaLCD::newline() { |
wjohnsto | 0:740a742e0efa | 260 | _column = 0; |
wjohnsto | 0:740a742e0efa | 261 | _row++; |
wjohnsto | 0:740a742e0efa | 262 | if (_row >= _rows) { |
wjohnsto | 0:740a742e0efa | 263 | _row = 0; |
wjohnsto | 0:740a742e0efa | 264 | } |
wjohnsto | 0:740a742e0efa | 265 | } |
wjohnsto | 0:740a742e0efa | 266 | |
wjohnsto | 0:740a742e0efa | 267 | int NokiaLCD::_putc(int value) { |
wjohnsto | 0:740a742e0efa | 268 | int x = _column * 8; // FIXME: Char sizes |
wjohnsto | 0:740a742e0efa | 269 | int y = _row * 8; |
wjohnsto | 0:740a742e0efa | 270 | bitblit(x + 1, y + 1, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); |
wjohnsto | 0:740a742e0efa | 271 | |
wjohnsto | 0:740a742e0efa | 272 | _column++; |
wjohnsto | 0:740a742e0efa | 273 | |
wjohnsto | 0:740a742e0efa | 274 | if (_column >= NOKIALCD_COLS) { |
wjohnsto | 0:740a742e0efa | 275 | _row++; |
wjohnsto | 0:740a742e0efa | 276 | _column = 0; |
wjohnsto | 0:740a742e0efa | 277 | } |
wjohnsto | 0:740a742e0efa | 278 | |
wjohnsto | 0:740a742e0efa | 279 | if (_row >= NOKIALCD_ROWS) { |
wjohnsto | 0:740a742e0efa | 280 | _row = 0; |
wjohnsto | 0:740a742e0efa | 281 | } |
wjohnsto | 0:740a742e0efa | 282 | |
wjohnsto | 0:740a742e0efa | 283 | return value; |
wjohnsto | 0:740a742e0efa | 284 | } |
wjohnsto | 0:740a742e0efa | 285 | |
wjohnsto | 0:740a742e0efa | 286 | void NokiaLCD::cls() { |
wjohnsto | 0:740a742e0efa | 287 | fill(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT, _background); |
wjohnsto | 0:740a742e0efa | 288 | _row = 0; |
wjohnsto | 0:740a742e0efa | 289 | _column = 0; |
wjohnsto | 0:740a742e0efa | 290 | } |
wjohnsto | 0:740a742e0efa | 291 | |
wjohnsto | 0:740a742e0efa | 292 | |
wjohnsto | 0:740a742e0efa | 293 | void NokiaLCD::window(int x, int y, int width, int height) { |
wjohnsto | 0:740a742e0efa | 294 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 295 | _window(x, y, width, height); |
wjohnsto | 0:740a742e0efa | 296 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 297 | } |
wjohnsto | 0:740a742e0efa | 298 | |
wjohnsto | 0:740a742e0efa | 299 | void NokiaLCD::putp(int colour) { |
wjohnsto | 0:740a742e0efa | 300 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 301 | _putp(colour); |
wjohnsto | 0:740a742e0efa | 302 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 303 | } |
wjohnsto | 0:740a742e0efa | 304 | |
wjohnsto | 0:740a742e0efa | 305 | void NokiaLCD::pixel(int x, int y, int colour) { |
wjohnsto | 0:740a742e0efa | 306 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 307 | _window(x, y, 1, 1); |
wjohnsto | 0:740a742e0efa | 308 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 309 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 310 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 311 | |
wjohnsto | 0:740a742e0efa | 312 | _putp(colour); |
wjohnsto | 0:740a742e0efa | 313 | |
wjohnsto | 0:740a742e0efa | 314 | break; |
wjohnsto | 0:740a742e0efa | 315 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 316 | |
wjohnsto | 0:740a742e0efa | 317 | int r4 = (colour >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 318 | int g4 = (colour >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 319 | int b4 = (colour >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 320 | int d1 = (r4 << 4) | g4; |
wjohnsto | 0:740a742e0efa | 321 | int d2 = (b4 << 4) | r4; |
wjohnsto | 0:740a742e0efa | 322 | int d3 = (g4 << 4) | b4; |
wjohnsto | 0:740a742e0efa | 323 | data(d1); |
wjohnsto | 0:740a742e0efa | 324 | data(d2); |
wjohnsto | 0:740a742e0efa | 325 | data(d3); |
wjohnsto | 0:740a742e0efa | 326 | |
wjohnsto | 0:740a742e0efa | 327 | break; |
wjohnsto | 0:740a742e0efa | 328 | } |
wjohnsto | 0:740a742e0efa | 329 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 330 | } |
wjohnsto | 0:740a742e0efa | 331 | |
wjohnsto | 0:740a742e0efa | 332 | void NokiaLCD::fill(int x, int y, int width, int height, int colour) { |
wjohnsto | 0:740a742e0efa | 333 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 334 | _window(x, y, width, height); |
wjohnsto | 0:740a742e0efa | 335 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 336 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 337 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 338 | for (int i=0; i<width*height; i++) { |
wjohnsto | 0:740a742e0efa | 339 | _putp(colour); |
wjohnsto | 0:740a742e0efa | 340 | } |
wjohnsto | 0:740a742e0efa | 341 | break; |
wjohnsto | 0:740a742e0efa | 342 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 343 | for (int i=0; i<width*height/2; i++) { |
wjohnsto | 0:740a742e0efa | 344 | int r4 = (colour >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 345 | int g4 = (colour >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 346 | int b4 = (colour >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 347 | int d1 = (r4 << 4) | g4; |
wjohnsto | 0:740a742e0efa | 348 | int d2 = (b4 << 4) | r4; |
wjohnsto | 0:740a742e0efa | 349 | int d3 = (g4 << 4) | b4; |
wjohnsto | 0:740a742e0efa | 350 | data(d1); |
wjohnsto | 0:740a742e0efa | 351 | data(d2); |
wjohnsto | 0:740a742e0efa | 352 | data(d3); |
wjohnsto | 0:740a742e0efa | 353 | } |
wjohnsto | 0:740a742e0efa | 354 | break; |
wjohnsto | 0:740a742e0efa | 355 | } |
wjohnsto | 0:740a742e0efa | 356 | _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT); |
wjohnsto | 0:740a742e0efa | 357 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 358 | } |
wjohnsto | 0:740a742e0efa | 359 | |
wjohnsto | 0:740a742e0efa | 360 | void NokiaLCD::blit(int x, int y, int width, int height, const int* colour) { |
wjohnsto | 0:740a742e0efa | 361 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 362 | _window(x, y, width, height); |
wjohnsto | 0:740a742e0efa | 363 | |
wjohnsto | 0:740a742e0efa | 364 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 365 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 366 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 367 | for (int i=0; i<width*height; i++) { |
wjohnsto | 0:740a742e0efa | 368 | _putp(colour[i]); |
wjohnsto | 0:740a742e0efa | 369 | } |
wjohnsto | 0:740a742e0efa | 370 | break; |
wjohnsto | 0:740a742e0efa | 371 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 372 | for (int i=0; i<width*height/2; i++) { |
wjohnsto | 0:740a742e0efa | 373 | int r41 = (colour[i*2] >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 374 | int g41 = (colour[i*2] >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 375 | int b41 = (colour[i*2] >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 376 | |
wjohnsto | 0:740a742e0efa | 377 | int r42 = (colour[i*2+1] >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 378 | int g42 = (colour[i*2+1] >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 379 | int b42 = (colour[i*2+1] >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 380 | int d1 = (r41 << 4) | g41; |
wjohnsto | 0:740a742e0efa | 381 | int d2 = (b41 << 4) | r42; |
wjohnsto | 0:740a742e0efa | 382 | int d3 = (g42 << 4) | b42; |
wjohnsto | 0:740a742e0efa | 383 | data(d1); |
wjohnsto | 0:740a742e0efa | 384 | data(d2); |
wjohnsto | 0:740a742e0efa | 385 | data(d3); |
wjohnsto | 0:740a742e0efa | 386 | } |
wjohnsto | 0:740a742e0efa | 387 | break; |
wjohnsto | 0:740a742e0efa | 388 | } |
wjohnsto | 0:740a742e0efa | 389 | _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT); |
wjohnsto | 0:740a742e0efa | 390 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 391 | } |
wjohnsto | 0:740a742e0efa | 392 | |
wjohnsto | 0:740a742e0efa | 393 | void NokiaLCD::bitblit(int x, int y, int width, int height, const char* bitstream) { |
wjohnsto | 0:740a742e0efa | 394 | _cs = 0; |
wjohnsto | 0:740a742e0efa | 395 | _window(x, y, width, height); |
wjohnsto | 0:740a742e0efa | 396 | |
wjohnsto | 0:740a742e0efa | 397 | switch (_type) { |
wjohnsto | 0:740a742e0efa | 398 | case LCD6100: |
wjohnsto | 0:740a742e0efa | 399 | case PCF8833: |
wjohnsto | 0:740a742e0efa | 400 | for (int i=0; i<height*width; i++) { |
wjohnsto | 0:740a742e0efa | 401 | int byte = i / 8; |
wjohnsto | 0:740a742e0efa | 402 | int bit = i % 8; |
wjohnsto | 0:740a742e0efa | 403 | int colour = ((bitstream[byte] << bit) & 0x80) ? _foreground : _background; |
wjohnsto | 0:740a742e0efa | 404 | _putp(colour); |
wjohnsto | 0:740a742e0efa | 405 | } |
wjohnsto | 0:740a742e0efa | 406 | break; |
wjohnsto | 0:740a742e0efa | 407 | case LCD6610: |
wjohnsto | 0:740a742e0efa | 408 | for(int i=0; i<height*width/2; i++) { |
wjohnsto | 0:740a742e0efa | 409 | int byte1 = (i*2) / 8; |
wjohnsto | 0:740a742e0efa | 410 | int bit1 = (i*2) % 8; |
wjohnsto | 0:740a742e0efa | 411 | int colour1 = ((bitstream[byte1] << bit1) & 0x80) ? _foreground : _background; |
wjohnsto | 0:740a742e0efa | 412 | int byte2 = (i*2+1) / 8; |
wjohnsto | 0:740a742e0efa | 413 | int bit2 = (i*2+1) % 8; |
wjohnsto | 0:740a742e0efa | 414 | int colour2 = ((bitstream[byte2] << bit2) & 0x80) ? _foreground : _background; |
wjohnsto | 0:740a742e0efa | 415 | |
wjohnsto | 0:740a742e0efa | 416 | int r41 = (colour1 >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 417 | int g41 = (colour1 >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 418 | int b41 = (colour1 >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 419 | |
wjohnsto | 0:740a742e0efa | 420 | int r42 = (colour2 >> (16 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 421 | int g42 = (colour2 >> (8 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 422 | int b42 = (colour2 >> (0 + 4)) & 0xF; |
wjohnsto | 0:740a742e0efa | 423 | int d1 = (r41 << 4) | g41; |
wjohnsto | 0:740a742e0efa | 424 | int d2 = (b41 << 4) | r42; |
wjohnsto | 0:740a742e0efa | 425 | int d3 = (g42 << 4) | b42; |
wjohnsto | 0:740a742e0efa | 426 | data(d1); |
wjohnsto | 0:740a742e0efa | 427 | data(d2); |
wjohnsto | 0:740a742e0efa | 428 | data(d3); |
wjohnsto | 0:740a742e0efa | 429 | } |
wjohnsto | 0:740a742e0efa | 430 | break; |
wjohnsto | 0:740a742e0efa | 431 | } |
wjohnsto | 0:740a742e0efa | 432 | _window(0, 0, _width, _height); |
wjohnsto | 0:740a742e0efa | 433 | _cs = 1; |
wjohnsto | 0:740a742e0efa | 434 | } |
wjohnsto | 0:740a742e0efa | 435 | |
wjohnsto | 0:740a742e0efa | 436 | void NokiaLCD::foreground(int c) { |
wjohnsto | 0:740a742e0efa | 437 | _foreground = c; |
wjohnsto | 0:740a742e0efa | 438 | } |
wjohnsto | 0:740a742e0efa | 439 | |
wjohnsto | 0:740a742e0efa | 440 | void NokiaLCD::background(int c) { |
wjohnsto | 0:740a742e0efa | 441 | _background = c; |
wjohnsto | 0:740a742e0efa | 442 | } |
wjohnsto | 0:740a742e0efa | 443 | |
wjohnsto | 0:740a742e0efa | 444 | int NokiaLCD::width() { |
wjohnsto | 0:740a742e0efa | 445 | return NOKIALCD_WIDTH; |
wjohnsto | 0:740a742e0efa | 446 | } |
wjohnsto | 0:740a742e0efa | 447 | |
wjohnsto | 0:740a742e0efa | 448 | int NokiaLCD::height() { |
wjohnsto | 0:740a742e0efa | 449 | return NOKIALCD_HEIGHT; |
wjohnsto | 0:740a742e0efa | 450 | } |
wjohnsto | 0:740a742e0efa | 451 | |
wjohnsto | 0:740a742e0efa | 452 | int NokiaLCD::columns() { |
wjohnsto | 0:740a742e0efa | 453 | return NOKIALCD_COLS; |
wjohnsto | 0:740a742e0efa | 454 | } |
wjohnsto | 0:740a742e0efa | 455 | |
wjohnsto | 0:740a742e0efa | 456 | int NokiaLCD::rows() { |
wjohnsto | 0:740a742e0efa | 457 | return NOKIALCD_ROWS; |
wjohnsto | 0:740a742e0efa | 458 | } |