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