This Program is for MAPLE board with OLED and GPS/RTC module. OLED module(OB) : 128 x 128 pixels, 4K color GPS/RTC module(GB) : UP501 These module can buy Marutyu (http://www.marutsu.co.jp)

Dependencies:   mbed

Committer:
y_notsu
Date:
Sun Jun 05 15:10:48 2011 +0000
Revision:
0:58e40a872950

        

Who changed what in which revision?

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