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 LCD.h Source File

LCD.h

00001 
00002 #ifndef MBED_LCD_H
00003 #define MBED_LCD_H
00004 
00005 #include "GraphicsDisplay.h"
00006 #include "PAR8.h"
00007 #include "BUS8.h"
00008 #include "SPI8.h"
00009 #include "SPI16.h"
00010 #include "Protocols.h "
00011 
00012 // undefine the KL43Z and KL46Z LCD macro
00013 #ifdef LCD
00014 #undef LCD
00015 #endif
00016 
00017 /** Draw mode
00018   * NORMAl
00019   * XOR set pixel by xor the screen
00020   */
00021 enum {NORMAL,XOR};
00022 
00023 /** Mirror mode */
00024 enum mirror_t {X,Y,XY,NONE};
00025 
00026 
00027 /** A common base class for monochrome Display
00028 */
00029 class LCD : public GraphicsDisplay
00030 {
00031 
00032 public:         
00033           
00034     /** Create a monochrome LCD Parallel Port interface
00035     * @param name The name used by the parent class to access the interface
00036     */
00037     LCD(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
00038     
00039     /** Create a monochrome LCD Parallel Bus interface
00040     * @param name The name used by the parent class to access the interface
00041     */
00042     LCD(proto_t displayproto,PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
00043     
00044     /** Create a monochrome LCD SPI interface
00045     * @param name The name used by the parent class to access the interface
00046     */
00047     LCD(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 int ic_x_segs, const int ic_y_coms, const char* name);
00048     
00049     /** Destructor
00050     * will free framebuffer
00051     */
00052     virtual ~LCD();
00053     
00054 
00055     
00056 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
00057 /////// ----------------------------------------------------///////////////////////////////////////////////////
00058 
00059     /** Draw a pixel in the specified color.
00060     * @param x is the horizontal offset to this pixel.
00061     * @param y is the vertical offset to this pixel.
00062     * @param color defines the color for the pixel.
00063     */
00064     virtual void pixel(int x, int y, unsigned short color);
00065 
00066     /** Set the window, which controls where items are written to the screen.
00067     * When something hits the window width, it wraps back to the left side
00068     * and down a row. If the initial write is outside the window, it will
00069     * be captured into the window when it crosses a boundary.
00070     * @param x is the left edge in pixels.
00071     * @param y is the top edge in pixels.
00072     * @param w is the window width in pixels.
00073     * @param h is the window height in pixels.
00074     */
00075     virtual void window(int x, int y, int w, int h);
00076     
00077     /** Read pixel color at location
00078     * @param x is the horizontal offset to this pixel.
00079     * @param y is the vertical offset to this pixel.
00080     * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear).
00081     */
00082     virtual unsigned short pixelread(int x, int y);
00083 
00084     /** Push a single pixel into the window and increment position.
00085     * You must first call window() then push pixels in loop.
00086     * @param color is the pixel color.
00087     */
00088     virtual void window_pushpixel(unsigned short color);
00089     
00090     /** Push some pixels of the same color into the window and increment position.
00091     * You must first call window() then push pixels.
00092     * @param color is the pixel color.
00093     * @param count: how many
00094     */
00095     virtual void window_pushpixel(unsigned short color, unsigned int count);
00096     
00097     /** Push array of pixel colors into the window and increment position.
00098     * You must first call window() then push pixels.
00099     * @param color is the pixel color.
00100     */
00101     virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
00102  
00103     /** Framebuffer is used, it needs to be sent to LCD from time to time
00104     */
00105     virtual void copy_to_lcd();
00106     
00107     /** set the contrast of the screen
00108       *
00109       * @param o contrast 0-63
00110       * @note may be overrided in case of not standard command
00111       */
00112     virtual void set_contrast(int o);
00113 
00114     /** read the contrast level
00115       *
00116       */
00117     int get_contrast(void);
00118 
00119     /** display inverted colors
00120       *
00121       * @param o = 0 normal, 1 invert
00122       */
00123     void invert(unsigned char o);
00124 
00125     /** clear the entire screen
00126     * The inherited one sets windomax then fill with background color
00127     * We override it to speedup
00128     */
00129     virtual void cls();
00130     
00131     /** Set the orientation of the screen
00132     *  x,y: 0,0 is always top left 
00133     *
00134     * @param o direction to use the screen (0-3)
00135     * 0 = -90°
00136     * 1 = default 0°
00137     * 2 = +90°
00138     * 3 = +180°
00139     *
00140     */  
00141     void set_orientation(int o);
00142     
00143     /** Set ChipSelect high or low
00144     * @param enable 0/1   
00145     */
00146     virtual void BusEnable(bool enable);
00147     
00148     /** get display X size in pixels (native, orientation independent)
00149     * @returns X size in pixels
00150     */
00151     int sizeX();
00152 
00153     /** get display Y size in pixels (native, orientation independent)
00154     * @returns Y size in pixels
00155     */
00156     int sizeY();
00157     
00158 ////////////////////////////////////////////////////////////////////////////////    
00159     // not implemented yet
00160 //////////////////////////////////////////////////////////////////
00161   //  virtual unsigned short pixelread(int x, int y){return 0;};
00162     virtual void window4read(int x, int y, int w, int h){};
00163     void setscrollarea (int startY, int areasize){};
00164     void scroll (int lines){};
00165     void scrollreset(){};
00166     void FastWindow(bool enable){};
00167     
00168     unsigned int tftID;
00169     
00170     
00171     
00172     
00173 protected:
00174 
00175     /** set mirror mode
00176       * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring 
00177       * @param mode NONE, X, Y, XY 
00178       */
00179     virtual void mirrorXY(mirror_t mode);
00180 
00181 ////// functions needed by parent class ///////////////////////////////////////
00182 ////// -------------------------------- ///////////////////////////////////////
00183 
00184     /** Send 8bit command to display controller 
00185     *
00186     * @param cmd: byte to send  
00187     * @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
00188     */   
00189     void wr_cmd8(unsigned char cmd);
00190     
00191     /** Send 8bit data to display controller 
00192     *
00193     * @param data: byte to send   
00194     *
00195     */   
00196     void wr_data8(unsigned char data);
00197     
00198     /** Send 16bit command to display controller 
00199     *
00200     * @param cmd: halfword to send  
00201     *
00202     */   
00203     void wr_cmd16(unsigned short cmd);
00204     
00205     /** Send same 16bit pixeldata to display controller multiple times
00206     *
00207     * @param data: halfword to send
00208     * @param count: how many
00209     *
00210     */   
00211     virtual void wr_gram(unsigned short data, unsigned int count);
00212     
00213     /** Send array of pixeldata shorts to display controller
00214     *
00215     * @param data: unsigned short pixeldata array
00216     * @param lenght: lenght (in shorts)
00217     *
00218     */   
00219     virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
00220     
00221     /** HW reset sequence (without display init commands)   
00222     */
00223     void hw_reset();
00224   
00225     int draw_mode;
00226     int contrast;
00227     
00228 private:
00229 
00230     Protocols* proto;
00231     unsigned char *buffer;
00232     unsigned short *buffer16;
00233     const int screensize_X;
00234     const int screensize_Y;
00235     const int _LCDPAGES;
00236     const int _IC_X_SEGS;
00237     const int _IC_Y_COMS;
00238     const int _IC_PAGES;
00239     
00240     int page_offset;
00241     int col_offset;
00242     // pixel location
00243     int cur_x;
00244     int cur_y;
00245     // window location
00246     int win_x1;
00247     int win_x2;
00248     int win_y1;
00249     int win_y2;
00250     int orientation;
00251     bool useNOP;
00252 };
00253 
00254 #endif