.

Committer:
dreschpe
Date:
Mon Oct 26 12:49:02 2015 +0000
Revision:
27:acb2594b8aa4
Parent:
25:daacdcf34e52
Child:
30:87855d03d91a
fix handling of PAR8 / PAR16 includes

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