Committer:
Wimpie
Date:
Thu May 19 18:06:13 2011 +0000
Revision:
1:ce391193b822
Parent:
0:6468a28a7b7d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wimpie 0:6468a28a7b7d 1 /* mbed PCD8544 - Graphic Library for driving monochrome displays based on PCD8544
Wimpie 0:6468a28a7b7d 2 * used in Nokia 3310, 3315, 3330, 3350, 3410, 3210, 5110, 5120, 5130, 5160, 6110, 6150
Wimpie 0:6468a28a7b7d 3 *
Wimpie 0:6468a28a7b7d 4 * Copyright (c) 2011, Wim De Roeve
Wimpie 0:6468a28a7b7d 5 * partial port of the code found on http://serdisplib.sourceforge.net/ser/pcd8544.html#links
Wimpie 0:6468a28a7b7d 6 * and by Petras Saduikis <petras@petras.co.uk>
Wimpie 0:6468a28a7b7d 7 *
Wimpie 0:6468a28a7b7d 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
Wimpie 0:6468a28a7b7d 9 * of this software and associated documentation files (the "Software"), to deal
Wimpie 0:6468a28a7b7d 10 * in the Software without restriction, including without limitation the rights
Wimpie 0:6468a28a7b7d 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Wimpie 0:6468a28a7b7d 12 * copies of the Software, and to permit persons to whom the Software is
Wimpie 0:6468a28a7b7d 13 * furnished to do so, subject to the following conditions:
Wimpie 0:6468a28a7b7d 14 *
Wimpie 0:6468a28a7b7d 15 * The above copyright notice and this permission notice shall be included in
Wimpie 0:6468a28a7b7d 16 * all copies or substantial portions of the Software.
Wimpie 0:6468a28a7b7d 17 *
Wimpie 0:6468a28a7b7d 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wimpie 0:6468a28a7b7d 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wimpie 0:6468a28a7b7d 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wimpie 0:6468a28a7b7d 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wimpie 0:6468a28a7b7d 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wimpie 0:6468a28a7b7d 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wimpie 0:6468a28a7b7d 24 * THE SOFTWARE.
Wimpie 0:6468a28a7b7d 25 */
Wimpie 0:6468a28a7b7d 26 #ifndef PCD8544LCD_H
Wimpie 0:6468a28a7b7d 27 #define PCD8544LCD_H
Wimpie 0:6468a28a7b7d 28
Wimpie 1:ce391193b822 29 // the Nokia 3310 has a resolution of 84 x 48
Wimpie 1:ce391193b822 30 // the Nokia 3410 has a resolution of 102 x 72
Wimpie 1:ce391193b822 31
Wimpie 0:6468a28a7b7d 32 #include "mbed.h"
Wimpie 0:6468a28a7b7d 33
Wimpie 0:6468a28a7b7d 34 /* Number of pixels on the LCD */
Wimpie 1:ce391193b822 35 #define LCD_X_RES 102 //84
Wimpie 1:ce391193b822 36 #define LCD_Y_RES 72 //48
Wimpie 0:6468a28a7b7d 37 #define LCD_BANKS (LCD_Y_RES / 8)
Wimpie 0:6468a28a7b7d 38
Wimpie 0:6468a28a7b7d 39 #define LCD_CACHE_SIZE ((LCD_X_RES * LCD_Y_RES) / 8)
Wimpie 0:6468a28a7b7d 40
Wimpie 0:6468a28a7b7d 41 #define MAX_ADR_X (LCD_X_RES)-1
Wimpie 0:6468a28a7b7d 42 #define MAX_ADR_Y LCD_BANKS-1
Wimpie 0:6468a28a7b7d 43
Wimpie 0:6468a28a7b7d 44 #define HIGH 1
Wimpie 0:6468a28a7b7d 45 #define LOW 0
Wimpie 0:6468a28a7b7d 46 #define TRUE 1
Wimpie 0:6468a28a7b7d 47 #define FALSE 0
Wimpie 0:6468a28a7b7d 48
Wimpie 0:6468a28a7b7d 49 /* Display control command */
Wimpie 0:6468a28a7b7d 50 #define EXTENDEDSET 0x21
Wimpie 0:6468a28a7b7d 51 #define STANDARDSET 0x20
Wimpie 0:6468a28a7b7d 52 #define DISPLAYOFF 0x08 // switch off display
Wimpie 0:6468a28a7b7d 53 #define ALL_SEG_ON 0x09 // switch on display and set to all pixels on
Wimpie 0:6468a28a7b7d 54 #define NORMAL_MODE 0x0C // NOREVERSE
Wimpie 0:6468a28a7b7d 55 #define INVERSE_MODE 0x0D // REVERSE
Wimpie 0:6468a28a7b7d 56
Wimpie 0:6468a28a7b7d 57 #define SET_ADDRES_X 0x80
Wimpie 0:6468a28a7b7d 58 #define SET_ADDRES_Y 0x40
Wimpie 0:6468a28a7b7d 59
Wimpie 0:6468a28a7b7d 60
Wimpie 0:6468a28a7b7d 61 typedef uint8_t BYTE;
Wimpie 0:6468a28a7b7d 62
Wimpie 0:6468a28a7b7d 63 typedef enum {
Wimpie 0:6468a28a7b7d 64 PIXEL_OFF = 0,
Wimpie 0:6468a28a7b7d 65 PIXEL_ON = 1,
Wimpie 0:6468a28a7b7d 66 PIXEL_XOR = 2
Wimpie 0:6468a28a7b7d 67 }ePixelMode;
Wimpie 0:6468a28a7b7d 68
Wimpie 0:6468a28a7b7d 69 typedef enum {
Wimpie 0:6468a28a7b7d 70 FILL_OFF = 0,
Wimpie 0:6468a28a7b7d 71 FILL_ON = 1
Wimpie 0:6468a28a7b7d 72 }eFillMode;
Wimpie 0:6468a28a7b7d 73
Wimpie 0:6468a28a7b7d 74 typedef enum {
Wimpie 0:6468a28a7b7d 75 RASTER_OFF = 0,
Wimpie 0:6468a28a7b7d 76 RASTER_ON = 1
Wimpie 0:6468a28a7b7d 77 }eRasterMode;
Wimpie 0:6468a28a7b7d 78
Wimpie 0:6468a28a7b7d 79 typedef enum {
Wimpie 1:ce391193b822 80 DRAW_OVERWRITE = 0,
Wimpie 1:ce391193b822 81 DRAW_MERGE = 1
Wimpie 1:ce391193b822 82 }eDrawMode;
Wimpie 1:ce391193b822 83
Wimpie 1:ce391193b822 84
Wimpie 1:ce391193b822 85 typedef enum {
Wimpie 0:6468a28a7b7d 86 VERYSMALLFONT = 0, //3x5
Wimpie 0:6468a28a7b7d 87 TINYFONT = 1, //5x7
Wimpie 0:6468a28a7b7d 88 SMALLFONT = 2, //6x8
Wimpie 0:6468a28a7b7d 89 NORMALFONT = 3, //8x8
Wimpie 0:6468a28a7b7d 90 BIGFONT = 4, //8x12&#65533;
Wimpie 0:6468a28a7b7d 91 TIMENUMBERFONT= 5, //16x20
Wimpie 0:6468a28a7b7d 92 BIGNUMBERFONT= 6
Wimpie 0:6468a28a7b7d 93 }eFonts;
Wimpie 0:6468a28a7b7d 94
Wimpie 1:ce391193b822 95 typedef enum {
Wimpie 1:ce391193b822 96 C_POINT = 0, //point
Wimpie 1:ce391193b822 97 C_LINE = 1, //line
Wimpie 1:ce391193b822 98 C_VLINE = 2, //Vertical Line
Wimpie 1:ce391193b822 99 C_HLINE = 3, //Horizontal Line
Wimpie 1:ce391193b822 100 }eChartMode;
Wimpie 1:ce391193b822 101
Wimpie 1:ce391193b822 102 typedef enum {
Wimpie 1:ce391193b822 103 SPACE_NONE = 0,
Wimpie 1:ce391193b822 104 SPACE_NORMAL = 1
Wimpie 1:ce391193b822 105 }eSpaceMode;
Wimpie 1:ce391193b822 106
Wimpie 1:ce391193b822 107
Wimpie 0:6468a28a7b7d 108
Wimpie 0:6468a28a7b7d 109 enum eDisplayMode {NORMAL, HIGHLIGHT};
Wimpie 0:6468a28a7b7d 110
Wimpie 0:6468a28a7b7d 111 class PCD8544LCD {
Wimpie 0:6468a28a7b7d 112
Wimpie 0:6468a28a7b7d 113 /* PCD8544 from Philips Semiconductors is
Wimpie 0:6468a28a7b7d 114 48 x 84 pixels monochrome matrix LCD controller/driver
Wimpie 0:6468a28a7b7d 115
Wimpie 0:6468a28a7b7d 116 The PCD8544 has a 504 byte memory with NO read function.
Wimpie 0:6468a28a7b7d 117 Each bit is a pixel
Wimpie 0:6468a28a7b7d 118 You can only write 1 byte at a time in vertical or horizontal mode.
Wimpie 0:6468a28a7b7d 119 There is no read functionality with the controller.
Wimpie 0:6468a28a7b7d 120 Caching a copy of the LCD-memory is the only solution if we want
Wimpie 0:6468a28a7b7d 121 to set one pixel at a time.
Wimpie 0:6468a28a7b7d 122
Wimpie 0:6468a28a7b7d 123 */
Wimpie 0:6468a28a7b7d 124 public:
Wimpie 0:6468a28a7b7d 125 PCD8544LCD(PinName mosi, PinName miso, PinName sclk,
Wimpie 0:6468a28a7b7d 126 PinName cs, PinName dc, PinName reset);
Wimpie 0:6468a28a7b7d 127
Wimpie 0:6468a28a7b7d 128 /** init()
Wimpie 0:6468a28a7b7d 129 *
Wimpie 0:6468a28a7b7d 130 * Initialise the device.
Wimpie 0:6468a28a7b7d 131 * @param PinName SPI mosi
Wimpie 0:6468a28a7b7d 132 * @param PinName SPI miso
Wimpie 0:6468a28a7b7d 133 * @param PinName SPI sclk
Wimpie 0:6468a28a7b7d 134 * @param PinName DigitalOut cs
Wimpie 0:6468a28a7b7d 135 * @param PinName DigitalOut dc
Wimpie 0:6468a28a7b7d 136 * @param PinName DigitalOut reset
Wimpie 0:6468a28a7b7d 137 */
Wimpie 0:6468a28a7b7d 138
Wimpie 0:6468a28a7b7d 139 void init();
Wimpie 0:6468a28a7b7d 140
Wimpie 0:6468a28a7b7d 141 /** cls()
Wimpie 0:6468a28a7b7d 142 * clears the cached copy of the screen
Wimpie 0:6468a28a7b7d 143 * and the screen itself
Wimpie 0:6468a28a7b7d 144 */
Wimpie 1:ce391193b822 145 void cls(bool fupdate=true);
Wimpie 0:6468a28a7b7d 146
Wimpie 0:6468a28a7b7d 147 /** update()
Wimpie 0:6468a28a7b7d 148 * copies the cached memory to the screen
Wimpie 0:6468a28a7b7d 149 * use this to update the screen after
Wimpie 0:6468a28a7b7d 150 * - drawBitmap
Wimpie 0:6468a28a7b7d 151 */
Wimpie 0:6468a28a7b7d 152 void update();
Wimpie 0:6468a28a7b7d 153
Wimpie 0:6468a28a7b7d 154 /** close()
Wimpie 0:6468a28a7b7d 155 * screen display OFF
Wimpie 0:6468a28a7b7d 156 */
Wimpie 0:6468a28a7b7d 157 void close();
Wimpie 0:6468a28a7b7d 158
Wimpie 0:6468a28a7b7d 159 /** locate(x,y)
Wimpie 0:6468a28a7b7d 160 * sets the cursor on position x,y
Wimpie 0:6468a28a7b7d 161 */
Wimpie 0:6468a28a7b7d 162 void locate (BYTE x0, BYTE y0);
Wimpie 0:6468a28a7b7d 163
Wimpie 0:6468a28a7b7d 164 void chooseFont(eFonts font);
Wimpie 0:6468a28a7b7d 165
Wimpie 1:ce391193b822 166 void writeString (BYTE x0, BYTE y0, char* string, eFonts font,eDisplayMode dmode,eSpaceMode smode, BYTE fupdate);
Wimpie 0:6468a28a7b7d 167 void writeChar (BYTE x0, BYTE y0, BYTE ch, eFonts font,eDisplayMode mode, BYTE update);
Wimpie 0:6468a28a7b7d 168
Wimpie 0:6468a28a7b7d 169 /** drawBitmap(x,y,bitmap,xsize,ysize)
Wimpie 0:6468a28a7b7d 170 * draw a monochrome bitmap on position x,y
Wimpie 0:6468a28a7b7d 171 * with size xsize,ysize
Wimpie 0:6468a28a7b7d 172 */
Wimpie 1:ce391193b822 173 void drawBitmap (BYTE x0, BYTE y0, const unsigned char* bitmap, BYTE bmpXSize, BYTE bmpYSize, BYTE update);
Wimpie 0:6468a28a7b7d 174
Wimpie 0:6468a28a7b7d 175 void drawpixel (BYTE x0, BYTE y0, ePixelMode pmode, BYTE update);
Wimpie 0:6468a28a7b7d 176 void drawline (BYTE x0, BYTE y0, BYTE x1,BYTE y1, ePixelMode pmode, BYTE update);
Wimpie 0:6468a28a7b7d 177 void drawcircle (BYTE x0, BYTE y0, BYTE radius, ePixelMode pmode, BYTE update);
Wimpie 0:6468a28a7b7d 178 void drawrectangle (BYTE x0, BYTE y0, BYTE x1,BYTE y1, eFillMode fill, ePixelMode pmode, BYTE update);
Wimpie 0:6468a28a7b7d 179 void drawprogressbar(BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE percentage, BYTE update);
Wimpie 0:6468a28a7b7d 180 void drawchart (BYTE x0, BYTE y0, BYTE w, BYTE h, BYTE unitx, BYTE unity,
Wimpie 1:ce391193b822 181 eRasterMode rMode, eChartMode cMode, eDrawMode dMode,int16_t * val, int size, int t);
Wimpie 0:6468a28a7b7d 182
Wimpie 0:6468a28a7b7d 183 private:
Wimpie 0:6468a28a7b7d 184
Wimpie 0:6468a28a7b7d 185 SPI _spi;
Wimpie 0:6468a28a7b7d 186 DigitalOut _cs; // chip select
Wimpie 0:6468a28a7b7d 187 DigitalOut _dc; // data / command
Wimpie 0:6468a28a7b7d 188 DigitalOut _reset; // reset
Wimpie 0:6468a28a7b7d 189
Wimpie 0:6468a28a7b7d 190 void writeCmd(BYTE data);
Wimpie 0:6468a28a7b7d 191 void writeData(BYTE data);
Wimpie 0:6468a28a7b7d 192
Wimpie 1:ce391193b822 193 BYTE LcdCache[LCD_CACHE_SIZE]; // __attribute__((section("AHBSRAM0")));
Wimpie 0:6468a28a7b7d 194
Wimpie 1:ce391193b822 195 int LcdCacheIdx;
Wimpie 0:6468a28a7b7d 196 int _LoMark;
Wimpie 0:6468a28a7b7d 197 int _HiMark;
Wimpie 1:ce391193b822 198 int Scale;
Wimpie 0:6468a28a7b7d 199
Wimpie 0:6468a28a7b7d 200 BYTE _font_width;
Wimpie 0:6468a28a7b7d 201 BYTE _font_height;
Wimpie 0:6468a28a7b7d 202 BYTE _font_start;
Wimpie 0:6468a28a7b7d 203 BYTE _font_end;
Wimpie 0:6468a28a7b7d 204 unsigned char* _pFont;
Wimpie 0:6468a28a7b7d 205
Wimpie 0:6468a28a7b7d 206 };
Wimpie 0:6468a28a7b7d 207
Wimpie 0:6468a28a7b7d 208 #endif