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