Driver for the range of Nokia 130x130 displays as found on Sparkfun and Olimex breakout boards, supporting the 6100, 6610 and PCF8833 drivers
Dependents: NokiaLCD_HelloWorld SpectrumAnalyzer MARMEX_OB_oled__HelloWorld GMT_counter ... more
NokiaLCD.h@0:ff874f85ed33, 2010-06-09 (annotated)
- Committer:
- simon
- Date:
- Wed Jun 09 08:02:04 2010 +0000
- Revision:
- 0:ff874f85ed33
- Child:
- 1:8f005b0dcfa7
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:ff874f85ed33 | 34 | * NokiaLCD lcd(p5, p7, p8, p9); // mosi, sclk, cs, rst |
simon | 0:ff874f85ed33 | 35 | * |
simon | 0:ff874f85ed33 | 36 | * int main() { |
simon | 0:ff874f85ed33 | 37 | * lcd.printf("Hello World!"); |
simon | 0:ff874f85ed33 | 38 | * } |
simon | 0:ff874f85ed33 | 39 | */ |
simon | 0:ff874f85ed33 | 40 | class NokiaLCD : public Stream { |
simon | 0:ff874f85ed33 | 41 | |
simon | 0:ff874f85ed33 | 42 | public: |
simon | 0:ff874f85ed33 | 43 | /** LCD panel format */ |
simon | 0:ff874f85ed33 | 44 | enum LCDType { |
simon | 0:ff874f85ed33 | 45 | LCD6100 /**< Nokia 6100, as found on sparkfun board (default) */ |
simon | 0:ff874f85ed33 | 46 | , LCD6610 /**< Nokia 6610, as found on olimex board */ |
simon | 0:ff874f85ed33 | 47 | , PCF8833 |
simon | 0:ff874f85ed33 | 48 | }; |
simon | 0:ff874f85ed33 | 49 | |
simon | 0:ff874f85ed33 | 50 | /** Create and Nokia LCD interface, using a SPI and two DigitalOut interfaces |
simon | 0:ff874f85ed33 | 51 | * |
simon | 0:ff874f85ed33 | 52 | * @param mosi SPI data out |
simon | 0:ff874f85ed33 | 53 | * @param sclk SPI clock |
simon | 0:ff874f85ed33 | 54 | * @param cs Chip Select (DigitalOut) |
simon | 0:ff874f85ed33 | 55 | * @param rst Reset (DigitalOut) |
simon | 0:ff874f85ed33 | 56 | * @param type The LCDType to select driver chip variants |
simon | 0:ff874f85ed33 | 57 | */ |
simon | 0:ff874f85ed33 | 58 | NokiaLCD(PinName mosi, PinName sclk, PinName cs, PinName rst, LCDType type = LCD6100); |
simon | 0:ff874f85ed33 | 59 | |
simon | 0:ff874f85ed33 | 60 | #if DOXYGEN_ONLY |
simon | 0:ff874f85ed33 | 61 | /** Write a character to the LCD |
simon | 0:ff874f85ed33 | 62 | * |
simon | 0:ff874f85ed33 | 63 | * @param c The character to write to the display |
simon | 0:ff874f85ed33 | 64 | */ |
simon | 0:ff874f85ed33 | 65 | int putc(int c); |
simon | 0:ff874f85ed33 | 66 | |
simon | 0:ff874f85ed33 | 67 | /** Write a formated string to the LCD |
simon | 0:ff874f85ed33 | 68 | * |
simon | 0:ff874f85ed33 | 69 | * @param format A printf-style format string, followed by the |
simon | 0:ff874f85ed33 | 70 | * variables to use in formating the string. |
simon | 0:ff874f85ed33 | 71 | */ |
simon | 0:ff874f85ed33 | 72 | int printf(const char* format, ...); |
simon | 0:ff874f85ed33 | 73 | #endif |
simon | 0:ff874f85ed33 | 74 | |
simon | 0:ff874f85ed33 | 75 | /** Locate to a screen column and row |
simon | 0:ff874f85ed33 | 76 | * |
simon | 0:ff874f85ed33 | 77 | * @param column The horizontal position from the left, indexed from 0 |
simon | 0:ff874f85ed33 | 78 | * @param row The vertical position from the top, indexed from 0 |
simon | 0:ff874f85ed33 | 79 | */ |
simon | 0:ff874f85ed33 | 80 | void locate(int column, int row); |
simon | 0:ff874f85ed33 | 81 | |
simon | 0:ff874f85ed33 | 82 | /** Clear the screen and locate to 0,0 */ |
simon | 0:ff874f85ed33 | 83 | void cls(); |
simon | 0:ff874f85ed33 | 84 | |
simon | 0:ff874f85ed33 | 85 | void pixel(int x, int y, int colour); |
simon | 0:ff874f85ed33 | 86 | void fill(int x, int y, int width, int height, int colour); |
simon | 0:ff874f85ed33 | 87 | |
simon | 0:ff874f85ed33 | 88 | void blit(int x, int y, int width, int height, const int* colour); |
simon | 0:ff874f85ed33 | 89 | void bitblit(int x, int y, int width, int height, const char* bitstream); |
simon | 0:ff874f85ed33 | 90 | |
simon | 0:ff874f85ed33 | 91 | int width(); |
simon | 0:ff874f85ed33 | 92 | int height(); |
simon | 0:ff874f85ed33 | 93 | int columns(); |
simon | 0:ff874f85ed33 | 94 | int rows(); |
simon | 0:ff874f85ed33 | 95 | |
simon | 0:ff874f85ed33 | 96 | void reset(); |
simon | 0:ff874f85ed33 | 97 | |
simon | 0:ff874f85ed33 | 98 | void foreground(int c); |
simon | 0:ff874f85ed33 | 99 | void background(int c); |
simon | 0:ff874f85ed33 | 100 | |
simon | 0:ff874f85ed33 | 101 | |
simon | 0:ff874f85ed33 | 102 | protected: |
simon | 0:ff874f85ed33 | 103 | virtual void _window(int x, int y, int width, int height); |
simon | 0:ff874f85ed33 | 104 | virtual void _putp(int colour); |
simon | 0:ff874f85ed33 | 105 | |
simon | 0:ff874f85ed33 | 106 | void command(int value); |
simon | 0:ff874f85ed33 | 107 | void data(int value); |
simon | 0:ff874f85ed33 | 108 | |
simon | 0:ff874f85ed33 | 109 | void newline(); |
simon | 0:ff874f85ed33 | 110 | virtual int _putc(int c); |
simon | 0:ff874f85ed33 | 111 | virtual int _getc() { |
simon | 0:ff874f85ed33 | 112 | return 0; |
simon | 0:ff874f85ed33 | 113 | } |
simon | 0:ff874f85ed33 | 114 | void putp(int v); |
simon | 0:ff874f85ed33 | 115 | void window(int x, int y, int width, int height); |
simon | 0:ff874f85ed33 | 116 | |
simon | 0:ff874f85ed33 | 117 | SPI _spi; |
simon | 0:ff874f85ed33 | 118 | DigitalOut _rst; |
simon | 0:ff874f85ed33 | 119 | DigitalOut _cs; |
simon | 0:ff874f85ed33 | 120 | |
simon | 0:ff874f85ed33 | 121 | LCDType _type; |
simon | 0:ff874f85ed33 | 122 | int _row, _column, _rows, _columns, _foreground, _background, _width, _height; |
simon | 0:ff874f85ed33 | 123 | }; |
simon | 0:ff874f85ed33 | 124 | |
simon | 0:ff874f85ed33 | 125 | #endif |
simon | 0:ff874f85ed33 | 126 | |
simon | 0:ff874f85ed33 | 127 |