Cave Runner Game w/Accelerometer and Nokia LCD

Dependencies:   mbed ADXL345 beep

Committer:
jhaksar
Date:
Tue Oct 11 16:42:41 2011 +0000
Revision:
0:200970a8c0bf

        

Who changed what in which revision?

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