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