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