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