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