My controller identifies as an ILI9328, but only works if initialised as an ILI9325. This fork includes a fix to force 9325 initialization when a 9328 is detected.

Dependents:   TouchScreenCalibrate TouchScreenGUIDemo

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TFT932x.h Source File

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 
00030     /** Create interface for MINI-STM32 board */
00031     TFT932x(const char* name);
00032 #endif
00033     
00034     /** Create TFT Parallel Bus interface
00035     * @param name The name used by the parent class to access the interface
00036     */
00037     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);
00038     
00039     /** Create TFT SPI interface
00040     * @note ILI9325D has different SPI protocol, not supported here
00041     * @param name The name used by the parent class to access the interface
00042     */
00043     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);
00044 
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 o);
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     /** Enable scroll
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     * @note ILI932x does not allow partial screen scrolling, only full screen is selectable
00145     * @param startY unused, always 0 for ILI932x
00146     * @param areasize unused, always screensize_Y for ILI932x
00147     */
00148     void setscrollarea (int startY=0, int areasize=0);
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     /** Disable scroll 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     /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
00183     * for PAR protocols: a signle RD bit toggle
00184     * for SPI8: 8clocks
00185     * for SPI16: 16 clocks
00186     */   
00187     virtual void dummyread ();
00188 
00189     /** ILI932x specific, select register for a successive write or read
00190     *
00191     * @param reg register to be selected
00192     * @param forread false = a write next (default), true = a read next
00193     * @note forread only used by SPI protocols
00194     */   
00195     virtual void reg_select(unsigned char reg, bool forread =false);
00196 
00197     /** ILI932x specific, write register with data
00198     *
00199     * @param reg register to write
00200     * @param data 16bit data
00201     */   
00202     virtual void reg_write(unsigned char reg, unsigned short data);
00203     
00204     /** ILI932x specific, read register
00205     *
00206     * @param reg register to be read
00207     * @returns 16bit register value
00208     */ 
00209     virtual unsigned short reg_read(unsigned char reg);
00210     
00211     /** Send 16bit pixeldata to display controller 
00212     *
00213     * @param data: halfword to send   
00214     *
00215     */   
00216     virtual void wr_gram(unsigned short data);
00217     
00218     /** Send same 16bit pixeldata to display controller multiple times
00219     *
00220     * @param data: halfword to send
00221     * @param count: how many
00222     *
00223     */   
00224     virtual void wr_gram(unsigned short data, unsigned int count);
00225     
00226     /** Send array of pixeldata shorts to display controller
00227     *
00228     * @param data: unsigned short pixeldata array
00229     * @param lenght: lenght (in shorts)
00230     *
00231     */   
00232     virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
00233     
00234     /** Read 16bit pixeldata from display controller (with dummy cycle)
00235     *
00236     * @note autoconverts 18to16bit based on display identify info
00237     * @returns 16bit color
00238     */ 
00239     virtual unsigned short rd_gram();
00240     
00241     /** HW reset sequence (without display init commands)   
00242     */
00243     void hw_reset();
00244     
00245     /** Try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR
00246     * autoset internal flags so pixelread() will always return correct value.
00247     */
00248     virtual void auto_gram_read_format();
00249     
00250     /** Try to identify display ID
00251     * @note support ILI9341,94xx, MIPI standard. May be be overridden in Init class for other specific IC
00252     */
00253     virtual void identify();
00254     
00255     unsigned int scrollbugfix;
00256     unsigned char flipped;
00257     
00258     
00259     
00260 private:
00261 
00262     Protocols* proto;
00263     const int screensize_X;
00264     const int screensize_Y;
00265     // pixel location
00266     int cur_x;
00267     int cur_y;
00268     // window location
00269     int win_x1;
00270     int win_x2;
00271     int win_y1;
00272     int win_y2;
00273     int orientation;
00274     bool dummycycles;
00275     bool usefastwindow;
00276     bool fastwindowready;
00277     bool fastwindowready4read;
00278     bool is18bit;
00279     bool isBGR;
00280     
00281 };
00282 
00283 #endif