Darren Ulrich / UniGraphic

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

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