Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Fork of UniGraphic by GraphicsDisplay

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