Simon Ford / Mbed 2 deprecated displays

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MobileLCD.cpp Source File

MobileLCD.cpp

00001 /* mbed MobileLCD (Sparkfun Nokia) Display Library
00002  * Copyright (c) 2007-2009 sford
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005   
00006 #include "MobileLCD.h"
00007 
00008 MobileLCD::MobileLCD(PinName mosi, PinName sclk, PinName cs, PinName rst) : _spi(mosi, NC, sclk), _cs(cs), _rst(rst) {
00009     _cs = 1;
00010     _rst = 0;
00011     _spi.format(9);
00012     _spi.frequency(5000000);
00013     wait(0.001);
00014     _rst = 1;
00015     wait(0.001);
00016     _cs = 0;
00017 
00018     command(0xCA); // display control 
00019     data(0);
00020     data(32);
00021     data(0);
00022 
00023     command(0xBB); 
00024     data(1);
00025 
00026     command(0xD1); // oscillator on
00027     command(0x94); // sleep out
00028     command(0x20); // power control
00029     data(0x0F);
00030 
00031     command(0xA7); // invert display
00032     command(0x81); // Voltage control
00033     data(39);      // contrast setting: 0..63
00034     data(3);       // resistance ratio
00035     wait(0.001);
00036 
00037     command(0xBC); // data control
00038     data(3); // scan dirs 
00039     data(1); // RGB
00040     data(4); // grayscale           
00041     
00042     command(0xAF);  // turn on the display   
00043     _cs = 1;
00044     
00045     cls();
00046 }
00047 
00048 void MobileLCD::pixel(int x, int y, int colour) {
00049     _cs = 0;
00050     
00051     command(0x15); // column
00052     data(2 + x);       
00053     data(2 + x); 
00054     command(0x75); // page
00055     data(y);            
00056     data(y);
00057     command(0x5C); // start write to ram
00058 
00059     int gr = ((colour >> 20) & 0x0F)
00060            | ((colour >> 8 ) & 0xF0);
00061     int nb = ((colour >> 4 ) & 0x0F);
00062     data(nb); 
00063     data(gr);
00064     
00065     _cs = 1; 
00066 }
00067     
00068 int MobileLCD::width() { return 130; }
00069 int MobileLCD::height() { return 130; }
00070     
00071 void MobileLCD::command(int value) {
00072     _spi.write(value & 0xFF);
00073 }
00074 
00075 void MobileLCD::data(int value) {
00076     _spi.write(value | 0x100);
00077 }
00078 
00079 #ifdef MBED_MOBILELCD_FASTER
00080 void MobileLCD::window(int x, int y, int w, int h) {
00081     _cs = 0;
00082     command(0x15); // column
00083     data(2 + x);       
00084     data(2 + x + w - 1); 
00085     command(0x75); // page
00086     data(y);            
00087     data(y + h - 1);
00088     command(0x5C); // start write to ram
00089     _cs = 1;
00090 }
00091 
00092 void MobileLCD::putp(int colour) {
00093     _cs = 0;
00094     int gr = ((colour >> 20) & 0x0F)
00095            | ((colour >> 8 ) & 0xF0);
00096     int nb = ((colour >> 4 ) & 0x0F);
00097     data(nb); 
00098     data(gr);
00099     _cs = 1; 
00100 }
00101 
00102 #endif