Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TFT932x.h
00001 #ifndef MBED_TFT932x_H 00002 #define MBED_TFT932x_H 00003 00004 #if DEVICE_PORTINOUT 00005 #include "PAR8.h" 00006 #include "PAR16.h" 00007 #endif 00008 00009 #include "BUS8.h" 00010 #include "BUS16.h" 00011 #include "SPI8.h" 00012 #include "SPI16.h" 00013 #include "Protocols.h " 00014 00015 #include "GraphicsDisplay.h" 00016 00017 /** A custom base class for ILI932x color TFT Display (except ILI9327 which is MIPI standard) 00018 */ 00019 class TFT932x : public GraphicsDisplay 00020 { 00021 00022 public: 00023 00024 #if DEVICE_PORTINOUT 00025 /** Create TFT Parallel Port interface 00026 * @param name The name used by the parent class to access the interface 00027 */ 00028 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); 00029 #endif 00030 00031 /** Create TFT Parallel Bus interface 00032 * @param name The name used by the parent class to access the interface 00033 */ 00034 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); 00035 00036 /** Create TFT SPI interface 00037 * @note ILI9325D has different SPI protocol, not supported here 00038 * @param name The name used by the parent class to access the interface 00039 */ 00040 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); 00041 00042 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// 00043 /////// ----------------------------------------------------/////////////////////////////////////////////////// 00044 00045 /** Draw a pixel in the specified color. 00046 * @param x is the horizontal offset to this pixel. 00047 * @param y is the vertical offset to this pixel. 00048 * @param color defines the color for the pixel. 00049 */ 00050 virtual void pixel(int x, int y, unsigned short color); 00051 00052 /** Set the window, which controls where items are written to the screen. 00053 * When something hits the window width, it wraps back to the left side 00054 * and down a row. If the initial write is outside the window, it will 00055 * be captured into the window when it crosses a boundary. 00056 * @param x is the left edge in pixels. 00057 * @param y is the top edge in pixels. 00058 * @param w is the window width in pixels. 00059 * @param h is the window height in pixels. 00060 */ 00061 virtual void window(int x, int y, int w, int h); 00062 00063 /** Read pixel color at location 00064 * @param x is the horizontal offset to this pixel. 00065 * @param y is the vertical offset to this pixel. 00066 * @returns 16bit color. 00067 */ 00068 virtual unsigned short pixelread(int x, int y); 00069 00070 /** Set the window from which gram is read from. Autoincrements row/column 00071 * @param x is the left edge in pixels. 00072 * @param y is the top edge in pixels. 00073 * @param w is the window width in pixels. 00074 * @param h is the window height in pixels. 00075 */ 00076 virtual void window4read(int x, int y, int w, int h); 00077 00078 /** Push a single pixel into the window and increment position. 00079 * You must first call window() then push pixels. 00080 * @param color is the pixel color. 00081 */ 00082 virtual void window_pushpixel(unsigned short color); 00083 00084 /** Push some pixels of the same color into the window and increment position. 00085 * You must first call window() then push pixels. 00086 * @param color is the pixel color. 00087 * @param count: how many 00088 */ 00089 virtual void window_pushpixel(unsigned short color, unsigned int count); 00090 00091 /** Push array of pixel colors into the window and increment position. 00092 * You must first call window() then push pixels. 00093 * @param color is the pixel color. 00094 */ 00095 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght); 00096 00097 /** Framebuffer is not used for TFT 00098 */ 00099 virtual void copy_to_lcd(){ }; 00100 00101 /** display inverted colors 00102 * 00103 * @param o = 0 normal, 1 invert 00104 */ 00105 void invert(unsigned char o); 00106 00107 /** clear the entire screen 00108 * The inherited one sets windomax then fill with background color 00109 * We override it to speedup 00110 */ 00111 virtual void cls(); 00112 00113 /** Set the orientation of the screen 00114 * x,y: 0,0 is always top left 00115 * 00116 * @param o direction to use the screen (0-3) 00117 * 0 = default 0° portrait view 00118 * 1 = +90° landscape view 00119 * 2 = +180° portrait view 00120 * 3 = -90° landscape view 00121 * 00122 */ 00123 virtual void set_orientation(int o); 00124 00125 /** Set ChipSelect high or low 00126 * @param enable true/false 00127 */ 00128 virtual void BusEnable(bool enable); 00129 00130 /** Enable fast window (default disabled) 00131 * used to speedup functions that plots single pixels, like circle, oblique lines or just sparse pixels 00132 * @param enable true/false 00133 * @note most but not all controllers support this, even if datasheet tells they should 00134 */ 00135 void FastWindow(bool enable); 00136 00137 /** Enable scroll 00138 * scroll is done in hw but only on the native vertical axis 00139 * TFTs are mainly native protrait view, so horizontal scroll if rotated in landscape view 00140 * @note ILI932x does not allow partial screen scrolling, only full screen is selectable 00141 * @param startY unused, always 0 for ILI932x 00142 * @param areasize unused, always screensize_Y for ILI932x 00143 */ 00144 void setscrollarea (int startY=0, int areasize=0); 00145 00146 /** Scroll up(or left) the scrollarea 00147 * 00148 * @param lines number of lines to scroll, 1= scrollup 1, areasize-1= scrolldown 1 00149 */ 00150 void scroll (int lines); 00151 00152 /** Disable scroll and display un-scrolled screen 00153 * 00154 */ 00155 void scrollreset(); 00156 00157 /** get display X size in pixels (native, orientation independent) 00158 * @returns X size in pixels 00159 */ 00160 int sizeX(); 00161 00162 /** get display Y size in pixels (native, orientation independent) 00163 * @returns Y size in pixels 00164 */ 00165 int sizeY(); 00166 00167 unsigned int tftID; 00168 00169 00170 00171 00172 protected: 00173 00174 00175 ////// functions needed by parent class /////////////////////////////////////// 00176 ////// -------------------------------- /////////////////////////////////////// 00177 00178 /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 00179 * for PAR protocols: a signle RD bit toggle 00180 * for SPI8: 8clocks 00181 * for SPI16: 16 clocks 00182 */ 00183 virtual void dummyread (); 00184 00185 /** ILI932x specific, select register for a successive write or read 00186 * 00187 * @param reg register to be selected 00188 * @param forread false = a write next (default), true = a read next 00189 * @note forread only used by SPI protocols 00190 */ 00191 virtual void reg_select(unsigned char reg, bool forread =false); 00192 00193 /** ILI932x specific, write register with data 00194 * 00195 * @param reg register to write 00196 * @param data 16bit data 00197 */ 00198 virtual void reg_write(unsigned char reg, unsigned short data); 00199 00200 /** ILI932x specific, read register 00201 * 00202 * @param reg register to be read 00203 * @returns 16bit register value 00204 */ 00205 virtual unsigned short reg_read(unsigned char reg); 00206 00207 /** Send 16bit pixeldata to display controller 00208 * 00209 * @param data: halfword to send 00210 * 00211 */ 00212 virtual void wr_gram(unsigned short data); 00213 00214 /** Send same 16bit pixeldata to display controller multiple times 00215 * 00216 * @param data: halfword to send 00217 * @param count: how many 00218 * 00219 */ 00220 virtual void wr_gram(unsigned short data, unsigned int count); 00221 00222 /** Send array of pixeldata shorts to display controller 00223 * 00224 * @param data: unsigned short pixeldata array 00225 * @param lenght: lenght (in shorts) 00226 * 00227 */ 00228 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 00229 00230 /** Read 16bit pixeldata from display controller (with dummy cycle) 00231 * 00232 * @note autoconverts 18to16bit based on display identify info 00233 * @returns 16bit color 00234 */ 00235 virtual unsigned short rd_gram(); 00236 00237 /** HW reset sequence (without display init commands) 00238 */ 00239 void hw_reset(); 00240 00241 /** Try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR 00242 * autoset internal flags so pixelread() will always return correct value. 00243 */ 00244 virtual void auto_gram_read_format(); 00245 00246 /** Try to identify display ID 00247 * @note support ILI9341,94xx, MIPI standard. May be be overridden in Init class for other specific IC 00248 */ 00249 virtual void identify(); 00250 00251 unsigned int scrollbugfix; 00252 unsigned char flipped; 00253 00254 00255 00256 private: 00257 00258 Protocols* proto; 00259 const int screensize_X; 00260 const int screensize_Y; 00261 // pixel location 00262 int cur_x; 00263 int cur_y; 00264 // window location 00265 int win_x1; 00266 int win_x2; 00267 int win_y1; 00268 int win_y2; 00269 int orientation; 00270 bool dummycycles; 00271 bool usefastwindow; 00272 bool fastwindowready; 00273 bool fastwindowready4read; 00274 bool is18bit; 00275 bool isBGR; 00276 00277 }; 00278 00279 #endif
Generated on Fri Jul 15 2022 13:58:04 by
