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