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