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