Eric Wieser
/
Bitmap_copy_copy
A Bitmap library created a while back. Probably still works...
Embed:
(wiki syntax)
Show/hide line numbers
MobileLCD.cpp
00001 /* mbed Library - MobileLCD 00002 * Copyright (c) 2007, sford 00003 */ 00004 00005 #include "MobileLCD.h" 00006 00007 #include "mbed.h" 00008 00009 using namespace mbed; 00010 00011 MobileLCD::MobileLCD(int mosi, int miso, int clk, int cs, int rst) 00012 : _spi(mosi, miso, clk) 00013 , _rst(rst) 00014 , _cs(cs) { 00015 00016 _row = 0; 00017 _column = 0; 00018 _rows = 16; 00019 _columns = 16; 00020 _width = 130; 00021 _height = 130; 00022 foreground(0x00FFFFFF); 00023 background(0x00000000); 00024 reset(); 00025 } 00026 00027 void MobileLCD::reset() { 00028 _cs = 1; 00029 _rst = 0; 00030 _spi.format(9); 00031 _spi.frequency(5000000); 00032 wait(0.001); 00033 _rst = 1; 00034 wait(0.001); 00035 _select(); 00036 command(0xCA); // display control 00037 data(0); 00038 data(32); 00039 data(0); 00040 command(0xBB); 00041 data(1); 00042 00043 command(0xD1); // oscillator on 00044 command(0x94); // sleep out 00045 command(0x20); // power control 00046 data(0x0F); 00047 00048 command(0xA7); // invert display 00049 00050 command(0x81); // Voltage control 00051 data(39); // contrast setting: 0..63 00052 data(3); // resistance ratio 00053 wait(0.001); 00054 00055 orientation(); 00056 00057 // clear screen, including surrounding border 00058 _window(0, 0, 130, 130); 00059 for(int i=0; i<130*130; i++) { 00060 _putp(0x000000); 00061 } 00062 command(0xAF); // turn on the display 00063 00064 _deselect(); 00065 00066 } 00067 00068 void MobileLCD::command(int value) { 00069 _spi.write(value & 0xFF); 00070 } 00071 00072 void MobileLCD::data(int value) { 00073 _spi.write(value | 0x100); 00074 } 00075 00076 void MobileLCD::_select() { 00077 _cs = 0; 00078 } 00079 00080 void MobileLCD::_deselect() { 00081 _cs = 1; 00082 } 00083 00084 void MobileLCD::_window(int x, int y, int width, int height) { 00085 int x1, x2, y1, y2; 00086 switch(0) { //_rotation) { 00087 default: 00088 case 0: 00089 x1 = x + 2; 00090 y1 = y + 0; 00091 x2 = x1 + width - 1; 00092 y2 = y1 + height - 1; 00093 break; 00094 case 1: 00095 x1 = y + 1; 00096 y1 = x + 1; 00097 x2 = x1 + height - 1; 00098 y2 = y1 + width - 1; 00099 break; 00100 case 2: 00101 x1 = x + 1; 00102 y1 = y + 3; 00103 x2 = x1 + width - 1; 00104 y2 = y1 + height - 1; 00105 break; 00106 case 3: 00107 x1 = y + 3; 00108 y1 = x + 3; 00109 x2 = x1 + height - 1; 00110 y2 = y1 + width - 1; 00111 break; 00112 } 00113 command(0x15); // column 00114 data(x1); 00115 data(x2); 00116 command(0x75); // page 00117 data(y1); 00118 data(y2); 00119 command(0x5C); // start write to ram 00120 } 00121 00122 void MobileLCD::_putp(int colour) { 00123 int gr = ((colour >> 20) & 0x0F) 00124 | ((colour >> 8 ) & 0xF0); 00125 int nb = ((colour >> 4 ) & 0x0F); 00126 data(nb); 00127 data(gr); 00128 } 00129 00130 void MobileLCD::orientation() { 00131 int m; 00132 switch(0) { //_rotation) { 00133 case 0: 00134 default: 00135 m = 3; 00136 break; 00137 case 2: 00138 m = 0; 00139 break; 00140 case 1: 00141 m = 5; 00142 break; 00143 case 3: 00144 m = 6; 00145 break; 00146 } 00147 00148 command(0xBC); // data control 00149 data(m); // scan dirs 00150 data(1); // RGB 00151 data(4); // grayscale 00152 } 00153 00154 00155 const unsigned char FONT8x8[97][8] = { 00156 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char 00157 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 00158 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! 00159 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " 00160 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # 00161 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ 00162 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % 00163 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & 00164 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' 00165 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( 00166 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) 00167 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * 00168 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + 00169 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , 00170 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - 00171 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . 00172 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) 00173 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 00174 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 00175 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 00176 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 00177 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 00178 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 00179 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 00180 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 00181 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 00182 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 00183 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : 00184 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; 00185 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < 00186 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = 00187 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > 00188 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? 00189 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 00190 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A 00191 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B 00192 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C 00193 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D 00194 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E 00195 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F 00196 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G 00197 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H 00198 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I 00199 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J 00200 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K 00201 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L 00202 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M 00203 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N 00204 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O 00205 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 00206 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q 00207 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R 00208 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S 00209 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T 00210 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U 00211 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V 00212 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W 00213 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X 00214 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y 00215 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z 00216 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ 00217 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) 00218 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] 00219 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ 00220 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ 00221 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 00222 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a 00223 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b 00224 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c 00225 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d 00226 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e 00227 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f 00228 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g 00229 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h 00230 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i 00231 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j 00232 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k 00233 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l 00234 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m 00235 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n 00236 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o 00237 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p 00238 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q 00239 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r 00240 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s 00241 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t 00242 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u 00243 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v 00244 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w 00245 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x 00246 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y 00247 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z 00248 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { 00249 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | 00250 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } 00251 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 00252 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL 00253 00254 void MobileLCD::locate(int column, int row) { 00255 _row = row; 00256 _column = column; 00257 } 00258 00259 void MobileLCD::newline() { 00260 _column = 0; 00261 _row++; 00262 if(_row >= _rows) { 00263 _row = 0; 00264 } 00265 } 00266 00267 int MobileLCD::_putc(int value) { 00268 int x = _column * 8; // FIXME: Char sizes 00269 int y = _row * 8; 00270 bitblit(x + 1, y + 1, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); 00271 00272 _column++; 00273 00274 if(_column >= _columns) { 00275 _row++; 00276 _column = 0; 00277 } 00278 00279 if(_row >= _rows) { 00280 _row = 0; 00281 } 00282 00283 return value; 00284 } 00285 00286 void MobileLCD::cls() { 00287 fill(0, 0, _width, _height, _background); 00288 _row = 0; 00289 _column = 0; 00290 } 00291 00292 int MobileLCD::width() { 00293 return _width; 00294 } 00295 00296 int MobileLCD::height() { 00297 return _height; 00298 } 00299 00300 int MobileLCD::columns() { 00301 return _columns; 00302 } 00303 00304 int MobileLCD::rows() { 00305 return _rows; 00306 } 00307 00308 void MobileLCD::window(int x, int y, int width, int height) { 00309 _select(); 00310 _window(x, y, width, height); 00311 _deselect(); 00312 } 00313 00314 void MobileLCD::putp(int colour) { 00315 _select(); 00316 _putp(colour); 00317 _deselect(); 00318 } 00319 00320 void MobileLCD::pixel(int x, int y, int colour) { 00321 _select(); 00322 _window(x, y, 1, 1); 00323 _putp(colour); 00324 _deselect(); 00325 } 00326 00327 void MobileLCD::fill(int x, int y, int width, int height, int colour) { 00328 _select(); 00329 _window(x, y, width, height); 00330 for(int i=0; i<width*height; i++) { 00331 _putp(colour); 00332 } 00333 _window(0, 0, _width, _height); 00334 _deselect(); 00335 } 00336 00337 00338 void MobileLCD::blit(int x, int y, int width, int height, const int* colour) { 00339 _select(); 00340 _window(x, y, width, height); 00341 for(int i=0; i<width*height; i++) { 00342 _putp(colour[i]); 00343 } 00344 _window(0, 0, _width, _height); 00345 _deselect(); 00346 } 00347 00348 void MobileLCD::foreground(int v) { 00349 _foreground = v; 00350 } 00351 00352 void MobileLCD::background(int v) { 00353 _background = v; 00354 } 00355 00356 void MobileLCD::bitblit(int x, int y, int width, int height, const char* bitstream) { 00357 _select(); 00358 _window(x, y, width, height); 00359 for(int i=0; i<height*width; i++) { 00360 int byte = i / 8; 00361 int bit = i % 8; 00362 int colour = ((bitstream[byte] << bit) & 0x80) ? _foreground : _background; 00363 _putp(colour); 00364 } 00365 _window(0, 0, _width, _height); 00366 _deselect(); 00367 } 00368 00369 00370
Generated on Wed Jul 20 2022 11:12:02 by 1.7.2