This includes all known improvements from other people's spins on the Nokia library, including Alistair Popple's fix to the very poor contrast on newer LCD 6100 displays.

Fork of NokiaLCD by Iftekhar Choudhury

Committer:
plskeggs
Date:
Sun Jan 26 23:10:31 2014 +0000
Revision:
4:0a17a8a82c4c
Parent:
2:2d1b23692cbb
Works with a Sparkfun LCD 6100.  Includes all changes from other people's spins of the original Nokia library, including the latest from Alistar Popple that fixes the very poor contrast issue.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:ff874f85ed33 1 /* mbed NokiaLCD Library, for a 130x130 Nokia colour LCD
simon 0:ff874f85ed33 2 * Copyright (c) 2007-2010, sford
simon 0:ff874f85ed33 3 *
simon 0:ff874f85ed33 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:ff874f85ed33 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:ff874f85ed33 6 * in the Software without restriction, including without limitation the rights
simon 0:ff874f85ed33 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:ff874f85ed33 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:ff874f85ed33 9 * furnished to do so, subject to the following conditions:
simon 0:ff874f85ed33 10 *
simon 0:ff874f85ed33 11 * The above copyright notice and this permission notice shall be included in
simon 0:ff874f85ed33 12 * all copies or substantial portions of the Software.
simon 0:ff874f85ed33 13 *
simon 0:ff874f85ed33 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:ff874f85ed33 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:ff874f85ed33 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:ff874f85ed33 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:ff874f85ed33 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:ff874f85ed33 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:ff874f85ed33 20 * THE SOFTWARE.
simon 0:ff874f85ed33 21 */
simon 0:ff874f85ed33 22
simon 0:ff874f85ed33 23 #ifndef MBED_NOKIALCD_H
simon 0:ff874f85ed33 24 #define MBED_NOKIALCD_H
simon 0:ff874f85ed33 25
simon 0:ff874f85ed33 26 #include "mbed.h"
simon 0:ff874f85ed33 27
simon 0:ff874f85ed33 28 /** An interface for the 130x130 Nokia Mobile phone screens
simon 0:ff874f85ed33 29 *
simon 0:ff874f85ed33 30 * @code
simon 0:ff874f85ed33 31 * #include "mbed.h"
simon 0:ff874f85ed33 32 * #include "NokiaLCD.h"
simon 0:ff874f85ed33 33 *
simon 2:2d1b23692cbb 34 * NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::6610); // mosi, sclk, cs, rst, type
simon 0:ff874f85ed33 35 *
simon 0:ff874f85ed33 36 * int main() {
simon 0:ff874f85ed33 37 * lcd.printf("Hello World!");
simon 0:ff874f85ed33 38 * }
simon 2:2d1b23692cbb 39 * @endcode
simon 0:ff874f85ed33 40 */
simon 0:ff874f85ed33 41 class NokiaLCD : public Stream {
simon 0:ff874f85ed33 42
simon 0:ff874f85ed33 43 public:
simon 0:ff874f85ed33 44 /** LCD panel format */
simon 0:ff874f85ed33 45 enum LCDType {
simon 0:ff874f85ed33 46 LCD6100 /**< Nokia 6100, as found on sparkfun board (default) */
simon 0:ff874f85ed33 47 , LCD6610 /**< Nokia 6610, as found on olimex board */
simon 0:ff874f85ed33 48 , PCF8833
simon 0:ff874f85ed33 49 };
simon 0:ff874f85ed33 50
simon 0:ff874f85ed33 51 /** Create and Nokia LCD interface, using a SPI and two DigitalOut interfaces
simon 0:ff874f85ed33 52 *
simon 0:ff874f85ed33 53 * @param mosi SPI data out
simon 0:ff874f85ed33 54 * @param sclk SPI clock
simon 0:ff874f85ed33 55 * @param cs Chip Select (DigitalOut)
simon 0:ff874f85ed33 56 * @param rst Reset (DigitalOut)
simon 0:ff874f85ed33 57 * @param type The LCDType to select driver chip variants
simon 0:ff874f85ed33 58 */
plskeggs 4:0a17a8a82c4c 59 NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type = LCD6100, int contrast = 39);
simon 0:ff874f85ed33 60
simon 0:ff874f85ed33 61 #if DOXYGEN_ONLY
simon 0:ff874f85ed33 62 /** Write a character to the LCD
simon 0:ff874f85ed33 63 *
simon 0:ff874f85ed33 64 * @param c The character to write to the display
simon 0:ff874f85ed33 65 */
simon 0:ff874f85ed33 66 int putc(int c);
simon 0:ff874f85ed33 67
simon 0:ff874f85ed33 68 /** Write a formated string to the LCD
simon 0:ff874f85ed33 69 *
simon 0:ff874f85ed33 70 * @param format A printf-style format string, followed by the
simon 0:ff874f85ed33 71 * variables to use in formating the string.
simon 0:ff874f85ed33 72 */
simon 0:ff874f85ed33 73 int printf(const char* format, ...);
simon 0:ff874f85ed33 74 #endif
simon 0:ff874f85ed33 75
simon 0:ff874f85ed33 76 /** Locate to a screen column and row
simon 0:ff874f85ed33 77 *
simon 0:ff874f85ed33 78 * @param column The horizontal position from the left, indexed from 0
simon 0:ff874f85ed33 79 * @param row The vertical position from the top, indexed from 0
simon 0:ff874f85ed33 80 */
simon 0:ff874f85ed33 81 void locate(int column, int row);
simon 0:ff874f85ed33 82
simon 0:ff874f85ed33 83 /** Clear the screen and locate to 0,0 */
simon 0:ff874f85ed33 84 void cls();
simon 0:ff874f85ed33 85
simon 2:2d1b23692cbb 86 /** Set a pixel on te screen
simon 2:2d1b23692cbb 87 *
simon 2:2d1b23692cbb 88 * @param x horizontal position from left
simon 2:2d1b23692cbb 89 * @param y vertical position from top
simon 2:2d1b23692cbb 90 * @param colour 24-bit colour in format 0x00RRGGBB
simon 2:2d1b23692cbb 91 */
simon 0:ff874f85ed33 92 void pixel(int x, int y, int colour);
simon 2:2d1b23692cbb 93
simon 2:2d1b23692cbb 94 /** Fill an area of the screen
simon 2:2d1b23692cbb 95 *
simon 2:2d1b23692cbb 96 * @param x horizontal position from left
simon 2:2d1b23692cbb 97 * @param y vertical position from top
simon 2:2d1b23692cbb 98 * @param width width in pixels
simon 2:2d1b23692cbb 99 * @param height height in pixels
simon 2:2d1b23692cbb 100 * @param colour 24-bit colour in format 0x00RRGGBB
simon 2:2d1b23692cbb 101 */
simon 0:ff874f85ed33 102 void fill(int x, int y, int width, int height, int colour);
plskeggs 4:0a17a8a82c4c 103 void circle(int x0, int y0, int r, int colour); // Added this to create circles easy.
plskeggs 4:0a17a8a82c4c 104 void line(int x0, int y0, int x1, int y1, int colour); // Added this to create lines easy.
simon 0:ff874f85ed33 105
simon 0:ff874f85ed33 106 void blit(int x, int y, int width, int height, const int* colour);
simon 0:ff874f85ed33 107 void bitblit(int x, int y, int width, int height, const char* bitstream);
simon 0:ff874f85ed33 108
simon 0:ff874f85ed33 109 int width();
simon 0:ff874f85ed33 110 int height();
simon 0:ff874f85ed33 111 int columns();
simon 0:ff874f85ed33 112 int rows();
simon 0:ff874f85ed33 113
plskeggs 4:0a17a8a82c4c 114 void reset(int contrast);
simon 0:ff874f85ed33 115
simon 2:2d1b23692cbb 116 /** Set the foreground colour
simon 2:2d1b23692cbb 117 *
simon 2:2d1b23692cbb 118 * @param c 24-bit colour
simon 2:2d1b23692cbb 119 */
simon 0:ff874f85ed33 120 void foreground(int c);
simon 2:2d1b23692cbb 121
simon 2:2d1b23692cbb 122 /** Set the background colour
simon 2:2d1b23692cbb 123 *
simon 2:2d1b23692cbb 124 * @param c 24-bit colour
simon 2:2d1b23692cbb 125 */
simon 0:ff874f85ed33 126 void background(int c);
plskeggs 4:0a17a8a82c4c 127
plskeggs 4:0a17a8a82c4c 128 /** Move to the next line
plskeggs 4:0a17a8a82c4c 129 *
plskeggs 4:0a17a8a82c4c 130 */
plskeggs 4:0a17a8a82c4c 131 void newline();
plskeggs 4:0a17a8a82c4c 132
simon 0:ff874f85ed33 133 protected:
simon 0:ff874f85ed33 134 virtual void _window(int x, int y, int width, int height);
simon 0:ff874f85ed33 135 virtual void _putp(int colour);
simon 0:ff874f85ed33 136
simon 0:ff874f85ed33 137 void command(int value);
simon 0:ff874f85ed33 138 void data(int value);
simon 0:ff874f85ed33 139
simon 0:ff874f85ed33 140 virtual int _putc(int c);
simon 0:ff874f85ed33 141 virtual int _getc() {
simon 0:ff874f85ed33 142 return 0;
simon 0:ff874f85ed33 143 }
simon 0:ff874f85ed33 144 void putp(int v);
simon 0:ff874f85ed33 145 void window(int x, int y, int width, int height);
simon 0:ff874f85ed33 146
simon 0:ff874f85ed33 147 SPI _spi;
simon 0:ff874f85ed33 148 DigitalOut _rst;
simon 0:ff874f85ed33 149 DigitalOut _cs;
simon 0:ff874f85ed33 150
simon 0:ff874f85ed33 151 LCDType _type;
simon 0:ff874f85ed33 152 int _row, _column, _rows, _columns, _foreground, _background, _width, _height;
simon 0:ff874f85ed33 153 };
simon 0:ff874f85ed33 154
simon 0:ff874f85ed33 155 #endif
simon 0:ff874f85ed33 156
simon 0:ff874f85ed33 157