Drivers for the Nokia LCD screen with a text error fixed and the dimensions of the screen fixed.

Fork of NokiaLCD by Simon Ford

Committer:
jlind6
Date:
Fri Oct 12 09:33:09 2012 +0000
Revision:
3:63ee0e0970ac
Parent:
1:8f005b0dcfa7
Fixed some of the display problems with the edges and with text

Who changed what in which revision?

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