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