This is a MIDI synthesizer with touchpads used for playing the notes. mbed will capture the touchpad press and release events and sends the appropriate MIDI commands to the PC. By using the C# windows forms application created by us, one can compose songs as though they were composed on a piano. We support all types of standard MIDI piano types.

Dependencies:   mbed

Committer:
thejasvi3
Date:
Thu Oct 13 06:17:30 2011 +0000
Revision:
0:e33f18af0471

        

Who changed what in which revision?

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