Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Fork of UniGraphic by GraphicsDisplay

Committer:
Geremia
Date:
Tue Feb 17 11:02:06 2015 +0000
Revision:
7:bb0383b91104
Parent:
6:8356d48a07db
Child:
8:26757296c79d
TFT: added get deviceID, scroll functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 2:713844a55c4e 1 #ifndef MBED_TFT_H
Geremia 2:713844a55c4e 2 #define MBED_TFT_H
Geremia 2:713844a55c4e 3
Geremia 2:713844a55c4e 4 #include "GraphicsDisplay.h"
Geremia 2:713844a55c4e 5 #include "PAR8.h"
Geremia 4:12ba0ecc2c1f 6 #include "PAR16.h"
Geremia 2:713844a55c4e 7 #include "SPI8.h"
Geremia 2:713844a55c4e 8 #include "SPI16.h"
Geremia 2:713844a55c4e 9 #include "Protocols.h"
Geremia 2:713844a55c4e 10
Geremia 2:713844a55c4e 11
Geremia 6:8356d48a07db 12 /** A common base class for color TFT Display
Geremia 2:713844a55c4e 13 */
Geremia 2:713844a55c4e 14 class TFT : public GraphicsDisplay
Geremia 2:713844a55c4e 15 {
Geremia 2:713844a55c4e 16
Geremia 2:713844a55c4e 17 public:
Geremia 2:713844a55c4e 18
Geremia 2:713844a55c4e 19 /** Create a monochrome LCD Parallel interface
Geremia 2:713844a55c4e 20 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 21 */
Geremia 2:713844a55c4e 22 TFT(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char* name);
Geremia 2:713844a55c4e 23
Geremia 2:713844a55c4e 24 /** Create a monochrome LCD SPI interface
Geremia 2:713844a55c4e 25 * @param name The name used by the parent class to access the interface
Geremia 2:713844a55c4e 26 */
Geremia 2:713844a55c4e 27 TFT(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const char* name);
Geremia 2:713844a55c4e 28
Geremia 2:713844a55c4e 29 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 2:713844a55c4e 30 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 2:713844a55c4e 31
Geremia 2:713844a55c4e 32 /** Draw a pixel in the specified color.
Geremia 2:713844a55c4e 33 * @param x is the horizontal offset to this pixel.
Geremia 2:713844a55c4e 34 * @param y is the vertical offset to this pixel.
Geremia 2:713844a55c4e 35 * @param color defines the color for the pixel.
Geremia 2:713844a55c4e 36 */
Geremia 2:713844a55c4e 37 virtual void pixel(int x, int y, unsigned short color);
Geremia 2:713844a55c4e 38
Geremia 2:713844a55c4e 39 /** Set the window, which controls where items are written to the screen.
Geremia 2:713844a55c4e 40 * When something hits the window width, it wraps back to the left side
Geremia 2:713844a55c4e 41 * and down a row. If the initial write is outside the window, it will
Geremia 2:713844a55c4e 42 * be captured into the window when it crosses a boundary.
Geremia 2:713844a55c4e 43 * @param x is the left edge in pixels.
Geremia 2:713844a55c4e 44 * @param y is the top edge in pixels.
Geremia 2:713844a55c4e 45 * @param w is the window width in pixels.
Geremia 2:713844a55c4e 46 * @param h is the window height in pixels.
Geremia 2:713844a55c4e 47 */
Geremia 2:713844a55c4e 48 virtual void window(int x, int y, int w, int h);
Geremia 5:b222a9461d6b 49
Geremia 5:b222a9461d6b 50 /** Read pixel color at current location
Geremia 5:b222a9461d6b 51 * @param x is the horizontal offset to this pixel.
Geremia 5:b222a9461d6b 52 * @param y is the vertical offset to this pixel.
Geremia 5:b222a9461d6b 53 * @param color defines the color for the pixel.
Geremia 5:b222a9461d6b 54 */
Geremia 5:b222a9461d6b 55 virtual unsigned short pixelread(int x, int y);
Geremia 5:b222a9461d6b 56
Geremia 5:b222a9461d6b 57 /** Set the window from which gram is read from. Autoincrements row/column
Geremia 5:b222a9461d6b 58 * @param x is the left edge in pixels.
Geremia 5:b222a9461d6b 59 * @param y is the top edge in pixels.
Geremia 5:b222a9461d6b 60 * @param w is the window width in pixels.
Geremia 5:b222a9461d6b 61 * @param h is the window height in pixels.
Geremia 5:b222a9461d6b 62 */
Geremia 5:b222a9461d6b 63 virtual void window4read(int x, int y, int w, int h);
Geremia 2:713844a55c4e 64
Geremia 2:713844a55c4e 65 /** Push a single pixel into the window and increment position.
Geremia 2:713844a55c4e 66 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 67 * @param color is the pixel color.
Geremia 2:713844a55c4e 68 */
Geremia 2:713844a55c4e 69 virtual void window_pushpixel(unsigned short color);
Geremia 2:713844a55c4e 70
Geremia 2:713844a55c4e 71 /** Push some pixels of the same color into the window and increment position.
Geremia 2:713844a55c4e 72 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 73 * @param color is the pixel color.
Geremia 2:713844a55c4e 74 * @param count: how many
Geremia 2:713844a55c4e 75 */
Geremia 2:713844a55c4e 76 virtual void window_pushpixel(unsigned short color, unsigned int count);
Geremia 2:713844a55c4e 77
Geremia 2:713844a55c4e 78 /** Push array of pixel colors into the window and increment position.
Geremia 2:713844a55c4e 79 * You must first call window() then push pixels.
Geremia 2:713844a55c4e 80 * @param color is the pixel color.
Geremia 2:713844a55c4e 81 */
Geremia 2:713844a55c4e 82 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
Geremia 2:713844a55c4e 83
Geremia 2:713844a55c4e 84 /** Framebuffer is not used for TFT
Geremia 2:713844a55c4e 85 */
Geremia 2:713844a55c4e 86 virtual void copy_to_lcd(){ };
Geremia 2:713844a55c4e 87
Geremia 7:bb0383b91104 88 /** display inverted colors
Geremia 2:713844a55c4e 89 *
Geremia 2:713844a55c4e 90 * @param o = 0 normal, 1 invert
Geremia 2:713844a55c4e 91 */
Geremia 2:713844a55c4e 92 void invert(unsigned char o);
Geremia 2:713844a55c4e 93
Geremia 2:713844a55c4e 94 /** clear the entire screen
Geremia 2:713844a55c4e 95 * The inherited one sets windomax then fill with background color
Geremia 2:713844a55c4e 96 * We override it to speedup
Geremia 2:713844a55c4e 97 */
Geremia 2:713844a55c4e 98 virtual void cls();
Geremia 2:713844a55c4e 99
Geremia 2:713844a55c4e 100 /** Set the orientation of the screen
Geremia 2:713844a55c4e 101 * x,y: 0,0 is always top left
Geremia 2:713844a55c4e 102 *
Geremia 2:713844a55c4e 103 * @param o direction to use the screen (0-3)
Geremia 2:713844a55c4e 104 * 0 = default 0° portrait view
Geremia 2:713844a55c4e 105 * 1 = +90° landscape view
Geremia 2:713844a55c4e 106 * 2 = +180° portrait view
Geremia 2:713844a55c4e 107 * 3 = -90° landscape view
Geremia 2:713844a55c4e 108 *
Geremia 2:713844a55c4e 109 */
Geremia 2:713844a55c4e 110 virtual void set_orientation(int o);
Geremia 2:713844a55c4e 111
Geremia 2:713844a55c4e 112 /** Set ChipSelect high or low
Geremia 2:713844a55c4e 113 * @param enable 0/1
Geremia 2:713844a55c4e 114 */
Geremia 2:713844a55c4e 115 virtual void BusEnable(bool enable);
Geremia 2:713844a55c4e 116
Geremia 7:bb0383b91104 117 /** Set scroll area boundaries
Geremia 7:bb0383b91104 118 * scroll is done in hw but only on the native vertical axis
Geremia 7:bb0383b91104 119 * TFTs are mainly native protrait view, so horizontal scroll if rotated in landscape view
Geremia 7:bb0383b91104 120 *
Geremia 7:bb0383b91104 121 * @param startY boundary offset from top (or left if rotated), 0 for fullscreen scroll
Geremia 7:bb0383b91104 122 * @param areasize size of the scroll area, 480 for fullscreen scroll of a 320x480 display
Geremia 7:bb0383b91104 123 */
Geremia 7:bb0383b91104 124 void setscrollarea (int startY, int areasize);
Geremia 7:bb0383b91104 125
Geremia 7:bb0383b91104 126 /** Scroll up(or left) the scrollarea
Geremia 7:bb0383b91104 127 *
Geremia 7:bb0383b91104 128 * @param lines number of lines to scroll, 1= scrollup 1, areasize-1= scrolldown 1
Geremia 7:bb0383b91104 129 */
Geremia 7:bb0383b91104 130 void scroll (int lines);
Geremia 7:bb0383b91104 131
Geremia 7:bb0383b91104 132 /** Reset the scrollarea and display un-scrolled screen
Geremia 7:bb0383b91104 133 *
Geremia 7:bb0383b91104 134 */
Geremia 7:bb0383b91104 135 void scrollreset();
Geremia 7:bb0383b91104 136
Geremia 7:bb0383b91104 137 /** get display X size in pixels (native, orientation independent)
Geremia 7:bb0383b91104 138 * @returns X size in pixels
Geremia 7:bb0383b91104 139 */
Geremia 7:bb0383b91104 140 int sizeX();
Geremia 7:bb0383b91104 141
Geremia 7:bb0383b91104 142 /** get display X size in pixels (native, orientation independent)
Geremia 7:bb0383b91104 143 * @returns screen height in pixels.
Geremia 7:bb0383b91104 144 */
Geremia 7:bb0383b91104 145 int sizeY();
Geremia 7:bb0383b91104 146
Geremia 7:bb0383b91104 147 unsigned int tftID;
Geremia 7:bb0383b91104 148
Geremia 7:bb0383b91104 149
Geremia 7:bb0383b91104 150
Geremia 2:713844a55c4e 151
Geremia 2:713844a55c4e 152 protected:
Geremia 2:713844a55c4e 153
Geremia 2:713844a55c4e 154
Geremia 2:713844a55c4e 155 ////// functions needed by parent class ///////////////////////////////////////
Geremia 2:713844a55c4e 156 ////// -------------------------------- ///////////////////////////////////////
Geremia 2:713844a55c4e 157
Geremia 2:713844a55c4e 158 /** Send 8bit command to display controller
Geremia 2:713844a55c4e 159 *
Geremia 2:713844a55c4e 160 * @param cmd: byte to send
Geremia 2:713844a55c4e 161 * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds
Geremia 2:713844a55c4e 162 */
Geremia 2:713844a55c4e 163 void wr_cmd8(unsigned char cmd);
Geremia 2:713844a55c4e 164
Geremia 2:713844a55c4e 165 /** Send 8bit data to display controller
Geremia 2:713844a55c4e 166 *
Geremia 2:713844a55c4e 167 * @param data: byte to send
Geremia 2:713844a55c4e 168 *
Geremia 2:713844a55c4e 169 */
Geremia 2:713844a55c4e 170 void wr_data8(unsigned char data);
Geremia 2:713844a55c4e 171
Geremia 4:12ba0ecc2c1f 172 /** Send 2x8bit data to display controller
Geremia 2:713844a55c4e 173 *
Geremia 2:713844a55c4e 174 * @param data: halfword to send
Geremia 2:713844a55c4e 175 *
Geremia 2:713844a55c4e 176 */
Geremia 2:713844a55c4e 177 void wr_data16(unsigned short data);
Geremia 2:713844a55c4e 178
Geremia 4:12ba0ecc2c1f 179 /** Send 16bit pixeldata to display controller
Geremia 4:12ba0ecc2c1f 180 *
Geremia 4:12ba0ecc2c1f 181 * @param data: halfword to send
Geremia 4:12ba0ecc2c1f 182 *
Geremia 4:12ba0ecc2c1f 183 */
Geremia 4:12ba0ecc2c1f 184 virtual void wr_gram(unsigned short data);
Geremia 4:12ba0ecc2c1f 185
Geremia 4:12ba0ecc2c1f 186 /** Send same 16bit pixeldata to display controller multiple times
Geremia 2:713844a55c4e 187 *
Geremia 2:713844a55c4e 188 * @param data: halfword to send
Geremia 2:713844a55c4e 189 * @param count: how many
Geremia 2:713844a55c4e 190 *
Geremia 2:713844a55c4e 191 */
Geremia 4:12ba0ecc2c1f 192 virtual void wr_gram(unsigned short data, unsigned int count);
Geremia 2:713844a55c4e 193
Geremia 4:12ba0ecc2c1f 194 /** Send array of pixeldata shorts to display controller
Geremia 2:713844a55c4e 195 *
Geremia 4:12ba0ecc2c1f 196 * @param data: unsigned short pixeldata array
Geremia 2:713844a55c4e 197 * @param lenght: lenght (in shorts)
Geremia 2:713844a55c4e 198 *
Geremia 2:713844a55c4e 199 */
Geremia 4:12ba0ecc2c1f 200 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
Geremia 2:713844a55c4e 201
Geremia 5:b222a9461d6b 202 /** Read 16bit pixeldata from display controller (with dummy cycle)
Geremia 5:b222a9461d6b 203 *
Geremia 5:b222a9461d6b 204 * @returns 16bit color
Geremia 5:b222a9461d6b 205 */
Geremia 5:b222a9461d6b 206 virtual unsigned short rd_gram();
Geremia 5:b222a9461d6b 207
Geremia 7:bb0383b91104 208 /** Read 4x8bit register data (with dummy cycle)
Geremia 7:bb0383b91104 209 * @param reg the register to read
Geremia 7:bb0383b91104 210 * @returns data as uint
Geremia 7:bb0383b91104 211 *
Geremia 7:bb0383b91104 212 */
Geremia 7:bb0383b91104 213 virtual unsigned int rd_reg_data32(unsigned char reg);
Geremia 7:bb0383b91104 214
Geremia 7:bb0383b91104 215 /** Read 3x8bit ExtendedCommands register data
Geremia 7:bb0383b91104 216 * @param reg the register to read
Geremia 7:bb0383b91104 217 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
Geremia 7:bb0383b91104 218 * @returns data as uint
Geremia 7:bb0383b91104 219 * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode
Geremia 7:bb0383b91104 220 */
Geremia 7:bb0383b91104 221 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
Geremia 7:bb0383b91104 222
Geremia 2:713844a55c4e 223 /** HW reset sequence (without display init commands)
Geremia 2:713844a55c4e 224 */
Geremia 2:713844a55c4e 225 void hw_reset();
Geremia 4:12ba0ecc2c1f 226
Geremia 7:bb0383b91104 227 /** Try to identify display ID
Geremia 7:bb0383b91104 228 * @note support ILI9341,94xx, MIPI standard. May be be overridden in Init class for other specific IC
Geremia 7:bb0383b91104 229 */
Geremia 7:bb0383b91104 230 virtual void identify();
Geremia 7:bb0383b91104 231
Geremia 4:12ba0ecc2c1f 232 unsigned int scrollbugfix;
Geremia 4:12ba0ecc2c1f 233 bool mipistd;
Geremia 2:713844a55c4e 234
Geremia 2:713844a55c4e 235 private:
Geremia 2:713844a55c4e 236
Geremia 2:713844a55c4e 237 Protocols* proto;
Geremia 7:bb0383b91104 238 const int screensize_X;
Geremia 7:bb0383b91104 239 const int screensize_Y;
Geremia 2:713844a55c4e 240 // pixel location
Geremia 2:713844a55c4e 241 int cur_x;
Geremia 2:713844a55c4e 242 int cur_y;
Geremia 2:713844a55c4e 243 // window location
Geremia 2:713844a55c4e 244 int win_x1;
Geremia 2:713844a55c4e 245 int win_x2;
Geremia 2:713844a55c4e 246 int win_y1;
Geremia 2:713844a55c4e 247 int win_y2;
Geremia 2:713844a55c4e 248 int orientation;
Geremia 7:bb0383b91104 249 int topfixedareasize;
Geremia 7:bb0383b91104 250 int scrollareasize;
Geremia 2:713844a55c4e 251 bool useNOP;
Geremia 2:713844a55c4e 252 };
Geremia 2:713844a55c4e 253
Geremia 2:713844a55c4e 254 #endif