LS020.h is a MobileLCD library for the LS020 display (used in GSM Siemens S65 family). Resolution 176x132

Committer:
Wimpie
Date:
Mon Dec 06 20:37:10 2010 +0000
Revision:
1:2269e07af50b
Parent:
0:d550841cd6eb
Child:
2:d048f09dcfb0

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wimpie 1:2269e07af50b 1 /* mbed LS020 Library, for driving the LCD display LS020 from SHARP used in
Wimpie 1:2269e07af50b 2 * GSM S65 Siemens
Wimpie 1:2269e07af50b 3 *
Wimpie 1:2269e07af50b 4 * Copyright (c) 2010, Wim De Roeve, thanks to Christian Kranz research
Wimpie 1:2269e07af50b 5 *
Wimpie 0:d550841cd6eb 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
Wimpie 0:d550841cd6eb 7 * of this software and associated documentation files (the "Software"), to deal
Wimpie 0:d550841cd6eb 8 * in the Software without restriction, including without limitation the rights
Wimpie 0:d550841cd6eb 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Wimpie 0:d550841cd6eb 10 * copies of the Software, and to permit persons to whom the Software is
Wimpie 0:d550841cd6eb 11 * furnished to do so, subject to the following conditions:
Wimpie 0:d550841cd6eb 12 *
Wimpie 0:d550841cd6eb 13 * The above copyright notice and this permission notice shall be included in
Wimpie 0:d550841cd6eb 14 * all copies or substantial portions of the Software.
Wimpie 0:d550841cd6eb 15 *
Wimpie 0:d550841cd6eb 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wimpie 0:d550841cd6eb 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wimpie 0:d550841cd6eb 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wimpie 0:d550841cd6eb 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wimpie 0:d550841cd6eb 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wimpie 0:d550841cd6eb 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wimpie 0:d550841cd6eb 22 * THE SOFTWARE.
Wimpie 0:d550841cd6eb 23 */
Wimpie 0:d550841cd6eb 24
Wimpie 0:d550841cd6eb 25 #include "LS020LCD.h"
Wimpie 0:d550841cd6eb 26 #include "mbed.h"
Wimpie 0:d550841cd6eb 27
Wimpie 0:d550841cd6eb 28 #include "fonts/font_6x8.h"
Wimpie 0:d550841cd6eb 29 #include "fonts/font_8x8.h"
Wimpie 0:d550841cd6eb 30 #include "fonts/font_8x12.h"
Wimpie 0:d550841cd6eb 31 #include "fonts/font_clock.h"
Wimpie 0:d550841cd6eb 32
Wimpie 0:d550841cd6eb 33 #define TINYFONT (0) //6x8
Wimpie 0:d550841cd6eb 34 #define TINYFONT_NAME font0
Wimpie 0:d550841cd6eb 35 #define TINYFONT_START FONT0_START
Wimpie 0:d550841cd6eb 36 #define TINYFONT_WIDTH FONT0_WIDTH
Wimpie 0:d550841cd6eb 37 #define TINYFONT_HEIGHT FONT0_HEIGHT
Wimpie 0:d550841cd6eb 38 #define SMALLFONT (1) //8x8
Wimpie 0:d550841cd6eb 39 #define SMALLFONT_NAME font1
Wimpie 0:d550841cd6eb 40 #define SMALLFONT_START FONT1_START
Wimpie 0:d550841cd6eb 41 #define SMALLFONT_WIDTH FONT1_WIDTH
Wimpie 0:d550841cd6eb 42 #define SMALLFONT_HEIGHT FONT1_HEIGHT
Wimpie 0:d550841cd6eb 43 #define NORMALFONT (2) //8x12
Wimpie 0:d550841cd6eb 44 #define NORMALFONT_NAME font2
Wimpie 0:d550841cd6eb 45 #define NORMALFONT_START FONT2_START
Wimpie 0:d550841cd6eb 46 #define NORMALFONT_WIDTH FONT2_WIDTH
Wimpie 0:d550841cd6eb 47 #define NORMALFONT_HEIGHT FONT2_HEIGHT
Wimpie 0:d550841cd6eb 48 #define TIMEFONT (3) //Clock
Wimpie 0:d550841cd6eb 49 #define TIMEFONT_NAME font3
Wimpie 0:d550841cd6eb 50 #define TIMEFONT_START FONT3_START
Wimpie 0:d550841cd6eb 51 #define TIMEFONT_WIDTH FONT3_WIDTH
Wimpie 0:d550841cd6eb 52 #define TIMEFONT_HEIGHT FONT3_HEIGHT
Wimpie 0:d550841cd6eb 53
Wimpie 0:d550841cd6eb 54 // colors in 8 bit mode BGR off RRRGGGBB
Wimpie 0:d550841cd6eb 55 #define BLACK 0x00
Wimpie 0:d550841cd6eb 56 #define WHITE 0xFF
Wimpie 0:d550841cd6eb 57 #define RED 0xE0
Wimpie 0:d550841cd6eb 58 #define GREEN 0x1C
Wimpie 0:d550841cd6eb 59 #define BLUE 0x03
Wimpie 0:d550841cd6eb 60
Wimpie 0:d550841cd6eb 61 using namespace mbed;
Wimpie 0:d550841cd6eb 62
Wimpie 0:d550841cd6eb 63 unsigned int checkbit(const unsigned long *data, unsigned int nr);
Wimpie 0:d550841cd6eb 64
Wimpie 0:d550841cd6eb 65
Wimpie 0:d550841cd6eb 66 LS020LCD::LS020LCD(PinName mosi, PinName miso, PinName clk, PinName cs, PinName rst, PinName rs)
Wimpie 0:d550841cd6eb 67 : _spi(mosi, miso, clk)
Wimpie 0:d550841cd6eb 68 , _rst(rst)
Wimpie 0:d550841cd6eb 69 , _cs(cs)
Wimpie 0:d550841cd6eb 70 , _rs(rs) {
Wimpie 0:d550841cd6eb 71 _rotate=false;
Wimpie 0:d550841cd6eb 72 _mirror=false;
Wimpie 0:d550841cd6eb 73 reset();
Wimpie 0:d550841cd6eb 74 }
Wimpie 0:d550841cd6eb 75
Wimpie 0:d550841cd6eb 76 void LS020LCD::write_cmdRG(uint8_t reg, uint8_t param) {
Wimpie 0:d550841cd6eb 77 _rs = 1; //cmd
Wimpie 0:d550841cd6eb 78 _cs = 0;
Wimpie 0:d550841cd6eb 79 _spi.write(reg);
Wimpie 0:d550841cd6eb 80 _spi.write(param);
Wimpie 0:d550841cd6eb 81 _cs = 1;
Wimpie 0:d550841cd6eb 82 }
Wimpie 0:d550841cd6eb 83
Wimpie 0:d550841cd6eb 84 void LS020LCD::write_cmd8(uint8_t cmd8) {
Wimpie 0:d550841cd6eb 85 _rs = 1; //cmd
Wimpie 0:d550841cd6eb 86 _cs = 0;
Wimpie 0:d550841cd6eb 87 _spi.write(cmd8);
Wimpie 0:d550841cd6eb 88 _cs = 1;
Wimpie 0:d550841cd6eb 89 }
Wimpie 0:d550841cd6eb 90
Wimpie 0:d550841cd6eb 91 void LS020LCD::write_cmd16(uint16_t cmd16) {
Wimpie 0:d550841cd6eb 92 _rs = 1; //cmd
Wimpie 0:d550841cd6eb 93 _cs = 0;
Wimpie 0:d550841cd6eb 94 _spi.write((cmd16>>8)&0xFF);
Wimpie 0:d550841cd6eb 95 _spi.write(cmd16&0xFF);
Wimpie 0:d550841cd6eb 96 _cs = 1;
Wimpie 0:d550841cd6eb 97 }
Wimpie 0:d550841cd6eb 98
Wimpie 0:d550841cd6eb 99 void LS020LCD::write_data8(char data) {
Wimpie 0:d550841cd6eb 100 _rs = 0; //data
Wimpie 0:d550841cd6eb 101 _cs = 0;
Wimpie 0:d550841cd6eb 102 _spi.write(data);
Wimpie 0:d550841cd6eb 103 _cs = 1;
Wimpie 0:d550841cd6eb 104 }
Wimpie 0:d550841cd6eb 105
Wimpie 0:d550841cd6eb 106 void LS020LCD::write_data16(uint16_t cmd16) {
Wimpie 0:d550841cd6eb 107 _rs = 0; //data
Wimpie 0:d550841cd6eb 108 _cs = 0;
Wimpie 0:d550841cd6eb 109 _spi.write((cmd16>>8)&0xFF);
Wimpie 0:d550841cd6eb 110 _spi.write(cmd16&0xFF);
Wimpie 0:d550841cd6eb 111 _cs = 1;
Wimpie 0:d550841cd6eb 112 }
Wimpie 0:d550841cd6eb 113
Wimpie 0:d550841cd6eb 114 void LS020LCD::draw(uint16_t cmd16) {
Wimpie 0:d550841cd6eb 115 _spi.write((cmd16>>8)&0xFF);
Wimpie 0:d550841cd6eb 116 _spi.write(cmd16&0xFF);
Wimpie 0:d550841cd6eb 117 }
Wimpie 0:d550841cd6eb 118
Wimpie 0:d550841cd6eb 119 void LS020LCD::drawstop(void) {
Wimpie 0:d550841cd6eb 120 _cs = 1;
Wimpie 0:d550841cd6eb 121 }
Wimpie 0:d550841cd6eb 122
Wimpie 0:d550841cd6eb 123
Wimpie 0:d550841cd6eb 124 void LS020LCD::drawstart(void) {
Wimpie 0:d550841cd6eb 125 _rs = 0; //data
Wimpie 0:d550841cd6eb 126 _cs = 0;
Wimpie 0:d550841cd6eb 127 }
Wimpie 0:d550841cd6eb 128
Wimpie 0:d550841cd6eb 129 void LS020LCD::locate(int column, int row) {
Wimpie 0:d550841cd6eb 130 _row = row;
Wimpie 0:d550841cd6eb 131 _column = column;
Wimpie 0:d550841cd6eb 132 }
Wimpie 0:d550841cd6eb 133
Wimpie 0:d550841cd6eb 134 void LS020LCD::newline() {
Wimpie 0:d550841cd6eb 135 _column = 0;
Wimpie 0:d550841cd6eb 136 _row++;
Wimpie 0:d550841cd6eb 137 if (_row >= _rows) {
Wimpie 0:d550841cd6eb 138 _row = 0;
Wimpie 0:d550841cd6eb 139 }
Wimpie 0:d550841cd6eb 140 }
Wimpie 0:d550841cd6eb 141
Wimpie 0:d550841cd6eb 142 int LS020LCD::columns() {
Wimpie 0:d550841cd6eb 143 return _columns;
Wimpie 0:d550841cd6eb 144 }
Wimpie 0:d550841cd6eb 145
Wimpie 0:d550841cd6eb 146 int LS020LCD::rows() {
Wimpie 0:d550841cd6eb 147 return _rows;
Wimpie 0:d550841cd6eb 148 }
Wimpie 0:d550841cd6eb 149
Wimpie 0:d550841cd6eb 150 // ***************** Init and reset
Wimpie 0:d550841cd6eb 151
Wimpie 0:d550841cd6eb 152 void LS020LCD::orientation(bool rotate, bool mirror) {
Wimpie 0:d550841cd6eb 153 _rotate=rotate;
Wimpie 0:d550841cd6eb 154 _mirror=mirror;
Wimpie 0:d550841cd6eb 155
Wimpie 0:d550841cd6eb 156 if (rotate==0) { //default = 176 x 132
Wimpie 0:d550841cd6eb 157 _width=132;
Wimpie 0:d550841cd6eb 158 _height=176;
Wimpie 0:d550841cd6eb 159 } else { //132 x 176
Wimpie 0:d550841cd6eb 160 _width=176;
Wimpie 0:d550841cd6eb 161 _height=132;
Wimpie 0:d550841cd6eb 162
Wimpie 0:d550841cd6eb 163 }
Wimpie 0:d550841cd6eb 164 }
Wimpie 0:d550841cd6eb 165
Wimpie 0:d550841cd6eb 166 void LS020LCD::reset(void) {
Wimpie 0:d550841cd6eb 167
Wimpie 0:d550841cd6eb 168 const unsigned char init_array_0[20]={
Wimpie 0:d550841cd6eb 169 0xEF, 0x00, 0xEE, 0x04, 0x1B, 0x04, 0xFE, 0xFE,
Wimpie 0:d550841cd6eb 170 0xFE, 0xFE, 0xEF, 0x90, 0x4A, 0x04, 0x7F, 0x3F,
Wimpie 0:d550841cd6eb 171 0xEE, 0x04, 0x43, 0x06
Wimpie 0:d550841cd6eb 172 };
Wimpie 0:d550841cd6eb 173
Wimpie 0:d550841cd6eb 174 const unsigned char init_array_1[46]= {
Wimpie 0:d550841cd6eb 175 0xEF, 0x90, 0x09, 0x83, 0x08, 0x00, 0x0B, 0xAF,
Wimpie 0:d550841cd6eb 176 0x0A, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00,
Wimpie 0:d550841cd6eb 177 0xEF, 0x00, 0xEE, 0x0C, 0xEF, 0x90, 0x00, 0x80,
Wimpie 0:d550841cd6eb 178 0xEF, 0xB0, 0x49, 0x02, 0xEF, 0x00, 0x7F, 0x01,
Wimpie 0:d550841cd6eb 179 0xE1, 0x81, 0xE2, 0x02, 0xE2, 0x76, 0xE1, 0x83,
Wimpie 0:d550841cd6eb 180 0x80, 0x01, 0xEF, 0x90, 0x00, 0x00
Wimpie 0:d550841cd6eb 181 };
Wimpie 0:d550841cd6eb 182
Wimpie 0:d550841cd6eb 183 int i;
Wimpie 0:d550841cd6eb 184
Wimpie 0:d550841cd6eb 185 // Setup the spi for 8 bit data, high steady state clock,
Wimpie 0:d550841cd6eb 186 // second edge capture, with a 8MHz clock rate
Wimpie 0:d550841cd6eb 187
Wimpie 0:d550841cd6eb 188 _spi.format(8,3);
Wimpie 0:d550841cd6eb 189 _spi.frequency(8000000);
Wimpie 0:d550841cd6eb 190
Wimpie 0:d550841cd6eb 191 //reset
Wimpie 0:d550841cd6eb 192 _cs = 1;
Wimpie 0:d550841cd6eb 193 _rs = 1;
Wimpie 0:d550841cd6eb 194 _rst= 0;
Wimpie 0:d550841cd6eb 195
Wimpie 0:d550841cd6eb 196 wait_ms(50);
Wimpie 0:d550841cd6eb 197
Wimpie 0:d550841cd6eb 198 _rst = 1;
Wimpie 0:d550841cd6eb 199 wait_ms(50);
Wimpie 0:d550841cd6eb 200 _cs = 0;
Wimpie 0:d550841cd6eb 201
Wimpie 0:d550841cd6eb 202 write_cmd16(0xFDFD);
Wimpie 0:d550841cd6eb 203 write_cmd16(0xFDFD);
Wimpie 0:d550841cd6eb 204
Wimpie 0:d550841cd6eb 205 wait_ms(68);
Wimpie 0:d550841cd6eb 206
Wimpie 0:d550841cd6eb 207 //init part 1
Wimpie 0:d550841cd6eb 208 for (i=0;i<20;i++) {
Wimpie 0:d550841cd6eb 209 write_cmd8(init_array_0[i]);
Wimpie 0:d550841cd6eb 210 }
Wimpie 0:d550841cd6eb 211
Wimpie 0:d550841cd6eb 212 //important: wait 10ms
Wimpie 0:d550841cd6eb 213 wait_ms(10);
Wimpie 0:d550841cd6eb 214
Wimpie 0:d550841cd6eb 215 //init part 2
Wimpie 0:d550841cd6eb 216 for (i=0;i<46;i++) {
Wimpie 0:d550841cd6eb 217 write_cmd8(init_array_1[i]);
Wimpie 0:d550841cd6eb 218 }
Wimpie 0:d550841cd6eb 219
Wimpie 0:d550841cd6eb 220 orientation(_rotate,_mirror);
Wimpie 0:d550841cd6eb 221 set_window(0, 0, (_width-1), (_height-1));
Wimpie 0:d550841cd6eb 222
Wimpie 0:d550841cd6eb 223 _foreground=BLACK;
Wimpie 0:d550841cd6eb 224 _background=WHITE;
Wimpie 0:d550841cd6eb 225 _row=0;
Wimpie 0:d550841cd6eb 226 _column=0;
Wimpie 0:d550841cd6eb 227 _font=1;
Wimpie 0:d550841cd6eb 228
Wimpie 0:d550841cd6eb 229 cls();
Wimpie 0:d550841cd6eb 230
Wimpie 0:d550841cd6eb 231 return;
Wimpie 0:d550841cd6eb 232
Wimpie 0:d550841cd6eb 233 };
Wimpie 0:d550841cd6eb 234
Wimpie 0:d550841cd6eb 235 // ***************** MODE settings
Wimpie 0:d550841cd6eb 236
Wimpie 0:d550841cd6eb 237 void LS020LCD::set_8bit_mode(char BGR) {
Wimpie 0:d550841cd6eb 238 // BGR=0 - disabled, BGR=1 - enabled.
Wimpie 0:d550841cd6eb 239 write_cmd16(0xE800+(BGR&0x01)*0x40);
Wimpie 0:d550841cd6eb 240 }
Wimpie 0:d550841cd6eb 241
Wimpie 0:d550841cd6eb 242 void LS020LCD::set_16bit_mode(void) {
Wimpie 0:d550841cd6eb 243 write_cmd16(0xE80F);
Wimpie 0:d550841cd6eb 244 }
Wimpie 0:d550841cd6eb 245
Wimpie 0:d550841cd6eb 246 void LS020LCD::set_8_color_mode(void) {
Wimpie 0:d550841cd6eb 247 write_cmd16(0x0401);
Wimpie 0:d550841cd6eb 248 write_cmd16(0x0000);
Wimpie 0:d550841cd6eb 249 }
Wimpie 0:d550841cd6eb 250
Wimpie 0:d550841cd6eb 251 void LS020LCD::set_65k_color_mode(void) {
Wimpie 0:d550841cd6eb 252 write_cmd16(0x0400);
Wimpie 0:d550841cd6eb 253 write_cmd16(0x0000);
Wimpie 0:d550841cd6eb 254 }
Wimpie 0:d550841cd6eb 255
Wimpie 0:d550841cd6eb 256 void LS020LCD::foreground(unsigned int color) {
Wimpie 0:d550841cd6eb 257 _foreground = color;
Wimpie 0:d550841cd6eb 258 }
Wimpie 0:d550841cd6eb 259
Wimpie 0:d550841cd6eb 260 void LS020LCD::background(unsigned int color) {
Wimpie 0:d550841cd6eb 261 _background = color;
Wimpie 0:d550841cd6eb 262 }
Wimpie 0:d550841cd6eb 263
Wimpie 0:d550841cd6eb 264 // ****************
Wimpie 0:d550841cd6eb 265
Wimpie 0:d550841cd6eb 266 void LS020LCD::set_cursor(unsigned int x, unsigned int y) {
Wimpie 0:d550841cd6eb 267 write_cmd16(0xEF90);
Wimpie 0:d550841cd6eb 268
Wimpie 0:d550841cd6eb 269 if (_rotate) {
Wimpie 0:d550841cd6eb 270 if (_mirror) {
Wimpie 0:d550841cd6eb 271 write_cmdRG(0x06, (_width-1)-x); //set x cursor pos
Wimpie 0:d550841cd6eb 272 write_cmdRG(0x07, (_height-1)-y); //set y cursor pos
Wimpie 0:d550841cd6eb 273 } else {
Wimpie 0:d550841cd6eb 274 write_cmdRG(0x06, x); //set x cursor pos
Wimpie 0:d550841cd6eb 275 write_cmdRG(0x07, y); //set y cursor pos
Wimpie 0:d550841cd6eb 276 }
Wimpie 0:d550841cd6eb 277 } else {
Wimpie 0:d550841cd6eb 278 if (_mirror) {
Wimpie 0:d550841cd6eb 279 write_cmdRG(0x06, (_height-1)-y); //set y cursor pos
Wimpie 0:d550841cd6eb 280 write_cmdRG(0x07, x); //set x cursor pos
Wimpie 0:d550841cd6eb 281 } else {
Wimpie 0:d550841cd6eb 282 write_cmdRG(0x06, y); //set y cursor pos
Wimpie 0:d550841cd6eb 283 write_cmdRG(0x07, (_width-1)-x); //set x cursor pos
Wimpie 0:d550841cd6eb 284 }
Wimpie 0:d550841cd6eb 285 }
Wimpie 0:d550841cd6eb 286 }
Wimpie 0:d550841cd6eb 287
Wimpie 0:d550841cd6eb 288 void LS020LCD::set_window(char x0, char y0, char x1,char y1) {
Wimpie 0:d550841cd6eb 289 // write_cmd16(0x0500);// Set Direction
Wimpie 0:d550841cd6eb 290 // write_cmd16(0x0A00+x1);
Wimpie 0:d550841cd6eb 291 // write_cmd16(0x0B00+x2);
Wimpie 0:d550841cd6eb 292 // write_cmd16(0x0800+y1);
Wimpie 0:d550841cd6eb 293 // write_cmd16(0x0900+y2);
Wimpie 0:d550841cd6eb 294
Wimpie 0:d550841cd6eb 295 //set area
Wimpie 0:d550841cd6eb 296 write_cmd16(0xEF90);
Wimpie 0:d550841cd6eb 297 if (_rotate) {
Wimpie 0:d550841cd6eb 298 if (_mirror) {
Wimpie 0:d550841cd6eb 299 write_cmdRG(0x08, (_width-1)-x0); //set x0
Wimpie 0:d550841cd6eb 300 write_cmdRG(0x09, (_width-1)-x1); //set x1
Wimpie 0:d550841cd6eb 301 write_cmdRG(0x0A, (_height-1)-y0); //set y0
Wimpie 0:d550841cd6eb 302 write_cmdRG(0x0B, (_height-1)-y1); //set y1
Wimpie 0:d550841cd6eb 303 } else {
Wimpie 0:d550841cd6eb 304 write_cmdRG(0x08, x0); //set x0
Wimpie 0:d550841cd6eb 305 write_cmdRG(0x09, x1); //set x1
Wimpie 0:d550841cd6eb 306 write_cmdRG(0x0A, y0); //set y0
Wimpie 0:d550841cd6eb 307 write_cmdRG(0x0B, y1); //set y1
Wimpie 0:d550841cd6eb 308 }
Wimpie 0:d550841cd6eb 309 } else {
Wimpie 0:d550841cd6eb 310 if (_mirror) {
Wimpie 0:d550841cd6eb 311 write_cmdRG(0x08, (_height-1)-y0); //set y0
Wimpie 0:d550841cd6eb 312 write_cmdRG(0x09, (_height-1)-y1); //set y1
Wimpie 0:d550841cd6eb 313 write_cmdRG(0x0A, x0); //set x0
Wimpie 0:d550841cd6eb 314 write_cmdRG(0x0B, x1); //set x1
Wimpie 0:d550841cd6eb 315 } else {
Wimpie 0:d550841cd6eb 316 write_cmdRG(0x08, y0); //set y0
Wimpie 0:d550841cd6eb 317 write_cmdRG(0x09, y1); //set y1
Wimpie 0:d550841cd6eb 318 write_cmdRG(0x0A, (_width-1)-x0); //set x0
Wimpie 0:d550841cd6eb 319 write_cmdRG(0x0B, (_width-1)-x1); //set x1
Wimpie 0:d550841cd6eb 320 }
Wimpie 0:d550841cd6eb 321 }
Wimpie 0:d550841cd6eb 322
Wimpie 0:d550841cd6eb 323 //set cursor
Wimpie 0:d550841cd6eb 324 set_cursor(x0, y0);
Wimpie 0:d550841cd6eb 325
Wimpie 0:d550841cd6eb 326 }
Wimpie 0:d550841cd6eb 327
Wimpie 0:d550841cd6eb 328 unsigned int LS020LCD::putc(unsigned int x, unsigned int y, unsigned int c, unsigned int size,unsigned int font, unsigned int color, unsigned int bgcolor) {
Wimpie 0:d550841cd6eb 329 unsigned int ret, i, j, width, height, w, h, wh;
Wimpie 0:d550841cd6eb 330 const unsigned long *ptr;
Wimpie 0:d550841cd6eb 331
Wimpie 0:d550841cd6eb 332 switch (font) {
Wimpie 0:d550841cd6eb 333 case TINYFONT:
Wimpie 0:d550841cd6eb 334 c -= TINYFONT_START;
Wimpie 0:d550841cd6eb 335 ptr = (const unsigned long*)&TINYFONT_NAME[c*(TINYFONT_WIDTH*TINYFONT_HEIGHT/8)];
Wimpie 0:d550841cd6eb 336 width = TINYFONT_WIDTH;
Wimpie 0:d550841cd6eb 337 height = TINYFONT_HEIGHT;
Wimpie 0:d550841cd6eb 338 break;
Wimpie 0:d550841cd6eb 339 case SMALLFONT:
Wimpie 0:d550841cd6eb 340 c -= SMALLFONT_START;
Wimpie 0:d550841cd6eb 341 ptr = (const unsigned long*)&SMALLFONT_NAME[c*(SMALLFONT_WIDTH*SMALLFONT_HEIGHT/8)];
Wimpie 0:d550841cd6eb 342 width = SMALLFONT_WIDTH;
Wimpie 0:d550841cd6eb 343 height = SMALLFONT_HEIGHT;
Wimpie 0:d550841cd6eb 344 break;
Wimpie 0:d550841cd6eb 345 case NORMALFONT:
Wimpie 0:d550841cd6eb 346 c -= NORMALFONT_START;
Wimpie 0:d550841cd6eb 347 ptr = (const unsigned long*)&NORMALFONT_NAME[c*(NORMALFONT_WIDTH*NORMALFONT_HEIGHT/8)];
Wimpie 0:d550841cd6eb 348 width = NORMALFONT_WIDTH;
Wimpie 0:d550841cd6eb 349 height = NORMALFONT_HEIGHT;
Wimpie 0:d550841cd6eb 350 break;
Wimpie 0:d550841cd6eb 351 case TIMEFONT:
Wimpie 0:d550841cd6eb 352 c -= TIMEFONT_START;
Wimpie 0:d550841cd6eb 353 ptr = (const unsigned long*)&TIMEFONT_NAME[c*(TIMEFONT_WIDTH*TIMEFONT_HEIGHT/8)];
Wimpie 0:d550841cd6eb 354 width = TIMEFONT_WIDTH;
Wimpie 0:d550841cd6eb 355 height = TIMEFONT_HEIGHT;
Wimpie 0:d550841cd6eb 356 break;
Wimpie 0:d550841cd6eb 357 }
Wimpie 0:d550841cd6eb 358
Wimpie 0:d550841cd6eb 359 ret = x+(width*size);
Wimpie 0:d550841cd6eb 360 if (ret > _width) {
Wimpie 0:d550841cd6eb 361 return _width+1;
Wimpie 0:d550841cd6eb 362 }
Wimpie 0:d550841cd6eb 363
Wimpie 0:d550841cd6eb 364 if (size <= 1) {
Wimpie 0:d550841cd6eb 365 set_window(x, y, x+(+width-1), y+(height-1));
Wimpie 0:d550841cd6eb 366 drawstart();
Wimpie 0:d550841cd6eb 367
Wimpie 0:d550841cd6eb 368 unsigned long data, mask;
Wimpie 0:d550841cd6eb 369 for (wh=(width*height)/32; wh!=0; wh--) {
Wimpie 0:d550841cd6eb 370 data = *ptr++;
Wimpie 0:d550841cd6eb 371 //data = ((data&0xFF000000UL)>>24)|((data&0x00FF0000UL)>>8)|((data&0x0000FF00UL)<<8)|((data&0x000000FFUL)<<24); //swap32
Wimpie 0:d550841cd6eb 372 for (mask=0x80000000UL; mask!=0UL; mask>>=1) {
Wimpie 0:d550841cd6eb 373 if (data & mask) {
Wimpie 0:d550841cd6eb 374 draw(color);
Wimpie 0:d550841cd6eb 375 } else {
Wimpie 0:d550841cd6eb 376 draw(bgcolor);
Wimpie 0:d550841cd6eb 377 }
Wimpie 0:d550841cd6eb 378 }
Wimpie 0:d550841cd6eb 379 }
Wimpie 0:d550841cd6eb 380
Wimpie 0:d550841cd6eb 381 drawstop();
Wimpie 0:d550841cd6eb 382 } else {
Wimpie 0:d550841cd6eb 383 set_window(x, y, x+(width*size)-1, y+(height*size)-1);
Wimpie 0:d550841cd6eb 384 drawstart();
Wimpie 0:d550841cd6eb 385
Wimpie 0:d550841cd6eb 386 unsigned int bit;
Wimpie 0:d550841cd6eb 387 wh = (width*height);
Wimpie 0:d550841cd6eb 388 for (h=0; h<wh; h+=width) {
Wimpie 0:d550841cd6eb 389 for (i=size; i!=0; i--) {
Wimpie 0:d550841cd6eb 390 bit = h;
Wimpie 0:d550841cd6eb 391 for (w=0; w<width; w++) {
Wimpie 0:d550841cd6eb 392 if (checkbit(ptr, bit++)) {
Wimpie 0:d550841cd6eb 393 for (j=size; j!=0; j--) {
Wimpie 0:d550841cd6eb 394 draw(color);
Wimpie 0:d550841cd6eb 395 }
Wimpie 0:d550841cd6eb 396 } else {
Wimpie 0:d550841cd6eb 397 for (j=size; j!=0; j--) {
Wimpie 0:d550841cd6eb 398 draw(bgcolor);
Wimpie 0:d550841cd6eb 399 }
Wimpie 0:d550841cd6eb 400 }
Wimpie 0:d550841cd6eb 401 }
Wimpie 0:d550841cd6eb 402 }
Wimpie 0:d550841cd6eb 403 }
Wimpie 0:d550841cd6eb 404
Wimpie 0:d550841cd6eb 405 drawstop();
Wimpie 0:d550841cd6eb 406 }
Wimpie 0:d550841cd6eb 407
Wimpie 0:d550841cd6eb 408 return ret;
Wimpie 0:d550841cd6eb 409 }
Wimpie 0:d550841cd6eb 410
Wimpie 0:d550841cd6eb 411
Wimpie 0:d550841cd6eb 412 void LS020LCD::fillrectangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int color) {
Wimpie 0:d550841cd6eb 413 unsigned int wh, tmp;
Wimpie 0:d550841cd6eb 414
Wimpie 0:d550841cd6eb 415 if (x0 > x1) {
Wimpie 0:d550841cd6eb 416 tmp = x0;
Wimpie 0:d550841cd6eb 417 x0 = x1;
Wimpie 0:d550841cd6eb 418 x1 = tmp;
Wimpie 0:d550841cd6eb 419 }
Wimpie 0:d550841cd6eb 420 if (y0 > y1) {
Wimpie 0:d550841cd6eb 421 tmp = y0;
Wimpie 0:d550841cd6eb 422 y0 = y1;
Wimpie 0:d550841cd6eb 423 y1 = tmp;
Wimpie 0:d550841cd6eb 424 }
Wimpie 0:d550841cd6eb 425
Wimpie 0:d550841cd6eb 426 if ((x1 >= _width) ||
Wimpie 0:d550841cd6eb 427 (y1 >= _height)) {
Wimpie 0:d550841cd6eb 428 return;
Wimpie 0:d550841cd6eb 429 }
Wimpie 0:d550841cd6eb 430
Wimpie 0:d550841cd6eb 431 set_window(x0, y0, x1, y1);
Wimpie 0:d550841cd6eb 432
Wimpie 0:d550841cd6eb 433 drawstart();
Wimpie 0:d550841cd6eb 434 for (wh=((1+(x1-x0))*(1+(y1-y0))); wh!=0; wh--) {
Wimpie 0:d550841cd6eb 435 draw(color);
Wimpie 0:d550841cd6eb 436 }
Wimpie 0:d550841cd6eb 437 drawstop();
Wimpie 0:d550841cd6eb 438
Wimpie 0:d550841cd6eb 439 return;
Wimpie 0:d550841cd6eb 440 }
Wimpie 0:d550841cd6eb 441
Wimpie 0:d550841cd6eb 442 void LS020LCD::drawpixel(unsigned int x, unsigned int y, unsigned int color) {
Wimpie 0:d550841cd6eb 443 if ((x >= _width) ||
Wimpie 0:d550841cd6eb 444 (y >= _height)) {
Wimpie 0:d550841cd6eb 445 return;
Wimpie 0:d550841cd6eb 446 }
Wimpie 0:d550841cd6eb 447 set_cursor(x, y);
Wimpie 0:d550841cd6eb 448 drawstart();
Wimpie 0:d550841cd6eb 449 draw(color);
Wimpie 0:d550841cd6eb 450 drawstop();
Wimpie 0:d550841cd6eb 451
Wimpie 0:d550841cd6eb 452 return;
Wimpie 0:d550841cd6eb 453 }
Wimpie 0:d550841cd6eb 454
Wimpie 0:d550841cd6eb 455 void LS020LCD::drawline(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int color) {
Wimpie 0:d550841cd6eb 456 int dx, dy, dx2, dy2, stepx, stepy, err;
Wimpie 0:d550841cd6eb 457
Wimpie 0:d550841cd6eb 458 if ((x0 == x1) ||
Wimpie 0:d550841cd6eb 459 (y0 == y1)) { //horizontal or vertical line
Wimpie 0:d550841cd6eb 460 fillrectangle(x0, y0, x1, y1, color);
Wimpie 0:d550841cd6eb 461 } else {
Wimpie 0:d550841cd6eb 462 //calculate direction
Wimpie 0:d550841cd6eb 463 dx = x1 - x0;
Wimpie 0:d550841cd6eb 464 dy = y1 - y0;
Wimpie 0:d550841cd6eb 465 if (dx < 0) {
Wimpie 0:d550841cd6eb 466 dx = -dx;
Wimpie 0:d550841cd6eb 467 stepx = -1;
Wimpie 0:d550841cd6eb 468 } else {
Wimpie 0:d550841cd6eb 469 stepx = +1;
Wimpie 0:d550841cd6eb 470 }
Wimpie 0:d550841cd6eb 471 if (dy < 0) {
Wimpie 0:d550841cd6eb 472 dy = -dy;
Wimpie 0:d550841cd6eb 473 stepy = -1;
Wimpie 0:d550841cd6eb 474 } else {
Wimpie 0:d550841cd6eb 475 stepy = +1;
Wimpie 0:d550841cd6eb 476 }
Wimpie 0:d550841cd6eb 477 dx2 = dx << 1;
Wimpie 0:d550841cd6eb 478 dy2 = dy << 1;
Wimpie 0:d550841cd6eb 479 //draw line
Wimpie 0:d550841cd6eb 480 set_window(0, 0, (_width-1), (_height-1));
Wimpie 0:d550841cd6eb 481 drawpixel(x0, y0, color);
Wimpie 0:d550841cd6eb 482 if (dx > dy) {
Wimpie 0:d550841cd6eb 483 err = dy2 - dx;
Wimpie 0:d550841cd6eb 484 while (x0 != x1) {
Wimpie 0:d550841cd6eb 485 if (err >= 0) {
Wimpie 0:d550841cd6eb 486 err -= dx2;
Wimpie 0:d550841cd6eb 487 y0 += stepy;
Wimpie 0:d550841cd6eb 488 }
Wimpie 0:d550841cd6eb 489 err += dy2;
Wimpie 0:d550841cd6eb 490 x0 += stepx;
Wimpie 0:d550841cd6eb 491 drawpixel(x0, y0, color);
Wimpie 0:d550841cd6eb 492 }
Wimpie 0:d550841cd6eb 493 } else {
Wimpie 0:d550841cd6eb 494 err = dx2 - dy;
Wimpie 0:d550841cd6eb 495 while (y0 != y1) {
Wimpie 0:d550841cd6eb 496 if (err >= 0) {
Wimpie 0:d550841cd6eb 497 err -= dy2;
Wimpie 0:d550841cd6eb 498 x0 += stepx;
Wimpie 0:d550841cd6eb 499 }
Wimpie 0:d550841cd6eb 500 err += dx2;
Wimpie 0:d550841cd6eb 501 y0 += stepy;
Wimpie 0:d550841cd6eb 502 drawpixel(x0, y0, color);
Wimpie 0:d550841cd6eb 503 }
Wimpie 0:d550841cd6eb 504 }
Wimpie 0:d550841cd6eb 505 }
Wimpie 0:d550841cd6eb 506
Wimpie 0:d550841cd6eb 507 return;
Wimpie 0:d550841cd6eb 508 }
Wimpie 0:d550841cd6eb 509
Wimpie 0:d550841cd6eb 510 void LS020LCD::drawrectangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int color) {
Wimpie 0:d550841cd6eb 511 fillrectangle(x0, y0, x0, y1, color);
Wimpie 0:d550841cd6eb 512 fillrectangle(x0, y1, x1, y1, color);
Wimpie 0:d550841cd6eb 513 fillrectangle(x1, y0, x1, y1, color);
Wimpie 0:d550841cd6eb 514 fillrectangle(x0, y0, x1, y0, color);
Wimpie 0:d550841cd6eb 515
Wimpie 0:d550841cd6eb 516 return;
Wimpie 0:d550841cd6eb 517 }
Wimpie 0:d550841cd6eb 518
Wimpie 0:d550841cd6eb 519
Wimpie 0:d550841cd6eb 520 void LS020LCD::fillcircle(unsigned int x0, unsigned int y0, unsigned int radius, unsigned int color) {
Wimpie 0:d550841cd6eb 521 int err, x, y;
Wimpie 0:d550841cd6eb 522
Wimpie 0:d550841cd6eb 523 err = -radius;
Wimpie 0:d550841cd6eb 524 x = radius;
Wimpie 0:d550841cd6eb 525 y = 0;
Wimpie 0:d550841cd6eb 526
Wimpie 0:d550841cd6eb 527 set_window(0, 0, (_width-1), (_height-1));
Wimpie 0:d550841cd6eb 528
Wimpie 0:d550841cd6eb 529 while (x >= y) {
Wimpie 0:d550841cd6eb 530 drawline(x0 - x, y0 + y, x0 + x, y0 + y, color);
Wimpie 0:d550841cd6eb 531 drawline(x0 - x, y0 - y, x0 + x, y0 - y, color);
Wimpie 0:d550841cd6eb 532 drawline(x0 - y, y0 + x, x0 + y, y0 + x, color);
Wimpie 0:d550841cd6eb 533 drawline(x0 - y, y0 - x, x0 + y, y0 - x, color);
Wimpie 0:d550841cd6eb 534
Wimpie 0:d550841cd6eb 535 err += y;
Wimpie 0:d550841cd6eb 536 y++;
Wimpie 0:d550841cd6eb 537 err += y;
Wimpie 0:d550841cd6eb 538 if (err >= 0) {
Wimpie 0:d550841cd6eb 539 x--;
Wimpie 0:d550841cd6eb 540 err -= x;
Wimpie 0:d550841cd6eb 541 err -= x;
Wimpie 0:d550841cd6eb 542 }
Wimpie 0:d550841cd6eb 543 }
Wimpie 0:d550841cd6eb 544
Wimpie 0:d550841cd6eb 545 return;
Wimpie 0:d550841cd6eb 546 }
Wimpie 0:d550841cd6eb 547
Wimpie 0:d550841cd6eb 548
Wimpie 0:d550841cd6eb 549 void LS020LCD::drawcircle(unsigned int x0, unsigned int y0, unsigned int radius, unsigned int color) {
Wimpie 0:d550841cd6eb 550 int err, x, y;
Wimpie 0:d550841cd6eb 551
Wimpie 0:d550841cd6eb 552 err = -radius;
Wimpie 0:d550841cd6eb 553 x = radius;
Wimpie 0:d550841cd6eb 554 y = 0;
Wimpie 0:d550841cd6eb 555
Wimpie 0:d550841cd6eb 556 set_window(0, 0, (_width-1), (_height-1));
Wimpie 0:d550841cd6eb 557
Wimpie 0:d550841cd6eb 558 while (x >= y) {
Wimpie 0:d550841cd6eb 559 drawpixel(x0 + x, y0 + y, color);
Wimpie 0:d550841cd6eb 560 drawpixel(x0 - x, y0 + y, color);
Wimpie 0:d550841cd6eb 561 drawpixel(x0 + x, y0 - y, color);
Wimpie 0:d550841cd6eb 562 drawpixel(x0 - x, y0 - y, color);
Wimpie 0:d550841cd6eb 563 drawpixel(x0 + y, y0 + x, color);
Wimpie 0:d550841cd6eb 564 drawpixel(x0 - y, y0 + x, color);
Wimpie 0:d550841cd6eb 565 drawpixel(x0 + y, y0 - x, color);
Wimpie 0:d550841cd6eb 566 drawpixel(x0 - y, y0 - x, color);
Wimpie 0:d550841cd6eb 567
Wimpie 0:d550841cd6eb 568 err += y;
Wimpie 0:d550841cd6eb 569 y++;
Wimpie 0:d550841cd6eb 570 err += y;
Wimpie 0:d550841cd6eb 571 if (err >= 0) {
Wimpie 0:d550841cd6eb 572 x--;
Wimpie 0:d550841cd6eb 573 err -= x;
Wimpie 0:d550841cd6eb 574 err -= x;
Wimpie 0:d550841cd6eb 575 }
Wimpie 0:d550841cd6eb 576 }
Wimpie 0:d550841cd6eb 577
Wimpie 0:d550841cd6eb 578 return;
Wimpie 0:d550841cd6eb 579 }
Wimpie 0:d550841cd6eb 580
Wimpie 0:d550841cd6eb 581 /*void LS020LCD::rectangle8(char x1, char y1, char x2, char y2, char color) {
Wimpie 0:d550841cd6eb 582 set_window(x1,y1,x2,y2);
Wimpie 0:d550841cd6eb 583 for (char y=y1;y<=y2;y++) {
Wimpie 0:d550841cd6eb 584 for (char x=x1;x<=x2;x++) {
Wimpie 0:d550841cd6eb 585 write_data8(color);
Wimpie 0:d550841cd6eb 586 }
Wimpie 0:d550841cd6eb 587 }
Wimpie 0:d550841cd6eb 588 }
Wimpie 0:d550841cd6eb 589
Wimpie 0:d550841cd6eb 590
Wimpie 0:d550841cd6eb 591 void LS020LCD::putpixel(unsigned char r,unsigned char g,unsigned char b, unsigned char x, unsigned char y) {
Wimpie 0:d550841cd6eb 592 uint16_t data;
Wimpie 0:d550841cd6eb 593 write_cmd16(0xEF90);
Wimpie 0:d550841cd6eb 594 write_cmd16(0x0500);
Wimpie 0:d550841cd6eb 595 write_cmd16(0x0800+ x);
Wimpie 0:d550841cd6eb 596 write_cmd16(0x0A00+ y);
Wimpie 0:d550841cd6eb 597 write_cmd16(0x0900+ x+1);
Wimpie 0:d550841cd6eb 598 write_cmd16(0x0B00+ y+1);
Wimpie 0:d550841cd6eb 599 data=0xffff-(((uint16_t)(31*b/255))*0x800)+(((uint16_t)(63*g/255))*0x20)+(((uint16_t)(31*r/255)));
Wimpie 0:d550841cd6eb 600 write_data16(data);
Wimpie 0:d550841cd6eb 601
Wimpie 0:d550841cd6eb 602 }
Wimpie 0:d550841cd6eb 603 void LS020LCD::put_char8(char x, char y, char symbol, char color, char bkcolor) {
Wimpie 0:d550841cd6eb 604 set_window(x,y,x+5,y+7);
Wimpie 0:d550841cd6eb 605 int offset=6*(symbol-0x20);
Wimpie 0:d550841cd6eb 606 for (char i=0;i<6;i++) {
Wimpie 0:d550841cd6eb 607 for (char j=0;j<8;j++) {
Wimpie 0:d550841cd6eb 608 if (((font0[offset+i]<<j)&0x80)==0x80) {
Wimpie 0:d550841cd6eb 609 write_data8(color);
Wimpie 0:d550841cd6eb 610 } else {
Wimpie 0:d550841cd6eb 611 write_data8(bkcolor);
Wimpie 0:d550841cd6eb 612 }
Wimpie 0:d550841cd6eb 613 }
Wimpie 0:d550841cd6eb 614 }
Wimpie 0:d550841cd6eb 615 }*/
Wimpie 0:d550841cd6eb 616
Wimpie 0:d550841cd6eb 617 void LS020LCD::drawtext(unsigned int x, unsigned int y, char* text, unsigned int size,unsigned int font, unsigned int color, unsigned int bgcolor) {
Wimpie 0:d550841cd6eb 618 char i=0;
Wimpie 0:d550841cd6eb 619 char x0=0;
Wimpie 0:d550841cd6eb 620
Wimpie 0:d550841cd6eb 621 while (text[i]!=0) {
Wimpie 0:d550841cd6eb 622 x=putc(x+x0,y,text[i],size,font,color,bgcolor);
Wimpie 0:d550841cd6eb 623 i++;
Wimpie 0:d550841cd6eb 624
Wimpie 0:d550841cd6eb 625 }
Wimpie 0:d550841cd6eb 626 }
Wimpie 0:d550841cd6eb 627
Wimpie 0:d550841cd6eb 628 void LS020LCD::cls() {
Wimpie 0:d550841cd6eb 629 fillrectangle(0, 0, _width, _height, _background);
Wimpie 0:d550841cd6eb 630 }
Wimpie 0:d550841cd6eb 631
Wimpie 0:d550841cd6eb 632 void LS020LCD::scroll(char offset) {
Wimpie 0:d550841cd6eb 633 write_cmd16(0x1100+offset);
Wimpie 0:d550841cd6eb 634 }
Wimpie 0:d550841cd6eb 635
Wimpie 0:d550841cd6eb 636 unsigned int checkbit(const unsigned long *data, unsigned int nr) {
Wimpie 0:d550841cd6eb 637 return (data[nr/32] & (0x80000000UL>>(nr&31))); // (data[nr/32] & (1<<(nr&31)))
Wimpie 0:d550841cd6eb 638 }