Added circle and line support

Committer:
Lerche
Date:
Mon Oct 04 08:14:06 2010 +0000
Revision:
1:14c8b85b34d0
Parent:
0:8439874eb019

        

Who changed what in which revision?

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