Added circle and line support

Committer:
Lerche
Date:
Thu Oct 07 14:34:47 2010 +0000
Revision:
4:92ccde806538
Parent:
2:d99e9681356b
Published as library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Lerche 0:8439874eb019 1 /* mbed Nokia LCD Library
Lerche 0:8439874eb019 2 * Copyright (c) 2007-2010, sford
Lerche 0:8439874eb019 3 */
Lerche 0:8439874eb019 4
Lerche 0:8439874eb019 5 #include "NokiaLCD.h"
Lerche 0:8439874eb019 6
Lerche 0:8439874eb019 7 #include "mbed.h"
Lerche 0:8439874eb019 8
Lerche 0:8439874eb019 9 #define NOKIALCD_ROWS 16
Lerche 0:8439874eb019 10 #define NOKIALCD_COLS 16
Lerche 0:8439874eb019 11 #define NOKIALCD_WIDTH 130
Lerche 0:8439874eb019 12 #define NOKIALCD_HEIGHT 130
Lerche 0:8439874eb019 13 #define NOKIALCD_FREQUENCY 5000000
Lerche 0:8439874eb019 14
Lerche 0:8439874eb019 15 NokiaLCD::NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type)
Lerche 0:8439874eb019 16 : _spi(mosi, NC, sclk)
Lerche 0:8439874eb019 17 , _rst(rst)
Lerche 0:8439874eb019 18 , _cs(cs) {
Lerche 0:8439874eb019 19
Lerche 0:8439874eb019 20 _type = type;
Lerche 0:8439874eb019 21
Lerche 0:8439874eb019 22 _row = 0;
Lerche 0:8439874eb019 23 _column = 0;
Lerche 0:8439874eb019 24 _foreground = 0x00FFFFFF;
Lerche 0:8439874eb019 25 _background = 0x00000000;
Lerche 0:8439874eb019 26
Lerche 0:8439874eb019 27 reset();
Lerche 0:8439874eb019 28 }
Lerche 0:8439874eb019 29
Lerche 0:8439874eb019 30 void NokiaLCD::reset() {
Lerche 0:8439874eb019 31
Lerche 0:8439874eb019 32 // setup the SPI interface and bring display out of reset
Lerche 0:8439874eb019 33 _cs = 1;
Lerche 0:8439874eb019 34 _rst = 0;
Lerche 0:8439874eb019 35 _spi.format(9);
Lerche 0:8439874eb019 36 _spi.frequency(NOKIALCD_FREQUENCY);
Lerche 0:8439874eb019 37 wait_ms(1);
Lerche 0:8439874eb019 38 _rst = 1;
Lerche 0:8439874eb019 39 wait_ms(1);
Lerche 0:8439874eb019 40
Lerche 0:8439874eb019 41 _cs = 0;
Lerche 0:8439874eb019 42
Lerche 0:8439874eb019 43 switch (_type) {
Lerche 0:8439874eb019 44 case LCD6100:
Lerche 0:8439874eb019 45 command(0xCA); // display control
Lerche 0:8439874eb019 46 data(0);
Lerche 0:8439874eb019 47 data(32);
Lerche 0:8439874eb019 48 data(0);
Lerche 0:8439874eb019 49 command(0xBB);
Lerche 0:8439874eb019 50 data(1);
Lerche 0:8439874eb019 51 command(0xD1); // oscillator on
Lerche 0:8439874eb019 52 command(0x94); // sleep out
Lerche 0:8439874eb019 53 command(0x20); // power control
Lerche 0:8439874eb019 54 data(0x0F);
Lerche 0:8439874eb019 55 command(0xA7); // invert display
Lerche 0:8439874eb019 56 command(0x81); // Voltage control
Lerche 0:8439874eb019 57 data(39); // contrast setting: 0..63
Lerche 0:8439874eb019 58 data(3); // resistance ratio
Lerche 0:8439874eb019 59 wait_ms(1);
Lerche 0:8439874eb019 60 command(0xBC);
Lerche 0:8439874eb019 61 data(0);
Lerche 0:8439874eb019 62 data(1);
Lerche 0:8439874eb019 63 data(4);
Lerche 0:8439874eb019 64 command(0xAF); // turn on the display
Lerche 0:8439874eb019 65 break;
Lerche 0:8439874eb019 66
Lerche 0:8439874eb019 67 case LCD6610:
Lerche 0:8439874eb019 68 command(0xCA); // display control
Lerche 0:8439874eb019 69 data(0);
Lerche 0:8439874eb019 70 data(31);
Lerche 0:8439874eb019 71 data(0);
Lerche 0:8439874eb019 72 command(0xBB);
Lerche 0:8439874eb019 73 data(1);
Lerche 0:8439874eb019 74 command(0xD1); // oscillator on
Lerche 0:8439874eb019 75 command(0x94); // sleep out
Lerche 0:8439874eb019 76 command(0x20); // power control
Lerche 0:8439874eb019 77 data(0x0F);
Lerche 0:8439874eb019 78 command(0xA7); // invert display
Lerche 0:8439874eb019 79 command(0x81); // Voltage control
Lerche 0:8439874eb019 80 data(39); // contrast setting: 0..63
Lerche 0:8439874eb019 81 data(3); // resistance ratio
Lerche 0:8439874eb019 82 wait_ms(1);
Lerche 0:8439874eb019 83 command(0xBC);
Lerche 0:8439874eb019 84 data(0);
Lerche 0:8439874eb019 85 data(0);
Lerche 0:8439874eb019 86 data(2);
Lerche 0:8439874eb019 87 command(0xAF); // turn on the display
Lerche 0:8439874eb019 88 break;
Lerche 0:8439874eb019 89
Lerche 0:8439874eb019 90 case PCF8833:
Lerche 0:8439874eb019 91 command(0x11); // sleep out
Lerche 0:8439874eb019 92 command(0x3A); // column mode
Lerche 0:8439874eb019 93 data(0x05);
Lerche 0:8439874eb019 94 command(0x36); // madctl
Lerche 0:8439874eb019 95 data(0x60); // vertical RAM, flip x
Lerche 0:8439874eb019 96 command(0x25); // setcon
Lerche 0:8439874eb019 97 data(0x30);// contrast 0x30
Lerche 0:8439874eb019 98 wait_ms(2);
Lerche 0:8439874eb019 99 command(0x29);//DISPON
Lerche 0:8439874eb019 100 command(0x03);//BSTRON
Lerche 0:8439874eb019 101 break;
Lerche 0:8439874eb019 102 }
Lerche 0:8439874eb019 103
Lerche 0:8439874eb019 104 _cs = 1;
Lerche 0:8439874eb019 105
Lerche 0:8439874eb019 106 cls();
Lerche 0:8439874eb019 107 }
Lerche 0:8439874eb019 108
Lerche 0:8439874eb019 109 void NokiaLCD::command(int value) {
Lerche 0:8439874eb019 110 _spi.write(value & 0xFF);
Lerche 0:8439874eb019 111 }
Lerche 0:8439874eb019 112
Lerche 0:8439874eb019 113 void NokiaLCD::data(int value) {
Lerche 0:8439874eb019 114 _spi.write(value | 0x100);
Lerche 0:8439874eb019 115 }
Lerche 0:8439874eb019 116
Lerche 0:8439874eb019 117 void NokiaLCD::_window(int x, int y, int width, int height) {
Lerche 0:8439874eb019 118 int x1 = x + 2;
Lerche 0:8439874eb019 119 int y1 = y + 0;
Lerche 0:8439874eb019 120 int x2 = x1 + width - 1;
Lerche 0:8439874eb019 121 int y2 = y1 + height - 1;
Lerche 0:8439874eb019 122
Lerche 0:8439874eb019 123 switch (_type) {
Lerche 0:8439874eb019 124 case LCD6100:
Lerche 0:8439874eb019 125 case LCD6610:
Lerche 0:8439874eb019 126 command(0x15); // column
Lerche 0:8439874eb019 127 data(x1);
Lerche 0:8439874eb019 128 data(x2);
Lerche 0:8439874eb019 129 command(0x75); // row
Lerche 0:8439874eb019 130 data(y1);
Lerche 0:8439874eb019 131 data(y2);
Lerche 0:8439874eb019 132 command(0x5C); // start write to ram
Lerche 0:8439874eb019 133 break;
Lerche 0:8439874eb019 134 case PCF8833:
Lerche 0:8439874eb019 135 command(0x2A); // column
Lerche 0:8439874eb019 136 data(x1);
Lerche 0:8439874eb019 137 data(x2);
Lerche 0:8439874eb019 138 command(0x2B); // row
Lerche 0:8439874eb019 139 data(y1);
Lerche 0:8439874eb019 140 data(y2);
Lerche 0:8439874eb019 141 command(0x2C); // start write to ram
Lerche 0:8439874eb019 142 break;
Lerche 0:8439874eb019 143 }
Lerche 0:8439874eb019 144 }
Lerche 0:8439874eb019 145
Lerche 0:8439874eb019 146 void NokiaLCD::_putp(int colour) {
Lerche 0:8439874eb019 147 int gr = ((colour >> 20) & 0x0F)
Lerche 0:8439874eb019 148 | ((colour >> 8 ) & 0xF0);
Lerche 0:8439874eb019 149 int nb = ((colour >> 4 ) & 0x0F);
Lerche 0:8439874eb019 150 data(nb);
Lerche 0:8439874eb019 151 data(gr);
Lerche 0:8439874eb019 152 }
Lerche 0:8439874eb019 153
Lerche 0:8439874eb019 154 const unsigned char FONT8x8[97][8] = {
Lerche 0:8439874eb019 155 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
Lerche 0:8439874eb019 156 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
Lerche 0:8439874eb019 157 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
Lerche 0:8439874eb019 158 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
Lerche 0:8439874eb019 159 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
Lerche 0:8439874eb019 160 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
Lerche 0:8439874eb019 161 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
Lerche 0:8439874eb019 162 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
Lerche 0:8439874eb019 163 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
Lerche 0:8439874eb019 164 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
Lerche 0:8439874eb019 165 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
Lerche 0:8439874eb019 166 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
Lerche 0:8439874eb019 167 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
Lerche 0:8439874eb019 168 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
Lerche 0:8439874eb019 169 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
Lerche 0:8439874eb019 170 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
Lerche 0:8439874eb019 171 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
Lerche 0:8439874eb019 172 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
Lerche 0:8439874eb019 173 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
Lerche 0:8439874eb019 174 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
Lerche 0:8439874eb019 175 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
Lerche 0:8439874eb019 176 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
Lerche 0:8439874eb019 177 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
Lerche 0:8439874eb019 178 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
Lerche 0:8439874eb019 179 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
Lerche 0:8439874eb019 180 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
Lerche 0:8439874eb019 181 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
Lerche 0:8439874eb019 182 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
Lerche 0:8439874eb019 183 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
Lerche 0:8439874eb019 184 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
Lerche 0:8439874eb019 185 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
Lerche 0:8439874eb019 186 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
Lerche 0:8439874eb019 187 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
Lerche 0:8439874eb019 188 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
Lerche 0:8439874eb019 189 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
Lerche 0:8439874eb019 190 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
Lerche 0:8439874eb019 191 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
Lerche 0:8439874eb019 192 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
Lerche 0:8439874eb019 193 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
Lerche 0:8439874eb019 194 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
Lerche 0:8439874eb019 195 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
Lerche 0:8439874eb019 196 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
Lerche 0:8439874eb019 197 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
Lerche 0:8439874eb019 198 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
Lerche 0:8439874eb019 199 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
Lerche 0:8439874eb019 200 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
Lerche 0:8439874eb019 201 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
Lerche 0:8439874eb019 202 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
Lerche 0:8439874eb019 203 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
Lerche 0:8439874eb019 204 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
Lerche 0:8439874eb019 205 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
Lerche 0:8439874eb019 206 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
Lerche 0:8439874eb019 207 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
Lerche 0:8439874eb019 208 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
Lerche 0:8439874eb019 209 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
Lerche 0:8439874eb019 210 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
Lerche 0:8439874eb019 211 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
Lerche 0:8439874eb019 212 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
Lerche 0:8439874eb019 213 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
Lerche 0:8439874eb019 214 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
Lerche 0:8439874eb019 215 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
Lerche 0:8439874eb019 216 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
Lerche 0:8439874eb019 217 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
Lerche 0:8439874eb019 218 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
Lerche 0:8439874eb019 219 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
Lerche 0:8439874eb019 220 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
Lerche 0:8439874eb019 221 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
Lerche 0:8439874eb019 222 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
Lerche 0:8439874eb019 223 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
Lerche 0:8439874eb019 224 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
Lerche 0:8439874eb019 225 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
Lerche 0:8439874eb019 226 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
Lerche 0:8439874eb019 227 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
Lerche 0:8439874eb019 228 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
Lerche 0:8439874eb019 229 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
Lerche 0:8439874eb019 230 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
Lerche 0:8439874eb019 231 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
Lerche 0:8439874eb019 232 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
Lerche 0:8439874eb019 233 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
Lerche 0:8439874eb019 234 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
Lerche 0:8439874eb019 235 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
Lerche 0:8439874eb019 236 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
Lerche 0:8439874eb019 237 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
Lerche 0:8439874eb019 238 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
Lerche 0:8439874eb019 239 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
Lerche 0:8439874eb019 240 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
Lerche 0:8439874eb019 241 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
Lerche 0:8439874eb019 242 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
Lerche 0:8439874eb019 243 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
Lerche 0:8439874eb019 244 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
Lerche 0:8439874eb019 245 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
Lerche 0:8439874eb019 246 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
Lerche 0:8439874eb019 247 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
Lerche 0:8439874eb019 248 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
Lerche 0:8439874eb019 249 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
Lerche 0:8439874eb019 250 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
Lerche 0:8439874eb019 251 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00
Lerche 0:8439874eb019 252 }; // DEL
Lerche 0:8439874eb019 253
Lerche 0:8439874eb019 254 void NokiaLCD::locate(int column, int row) {
Lerche 0:8439874eb019 255 _column = column;
Lerche 0:8439874eb019 256 _row = row;
Lerche 0:8439874eb019 257 }
Lerche 0:8439874eb019 258
Lerche 0:8439874eb019 259 void NokiaLCD::newline() {
Lerche 0:8439874eb019 260 _column = 0;
Lerche 0:8439874eb019 261 _row++;
Lerche 0:8439874eb019 262 if (_row >= _rows) {
Lerche 0:8439874eb019 263 _row = 0;
Lerche 0:8439874eb019 264 }
Lerche 0:8439874eb019 265 }
Lerche 0:8439874eb019 266
Lerche 0:8439874eb019 267 int NokiaLCD::_putc(int value) {
Lerche 0:8439874eb019 268 int x = _column * 8; // FIXME: Char sizes
Lerche 0:8439874eb019 269 int y = _row * 8;
Lerche 0:8439874eb019 270 bitblit(x + 1, y + 1, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
Lerche 0:8439874eb019 271
Lerche 0:8439874eb019 272 _column++;
Lerche 0:8439874eb019 273
Lerche 0:8439874eb019 274 if (_column >= NOKIALCD_COLS) {
Lerche 0:8439874eb019 275 _row++;
Lerche 0:8439874eb019 276 _column = 0;
Lerche 0:8439874eb019 277 }
Lerche 0:8439874eb019 278
Lerche 0:8439874eb019 279 if (_row >= NOKIALCD_ROWS) {
Lerche 0:8439874eb019 280 _row = 0;
Lerche 0:8439874eb019 281 }
Lerche 0:8439874eb019 282
Lerche 0:8439874eb019 283 return value;
Lerche 0:8439874eb019 284 }
Lerche 0:8439874eb019 285
Lerche 0:8439874eb019 286 void NokiaLCD::cls() {
Lerche 0:8439874eb019 287 fill(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT, _background);
Lerche 0:8439874eb019 288 _row = 0;
Lerche 0:8439874eb019 289 _column = 0;
Lerche 0:8439874eb019 290 }
Lerche 0:8439874eb019 291
Lerche 0:8439874eb019 292
Lerche 0:8439874eb019 293 void NokiaLCD::window(int x, int y, int width, int height) {
Lerche 0:8439874eb019 294 _cs = 0;
Lerche 0:8439874eb019 295 _window(x, y, width, height);
Lerche 0:8439874eb019 296 _cs = 1;
Lerche 0:8439874eb019 297 }
Lerche 0:8439874eb019 298
Lerche 0:8439874eb019 299 void NokiaLCD::putp(int colour) {
Lerche 0:8439874eb019 300 _cs = 0;
Lerche 0:8439874eb019 301 _putp(colour);
Lerche 0:8439874eb019 302 _cs = 1;
Lerche 0:8439874eb019 303 }
Lerche 0:8439874eb019 304
Lerche 0:8439874eb019 305 void NokiaLCD::pixel(int x, int y, int colour) {
Lerche 0:8439874eb019 306 _cs = 0;
Lerche 0:8439874eb019 307 _window(x, y, 1, 1);
Lerche 0:8439874eb019 308 _putp(colour);
Lerche 0:8439874eb019 309 _cs = 1;
Lerche 0:8439874eb019 310 }
Lerche 0:8439874eb019 311
Lerche 0:8439874eb019 312 void NokiaLCD::fill(int x, int y, int width, int height, int colour) {
Lerche 0:8439874eb019 313 _cs = 0;
Lerche 0:8439874eb019 314 _window(x, y, width, height);
Lerche 0:8439874eb019 315 for (int i=0; i<width*height; i++) {
Lerche 0:8439874eb019 316 _putp(colour);
Lerche 0:8439874eb019 317 }
Lerche 0:8439874eb019 318 _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT);
Lerche 0:8439874eb019 319 _cs = 1;
Lerche 0:8439874eb019 320 }
Lerche 0:8439874eb019 321
Lerche 0:8439874eb019 322 void NokiaLCD::circle(int x0, int y0, int r, int colour) {
Lerche 0:8439874eb019 323 int draw_x0, draw_y0;
Lerche 0:8439874eb019 324 int draw_x1, draw_y1;
Lerche 0:8439874eb019 325 int draw_x2, draw_y2;
Lerche 0:8439874eb019 326 int draw_x3, draw_y3;
Lerche 0:8439874eb019 327 int draw_x4, draw_y4;
Lerche 0:8439874eb019 328 int draw_x5, draw_y5;
Lerche 0:8439874eb019 329 int draw_x6, draw_y6;
Lerche 0:8439874eb019 330 int draw_x7, draw_y7;
Lerche 0:8439874eb019 331 int xx, yy;
Lerche 0:8439874eb019 332 int di;
Lerche 0:8439874eb019 333
Lerche 0:8439874eb019 334 _cs = 0;
Lerche 0:8439874eb019 335 _window(x0, y0, 1, 1);
Lerche 0:8439874eb019 336
Lerche 0:8439874eb019 337 if(r == 0) /* no radius */
Lerche 0:8439874eb019 338 {
Lerche 0:8439874eb019 339 return;
Lerche 0:8439874eb019 340 }
Lerche 0:8439874eb019 341
Lerche 0:8439874eb019 342 draw_x0 = draw_x1 = x0;
Lerche 0:8439874eb019 343 draw_y0 = draw_y1 = y0 + r;
Lerche 0:8439874eb019 344 if(draw_y0 < NOKIALCD_HEIGHT)
Lerche 0:8439874eb019 345 {
Lerche 0:8439874eb019 346 _window(draw_x0, draw_y0, 1, 1);
Lerche 0:8439874eb019 347 _putp(colour); /* 90 degree */
Lerche 0:8439874eb019 348 }
Lerche 0:8439874eb019 349
Lerche 0:8439874eb019 350 draw_x2 = draw_x3 = x0;
Lerche 0:8439874eb019 351 draw_y2 = draw_y3 = y0 - r;
Lerche 0:8439874eb019 352 if(draw_y2 >= 0)
Lerche 0:8439874eb019 353 {
Lerche 0:8439874eb019 354 _window(draw_x2, draw_y2, 1, 1);
Lerche 0:8439874eb019 355 _putp(colour); /* 270 degree */
Lerche 0:8439874eb019 356 }
Lerche 0:8439874eb019 357
Lerche 0:8439874eb019 358 draw_x4 = draw_x6 = x0 + r;
Lerche 0:8439874eb019 359 draw_y4 = draw_y6 = y0;
Lerche 0:8439874eb019 360 if(draw_x4 < NOKIALCD_WIDTH)
Lerche 0:8439874eb019 361 {
Lerche 0:8439874eb019 362 _window(draw_x4, draw_y4, 1, 1);
Lerche 0:8439874eb019 363 _putp(colour); /* 0 degree */
Lerche 0:8439874eb019 364 }
Lerche 0:8439874eb019 365
Lerche 0:8439874eb019 366 draw_x5 = draw_x7 = x0 - r;
Lerche 0:8439874eb019 367 draw_y5 = draw_y7 = y0;
Lerche 0:8439874eb019 368 if(draw_x5>=0)
Lerche 0:8439874eb019 369 {
Lerche 0:8439874eb019 370 _window(draw_x5, draw_y5, 1, 1);
Lerche 0:8439874eb019 371 _putp(colour); /* 90 degree */ /* 180 degree */
Lerche 0:8439874eb019 372 }
Lerche 0:8439874eb019 373
Lerche 0:8439874eb019 374 if(r == 1)
Lerche 0:8439874eb019 375 {
Lerche 0:8439874eb019 376 return;
Lerche 0:8439874eb019 377 }
Lerche 0:8439874eb019 378
Lerche 0:8439874eb019 379 di = 3 - 2*r;
Lerche 0:8439874eb019 380 xx = 0;
Lerche 0:8439874eb019 381 yy = r;
Lerche 0:8439874eb019 382 while(xx < yy)
Lerche 0:8439874eb019 383 {
Lerche 0:8439874eb019 384
Lerche 0:8439874eb019 385 if(di < 0)
Lerche 0:8439874eb019 386 {
Lerche 0:8439874eb019 387 di += 4*xx + 6;
Lerche 0:8439874eb019 388 }
Lerche 0:8439874eb019 389 else
Lerche 0:8439874eb019 390 {
Lerche 0:8439874eb019 391 di += 4*(xx - yy) + 10;
Lerche 0:8439874eb019 392 yy--;
Lerche 0:8439874eb019 393 draw_y0--;
Lerche 0:8439874eb019 394 draw_y1--;
Lerche 0:8439874eb019 395 draw_y2++;
Lerche 0:8439874eb019 396 draw_y3++;
Lerche 0:8439874eb019 397 draw_x4--;
Lerche 0:8439874eb019 398 draw_x5++;
Lerche 0:8439874eb019 399 draw_x6--;
Lerche 0:8439874eb019 400 draw_x7++;
Lerche 0:8439874eb019 401 }
Lerche 0:8439874eb019 402 xx++;
Lerche 0:8439874eb019 403 draw_x0++;
Lerche 0:8439874eb019 404 draw_x1--;
Lerche 0:8439874eb019 405 draw_x2++;
Lerche 0:8439874eb019 406 draw_x3--;
Lerche 0:8439874eb019 407 draw_y4++;
Lerche 0:8439874eb019 408 draw_y5++;
Lerche 0:8439874eb019 409 draw_y6--;
Lerche 0:8439874eb019 410 draw_y7--;
Lerche 0:8439874eb019 411
Lerche 0:8439874eb019 412 if( (draw_x0 <= NOKIALCD_WIDTH) && (draw_y0>=0) )
Lerche 0:8439874eb019 413 {
Lerche 0:8439874eb019 414 _window(draw_x0, draw_y0, 1, 1);
Lerche 0:8439874eb019 415 _putp(colour);
Lerche 0:8439874eb019 416 }
Lerche 0:8439874eb019 417
Lerche 0:8439874eb019 418 if( (draw_x1 >= 0) && (draw_y1 >= 0) )
Lerche 0:8439874eb019 419 {
Lerche 0:8439874eb019 420 _window(draw_x1, draw_y1, 1, 1);
Lerche 0:8439874eb019 421 _putp(colour);
Lerche 0:8439874eb019 422 }
Lerche 0:8439874eb019 423
Lerche 0:8439874eb019 424 if( (draw_x2 <= NOKIALCD_WIDTH) && (draw_y2 <= NOKIALCD_HEIGHT) )
Lerche 0:8439874eb019 425 {
Lerche 0:8439874eb019 426 _window(draw_x2, draw_y2, 1, 1);
Lerche 0:8439874eb019 427 _putp(colour);
Lerche 0:8439874eb019 428 }
Lerche 0:8439874eb019 429
Lerche 0:8439874eb019 430 if( (draw_x3 >=0 ) && (draw_y3 <= NOKIALCD_HEIGHT) )
Lerche 0:8439874eb019 431 {
Lerche 0:8439874eb019 432 _window(draw_x3, draw_y3, 1, 1);
Lerche 0:8439874eb019 433 _putp(colour);
Lerche 0:8439874eb019 434 }
Lerche 0:8439874eb019 435
Lerche 0:8439874eb019 436 if( (draw_x4 <= /*OLED_DISPLAY_HEIGHT*/NOKIALCD_WIDTH) && (draw_y4 >= 0) )
Lerche 0:8439874eb019 437 {
Lerche 0:8439874eb019 438 _window(draw_x4, draw_y4, 1, 1);
Lerche 0:8439874eb019 439 _putp(colour);
Lerche 0:8439874eb019 440 }
Lerche 0:8439874eb019 441
Lerche 0:8439874eb019 442 if( (draw_x5 >= 0) && (draw_y5 >= 0) )
Lerche 0:8439874eb019 443 {
Lerche 0:8439874eb019 444 _window(draw_x5, draw_y5, 1, 1);
Lerche 0:8439874eb019 445 _putp(colour);
Lerche 0:8439874eb019 446 }
Lerche 0:8439874eb019 447 if( (draw_x6 <= NOKIALCD_WIDTH) && (draw_y6 <= NOKIALCD_HEIGHT) )
Lerche 0:8439874eb019 448 {
Lerche 0:8439874eb019 449 _window(draw_x6, draw_y6, 1, 1);
Lerche 0:8439874eb019 450 _putp(colour);
Lerche 0:8439874eb019 451 }
Lerche 0:8439874eb019 452 if( (draw_x7 >= 0) && (draw_y7 <= NOKIALCD_HEIGHT) )
Lerche 0:8439874eb019 453 {
Lerche 0:8439874eb019 454 _window(draw_x7, draw_y7, 1, 1);
Lerche 0:8439874eb019 455 _putp(colour);
Lerche 0:8439874eb019 456 }
Lerche 0:8439874eb019 457 }
Lerche 0:8439874eb019 458 _cs = 1;
Lerche 0:8439874eb019 459 return;
Lerche 0:8439874eb019 460 }
Lerche 0:8439874eb019 461
Lerche 1:14c8b85b34d0 462 void NokiaLCD::line(int x0, int y0, int x1, int y1, int colour) {
Lerche 1:14c8b85b34d0 463 int dx = 0, dy = 0;
Lerche 1:14c8b85b34d0 464 int dx_sym = 0, dy_sym = 0;
Lerche 1:14c8b85b34d0 465 int dx_x2 = 0, dy_x2 = 0;
Lerche 1:14c8b85b34d0 466 int di = 0;
Lerche 1:14c8b85b34d0 467
Lerche 1:14c8b85b34d0 468 _cs = 0; // Chipselect the LCD.
Lerche 1:14c8b85b34d0 469
Lerche 1:14c8b85b34d0 470 dx = x1-x0;
Lerche 1:14c8b85b34d0 471 dy = y1-y0;
Lerche 1:14c8b85b34d0 472
Lerche 1:14c8b85b34d0 473
Lerche 1:14c8b85b34d0 474 if(dx == 0) /* vertical line */
Lerche 1:14c8b85b34d0 475 {
Lerche 1:14c8b85b34d0 476 for(int y=y0; y<y1; y++){
Lerche 1:14c8b85b34d0 477 _window(x0, y, 1, 1);
Lerche 1:14c8b85b34d0 478 _putp(colour);
Lerche 1:14c8b85b34d0 479 }
Lerche 1:14c8b85b34d0 480 return;
Lerche 1:14c8b85b34d0 481 }
Lerche 1:14c8b85b34d0 482
Lerche 1:14c8b85b34d0 483 if(dx > 0)
Lerche 1:14c8b85b34d0 484 {
Lerche 1:14c8b85b34d0 485 dx_sym = 1;
Lerche 1:14c8b85b34d0 486 }
Lerche 1:14c8b85b34d0 487 else
Lerche 1:14c8b85b34d0 488 {
Lerche 1:14c8b85b34d0 489 dx_sym = -1;
Lerche 1:14c8b85b34d0 490 }
Lerche 1:14c8b85b34d0 491
Lerche 1:14c8b85b34d0 492
Lerche 1:14c8b85b34d0 493 if(dy == 0) /* horizontal line */
Lerche 1:14c8b85b34d0 494 {
Lerche 1:14c8b85b34d0 495 for(int x=x0; x<x1; x++){
Lerche 1:14c8b85b34d0 496 _window(x, y0, 1, 1);
Lerche 1:14c8b85b34d0 497 _putp(colour);
Lerche 1:14c8b85b34d0 498 }
Lerche 1:14c8b85b34d0 499 return;
Lerche 1:14c8b85b34d0 500 }
Lerche 1:14c8b85b34d0 501
Lerche 1:14c8b85b34d0 502
Lerche 1:14c8b85b34d0 503 if(dy > 0)
Lerche 1:14c8b85b34d0 504 {
Lerche 1:14c8b85b34d0 505 dy_sym = 1;
Lerche 1:14c8b85b34d0 506 }
Lerche 1:14c8b85b34d0 507 else
Lerche 1:14c8b85b34d0 508 {
Lerche 1:14c8b85b34d0 509 dy_sym = -1;
Lerche 1:14c8b85b34d0 510 }
Lerche 1:14c8b85b34d0 511
Lerche 1:14c8b85b34d0 512 dx = dx_sym*dx;
Lerche 1:14c8b85b34d0 513 dy = dy_sym*dy;
Lerche 1:14c8b85b34d0 514
Lerche 1:14c8b85b34d0 515 dx_x2 = dx*2;
Lerche 1:14c8b85b34d0 516 dy_x2 = dy*2;
Lerche 1:14c8b85b34d0 517
Lerche 1:14c8b85b34d0 518 if(dx >= dy)
Lerche 1:14c8b85b34d0 519 {
Lerche 1:14c8b85b34d0 520 di = dy_x2 - dx;
Lerche 1:14c8b85b34d0 521 while(x0 != x1)
Lerche 1:14c8b85b34d0 522 {
Lerche 1:14c8b85b34d0 523
Lerche 1:14c8b85b34d0 524 _window(x0, y0, 1, 1);
Lerche 1:14c8b85b34d0 525 _putp(colour);
Lerche 1:14c8b85b34d0 526 x0 += dx_sym;
Lerche 1:14c8b85b34d0 527 if(di<0)
Lerche 1:14c8b85b34d0 528 {
Lerche 1:14c8b85b34d0 529 di += dy_x2;
Lerche 1:14c8b85b34d0 530 }
Lerche 1:14c8b85b34d0 531 else
Lerche 1:14c8b85b34d0 532 {
Lerche 1:14c8b85b34d0 533 di += dy_x2 - dx_x2;
Lerche 1:14c8b85b34d0 534 y0 += dy_sym;
Lerche 1:14c8b85b34d0 535 }
Lerche 1:14c8b85b34d0 536 }
Lerche 1:14c8b85b34d0 537 _window(x0, y0, 1, 1);
Lerche 1:14c8b85b34d0 538 _putp(colour);
Lerche 1:14c8b85b34d0 539 }
Lerche 1:14c8b85b34d0 540 else
Lerche 1:14c8b85b34d0 541 {
Lerche 1:14c8b85b34d0 542 di = dx_x2 - dy;
Lerche 1:14c8b85b34d0 543 while(y0 != y1)
Lerche 1:14c8b85b34d0 544 {
Lerche 1:14c8b85b34d0 545 _window(x0, y0, 1, 1);
Lerche 1:14c8b85b34d0 546 _putp(colour);
Lerche 1:14c8b85b34d0 547 y0 += dy_sym;
Lerche 1:14c8b85b34d0 548 if(di < 0)
Lerche 1:14c8b85b34d0 549 {
Lerche 1:14c8b85b34d0 550 di += dx_x2;
Lerche 1:14c8b85b34d0 551 }
Lerche 1:14c8b85b34d0 552 else
Lerche 1:14c8b85b34d0 553 {
Lerche 1:14c8b85b34d0 554 di += dx_x2 - dy_x2;
Lerche 1:14c8b85b34d0 555 x0 += dx_sym;
Lerche 1:14c8b85b34d0 556 }
Lerche 1:14c8b85b34d0 557 }
Lerche 2:d99e9681356b 558 _window(x0, y0, 1, 1);
Lerche 1:14c8b85b34d0 559 _putp(colour);
Lerche 1:14c8b85b34d0 560 }
Lerche 1:14c8b85b34d0 561 _cs = 1;
Lerche 1:14c8b85b34d0 562 return;
Lerche 1:14c8b85b34d0 563 }
Lerche 1:14c8b85b34d0 564
Lerche 0:8439874eb019 565 void NokiaLCD::blit(int x, int y, int width, int height, const int* colour) {
Lerche 0:8439874eb019 566 _cs = 0;
Lerche 0:8439874eb019 567 _window(x, y, width, height);
Lerche 0:8439874eb019 568 for (int i=0; i<width*height; i++) {
Lerche 0:8439874eb019 569 _putp(colour[i]);
Lerche 0:8439874eb019 570 }
Lerche 0:8439874eb019 571 _window(0, 0, NOKIALCD_WIDTH, NOKIALCD_HEIGHT);
Lerche 0:8439874eb019 572 _cs = 1;
Lerche 0:8439874eb019 573 }
Lerche 0:8439874eb019 574
Lerche 0:8439874eb019 575 void NokiaLCD::bitblit(int x, int y, int width, int height, const char* bitstream) {
Lerche 0:8439874eb019 576 _cs = 0;
Lerche 0:8439874eb019 577 _window(x, y, width, height);
Lerche 0:8439874eb019 578 for (int i=0; i<height*width; i++) {
Lerche 0:8439874eb019 579 int byte = i / 8;
Lerche 0:8439874eb019 580 int bit = i % 8;
Lerche 0:8439874eb019 581 int colour = ((bitstream[byte] << bit) & 0x80) ? _foreground : _background;
Lerche 0:8439874eb019 582 _putp(colour);
Lerche 0:8439874eb019 583 }
Lerche 0:8439874eb019 584 _window(0, 0, _width, _height);
Lerche 0:8439874eb019 585 _cs = 1;
Lerche 0:8439874eb019 586 }
Lerche 0:8439874eb019 587
Lerche 0:8439874eb019 588 void NokiaLCD::foreground(int c) {
Lerche 0:8439874eb019 589 _foreground = c;
Lerche 0:8439874eb019 590 }
Lerche 0:8439874eb019 591
Lerche 0:8439874eb019 592 void NokiaLCD::background(int c) {
Lerche 0:8439874eb019 593 _background = c;
Lerche 0:8439874eb019 594 }
Lerche 0:8439874eb019 595
Lerche 0:8439874eb019 596 int NokiaLCD::width() {
Lerche 0:8439874eb019 597 return NOKIALCD_WIDTH;
Lerche 0:8439874eb019 598 }
Lerche 0:8439874eb019 599
Lerche 0:8439874eb019 600 int NokiaLCD::height() {
Lerche 0:8439874eb019 601 return NOKIALCD_HEIGHT;
Lerche 0:8439874eb019 602 }
Lerche 0:8439874eb019 603
Lerche 0:8439874eb019 604 int NokiaLCD::columns() {
Lerche 0:8439874eb019 605 return NOKIALCD_COLS;
Lerche 0:8439874eb019 606 }
Lerche 0:8439874eb019 607
Lerche 0:8439874eb019 608 int NokiaLCD::rows() {
Lerche 0:8439874eb019 609 return NOKIALCD_ROWS;
Lerche 0:8439874eb019 610 }