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