Zoltan Hudak / Mbed OS LCD_McuFriend_FSMC_STM32F407
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TFT.h Source File

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