Committer:
Wimpie
Date:
Thu May 19 18:06:13 2011 +0000
Revision:
1:ce391193b822
Parent:
0:6468a28a7b7d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wimpie 0:6468a28a7b7d 1 /* mbed PCD8544 - Graphic Library for driving monochrome displays based on
Wimpie 0:6468a28a7b7d 2 * the PCD8544 48 x 84 pixels matrix LCD controller/driver
Wimpie 0:6468a28a7b7d 3 * used in Nokia 3310, 3315, 3330, 3350, 3410, 3210, 5110, 5120, 5130, 5160, 6110, 6150
Wimpie 0:6468a28a7b7d 4 *
Wimpie 0:6468a28a7b7d 5 * Copyright (c) 2011, Wim De Roeve
Wimpie 0:6468a28a7b7d 6 * partial port of the code found on http://serdisplib.sourceforge.net/ser/pcd8544.html#links
Wimpie 0:6468a28a7b7d 7 * and by Petras Saduikis <petras@petras.co.uk>
Wimpie 0:6468a28a7b7d 8 *
Wimpie 0:6468a28a7b7d 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
Wimpie 0:6468a28a7b7d 10 * of this software and associated documentation files (the "Software"), to deal
Wimpie 0:6468a28a7b7d 11 * in the Software without restriction, including without limitation the rights
Wimpie 0:6468a28a7b7d 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Wimpie 0:6468a28a7b7d 13 * copies of the updaSoftware, and to permit persons to whom the Software is
Wimpie 0:6468a28a7b7d 14 * furnished to do so, subject to the following conditions:
Wimpie 0:6468a28a7b7d 15 *
Wimpie 0:6468a28a7b7d 16 * The above copyright notice and this permission notice shall be included in
Wimpie 0:6468a28a7b7d 17 * all copies or substantial portions of the Software.
Wimpie 0:6468a28a7b7d 18 *
Wimpie 0:6468a28a7b7d 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wimpie 0:6468a28a7b7d 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wimpie 0:6468a28a7b7d 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wimpie 0:6468a28a7b7d 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wimpie 0:6468a28a7b7d 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wimpie 0:6468a28a7b7d 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wimpie 0:6468a28a7b7d 25 * THE SOFTWARE.
Wimpie 0:6468a28a7b7d 26 */
Wimpie 0:6468a28a7b7d 27
Wimpie 0:6468a28a7b7d 28 #include "PCD8544LCD.h"
Wimpie 0:6468a28a7b7d 29
Wimpie 0:6468a28a7b7d 30 #include "fonts/font_3x5.h"
Wimpie 0:6468a28a7b7d 31 #include "fonts/font_5x7.h"
Wimpie 0:6468a28a7b7d 32 #include "fonts/font_6x8.h"
Wimpie 0:6468a28a7b7d 33 #include "fonts/font_8x8.h"
Wimpie 0:6468a28a7b7d 34 #include "fonts/font_8x12.h"
Wimpie 0:6468a28a7b7d 35 #include "fonts/font_16x20.h"
Wimpie 0:6468a28a7b7d 36 #include "fonts/font_16x24.h"
Wimpie 0:6468a28a7b7d 37
Wimpie 0:6468a28a7b7d 38 #include "DebugTrace.h"
Wimpie 0:6468a28a7b7d 39 #include "sstream"
Wimpie 1:ce391193b822 40 #include "stdio.h"
Wimpie 1:ce391193b822 41 #include "stringman.h"
Wimpie 0:6468a28a7b7d 42
Wimpie 0:6468a28a7b7d 43 DebugTrace pc_PCD8544(ON, TO_SERIAL);
Wimpie 0:6468a28a7b7d 44
Wimpie 0:6468a28a7b7d 45 /*
Wimpie 0:6468a28a7b7d 46 PCD8544 from Philips Semiconductors is
Wimpie 0:6468a28a7b7d 47 48 x 84 pixels monochrome matrix LCD controller/driver
Wimpie 0:6468a28a7b7d 48
Wimpie 0:6468a28a7b7d 49 generic for LPH7366, LPH7677, and LPH7779; no backlight
Wimpie 0:6468a28a7b7d 50
Wimpie 0:6468a28a7b7d 51 model name (of display) type used in cellphones
Wimpie 0:6468a28a7b7d 52 LPH 7366 2 Nokia 5110, 5120, 5130, 5160, 6110, 6150
Wimpie 0:6468a28a7b7d 53 LPH 7677 1 Nokia 3210
Wimpie 0:6468a28a7b7d 54 LPH 7779 1 Nokia 3310, 3315, 3330, 3350, 3410
Wimpie 0:6468a28a7b7d 55
Wimpie 0:6468a28a7b7d 56
Wimpie 0:6468a28a7b7d 57 +-------------------------+
Wimpie 0:6468a28a7b7d 58 | 1 2 3 4 5 6 7 8 |
Wimpie 0:6468a28a7b7d 59 | # # # # # # # # |
Wimpie 1:ce391193b822 60 | ===#=#=#=#=#=#=#=#=== | Red 1 .. VDD - chip power supply +3.3V
Wimpie 0:6468a28a7b7d 61 +--=====================--+ Green 2 .. SCLK - serial clock line of LCD
Wimpie 0:6468a28a7b7d 62 | | Yellow 3 .. SI - serial data input of LCD
Wimpie 0:6468a28a7b7d 63 | | Gray 4 .. D/C - command/data switch
Wimpie 0:6468a28a7b7d 64 | rear view | Blue 5 .. /CS - active low chip select
Wimpie 0:6468a28a7b7d 65 | connector is visible | Black 6 .. GND - for VDD
Wimpie 0:6468a28a7b7d 66 | | 7 .. Vout - output of display-internal dc/dc converter
Wimpie 0:6468a28a7b7d 67 | LPH7779 | White 8 .. /RES - active low reset
Wimpie 0:6468a28a7b7d 68 | |
Wimpie 0:6468a28a7b7d 69 +-------------------------+
Wimpie 0:6468a28a7b7d 70
Wimpie 0:6468a28a7b7d 71 */
Wimpie 0:6468a28a7b7d 72
Wimpie 1:ce391193b822 73
Wimpie 0:6468a28a7b7d 74 PCD8544LCD::PCD8544LCD (PinName mosi, PinName miso, PinName sck,
Wimpie 0:6468a28a7b7d 75 PinName cs, PinName data_cmd, PinName reset):
Wimpie 0:6468a28a7b7d 76 _spi(mosi, miso, sck),
Wimpie 0:6468a28a7b7d 77 _cs(cs),
Wimpie 0:6468a28a7b7d 78 _dc(data_cmd),
Wimpie 0:6468a28a7b7d 79 _reset(reset) {
Wimpie 0:6468a28a7b7d 80
Wimpie 0:6468a28a7b7d 81 _cs = HIGH;
Wimpie 0:6468a28a7b7d 82 _reset = HIGH;
Wimpie 0:6468a28a7b7d 83
Wimpie 0:6468a28a7b7d 84 init();
Wimpie 0:6468a28a7b7d 85 }
Wimpie 0:6468a28a7b7d 86
Wimpie 0:6468a28a7b7d 87 void PCD8544LCD::init() {
Wimpie 0:6468a28a7b7d 88
Wimpie 1:ce391193b822 89 pc_PCD8544.traceOut("Init PCD8544\r\n");
Wimpie 0:6468a28a7b7d 90 _spi.format(8,0);
Wimpie 0:6468a28a7b7d 91 _spi.frequency(1000000);
Wimpie 0:6468a28a7b7d 92
Wimpie 0:6468a28a7b7d 93 /* reset lcd
Wimpie 0:6468a28a7b7d 94
Wimpie 0:6468a28a7b7d 95 After reset, the LCD driver has the following state:
Wimpie 0:6468a28a7b7d 96 - Power-down mode (bit PD = 1)
Wimpie 0:6468a28a7b7d 97 - Horizontal addressing (bit V = 0)
Wimpie 0:6468a28a7b7d 98 - normal instruction set (bit H = 0)
Wimpie 0:6468a28a7b7d 99 - Display blank (bit E = D = 0)
Wimpie 0:6468a28a7b7d 100 - Address counter X6 to X0 = 0; Y2 to Y0 = 0
Wimpie 0:6468a28a7b7d 101 - Temperature control mode (TC1 TC0 = 0)
Wimpie 0:6468a28a7b7d 102 - Bias system (BS2 to BS0 = 0)
Wimpie 0:6468a28a7b7d 103 - VLCD is equal to 0, the HV generator is switched off
Wimpie 0:6468a28a7b7d 104 (VOP6 to VOP0 = 0)
Wimpie 0:6468a28a7b7d 105 - After power-on, the RAM contents are undefined.
Wimpie 0:6468a28a7b7d 106 */
Wimpie 0:6468a28a7b7d 107
Wimpie 0:6468a28a7b7d 108 wait_ms(1);
Wimpie 0:6468a28a7b7d 109 _reset = LOW; // reset
Wimpie 0:6468a28a7b7d 110 wait_ms(1);
Wimpie 0:6468a28a7b7d 111 _reset = HIGH;
Wimpie 0:6468a28a7b7d 112
Wimpie 0:6468a28a7b7d 113 writeCmd(EXTENDEDSET); // folowing commands are extended ones
Wimpie 0:6468a28a7b7d 114 writeCmd(0xc8); // Set Voltage 0x80+value: set contrast
Wimpie 0:6468a28a7b7d 115 writeCmd(0x06); // set temp coefficient
Wimpie 0:6468a28a7b7d 116 writeCmd(0x13); // set BIAS mode 1:48
Wimpie 0:6468a28a7b7d 117 writeCmd(STANDARDSET); // STANDARDSET: following commands are standard ones
Wimpie 0:6468a28a7b7d 118
Wimpie 0:6468a28a7b7d 119 writeCmd(NORMAL_MODE);
Wimpie 0:6468a28a7b7d 120
Wimpie 1:ce391193b822 121
Wimpie 1:ce391193b822 122 _LoMark = 0;
Wimpie 1:ce391193b822 123 _HiMark = LCD_CACHE_SIZE - 1;
Wimpie 1:ce391193b822 124 //_LoMark = LCD_CACHE_SIZE; // Reset watermark pointers.
Wimpie 1:ce391193b822 125 // _HiMark = 0;
Wimpie 0:6468a28a7b7d 126
Wimpie 0:6468a28a7b7d 127 cls();
Wimpie 0:6468a28a7b7d 128 }
Wimpie 0:6468a28a7b7d 129
Wimpie 0:6468a28a7b7d 130 void PCD8544LCD::writeCmd(BYTE data) {
Wimpie 0:6468a28a7b7d 131 _cs = LOW;
Wimpie 0:6468a28a7b7d 132 _dc = LOW;
Wimpie 0:6468a28a7b7d 133 _spi.write(data);
Wimpie 0:6468a28a7b7d 134 _cs = HIGH;
Wimpie 0:6468a28a7b7d 135 }
Wimpie 0:6468a28a7b7d 136
Wimpie 0:6468a28a7b7d 137 void PCD8544LCD::writeData(BYTE data) {
Wimpie 0:6468a28a7b7d 138 _cs = LOW;
Wimpie 0:6468a28a7b7d 139 _dc = HIGH;
Wimpie 0:6468a28a7b7d 140 _spi.write(data);
Wimpie 0:6468a28a7b7d 141 _cs = HIGH;
Wimpie 0:6468a28a7b7d 142 }
Wimpie 0:6468a28a7b7d 143
Wimpie 0:6468a28a7b7d 144 void PCD8544LCD::close() {
Wimpie 0:6468a28a7b7d 145 writeCmd(DISPLAYOFF);
Wimpie 0:6468a28a7b7d 146 _cs = HIGH;
Wimpie 0:6468a28a7b7d 147 _reset = HIGH;
Wimpie 0:6468a28a7b7d 148 }
Wimpie 0:6468a28a7b7d 149
Wimpie 0:6468a28a7b7d 150 // GRAPHICAL functions
Wimpie 0:6468a28a7b7d 151
Wimpie 1:ce391193b822 152 void PCD8544LCD::cls(bool fupdate) {
Wimpie 0:6468a28a7b7d 153 for (int i = 0; i < LCD_CACHE_SIZE ; i++) {
Wimpie 1:ce391193b822 154 LcdCache[i]=0x00;
Wimpie 0:6468a28a7b7d 155 }
Wimpie 0:6468a28a7b7d 156 _LoMark = 0;
Wimpie 0:6468a28a7b7d 157 _HiMark = LCD_CACHE_SIZE - 1;
Wimpie 1:ce391193b822 158 if (fupdate)
Wimpie 1:ce391193b822 159 update();
Wimpie 0:6468a28a7b7d 160 }
Wimpie 0:6468a28a7b7d 161
Wimpie 0:6468a28a7b7d 162 void PCD8544LCD::update() {
Wimpie 0:6468a28a7b7d 163
Wimpie 0:6468a28a7b7d 164 if ( _LoMark < 0 )
Wimpie 0:6468a28a7b7d 165 _LoMark = 0;
Wimpie 0:6468a28a7b7d 166 else if ( _LoMark >= LCD_CACHE_SIZE )
Wimpie 0:6468a28a7b7d 167 _LoMark = LCD_CACHE_SIZE - 1;
Wimpie 0:6468a28a7b7d 168 if ( _HiMark < 0 )
Wimpie 0:6468a28a7b7d 169 _HiMark = 0;
Wimpie 0:6468a28a7b7d 170 else if ( _HiMark >= LCD_CACHE_SIZE )
Wimpie 0:6468a28a7b7d 171 _HiMark = LCD_CACHE_SIZE - 1;
Wimpie 0:6468a28a7b7d 172
Wimpie 0:6468a28a7b7d 173 writeCmd(SET_ADDRES_X | (_LoMark % LCD_X_RES));
Wimpie 0:6468a28a7b7d 174 writeCmd(SET_ADDRES_Y | (_LoMark / LCD_X_RES));
Wimpie 0:6468a28a7b7d 175
Wimpie 0:6468a28a7b7d 176 for (int i = _LoMark; i <= _HiMark; i++ ) {
Wimpie 1:ce391193b822 177 writeData( LcdCache[i]);
Wimpie 0:6468a28a7b7d 178 }
Wimpie 0:6468a28a7b7d 179 _LoMark = LCD_CACHE_SIZE - 1;
Wimpie 0:6468a28a7b7d 180 _HiMark = 0;
Wimpie 0:6468a28a7b7d 181 }
Wimpie 0:6468a28a7b7d 182
Wimpie 0:6468a28a7b7d 183
Wimpie 0:6468a28a7b7d 184
Wimpie 0:6468a28a7b7d 185 void PCD8544LCD::locate(BYTE x0, BYTE y0) {
Wimpie 1:ce391193b822 186 LcdCacheIdx = x0*LCD_BANKS + y0 * LCD_X_RES;
Wimpie 0:6468a28a7b7d 187 }
Wimpie 0:6468a28a7b7d 188
Wimpie 0:6468a28a7b7d 189 // Bitmap
Wimpie 0:6468a28a7b7d 190
Wimpie 1:ce391193b822 191 void PCD8544LCD::drawBitmap(BYTE x0, BYTE y0, const unsigned char* bitmap, BYTE bmpXSize, BYTE bmpYSize,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 192 BYTE row;
Wimpie 0:6468a28a7b7d 193
Wimpie 0:6468a28a7b7d 194 if (0 == bmpYSize % 8)
Wimpie 0:6468a28a7b7d 195 row = bmpYSize/8;
Wimpie 0:6468a28a7b7d 196 else
Wimpie 0:6468a28a7b7d 197 row = bmpYSize/8 + 1;
Wimpie 0:6468a28a7b7d 198
Wimpie 0:6468a28a7b7d 199 _LoMark= 0;
Wimpie 0:6468a28a7b7d 200 _HiMark= LCD_CACHE_SIZE - 1;
Wimpie 0:6468a28a7b7d 201
Wimpie 0:6468a28a7b7d 202 for (BYTE n = 0; n < row; n++) {
Wimpie 0:6468a28a7b7d 203 locate(x0, y0);
Wimpie 0:6468a28a7b7d 204
Wimpie 0:6468a28a7b7d 205 for (BYTE i = 0; i < bmpXSize; i++) {
Wimpie 1:ce391193b822 206 LcdCache[LcdCacheIdx+ i]=bitmap[i + (n * bmpXSize)];
Wimpie 0:6468a28a7b7d 207 }
Wimpie 0:6468a28a7b7d 208 y0++;
Wimpie 0:6468a28a7b7d 209 }
Wimpie 0:6468a28a7b7d 210 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 211 update();
Wimpie 0:6468a28a7b7d 212 }
Wimpie 0:6468a28a7b7d 213
Wimpie 1:ce391193b822 214 void PCD8544LCD::writeString(BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode dmode,eSpaceMode smode, BYTE fupdate) {
Wimpie 0:6468a28a7b7d 215 locate(x0, y0);
Wimpie 0:6468a28a7b7d 216 chooseFont(font);
Wimpie 0:6468a28a7b7d 217
Wimpie 0:6468a28a7b7d 218 while (*string) {
Wimpie 1:ce391193b822 219 writeChar(x0,y0,*string++,font, dmode, FALSE);
Wimpie 0:6468a28a7b7d 220 x0+=_font_width; // width +1;
Wimpie 1:ce391193b822 221 if (smode==SPACE_NORMAL)
Wimpie 1:ce391193b822 222 x0++;
Wimpie 0:6468a28a7b7d 223 }
Wimpie 0:6468a28a7b7d 224 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 225 update();
Wimpie 0:6468a28a7b7d 226 }
Wimpie 0:6468a28a7b7d 227
Wimpie 0:6468a28a7b7d 228 void PCD8544LCD::chooseFont(eFonts font) {
Wimpie 0:6468a28a7b7d 229
Wimpie 0:6468a28a7b7d 230 switch (font) {
Wimpie 0:6468a28a7b7d 231
Wimpie 0:6468a28a7b7d 232 case VERYSMALLFONT: {
Wimpie 0:6468a28a7b7d 233 _font_width = FONT3x5_WIDTH;
Wimpie 0:6468a28a7b7d 234 _font_height = FONT3x5_HEIGHT;
Wimpie 0:6468a28a7b7d 235 _font_start = FONT3x5_START;
Wimpie 0:6468a28a7b7d 236 _font_end = FONT3x5_END;
Wimpie 0:6468a28a7b7d 237
Wimpie 0:6468a28a7b7d 238 _pFont = (unsigned char*) font_3x5;
Wimpie 0:6468a28a7b7d 239
Wimpie 0:6468a28a7b7d 240 break;
Wimpie 0:6468a28a7b7d 241 }
Wimpie 0:6468a28a7b7d 242 case TINYFONT: {
Wimpie 0:6468a28a7b7d 243 _font_width = FONT5x7_WIDTH;
Wimpie 0:6468a28a7b7d 244 _font_height = FONT5x7_HEIGHT;
Wimpie 0:6468a28a7b7d 245 _font_start = FONT5x7_START;
Wimpie 0:6468a28a7b7d 246 _font_end = FONT5x7_END;
Wimpie 0:6468a28a7b7d 247
Wimpie 0:6468a28a7b7d 248 _pFont = (unsigned char*) font_5x7;
Wimpie 0:6468a28a7b7d 249
Wimpie 0:6468a28a7b7d 250 break;
Wimpie 0:6468a28a7b7d 251 }
Wimpie 0:6468a28a7b7d 252
Wimpie 0:6468a28a7b7d 253 case SMALLFONT: {
Wimpie 0:6468a28a7b7d 254 _font_width = FONT6x8_WIDTH;
Wimpie 0:6468a28a7b7d 255 _font_height = FONT6x8_HEIGHT;
Wimpie 0:6468a28a7b7d 256 _font_start = FONT6x8_START;
Wimpie 0:6468a28a7b7d 257 _font_end = FONT6x8_END;
Wimpie 0:6468a28a7b7d 258
Wimpie 0:6468a28a7b7d 259 _pFont = (unsigned char*) font_6x8;
Wimpie 0:6468a28a7b7d 260
Wimpie 0:6468a28a7b7d 261 break;
Wimpie 0:6468a28a7b7d 262 }
Wimpie 0:6468a28a7b7d 263 case NORMALFONT: {
Wimpie 0:6468a28a7b7d 264 _font_width = FONT8x8_WIDTH;
Wimpie 0:6468a28a7b7d 265 _font_height = FONT8x8_HEIGHT;
Wimpie 0:6468a28a7b7d 266 _font_start = FONT8x8_START;
Wimpie 0:6468a28a7b7d 267 _font_end = FONT8x8_END;
Wimpie 0:6468a28a7b7d 268
Wimpie 0:6468a28a7b7d 269 _pFont = (unsigned char*) font_8x8;
Wimpie 0:6468a28a7b7d 270
Wimpie 0:6468a28a7b7d 271 break;
Wimpie 0:6468a28a7b7d 272 }
Wimpie 0:6468a28a7b7d 273 case BIGFONT: {
Wimpie 0:6468a28a7b7d 274 _font_width = FONT8x12_WIDTH;
Wimpie 0:6468a28a7b7d 275 _font_height = FONT8x12_HEIGHT;
Wimpie 0:6468a28a7b7d 276 _font_start = FONT8x12_START;
Wimpie 0:6468a28a7b7d 277 _font_end = FONT8x12_END;
Wimpie 0:6468a28a7b7d 278
Wimpie 0:6468a28a7b7d 279 _pFont = (unsigned char*) font_8x12;
Wimpie 0:6468a28a7b7d 280
Wimpie 0:6468a28a7b7d 281 break;
Wimpie 0:6468a28a7b7d 282 }
Wimpie 0:6468a28a7b7d 283
Wimpie 0:6468a28a7b7d 284 case TIMENUMBERFONT: {
Wimpie 0:6468a28a7b7d 285 _font_width = FONT16x20_WIDTH;
Wimpie 0:6468a28a7b7d 286 _font_height = FONT16x20_HEIGHT;
Wimpie 0:6468a28a7b7d 287 _font_start = FONT16x20_START;
Wimpie 0:6468a28a7b7d 288 _font_end = FONT16x20_END;
Wimpie 0:6468a28a7b7d 289
Wimpie 0:6468a28a7b7d 290 _pFont = (unsigned char*) font_16x20;
Wimpie 0:6468a28a7b7d 291
Wimpie 0:6468a28a7b7d 292 break;
Wimpie 0:6468a28a7b7d 293 }
Wimpie 0:6468a28a7b7d 294
Wimpie 0:6468a28a7b7d 295 case BIGNUMBERFONT: {
Wimpie 0:6468a28a7b7d 296 _font_width = FONT16x24_WIDTH;
Wimpie 0:6468a28a7b7d 297 _font_height = FONT16x24_HEIGHT;
Wimpie 0:6468a28a7b7d 298 _font_start = FONT16x24_START;
Wimpie 0:6468a28a7b7d 299 _font_end = FONT16x24_END;
Wimpie 0:6468a28a7b7d 300
Wimpie 0:6468a28a7b7d 301 _pFont = (unsigned char*) font_16x24;
Wimpie 0:6468a28a7b7d 302
Wimpie 0:6468a28a7b7d 303 break;
Wimpie 0:6468a28a7b7d 304 }
Wimpie 0:6468a28a7b7d 305 }
Wimpie 0:6468a28a7b7d 306 }
Wimpie 0:6468a28a7b7d 307
Wimpie 0:6468a28a7b7d 308 void PCD8544LCD::writeChar(BYTE x0, BYTE y0, BYTE ch, eFonts font, eDisplayMode mode,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 309 BYTE sendByte;
Wimpie 0:6468a28a7b7d 310
Wimpie 0:6468a28a7b7d 311 chooseFont(font);
Wimpie 0:6468a28a7b7d 312
Wimpie 0:6468a28a7b7d 313 if ((ch <= _font_start) || (ch > _font_end))
Wimpie 0:6468a28a7b7d 314 ch=_font_start;
Wimpie 0:6468a28a7b7d 315
Wimpie 0:6468a28a7b7d 316 ch -= _font_start;
Wimpie 0:6468a28a7b7d 317
Wimpie 0:6468a28a7b7d 318 for (int i = 0; i < _font_width; i++ ) {
Wimpie 0:6468a28a7b7d 319
Wimpie 0:6468a28a7b7d 320 sendByte = *(_pFont + ch*_font_width +i);
Wimpie 0:6468a28a7b7d 321 sendByte = ((mode == NORMAL)? sendByte:(sendByte ^ 0xff));
Wimpie 0:6468a28a7b7d 322
Wimpie 0:6468a28a7b7d 323 for (int j=0 ; j<_font_height; j++) {
Wimpie 0:6468a28a7b7d 324 if ((sendByte & 0x01) == 0x01) {
Wimpie 0:6468a28a7b7d 325 drawpixel(x0,y0+j,PIXEL_ON,FALSE);
Wimpie 0:6468a28a7b7d 326 } else {
Wimpie 0:6468a28a7b7d 327 drawpixel(x0,y0+j,PIXEL_OFF,FALSE);
Wimpie 0:6468a28a7b7d 328 }
Wimpie 0:6468a28a7b7d 329 sendByte=sendByte>>1;
Wimpie 0:6468a28a7b7d 330 }
Wimpie 0:6468a28a7b7d 331 x0++;
Wimpie 0:6468a28a7b7d 332 }
Wimpie 0:6468a28a7b7d 333 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 334 update();
Wimpie 0:6468a28a7b7d 335 }
Wimpie 0:6468a28a7b7d 336
Wimpie 0:6468a28a7b7d 337
Wimpie 0:6468a28a7b7d 338 void PCD8544LCD::drawpixel(BYTE x0, BYTE y0, ePixelMode mode,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 339 uint16_t index;
Wimpie 0:6468a28a7b7d 340 BYTE offset;
Wimpie 0:6468a28a7b7d 341 BYTE data;
Wimpie 0:6468a28a7b7d 342
Wimpie 0:6468a28a7b7d 343 if ( x0 > LCD_X_RES-1 ) return;
Wimpie 0:6468a28a7b7d 344 if ( y0 > LCD_Y_RES-1 ) return;
Wimpie 0:6468a28a7b7d 345
Wimpie 0:6468a28a7b7d 346 index = ((y0 / 8) * LCD_X_RES) + x0;
Wimpie 0:6468a28a7b7d 347 offset = y0 - ((y0 / 8) * 8);
Wimpie 0:6468a28a7b7d 348
Wimpie 1:ce391193b822 349 data = LcdCache[index];
Wimpie 0:6468a28a7b7d 350
Wimpie 0:6468a28a7b7d 351 if ( mode == PIXEL_OFF ) {
Wimpie 0:6468a28a7b7d 352 data &= (~(0x01 << offset));
Wimpie 0:6468a28a7b7d 353 } else if ( mode == PIXEL_ON ) {
Wimpie 0:6468a28a7b7d 354 data |= (0x01 << offset);
Wimpie 0:6468a28a7b7d 355 } else if ( mode == PIXEL_XOR ) {
Wimpie 0:6468a28a7b7d 356 data ^= (0x01 << offset);
Wimpie 0:6468a28a7b7d 357 }
Wimpie 1:ce391193b822 358 LcdCache[index] = data;
Wimpie 0:6468a28a7b7d 359
Wimpie 0:6468a28a7b7d 360 if ( index < _LoMark ) {
Wimpie 0:6468a28a7b7d 361 _LoMark = index;
Wimpie 0:6468a28a7b7d 362 }
Wimpie 0:6468a28a7b7d 363 if ( index > _HiMark ) {
Wimpie 0:6468a28a7b7d 364 _HiMark = index;
Wimpie 0:6468a28a7b7d 365 }
Wimpie 0:6468a28a7b7d 366 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 367 update();
Wimpie 0:6468a28a7b7d 368 }
Wimpie 0:6468a28a7b7d 369
Wimpie 0:6468a28a7b7d 370 void PCD8544LCD::drawline(BYTE x0, BYTE y0, BYTE x1, BYTE y1, ePixelMode mode,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 371 int dx, dy, stepx, stepy, fraction;
Wimpie 0:6468a28a7b7d 372
Wimpie 0:6468a28a7b7d 373 dy = y1 - y0;
Wimpie 0:6468a28a7b7d 374 dx = x1 - x0;
Wimpie 0:6468a28a7b7d 375 if ( dy < 0 ) {
Wimpie 0:6468a28a7b7d 376 dy = -dy;
Wimpie 0:6468a28a7b7d 377 stepy = -1;
Wimpie 0:6468a28a7b7d 378 } else {
Wimpie 0:6468a28a7b7d 379 stepy = 1;
Wimpie 0:6468a28a7b7d 380 }
Wimpie 0:6468a28a7b7d 381 if ( dx < 0 ) {
Wimpie 0:6468a28a7b7d 382 dx = -dx;
Wimpie 0:6468a28a7b7d 383 stepx = -1;
Wimpie 0:6468a28a7b7d 384 } else {
Wimpie 0:6468a28a7b7d 385 stepx = 1;
Wimpie 0:6468a28a7b7d 386 }
Wimpie 0:6468a28a7b7d 387 dx <<= 1;
Wimpie 0:6468a28a7b7d 388 dy <<= 1;
Wimpie 0:6468a28a7b7d 389
Wimpie 0:6468a28a7b7d 390 drawpixel( x0, y0, mode , FALSE);
Wimpie 0:6468a28a7b7d 391 if ( dx > dy ) {
Wimpie 0:6468a28a7b7d 392 fraction = dy - (dx >> 1);
Wimpie 0:6468a28a7b7d 393 while ( x0 != x1 ) {
Wimpie 0:6468a28a7b7d 394 if ( fraction >= 0 ) {
Wimpie 0:6468a28a7b7d 395 y0 += stepy;
Wimpie 0:6468a28a7b7d 396 fraction -= dx;
Wimpie 0:6468a28a7b7d 397 }
Wimpie 0:6468a28a7b7d 398 x0 += stepx;
Wimpie 0:6468a28a7b7d 399 fraction += dy;
Wimpie 0:6468a28a7b7d 400 drawpixel( x0, y0, mode , FALSE);
Wimpie 0:6468a28a7b7d 401 }
Wimpie 0:6468a28a7b7d 402 } else {
Wimpie 0:6468a28a7b7d 403 fraction = dx - (dy >> 1);
Wimpie 0:6468a28a7b7d 404 while ( y0 != y1 ) {
Wimpie 0:6468a28a7b7d 405 if ( fraction >= 0 ) {
Wimpie 0:6468a28a7b7d 406 x0 += stepx;
Wimpie 0:6468a28a7b7d 407 fraction -= dy;
Wimpie 0:6468a28a7b7d 408 }
Wimpie 0:6468a28a7b7d 409 y0 += stepy;
Wimpie 0:6468a28a7b7d 410 fraction += dx;
Wimpie 0:6468a28a7b7d 411 drawpixel( x0, y0, mode , FALSE);
Wimpie 0:6468a28a7b7d 412 }
Wimpie 0:6468a28a7b7d 413 }
Wimpie 0:6468a28a7b7d 414 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 415 update();
Wimpie 0:6468a28a7b7d 416 }
Wimpie 0:6468a28a7b7d 417
Wimpie 0:6468a28a7b7d 418 void PCD8544LCD::drawrectangle(BYTE x0, BYTE y0, BYTE x1, BYTE y1, eFillMode fill, ePixelMode mode,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 419 if (fill==1) {
Wimpie 0:6468a28a7b7d 420 BYTE i, xmin, xmax, ymin, ymax;
Wimpie 0:6468a28a7b7d 421 if (x0 < x1) { // Find x min and max
Wimpie 0:6468a28a7b7d 422 xmin = x0;
Wimpie 0:6468a28a7b7d 423 xmax = x1;
Wimpie 0:6468a28a7b7d 424 } else {
Wimpie 0:6468a28a7b7d 425 xmin = x1;
Wimpie 0:6468a28a7b7d 426 xmax = x0;
Wimpie 0:6468a28a7b7d 427 }
Wimpie 0:6468a28a7b7d 428 if (y0 < y1) { // Find the y min and max
Wimpie 0:6468a28a7b7d 429 ymin = y0;
Wimpie 0:6468a28a7b7d 430 ymax = y1;
Wimpie 0:6468a28a7b7d 431 } else {
Wimpie 0:6468a28a7b7d 432 ymin = y1;
Wimpie 0:6468a28a7b7d 433 ymax = y0;
Wimpie 0:6468a28a7b7d 434 }
Wimpie 0:6468a28a7b7d 435 for (; xmin <= xmax; ++xmin) {
Wimpie 0:6468a28a7b7d 436 for (i=ymin; i<=ymax; ++i) {
Wimpie 0:6468a28a7b7d 437 drawpixel(xmin, i, mode, FALSE);
Wimpie 0:6468a28a7b7d 438 }
Wimpie 0:6468a28a7b7d 439 }
Wimpie 0:6468a28a7b7d 440 } else {
Wimpie 0:6468a28a7b7d 441 drawline(x0, y0, x1, y0, mode, FALSE); // Draw the 4 sides
Wimpie 0:6468a28a7b7d 442 drawline(x0, y1, x1, y1, mode, FALSE);
Wimpie 0:6468a28a7b7d 443 drawline(x0, y0, x0, y1, mode, FALSE);
Wimpie 0:6468a28a7b7d 444 drawline(x1, y0, x1, y1, mode, FALSE);
Wimpie 0:6468a28a7b7d 445 }
Wimpie 0:6468a28a7b7d 446 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 447 update();
Wimpie 0:6468a28a7b7d 448 }
Wimpie 0:6468a28a7b7d 449
Wimpie 0:6468a28a7b7d 450 void PCD8544LCD::drawprogressbar(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE percentage,BYTE fupdate) {
Wimpie 0:6468a28a7b7d 451 drawrectangle(x0,y0,x0+w,y0+h,FILL_OFF,PIXEL_ON, FALSE);
Wimpie 0:6468a28a7b7d 452 drawrectangle(x0+2,y0+2,x0+w-2,y0+h-2,FILL_ON,PIXEL_OFF, FALSE);
Wimpie 0:6468a28a7b7d 453 drawrectangle(x0+2,y0+2,x0+2+(percentage*(w-4)/100),y0+h-2,FILL_ON,PIXEL_ON, FALSE);
Wimpie 0:6468a28a7b7d 454 if (fupdate==TRUE)
Wimpie 0:6468a28a7b7d 455 update();
Wimpie 0:6468a28a7b7d 456 }
Wimpie 0:6468a28a7b7d 457
Wimpie 0:6468a28a7b7d 458 void PCD8544LCD::drawchart(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE unitx, BYTE unity,
Wimpie 1:ce391193b822 459 eRasterMode rMode, eChartMode cMode,eDrawMode dMode, int16_t * val, int size, int t) {
Wimpie 1:ce391193b822 460 int maxy;
Wimpie 1:ce391193b822 461 int _scale=1;
Wimpie 1:ce391193b822 462 int prescale=1;
Wimpie 0:6468a28a7b7d 463
Wimpie 1:ce391193b822 464 signed char v1,v2;
Wimpie 1:ce391193b822 465 char buffer[4];
Wimpie 0:6468a28a7b7d 466
Wimpie 1:ce391193b822 467 if (size>w)
Wimpie 1:ce391193b822 468 size=w;
Wimpie 0:6468a28a7b7d 469
Wimpie 1:ce391193b822 470 // search maximum value to calculate scale
Wimpie 1:ce391193b822 471 if (dMode==DRAW_OVERWRITE) {
Wimpie 1:ce391193b822 472 maxy=0;
Wimpie 1:ce391193b822 473 for (int i=0; i<size;i++) {
Wimpie 1:ce391193b822 474 if (val[i]>maxy)
Wimpie 1:ce391193b822 475 maxy=val[i];
Wimpie 0:6468a28a7b7d 476
Wimpie 1:ce391193b822 477 }
Wimpie 0:6468a28a7b7d 478
Wimpie 1:ce391193b822 479 if (maxy>h) { //scale can be 1,2,5 *10i
Wimpie 1:ce391193b822 480 prescale= ((maxy-1)/((h/unity)*unity));
Wimpie 1:ce391193b822 481 _scale=1;
Wimpie 1:ce391193b822 482 while (prescale>10) {
Wimpie 1:ce391193b822 483 _scale=_scale*10;
Wimpie 1:ce391193b822 484 prescale=prescale/10;
Wimpie 1:ce391193b822 485 }
Wimpie 1:ce391193b822 486 if (prescale>1)
Wimpie 1:ce391193b822 487 _scale=_scale*5;
Wimpie 1:ce391193b822 488 else
Wimpie 1:ce391193b822 489 if (prescale==1)
Wimpie 1:ce391193b822 490 _scale =_scale*2;
Wimpie 0:6468a28a7b7d 491
Wimpie 0:6468a28a7b7d 492
Wimpie 1:ce391193b822 493 }
Wimpie 1:ce391193b822 494 Scale=_scale;
Wimpie 0:6468a28a7b7d 495 }
Wimpie 0:6468a28a7b7d 496
Wimpie 1:ce391193b822 497 if (dMode==DRAW_OVERWRITE) {
Wimpie 1:ce391193b822 498 drawrectangle(x0-11,y0-h,x0+w,y0+4+7,FILL_ON,PIXEL_OFF,FALSE);
Wimpie 1:ce391193b822 499 drawline(x0,y0,x0,y0-h,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 500 drawline(x0,y0,x0+w,y0,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 501
Wimpie 1:ce391193b822 502 //drawrectangle(x0,y0-h,x0+w,y0,FILL_OFF,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 503
Wimpie 1:ce391193b822 504 for (int i=0;i<=h;i++) {
Wimpie 1:ce391193b822 505 if ((i % unity) == 0) {
Wimpie 1:ce391193b822 506 drawpixel(x0-2,y0-i,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 507 // drawpixel(x0+w+2,y0-i,PIXEL_ON,FALSE);
Wimpie 0:6468a28a7b7d 508
Wimpie 1:ce391193b822 509 if (rMode==RASTER_ON) {
Wimpie 1:ce391193b822 510 for (int r=0;r<=w;r++) {
Wimpie 1:ce391193b822 511 if ((r % 2) ==0)
Wimpie 1:ce391193b822 512 drawpixel(x0+r,y0-i,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 513 }
Wimpie 1:ce391193b822 514 }
Wimpie 1:ce391193b822 515 // draw vertical axis labels
Wimpie 0:6468a28a7b7d 516
Wimpie 1:ce391193b822 517 itostr(buffer,i*Scale);
Wimpie 1:ce391193b822 518
Wimpie 1:ce391193b822 519 // pc_PCD8544.traceOut(" %i %s |",i*Scale,buffer);
Wimpie 1:ce391193b822 520 writeString(x0-11,y0-i+1,buffer,VERYSMALLFONT,NORMAL,SPACE_NONE,FALSE);
Wimpie 0:6468a28a7b7d 521
Wimpie 1:ce391193b822 522 }
Wimpie 1:ce391193b822 523 if ((i % 2) == 0) {
Wimpie 1:ce391193b822 524 drawpixel(x0-1,y0-i,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 525 // drawpixel(x0+w+1,y0-i,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 526 }
Wimpie 1:ce391193b822 527 }
Wimpie 1:ce391193b822 528
Wimpie 1:ce391193b822 529 for (int i=0;i<=w;i++) {
Wimpie 1:ce391193b822 530 if (((i+(t % unitx)) % unitx) == 0) {
Wimpie 1:ce391193b822 531 drawpixel(x0+i,y0+2,PIXEL_ON,FALSE);
Wimpie 0:6468a28a7b7d 532
Wimpie 1:ce391193b822 533 if (rMode==RASTER_ON) {
Wimpie 1:ce391193b822 534 for (int r=0;r<=h;r++) {
Wimpie 1:ce391193b822 535 if ((r % 2) ==0)
Wimpie 1:ce391193b822 536 drawpixel(x0+i,y0-r,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 537 }
Wimpie 1:ce391193b822 538 }
Wimpie 1:ce391193b822 539 if (((t-w+i)/unitx)>=0)
Wimpie 1:ce391193b822 540 snprintf(buffer,3,"%i",((t-w+i)/unitx));
Wimpie 1:ce391193b822 541 else
Wimpie 1:ce391193b822 542 snprintf(buffer,3,"%i",24+((t-w+i)/unitx));
Wimpie 1:ce391193b822 543
Wimpie 1:ce391193b822 544 // pc_PCD8544.traceOut(" %i %s ",(t-w+i)/unitx,buffer);
Wimpie 1:ce391193b822 545 writeString(x0+i-3,y0+4,buffer,VERYSMALLFONT,NORMAL,SPACE_NORMAL,FALSE);
Wimpie 1:ce391193b822 546 }
Wimpie 1:ce391193b822 547 if ((i % 2) == 0) {
Wimpie 1:ce391193b822 548 drawpixel(x0+i,y0+1,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 549 }
Wimpie 1:ce391193b822 550 }
Wimpie 1:ce391193b822 551 // update();
Wimpie 0:6468a28a7b7d 552 }
Wimpie 0:6468a28a7b7d 553
Wimpie 1:ce391193b822 554 for (int i=0;i<size;i++) {
Wimpie 1:ce391193b822 555 // pc_PCD8544.traceOut(" %i ",val[i]);
Wimpie 1:ce391193b822 556 v1 = val[i] / Scale;
Wimpie 1:ce391193b822 557 if (v1>h)
Wimpie 1:ce391193b822 558 v1=h;
Wimpie 0:6468a28a7b7d 559
Wimpie 1:ce391193b822 560 if (i!=(size-1)) {
Wimpie 1:ce391193b822 561 v2 = val[i+1] / Scale;
Wimpie 1:ce391193b822 562 if (v2>h)
Wimpie 1:ce391193b822 563 v2=h;
Wimpie 1:ce391193b822 564 } else
Wimpie 1:ce391193b822 565 v2=v1;
Wimpie 0:6468a28a7b7d 566
Wimpie 0:6468a28a7b7d 567
Wimpie 1:ce391193b822 568 switch (cMode) {
Wimpie 1:ce391193b822 569 case C_POINT: {
Wimpie 1:ce391193b822 570 drawpixel(x0+i,y0-v1,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 571 break;
Wimpie 1:ce391193b822 572 }
Wimpie 1:ce391193b822 573 case C_LINE: {
Wimpie 1:ce391193b822 574 drawline(x0+i,y0-v1,x0+i+1,y0-v2,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 575 break;
Wimpie 1:ce391193b822 576 }
Wimpie 1:ce391193b822 577 case C_VLINE: {
Wimpie 1:ce391193b822 578 drawline(x0+i,y0-v1,x0+i,y0,PIXEL_ON,FALSE);
Wimpie 1:ce391193b822 579 break;
Wimpie 1:ce391193b822 580 }
Wimpie 1:ce391193b822 581 }
Wimpie 1:ce391193b822 582 }
Wimpie 0:6468a28a7b7d 583
Wimpie 0:6468a28a7b7d 584 update();
Wimpie 0:6468a28a7b7d 585 }
Wimpie 0:6468a28a7b7d 586
Wimpie 0:6468a28a7b7d 587 /*
Wimpie 0:6468a28a7b7d 588 void PCD8544LCD::writeCharBig(BYTE x, BYTE y, BYTE ch, eDisplayMode mode) {
Wimpie 0:6468a28a7b7d 589 BYTE sendByte;
Wimpie 0:6468a28a7b7d 590
Wimpie 0:6468a28a7b7d 591 unsigned char* pFont = (unsigned char *) font_bignumber;
Wimpie 0:6468a28a7b7d 592
Wimpie 0:6468a28a7b7d 593 if ('.' == ch)
Wimpie 0:6468a28a7b7d 594 ch = 10;
Wimpie 0:6468a28a7b7d 595 else if ('+' == ch)
Wimpie 0:6468a28a7b7d 596 ch = 11;
Wimpie 0:6468a28a7b7d 597 else if ('-' == ch)
Wimpie 0:6468a28a7b7d 598 ch = 12;
Wimpie 0:6468a28a7b7d 599 else
Wimpie 0:6468a28a7b7d 600 ch = ch & 0x0f;
Wimpie 0:6468a28a7b7d 601
Wimpie 0:6468a28a7b7d 602 for (BYTE i = 0; i < 3; i++) {
Wimpie 0:6468a28a7b7d 603 locate(x, y + i);
Wimpie 0:6468a28a7b7d 604
Wimpie 0:6468a28a7b7d 605 for (BYTE j = 0; j < 16; j++) {
Wimpie 0:6468a28a7b7d 606 sendByte = *(pFont + ch*48 + i*16 + j);
Wimpie 0:6468a28a7b7d 607 writeData((mode == NORMAL)? sendByte : (sendByte^0xff));
Wimpie 0:6468a28a7b7d 608 }
Wimpie 0:6468a28a7b7d 609 }
Wimpie 0:6468a28a7b7d 610 }
Wimpie 0:6468a28a7b7d 611
Wimpie 0:6468a28a7b7d 612
Wimpie 0:6468a28a7b7d 613 void PCD8544LCD::writeStringBig(BYTE x0, BYTE y0, char* string, eDisplayMode mode, BYTE fupdate) {
Wimpie 0:6468a28a7b7d 614 while (*string) {
Wimpie 0:6468a28a7b7d 615 writeCharBig(x0, y0, *string , mode);
Wimpie 0:6468a28a7b7d 616
Wimpie 0:6468a28a7b7d 617 if ('.' == *string++)
Wimpie 0:6468a28a7b7d 618 x0 += 5;
Wimpie 0:6468a28a7b7d 619 else
Wimpie 0:6468a28a7b7d 620 x0 += 12;
Wimpie 0:6468a28a7b7d 621 }
Wimpie 0:6468a28a7b7d 622 }
Wimpie 0:6468a28a7b7d 623 */