This builds on TCPSocket_HelloWorld and others to read an in-coming buffer and then build and send a buffer. Very much work in progress

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Committer:
acodd
Date:
Sat Feb 09 22:29:18 2013 +0000
Revision:
12:cce8fa67de18
First main release

Who changed what in which revision?

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