64x128 Graphic LCD Library

Dependencies:   LCD_fonts

Fork of C12832_lcd by Peter Drescher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gLCD.h Source File

gLCD.h

00001 /* mbed library for the mbed Lab Board  128*32 pixel LCD
00002  * use C12832 controller
00003  * Copyright (c) 2012 Peter Drescher - DC2PD
00004  * Released under the MIT License: http://mbed.org/license/mit
00005  *
00006  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00007  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00008  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00009  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00010  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00011  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00012  * THE SOFTWARE.
00013  */
00014 
00015 /** 64x128pixel graphic LCD display class adapted from the C12832 library */
00016 #ifndef GLCD_H
00017 #define GLCD_H
00018 
00019 #include "mbed.h"
00020 #include "GraphicsDisplay.h"
00021 #include "Small_7.h"
00022 #include "Arial12x12.h"
00023 #include "Arial24x23.h"
00024 #include "Arial_9.h"
00025 
00026 
00027 /** optional Defines :
00028   * #define debug_lcd  1  enable infos to PC_USB
00029   */
00030 
00031 // some defines for the DMA use
00032 #define DMA_CHANNEL_ENABLE      1
00033 #define DMA_TRANSFER_TYPE_M2P   (1UL << 11)
00034 #define DMA_CHANNEL_TCIE        (1UL << 31)
00035 #define DMA_CHANNEL_SRC_INC     (1UL << 26)
00036 #define DMA_MASK_IE             (1UL << 14)
00037 #define DMA_MASK_ITC            (1UL << 15)
00038 #define DMA_SSP1_TX             (1UL << 2)
00039 #define DMA_SSP0_TX             (0)
00040 #define DMA_DEST_SSP1_TX        (2UL << 6)
00041 #define DMA_DEST_SSP0_TX        (0UL << 6)
00042 
00043 /** Draw mode
00044   * NORMAl
00045   * XOR set pixel by xor the screen
00046   */
00047 enum {NORMAL,XOR};
00048 
00049 class gLCD : public GraphicsDisplay
00050 {
00051 public:
00052     /** Create a gLCD object connected to SPI bus
00053       *
00054       */
00055 
00056     gLCD(PinName cs, //chip select
00057          PinName res, //reset
00058          PinName rs, //register select
00059          PinName sdo, PinName sdi, PinName scl, //spi bus pins 
00060          PinName bcl, //backlight
00061          const char* name = "LCD");
00062 
00063     /** Get the width of the screen in pixel
00064       *
00065       * @param
00066       * @returns width of screen in pixel
00067       *
00068       */
00069     virtual int width();
00070 
00071     /** Get the height of the screen in pixel
00072      *
00073      * @returns height of screen in pixel
00074      *
00075      */
00076     virtual int height();
00077 
00078     /** Draw a pixel at x,y black or white
00079      *
00080      * @param x horizontal position
00081      * @param y vertical position
00082      * @param colour ,1 set pixel ,0 erase pixel
00083      */
00084      
00085     void set_orientation(unsigned int o);
00086     virtual void pixel(int x, int y,int colour);
00087 
00088     /** draw a circle
00089       *
00090       * @param x0,y0 center
00091       * @param r radius
00092       * @param colour ,1 set pixel ,0 erase pixel
00093       *
00094       */
00095     void bclIncrease();
00096     void bclDecrease();  
00097     void circle(int x, int y, int r, int colour);
00098 
00099     /** draw a filled circle
00100      *
00101      * @param x0,y0 center
00102      * @param r radius
00103      * @param color ,1 set pixel ,0 erase pixel
00104      *
00105      * use circle with different radius,
00106      * can miss some pixel
00107      */
00108     void fillcircle(int x, int y, int r, int colour);
00109 
00110     /** draw a 1 pixel line
00111       *
00112       * @param x0,y0 start point
00113       * @param x1,y1 stop point
00114       * @param color ,1 set pixel ,0 erase pixel
00115       *
00116       */
00117     void line(int x0, int y0, int x1, int y1, int colour);
00118 
00119     /** draw a rect
00120     *
00121     * @param x0,y0 top left corner
00122     * @param x1,y1 down right corner
00123     * @param color 1 set pixel ,0 erase pixel
00124     *                                                   *
00125     */
00126     void rect(int x0, int y0, int x1, int y1, int colour);
00127 
00128     /** draw a filled rect
00129       *
00130       * @param x0,y0 top left corner
00131       * @param x1,y1 down right corner
00132       * @param color 1 set pixel ,0 erase pixel
00133       *
00134       */
00135     void fillrect(int x0, int y0, int x1, int y1, int colour);
00136 
00137     /** copy display buffer to lcd
00138       *
00139       */
00140 
00141     void copy_to_lcd(void);
00142 
00143     /** set the orienation of the screen
00144       *
00145       */
00146 
00147     //void set_orientation(unsigned int o);
00148 
00149     /** set the contrast of the screen
00150       *
00151       * @param o contrast 0-63
00152       */
00153 
00154     void set_contrast(unsigned int o);
00155 
00156     /** read the contrast level
00157       *
00158       */
00159     unsigned int get_contrast(void);
00160 
00161 
00162 
00163     /** invert the screen
00164       *
00165       * @param o = 0 normal, 1 invert
00166       */
00167     void invert(unsigned int o);
00168 
00169     /** clear the screen
00170        *
00171        */
00172     virtual void cls(void);
00173 
00174     /** set the drawing mode
00175       *
00176       * @param mode NORMAl or XOR
00177       */
00178 
00179     void setmode(int mode);
00180 
00181     int columns(void);
00182 
00183     /** calculate the max number of columns
00184      *
00185      * @returns max column
00186      * depends on actual font size
00187      *
00188      */
00189     int rows(void);
00190 
00191     /** put a char on the screen
00192      *
00193      * @param value char to print
00194      * @returns printed char
00195      *
00196      */
00197     int _putc(int value);
00198 
00199     /** draw a character on given position out of the active font to the LCD
00200      *
00201      * @param x x-position of char (top left)
00202      * @param y y-position
00203      * @param c char to print
00204      *
00205      */
00206     virtual void character(int x, int y, int c);
00207 
00208     /** setup cursor position
00209      *
00210      * @param x x-position (top left)
00211      * @param y y-position
00212      */
00213     void locate(int x, int y);
00214     
00215     /** setup auto update of screen 
00216       *
00217       * @param up 1 = on , 0 = off
00218       * if switched off the program has to call copy_to_lcd() 
00219       * to update screen from framebuffer
00220       */
00221     void set_auto_up(unsigned int up);
00222 
00223     /** get status of the auto update function
00224       *
00225       *  @returns if auto update is on
00226       */
00227     unsigned int get_auto_up(void);
00228 
00229     /** Vars     */
00230     SPI _spi;
00231     DigitalOut _reset;
00232     DigitalOut _A0;
00233     DigitalOut _CS;
00234     PwmOut backLight;
00235     unsigned char* font;
00236     unsigned int draw_mode;
00237 
00238 
00239     /** select the font to use
00240       *
00241       * @param f pointer to font array
00242       *
00243       *   font array can created with GLCD Font Creator from http://www.mikroe.com
00244       *   you have to add 4 parameter at the beginning of the font array to use:
00245       *   - the number of byte / char
00246       *   - the vertial size in pixel
00247       *   - the horizontal size in pixel
00248       *   - the number of byte per vertical line
00249       *   you also have to change the array to char[]
00250       *
00251       */
00252     void set_font(unsigned char* f);
00253 
00254 
00255 protected:
00256 
00257     /** draw a horizontal line
00258       *
00259       * @param x0 horizontal start
00260       * @param x1 horizontal stop
00261       * @param y vertical position
00262       * @param ,1 set pixel ,0 erase pixel
00263       *
00264       */
00265     void hline(int x0, int x1, int y, int colour);
00266 
00267     /** draw a vertical line
00268      *
00269      * @param x horizontal position
00270      * @param y0 vertical start
00271      * @param y1 vertical stop
00272      * @param ,1 set pixel ,0 erase pixel
00273      */
00274     void vline(int y0, int y1, int x, int colour);
00275 
00276     /** Init the C12832 LCD controller
00277      *
00278      */
00279     void lcd_reset();
00280 
00281     /** Write data to the LCD controller
00282      *
00283      * @param dat data written to LCD controller
00284      *
00285      */
00286     void wr_dat(unsigned char value);
00287 
00288     /** Write a command the LCD controller
00289       *
00290       * @param cmd: command to be written
00291       *
00292       */
00293     void wr_cmd(unsigned char value);
00294 
00295     void wr_cnt(unsigned char cmd);
00296 
00297     unsigned int orientation;
00298     unsigned int char_x;
00299     unsigned int oldchar_x;
00300     unsigned int char_y;
00301     unsigned char buffer[1024];
00302     unsigned int contrast;
00303     unsigned int auto_up;
00304 
00305 };
00306 
00307 
00308 
00309 
00310 #endif