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:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Committer:
dreschpe
Date:
Sun Oct 18 13:53:20 2015 +0000
Revision:
25:daacdcf34e52
Parent:
21:ae0a4eedfc90
Child:
27:acb2594b8aa4
Add check if platform supports par port mode

Who changed what in which revision?

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