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.

Dependents:   Brew

Committer:
Geremia
Date:
Tue Mar 31 21:14:48 2015 +0000
Revision:
21:ae0a4eedfc90
Parent:
20:14daa48ffd4c
Child:
25:daacdcf34e52
Add BUS_8 and BUS_16 (slow as expected)

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