TFT 1.44

Dependencies:   mbed

Fork of DL144128_LCD by Jun Morita

Committer:
rs27
Date:
Sat Feb 28 20:26:45 2015 +0000
Revision:
1:b64c81071d96
Parent:
0:c0be4e018a09
TFT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morita 0:c0be4e018a09 1 /**
morita 0:c0be4e018a09 2 * @file ili9163lcd.h
morita 0:c0be4e018a09 3 * @brief ILI9163 128x128 LCD Driver (Header file)
morita 0:c0be4e018a09 4 *
morita 0:c0be4e018a09 5 * This code has been ported from the ili9163lcd library for mbed
morita 0:c0be4e018a09 6 * made by Jun Morita.
morita 0:c0be4e018a09 7 * Source form <http://files.noccylabs.info/lib430/liblcd/ili9163lcd_8c.html>
morita 0:c0be4e018a09 8 *
morita 0:c0be4e018a09 9 * This code has been ported from the ili9163lcd library for avr made
morita 0:c0be4e018a09 10 * by Simon Inns, to run on a msp430.
morita 0:c0be4e018a09 11 *
morita 0:c0be4e018a09 12 * This program is free software: you can redistribute it and/or modify
morita 0:c0be4e018a09 13 * it under the terms of the GNU General Public License as published by
morita 0:c0be4e018a09 14 * the Free Software Foundation, either version 3 of the License, or
morita 0:c0be4e018a09 15 * (at your option) any later version.
morita 0:c0be4e018a09 16 *
morita 0:c0be4e018a09 17 * This program is distributed in the hope that it will be useful,
morita 0:c0be4e018a09 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
morita 0:c0be4e018a09 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
morita 0:c0be4e018a09 20 * GNU General Public License for more details.
morita 0:c0be4e018a09 21 *
morita 0:c0be4e018a09 22 * You should have received a copy of the GNU General Public License
morita 0:c0be4e018a09 23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
morita 0:c0be4e018a09 24 *
morita 0:c0be4e018a09 25 * @author Jun Morita (iccraft)
morita 0:c0be4e018a09 26 * @author Simon Inns <simon.inns@gmail.com>
morita 0:c0be4e018a09 27 * @author Christopher Vagnetoft (NoccyLabs)
morita 0:c0be4e018a09 28 * @copyright (C) 2012 Simon Inns
morita 0:c0be4e018a09 29 * @copyright parts (C) 2012 NoccyLabs
morita 0:c0be4e018a09 30 */
morita 0:c0be4e018a09 31
morita 0:c0be4e018a09 32 #ifndef ILI9163LCD_H_
morita 0:c0be4e018a09 33 #define ILI9163LCD_H_
morita 0:c0be4e018a09 34
rs27 1:b64c81071d96 35 #include "mbed.h"
rs27 1:b64c81071d96 36 #include "font5x8.h"
rs27 1:b64c81071d96 37 #include "font8x8.h"
rs27 1:b64c81071d96 38 #include "font5x12.h"
rs27 1:b64c81071d96 39 #include "font11x16.h"
rs27 1:b64c81071d96 40 #include "font12x12.h"
rs27 1:b64c81071d96 41 #include "font24x23.h"
rs27 1:b64c81071d96 42
morita 0:c0be4e018a09 43 // Definitions for control lines (port C)
morita 0:c0be4e018a09 44 #define LCD_WR (1 << 2)
morita 0:c0be4e018a09 45 #define LCD_RS (1 << 4)
morita 0:c0be4e018a09 46 #define LCD_RD (1 << 5)
morita 0:c0be4e018a09 47 #define LCD_CS (1 << 6)
morita 0:c0be4e018a09 48 #define LCD_RESET (1 << 7)
morita 0:c0be4e018a09 49
morita 0:c0be4e018a09 50 // Screen orientation defines:
morita 0:c0be4e018a09 51 // 0 = Ribbon at top
morita 0:c0be4e018a09 52 // 1 = Ribbon at left
morita 0:c0be4e018a09 53 // 2 = Ribbon at right
morita 0:c0be4e018a09 54 // 3 = Ribbon at bottom
morita 0:c0be4e018a09 55 #define LCD_ORIENTATION0 0
morita 0:c0be4e018a09 56 #define LCD_ORIENTATION1 96
morita 0:c0be4e018a09 57 #define LCD_ORIENTATION2 160
morita 0:c0be4e018a09 58 #define LCD_ORIENTATION3 192
morita 0:c0be4e018a09 59
rs27 1:b64c81071d96 60 // eine Farbe belegt 5 Bit,
rs27 1:b64c81071d96 61 // die Farbe Grün wird 6 bit nch links geshiftet
rs27 1:b64c81071d96 62 // die Farbe Blau wird 11 bit nach links geshiftet
rs27 1:b64c81071d96 63 // some RGB color definitions BLUE GREEN RED
rs27 1:b64c81071d96 64 #define Black 0x0000 /* 0, 0, 0 */
rs27 1:b64c81071d96 65 #define Navy 0x000F /* 0, 0,15 */
rs27 1:b64c81071d96 66 #define DarkGreen 0x03C0 /* 0,15, 0 */
rs27 1:b64c81071d96 67 #define DarkCyan 0x03EF /* 0, 128, 128 */
rs27 1:b64c81071d96 68 #define Maroon 0x7800 /* 15, 0, 0 */
rs27 1:b64c81071d96 69 #define Purple 0x780F /* 128, 0, 128 */
rs27 1:b64c81071d96 70 #define Olive 0x7BE0 /* 128, 128, 0 */
rs27 1:b64c81071d96 71 #define LightGrey 0xC618 /* 192, 192, 192 */
rs27 1:b64c81071d96 72 #define DarkGrey 0x7BEF /* 128, 128, 128 */
rs27 1:b64c81071d96 73 #define Red 0x001F /* 0, 0,31 */
rs27 1:b64c81071d96 74 #define Green 0x07C0 /* 0,31, 0 */
rs27 1:b64c81071d96 75 #define Cyan 0x07DF /* 0,31,31 */
rs27 1:b64c81071d96 76 #define Blue 0xF800 /* 31, 0, 0 */
rs27 1:b64c81071d96 77 #define Yellow 0xF81F /* 31, 0,31 */
rs27 1:b64c81071d96 78 #define Magenta 0xFFC0 /* 31,31, 0 */
rs27 1:b64c81071d96 79 #define White 0xFFFF /* 31,31,31 */
rs27 1:b64c81071d96 80 #define Orange 0xFD20 /* 255, 165, 0 */
rs27 1:b64c81071d96 81 #define GreenYellow 0xAFE5 /* 173, 255, 47 */
rs27 1:b64c81071d96 82 #define LightBlue 0x04FF
rs27 1:b64c81071d96 83
morita 0:c0be4e018a09 84 // ILI9163 LCD Controller Commands
morita 0:c0be4e018a09 85 #define NOP 0x00
morita 0:c0be4e018a09 86 #define SOFT_RESET 0x01
morita 0:c0be4e018a09 87 #define GET_RED_CHANNEL 0x06
morita 0:c0be4e018a09 88 #define GET_GREEN_CHANNEL 0x07
morita 0:c0be4e018a09 89 #define GET_BLUE_CHANNEL 0x08
morita 0:c0be4e018a09 90 #define GET_PIXEL_FORMAT 0x0C
morita 0:c0be4e018a09 91 #define GET_POWER_MODE 0x0A
morita 0:c0be4e018a09 92 #define GET_ADDRESS_MODE 0x0B
morita 0:c0be4e018a09 93 #define GET_DISPLAY_MODE 0x0D
morita 0:c0be4e018a09 94 #define GET_SIGNAL_MODE 0x0E
morita 0:c0be4e018a09 95 #define GET_DIAGNOSTIC_RESULT 0x0F
morita 0:c0be4e018a09 96 #define ENTER_SLEEP_MODE 0x10
morita 0:c0be4e018a09 97 #define EXIT_SLEEP_MODE 0x11
morita 0:c0be4e018a09 98 #define ENTER_PARTIAL_MODE 0x12
morita 0:c0be4e018a09 99 #define ENTER_NORMAL_MODE 0x13
morita 0:c0be4e018a09 100 #define EXIT_INVERT_MODE 0x20
morita 0:c0be4e018a09 101 #define ENTER_INVERT_MODE 0x21
morita 0:c0be4e018a09 102 #define SET_GAMMA_CURVE 0x26
morita 0:c0be4e018a09 103 #define SET_DISPLAY_OFF 0x28
morita 0:c0be4e018a09 104 #define SET_DISPLAY_ON 0x29
morita 0:c0be4e018a09 105 #define SET_COLUMN_ADDRESS 0x2A
morita 0:c0be4e018a09 106 #define SET_PAGE_ADDRESS 0x2B
morita 0:c0be4e018a09 107 #define WRITE_MEMORY_START 0x2C
morita 0:c0be4e018a09 108 #define WRITE_LUT 0x2D
morita 0:c0be4e018a09 109 #define READ_MEMORY_START 0x2E
morita 0:c0be4e018a09 110 #define SET_PARTIAL_AREA 0x30
morita 0:c0be4e018a09 111 #define SET_SCROLL_AREA 0x33
morita 0:c0be4e018a09 112 #define SET_TEAR_OFF 0x34
morita 0:c0be4e018a09 113 #define SET_TEAR_ON 0x35
morita 0:c0be4e018a09 114 #define SET_ADDRESS_MODE 0x36
morita 0:c0be4e018a09 115 #define SET_SCROLL_START 0X37
morita 0:c0be4e018a09 116 #define EXIT_IDLE_MODE 0x38
morita 0:c0be4e018a09 117 #define ENTER_IDLE_MODE 0x39
morita 0:c0be4e018a09 118 #define SET_PIXEL_FORMAT 0x3A
morita 0:c0be4e018a09 119 #define WRITE_MEMORY_CONTINUE 0x3C
morita 0:c0be4e018a09 120 #define READ_MEMORY_CONTINUE 0x3E
morita 0:c0be4e018a09 121 #define SET_TEAR_SCANLINE 0x44
morita 0:c0be4e018a09 122 #define GET_SCANLINE 0x45
morita 0:c0be4e018a09 123 #define READ_ID1 0xDA
morita 0:c0be4e018a09 124 #define READ_ID2 0xDB
morita 0:c0be4e018a09 125 #define READ_ID3 0xDC
morita 0:c0be4e018a09 126 #define FRAME_RATE_CONTROL1 0xB1
morita 0:c0be4e018a09 127 #define FRAME_RATE_CONTROL2 0xB2
morita 0:c0be4e018a09 128 #define FRAME_RATE_CONTROL3 0xB3
morita 0:c0be4e018a09 129 #define DISPLAY_INVERSION 0xB4
morita 0:c0be4e018a09 130 #define SOURCE_DRIVER_DIRECTION 0xB7
morita 0:c0be4e018a09 131 #define GATE_DRIVER_DIRECTION 0xB8
morita 0:c0be4e018a09 132 #define POWER_CONTROL1 0xC0
morita 0:c0be4e018a09 133 #define POWER_CONTROL2 0xC1
morita 0:c0be4e018a09 134 #define POWER_CONTROL3 0xC2
morita 0:c0be4e018a09 135 #define POWER_CONTROL4 0xC3
morita 0:c0be4e018a09 136 #define POWER_CONTROL5 0xC4
morita 0:c0be4e018a09 137 #define VCOM_CONTROL1 0xC5
morita 0:c0be4e018a09 138 #define VCOM_CONTROL2 0xC6
morita 0:c0be4e018a09 139 #define VCOM_OFFSET_CONTROL 0xC7
morita 0:c0be4e018a09 140 #define WRITE_ID4_VALUE 0xD3
morita 0:c0be4e018a09 141 #define NV_MEMORY_FUNCTION1 0xD7
morita 0:c0be4e018a09 142 #define NV_MEMORY_FUNCTION2 0xDE
morita 0:c0be4e018a09 143 #define POSITIVE_GAMMA_CORRECT 0xE0
morita 0:c0be4e018a09 144 #define NEGATIVE_GAMMA_CORRECT 0xE1
morita 0:c0be4e018a09 145 #define GAM_R_SEL 0xF2
morita 0:c0be4e018a09 146
rs27 1:b64c81071d96 147
rs27 1:b64c81071d96 148 class ILI9163 {
rs27 1:b64c81071d96 149 public:
rs27 1:b64c81071d96 150
rs27 1:b64c81071d96 151 // Das ILI9163 Objekt anlegen
rs27 1:b64c81071d96 152 //
rs27 1:b64c81071d96 153 // @param D2 SCK_
rs27 1:b64c81071d96 154 // @param D3 SDA
rs27 1:b64c81071d96 155 // @param D4 A0_
rs27 1:b64c81071d96 156 // @param D5 RESET pin connected to RESET of display
rs27 1:b64c81071d96 157 // @param D6 CS cs pin connected to CS of display
rs27 1:b64c81071d96 158 //
rs27 1:b64c81071d96 159 // ILI9163 tft(D2,D3,D4,D5,D6);
rs27 1:b64c81071d96 160 //
rs27 1:b64c81071d96 161 ILI9163(PinName SCK, PinName SDA, PinName A0, PinName RESET, PinName CS);
morita 0:c0be4e018a09 162
rs27 1:b64c81071d96 163 DigitalOut SCK_;
rs27 1:b64c81071d96 164 DigitalOut SDA_;
rs27 1:b64c81071d96 165 DigitalOut A0_;
rs27 1:b64c81071d96 166 DigitalOut RESET_;
rs27 1:b64c81071d96 167 DigitalOut CS_;
rs27 1:b64c81071d96 168
rs27 1:b64c81071d96 169 uint8_t tm;
rs27 1:b64c81071d96 170 uint8_t R,G,B;
rs27 1:b64c81071d96 171 uint8_t RGB_state;
rs27 1:b64c81071d96 172
rs27 1:b64c81071d96 173 // font Array
rs27 1:b64c81071d96 174 unsigned char* font;
rs27 1:b64c81071d96 175 uint8_t font_bp_char; // Bytes pro Zeichen
rs27 1:b64c81071d96 176 uint8_t font_hor; // Bytes Horizontal
rs27 1:b64c81071d96 177 uint8_t font_vert; // Bytes Vertikal
rs27 1:b64c81071d96 178 uint8_t font_bp_line; // Bytes pro Zeile
rs27 1:b64c81071d96 179 uint8_t font_size; // Vergrößerung des Zeichens
rs27 1:b64c81071d96 180 // Macros and in-lines:
rs27 1:b64c81071d96 181
rs27 1:b64c81071d96 182 // Translates a 3 byte RGB value into a 2 byte value for the LCD (values should be 0-31)
rs27 1:b64c81071d96 183 inline uint16_t decodeRgbValue(uint8_t r, uint8_t g, uint8_t b)
rs27 1:b64c81071d96 184 {
morita 0:c0be4e018a09 185 return (b << 11) | (g << 6) | (r);
rs27 1:b64c81071d96 186 }
morita 0:c0be4e018a09 187
rs27 1:b64c81071d96 188 // This routine takes a row number from 0 to 20 and
rs27 1:b64c81071d96 189 // returns the x coordinate on the screen (0-127) to make
rs27 1:b64c81071d96 190 // it easy to place text
rs27 1:b64c81071d96 191 inline uint8_t lcdTextX(uint8_t x) { return x*font_vert; }
rs27 1:b64c81071d96 192
rs27 1:b64c81071d96 193 // This routine takes a column number from 0 to 20 and
rs27 1:b64c81071d96 194 // returns the y coordinate on the screen (0-127) to make
rs27 1:b64c81071d96 195 // it easy to place text
rs27 1:b64c81071d96 196 inline uint8_t lcdTextY(uint8_t y) { return y*font_hor; }
rs27 1:b64c81071d96 197
rs27 1:b64c81071d96 198 // LCD function prototypes
rs27 1:b64c81071d96 199 void lcdReset(void);
rs27 1:b64c81071d96 200 void lcdWriteCommand(uint8_t address);
rs27 1:b64c81071d96 201 void lcdWriteParameter(uint8_t parameter);
rs27 1:b64c81071d96 202 void lcdWriteData(uint8_t dataByte1, uint8_t dataByte2);
rs27 1:b64c81071d96 203 void lcdInitialise(uint8_t orientation);
morita 0:c0be4e018a09 204
rs27 1:b64c81071d96 205 void lcdClearDisplay(uint16_t colour);
rs27 1:b64c81071d96 206 void lcdPlot(uint8_t x, uint8_t y, uint16_t colour);
rs27 1:b64c81071d96 207 void lcdLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
rs27 1:b64c81071d96 208 void lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
rs27 1:b64c81071d96 209 void lcdFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour);
rs27 1:b64c81071d96 210 void lcdCircle(int16_t xCentre, int16_t yCentre, int16_t radius, uint16_t colour);
morita 0:c0be4e018a09 211
rs27 1:b64c81071d96 212 // select the font to use
rs27 1:b64c81071d96 213 //
rs27 1:b64c81071d96 214 // @param f pointer to font array
rs27 1:b64c81071d96 215 //
rs27 1:b64c81071d96 216 // font array can created with GLCD Font Creator from http://www.mikroe.com
rs27 1:b64c81071d96 217 // you have to add 4 parameter at the beginning of the font array to use:
rs27 1:b64c81071d96 218 // - the number of byte / char
rs27 1:b64c81071d96 219 // - the vertial size in pixel
rs27 1:b64c81071d96 220 // - the horizontal size in pixel
rs27 1:b64c81071d96 221 // - the number of byte per vertical line
rs27 1:b64c81071d96 222 // you also have to change the array to char[]
rs27 1:b64c81071d96 223 //
rs27 1:b64c81071d96 224 void set_font(unsigned char* f);
rs27 1:b64c81071d96 225
rs27 1:b64c81071d96 226 void lcdPutCh(unsigned char character, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour);
rs27 1:b64c81071d96 227 void lcdPutS(const char *string, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour);
morita 0:c0be4e018a09 228
rs27 1:b64c81071d96 229 }; // end class
morita 0:c0be4e018a09 230
morita 0:c0be4e018a09 231 #endif /* ILI9163LCD_H_ */