Library for Nuelectronics Nokia 3310/5110 LCD Display and joystick.

Dependents:   N3310LCD_Demo FRDM_N3110LCD

Committer:
SomeRandomBloke
Date:
Fri Jul 19 13:42:00 2013 +0000
Revision:
6:46bcc4e584c4
Parent:
5:1fd7af32e521
code comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 6:46bcc4e584c4 1 /**
SomeRandomBloke 6:46bcc4e584c4 2 * @section DESCRIPTION
SomeRandomBloke 6:46bcc4e584c4 3 * N3310LCD. A program to interface mbed with the nuelectronics
SomeRandomBloke 6:46bcc4e584c4 4 * Nokia 3310 LCD shield from www.nuelectronics.com. Ported from
SomeRandomBloke 6:46bcc4e584c4 5 * the nuelectronics Arduino code.
SomeRandomBloke 6:46bcc4e584c4 6 *
SomeRandomBloke 6:46bcc4e584c4 7 * @section LICENSE
SomeRandomBloke 6:46bcc4e584c4 8 *
SomeRandomBloke 6:46bcc4e584c4 9 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
SomeRandomBloke 6:46bcc4e584c4 10 *
SomeRandomBloke 6:46bcc4e584c4 11 * Converted to a mbed library by Andrew D. Lindsay
SomeRandomBloke 6:46bcc4e584c4 12 *
SomeRandomBloke 6:46bcc4e584c4 13 * This file is part of N3310LCD.
SomeRandomBloke 6:46bcc4e584c4 14 *
SomeRandomBloke 6:46bcc4e584c4 15 * N3310LCD is free software: you can redistribute it and/or modify
SomeRandomBloke 6:46bcc4e584c4 16 * it under the terms of the GNU General Public License as published by
SomeRandomBloke 6:46bcc4e584c4 17 * the Free Software Foundation, either version 3 of the License, or
SomeRandomBloke 6:46bcc4e584c4 18 * (at your option) any later version.
SomeRandomBloke 6:46bcc4e584c4 19 *
SomeRandomBloke 6:46bcc4e584c4 20 * N3310LCD is distributed in the hope that it will be useful,
SomeRandomBloke 6:46bcc4e584c4 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
SomeRandomBloke 6:46bcc4e584c4 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
SomeRandomBloke 6:46bcc4e584c4 23 * GNU General Public License for more details.
SomeRandomBloke 6:46bcc4e584c4 24 *
SomeRandomBloke 6:46bcc4e584c4 25 * You should have received a copy of the GNU General Public License
SomeRandomBloke 6:46bcc4e584c4 26 * along with N3310LCD. If not, see <http://www.gnu.org/licenses/>.
SomeRandomBloke 6:46bcc4e584c4 27 */
SomeRandomBloke 0:7efa6655d94b 28
SomeRandomBloke 6:46bcc4e584c4 29 #ifndef N3310LCD_H
SomeRandomBloke 6:46bcc4e584c4 30 #define N3310LCD_H
SomeRandomBloke 0:7efa6655d94b 31
SomeRandomBloke 0:7efa6655d94b 32 #include <mbed.h>
SomeRandomBloke 0:7efa6655d94b 33 #include "N3310LCDDefs.h"
SomeRandomBloke 0:7efa6655d94b 34
SomeRandomBloke 0:7efa6655d94b 35 #define LCDCOLMAX 84
SomeRandomBloke 0:7efa6655d94b 36 #define LCDROWMAX 6
SomeRandomBloke 0:7efa6655d94b 37 #define LCDPIXELROWMAX 48
SomeRandomBloke 0:7efa6655d94b 38 #define PIXEL_OFF 0
SomeRandomBloke 0:7efa6655d94b 39 #define PIXEL_ON 1
SomeRandomBloke 0:7efa6655d94b 40 #define PIXEL_XOR 2
SomeRandomBloke 3:9808f63fd2fe 41 #define FONT_5x7 0
SomeRandomBloke 3:9808f63fd2fe 42 #define FONT_6x8 1
SomeRandomBloke 4:90dce6032a37 43 #define FONT_ALPHA_17x17 2
SomeRandomBloke 4:90dce6032a37 44
SomeRandomBloke 0:7efa6655d94b 45
SomeRandomBloke 5:1fd7af32e521 46 class N3310LCD : public Stream
SomeRandomBloke 0:7efa6655d94b 47 {
SomeRandomBloke 0:7efa6655d94b 48 public:
SomeRandomBloke 6:46bcc4e584c4 49 /** Constructor
SomeRandomBloke 6:46bcc4e584c4 50 *
SomeRandomBloke 6:46bcc4e584c4 51 * @param mosi Pin name
SomeRandomBloke 6:46bcc4e584c4 52 * @param miso pin name
SomeRandomBloke 6:46bcc4e584c4 53 * @param sck Clock pin name
SomeRandomBloke 6:46bcc4e584c4 54 * @param cd Chip enable pin name
SomeRandomBloke 6:46bcc4e584c4 55 * @param dat_cmd Data/Command selection pin
SomeRandomBloke 6:46bcc4e584c4 56 * @param lcd_rst Reset pin name
SomeRandomBloke 6:46bcc4e584c4 57 * @param bl_on Backlight control pin
SomeRandomBloke 6:46bcc4e584c4 58 */
SomeRandomBloke 1:51961974fe55 59 N3310LCD(PinName mosi, PinName miso, PinName sck,
SomeRandomBloke 0:7efa6655d94b 60 PinName ce, PinName dat_cmd, PinName lcd_rst, PinName bl_on);
SomeRandomBloke 1:51961974fe55 61
SomeRandomBloke 6:46bcc4e584c4 62 /** Main initialisation function
SomeRandomBloke 6:46bcc4e584c4 63 */
SomeRandomBloke 0:7efa6655d94b 64 void init();
SomeRandomBloke 6:46bcc4e584c4 65
SomeRandomBloke 6:46bcc4e584c4 66 /** Clear LCD screen and home cursor
SomeRandomBloke 6:46bcc4e584c4 67 */
SomeRandomBloke 0:7efa6655d94b 68 void cls();
SomeRandomBloke 6:46bcc4e584c4 69
SomeRandomBloke 6:46bcc4e584c4 70 /** Set backlight state, either on or off
SomeRandomBloke 6:46bcc4e584c4 71 *
SomeRandomBloke 6:46bcc4e584c4 72 * @param state The backlight state, ON or OFF
SomeRandomBloke 6:46bcc4e584c4 73 */
SomeRandomBloke 0:7efa6655d94b 74 void backlight(eBacklight state);
SomeRandomBloke 6:46bcc4e584c4 75
SomeRandomBloke 6:46bcc4e584c4 76 /** Write a single command to the LCD module
SomeRandomBloke 6:46bcc4e584c4 77 *
SomeRandomBloke 6:46bcc4e584c4 78 * @param data The command data to send
SomeRandomBloke 6:46bcc4e584c4 79 */
SomeRandomBloke 3:9808f63fd2fe 80 void writeCommand(BYTE data);
SomeRandomBloke 6:46bcc4e584c4 81
SomeRandomBloke 6:46bcc4e584c4 82 /** Write a byte of data to LCD module
SomeRandomBloke 6:46bcc4e584c4 83 *
SomeRandomBloke 6:46bcc4e584c4 84 * @param data The data byte to send
SomeRandomBloke 6:46bcc4e584c4 85 */
SomeRandomBloke 3:9808f63fd2fe 86 void writeData(BYTE data);
SomeRandomBloke 6:46bcc4e584c4 87
SomeRandomBloke 6:46bcc4e584c4 88 /** Move the cursor to a particular location
SomeRandomBloke 6:46bcc4e584c4 89 *
SomeRandomBloke 6:46bcc4e584c4 90 * @param xPos X position, 0 to 83, left to right
SomeRandomBloke 6:46bcc4e584c4 91 * @param yPos Y position, 0 to 47, top to bottom
SomeRandomBloke 6:46bcc4e584c4 92 */
SomeRandomBloke 0:7efa6655d94b 93 void locate(BYTE xPos, BYTE yPos);
SomeRandomBloke 1:51961974fe55 94
SomeRandomBloke 6:46bcc4e584c4 95 /** Copy bitmap data to display, can be smaller than full screen for partial updates
SomeRandomBloke 6:46bcc4e584c4 96 *
SomeRandomBloke 6:46bcc4e584c4 97 * @param xPos X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 98 * @param yPos Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 99 * @param bitmap Bitmap data
SomeRandomBloke 6:46bcc4e584c4 100 * @param bmpXSise Number of X pixels in bitmap
SomeRandomBloke 6:46bcc4e584c4 101 * @param bmpYSize Number of Y pixels in bitmap
SomeRandomBloke 6:46bcc4e584c4 102 */
SomeRandomBloke 0:7efa6655d94b 103 void drawBitmap(BYTE xPos, BYTE yPos, BYTE* bitmap, BYTE bmpXSize, BYTE bmpYSize);
SomeRandomBloke 6:46bcc4e584c4 104
SomeRandomBloke 6:46bcc4e584c4 105 /** Clear an area of the display
SomeRandomBloke 6:46bcc4e584c4 106 *
SomeRandomBloke 6:46bcc4e584c4 107 * @param xPos X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 108 * @param yPos Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 109 * @param bmpXSise Number of X pixels in bitmap
SomeRandomBloke 6:46bcc4e584c4 110 * @param bmpYSize Number of Y pixels in bitmap
SomeRandomBloke 6:46bcc4e584c4 111 */
SomeRandomBloke 0:7efa6655d94b 112 void clearBitmap(BYTE xPos,BYTE yPos, BYTE size_x, BYTE size_y);
SomeRandomBloke 6:46bcc4e584c4 113
SomeRandomBloke 6:46bcc4e584c4 114 /** Set the font to use for future characters
SomeRandomBloke 6:46bcc4e584c4 115 *
SomeRandomBloke 6:46bcc4e584c4 116 * @param fornt The font to use
SomeRandomBloke 6:46bcc4e584c4 117 */
SomeRandomBloke 3:9808f63fd2fe 118 void setFont(BYTE font );
SomeRandomBloke 6:46bcc4e584c4 119
SomeRandomBloke 6:46bcc4e584c4 120 /** Write a string of chars to the display starting at specified position
SomeRandomBloke 6:46bcc4e584c4 121 * and using specified display mode
SomeRandomBloke 6:46bcc4e584c4 122 *
SomeRandomBloke 6:46bcc4e584c4 123 * @param xPos X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 124 * @param yPos Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 125 * @param string The string to display
SomeRandomBloke 6:46bcc4e584c4 126 * @param mode NORMAL or HIGHLIGHT used to diplay text
SomeRandomBloke 6:46bcc4e584c4 127 */
SomeRandomBloke 1:51961974fe55 128 void writeString(BYTE xPos, BYTE yPos, char* string, eDisplayMode mode);
SomeRandomBloke 6:46bcc4e584c4 129
SomeRandomBloke 6:46bcc4e584c4 130 /** Write a string of chars to the display starting at specified position
SomeRandomBloke 6:46bcc4e584c4 131 * and using specified display mode in the big font
SomeRandomBloke 6:46bcc4e584c4 132 *
SomeRandomBloke 6:46bcc4e584c4 133 * @param xPos X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 134 * @param yPos Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 135 * @param string The string to display
SomeRandomBloke 6:46bcc4e584c4 136 * @param mode NORMAL or HIGHLIGHT used to diplay text
SomeRandomBloke 6:46bcc4e584c4 137 */
SomeRandomBloke 0:7efa6655d94b 138 void writeStringBig(BYTE xPos, BYTE yPos, char* string, eDisplayMode mode);
SomeRandomBloke 6:46bcc4e584c4 139
SomeRandomBloke 6:46bcc4e584c4 140 /** Write a single character to display in specified mode
SomeRandomBloke 6:46bcc4e584c4 141 *
SomeRandomBloke 6:46bcc4e584c4 142 * @param ch The character to display
SomeRandomBloke 6:46bcc4e584c4 143 * @param mode NORMAL or HIGHLIGHT used to diplay text
SomeRandomBloke 6:46bcc4e584c4 144 */
SomeRandomBloke 0:7efa6655d94b 145 void writeChar(BYTE ch, eDisplayMode mode);
SomeRandomBloke 6:46bcc4e584c4 146
SomeRandomBloke 6:46bcc4e584c4 147 /** Write a single big character to display in specified mode
SomeRandomBloke 6:46bcc4e584c4 148 *
SomeRandomBloke 6:46bcc4e584c4 149 * @param xPos X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 150 * @param yPos Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 151 * @param ch The character to display
SomeRandomBloke 6:46bcc4e584c4 152 * @param mode NORMAL or HIGHLIGHT used to diplay text
SomeRandomBloke 6:46bcc4e584c4 153 */
SomeRandomBloke 0:7efa6655d94b 154 void writeCharBig(BYTE xPos, BYTE yPos, BYTE ch, eDisplayMode mode);
SomeRandomBloke 1:51961974fe55 155
SomeRandomBloke 6:46bcc4e584c4 156 /** Set a single pixel either on or off
SomeRandomBloke 6:46bcc4e584c4 157 *
SomeRandomBloke 6:46bcc4e584c4 158 * @param x The X position, 0 to 83
SomeRandomBloke 6:46bcc4e584c4 159 * @param y The Y position, 0 to 47
SomeRandomBloke 6:46bcc4e584c4 160 * @param c The state, on or off.
SomeRandomBloke 6:46bcc4e584c4 161 */
SomeRandomBloke 1:51961974fe55 162 void setPixel( BYTE x, BYTE y, BYTE c );
SomeRandomBloke 6:46bcc4e584c4 163
SomeRandomBloke 6:46bcc4e584c4 164 /** Draw a line from one point to another in the specified colour
SomeRandomBloke 6:46bcc4e584c4 165 *
SomeRandomBloke 6:46bcc4e584c4 166 * @param x1 Origin X
SomeRandomBloke 6:46bcc4e584c4 167 * @param y1 Origin Y
SomeRandomBloke 6:46bcc4e584c4 168 * @param x2 Destination X
SomeRandomBloke 6:46bcc4e584c4 169 * @param y2 Destination Y
SomeRandomBloke 6:46bcc4e584c4 170 * @param c Colour, either PIXEL_ON, PIXEL_OFF or PIXEL_XOR
SomeRandomBloke 6:46bcc4e584c4 171 */
SomeRandomBloke 0:7efa6655d94b 172 void drawLine(BYTE x1, BYTE y1, BYTE x2, BYTE y2, BYTE c);
SomeRandomBloke 6:46bcc4e584c4 173
SomeRandomBloke 6:46bcc4e584c4 174 /** Draw a rectangle by specifying opposite corners. Can be on or off to draw or clear.
SomeRandomBloke 6:46bcc4e584c4 175 *
SomeRandomBloke 6:46bcc4e584c4 176 * @param x1 Origin X
SomeRandomBloke 6:46bcc4e584c4 177 * @param y1 Origin Y
SomeRandomBloke 6:46bcc4e584c4 178 * @param x2 Destination X
SomeRandomBloke 6:46bcc4e584c4 179 * @param y2 Destination Y
SomeRandomBloke 6:46bcc4e584c4 180 * @param c Colour, either PIXEL_ON, PIXEL_OFF or PIXEL_XOR
SomeRandomBloke 6:46bcc4e584c4 181 */
SomeRandomBloke 0:7efa6655d94b 182 void drawRectangle(BYTE x1, BYTE y1,BYTE x2, BYTE y2, BYTE c);
SomeRandomBloke 6:46bcc4e584c4 183
SomeRandomBloke 6:46bcc4e584c4 184 /** Draw a solid filled rectangle by specifying opposite corners. Can be on or off to draw or clear.
SomeRandomBloke 6:46bcc4e584c4 185 *
SomeRandomBloke 6:46bcc4e584c4 186 * @param x1 Origin X
SomeRandomBloke 6:46bcc4e584c4 187 * @param y1 Origin Y
SomeRandomBloke 6:46bcc4e584c4 188 * @param x2 Destination X
SomeRandomBloke 6:46bcc4e584c4 189 * @param y2 Destination Y
SomeRandomBloke 6:46bcc4e584c4 190 * @param c Colour, either PIXEL_ON, PIXEL_OFF or PIXEL_XOR
SomeRandomBloke 6:46bcc4e584c4 191 */
SomeRandomBloke 0:7efa6655d94b 192 void drawFilledRectangle(BYTE x1, BYTE y1, BYTE x2, BYTE y2, BYTE c);
SomeRandomBloke 6:46bcc4e584c4 193
SomeRandomBloke 6:46bcc4e584c4 194 /** Draw a circle of a given radius. Points outside of the display are not plotted allowing
SomeRandomBloke 6:46bcc4e584c4 195 * circles that go outside of display to be drawn.
SomeRandomBloke 6:46bcc4e584c4 196 *
SomeRandomBloke 6:46bcc4e584c4 197 * @param x1 Centre X
SomeRandomBloke 6:46bcc4e584c4 198 * @param y1 Centre Y
SomeRandomBloke 6:46bcc4e584c4 199 * @param r Radius length
SomeRandomBloke 6:46bcc4e584c4 200 * @param c Colour, either PIXEL_ON, PIXEL_OFF or PIXEL_XOR
SomeRandomBloke 6:46bcc4e584c4 201 */
SomeRandomBloke 0:7efa6655d94b 202 void drawCircle(BYTE xc, BYTE yc, BYTE r, BYTE c);
SomeRandomBloke 1:51961974fe55 203
SomeRandomBloke 5:1fd7af32e521 204 protected:
SomeRandomBloke 6:46bcc4e584c4 205 /** Implementation of virtual functions used by printf stream
SomeRandomBloke 6:46bcc4e584c4 206 */
SomeRandomBloke 5:1fd7af32e521 207 virtual int _putc(int value);
SomeRandomBloke 6:46bcc4e584c4 208 /** Dummy for stream read
SomeRandomBloke 6:46bcc4e584c4 209 */
SomeRandomBloke 5:1fd7af32e521 210 virtual int _getc();
SomeRandomBloke 6:46bcc4e584c4 211
SomeRandomBloke 0:7efa6655d94b 212 private:
SomeRandomBloke 0:7efa6655d94b 213 // I/O
SomeRandomBloke 0:7efa6655d94b 214 SPI lcdPort; // does SPI MOSI, MISO and SCK
SomeRandomBloke 0:7efa6655d94b 215 DigitalOut ceWire; // does SPI CE
SomeRandomBloke 0:7efa6655d94b 216 DigitalOut dcWire; // does 3310 DAT_CMD
SomeRandomBloke 0:7efa6655d94b 217 DigitalOut rstWire; // does 3310 LCD_RST
SomeRandomBloke 1:51961974fe55 218 DigitalOut blWire; // does 3310 BL_ON (backlight)
SomeRandomBloke 0:7efa6655d94b 219 };
SomeRandomBloke 0:7efa6655d94b 220
SomeRandomBloke 0:7efa6655d94b 221 #endif