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:25:44 2010 +0000
Revision:
0:d550841cd6eb
Child:
1:2269e07af50b

        

Who changed what in which revision?

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