.

Committer:
Geremia
Date:
Mon Mar 23 14:08:04 2015 +0000
Revision:
20:14daa48ffd4c
Child:
21:ae0a4eedfc90
Add  ILI 9320/9325/9328 custom TFT932x class, parallel/spi 8/16bit, with orientation, scroll, pixelread, fastwindow.; Par8 and 16 tested, SPI not at all, needs checking if the CS toggle is necessary (see SPI8.cpp SPI16.cpp).

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