lcd for LPC1768

Dependents:   exercise_application_shield FRDM_K64F_LCD shot_game shot_game ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers C12832.h Source File

C12832.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 #ifndef C12832_H
00016 #define C12832_H
00017 
00018 #include "mbed.h"
00019 #include "GraphicsDisplay.h"
00020 
00021 
00022 /** optional Defines :
00023   * #define debug_lcd  1  enable infos to PC_USB
00024   */
00025 
00026 // some defines for the DMA use
00027 #define DMA_CHANNEL_ENABLE      1
00028 #define DMA_TRANSFER_TYPE_M2P   (1UL << 11)
00029 #define DMA_CHANNEL_TCIE        (1UL << 31)
00030 #define DMA_CHANNEL_SRC_INC     (1UL << 26)
00031 #define DMA_MASK_IE             (1UL << 14)
00032 #define DMA_MASK_ITC            (1UL << 15)
00033 #define DMA_SSP1_TX             (1UL << 2)
00034 #define DMA_SSP0_TX             (0)
00035 #define DMA_DEST_SSP1_TX        (2UL << 6)
00036 #define DMA_DEST_SSP0_TX        (0UL << 6)
00037 
00038 /** Draw mode
00039   * NORMAl
00040   * XOR set pixel by xor the screen
00041   */
00042 enum {NORMAL,XOR};
00043 
00044 /** Bitmap
00045  */
00046 struct Bitmap{
00047     int xSize;
00048     int ySize;
00049     int Byte_in_Line;
00050     char* data;
00051     };
00052 
00053 class C12832 : public GraphicsDisplay
00054 {
00055 public:
00056     /** Create a C12832 object connected to SPI1
00057       *
00058       */
00059 
00060     C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name = "LCD");
00061 
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     virtual void pixel(int x, int y,int colour);
00085 
00086     /** draw a circle
00087       *
00088       * @param x0,y0 center
00089       * @param r radius
00090       * @param colour ,1 set pixel ,0 erase pixel
00091       *
00092       */
00093     void circle(int x, int y, int r, int colour);
00094 
00095     /** draw a filled circle
00096      *
00097      * @param x0,y0 center
00098      * @param r radius
00099      * @param color ,1 set pixel ,0 erase pixel
00100      *
00101      * use circle with different radius,
00102      * can miss some pixel
00103      */
00104     void fillcircle(int x, int y, int r, int colour);
00105 
00106     /** draw a 1 pixel line
00107       *
00108       * @param x0,y0 start point
00109       * @param x1,y1 stop point
00110       * @param color ,1 set pixel ,0 erase pixel
00111       *
00112       */
00113     void line(int x0, int y0, int x1, int y1, int colour);
00114 
00115     /** draw a rect
00116     *
00117     * @param x0,y0 top left corner
00118     * @param x1,y1 down right corner
00119     * @param color 1 set pixel ,0 erase pixel
00120     *                                                   *
00121     */
00122     void rect(int x0, int y0, int x1, int y1, int colour);
00123 
00124     /** draw a filled rect
00125       *
00126       * @param x0,y0 top left corner
00127       * @param x1,y1 down right corner
00128       * @param color 1 set pixel ,0 erase pixel
00129       *
00130       */
00131     void fillrect(int x0, int y0, int x1, int y1, int colour);
00132 
00133     /** copy display buffer to lcd
00134       *
00135       */
00136 
00137     void copy_to_lcd(void);
00138 
00139     /** set the orienation of the screen
00140       *
00141       */
00142 
00143 
00144     void set_contrast(unsigned int o);
00145 
00146     /** read the contrast level
00147       *
00148       */
00149     unsigned int get_contrast(void);
00150 
00151 
00152     /** invert the screen
00153       *
00154       * @param o = 0 normal, 1 invert
00155       */
00156     void invert(unsigned int o);
00157 
00158     /** clear the screen
00159        *
00160        */
00161     virtual void cls(void);
00162 
00163     /** set the drawing mode
00164       *
00165       * @param mode NORMAl or XOR
00166       */
00167 
00168     void setmode(int mode);
00169 
00170     virtual int columns(void);
00171 
00172     /** calculate the max number of columns
00173      *
00174      * @returns max column
00175      * depends on actual font size
00176      *
00177      */
00178     virtual int rows(void);
00179 
00180     /** put a char on the screen
00181      *
00182      * @param value char to print
00183      * @returns printed char
00184      *
00185      */
00186     virtual int _putc(int value);
00187 
00188     /** draw a character on given position out of the active font to the LCD
00189      *
00190      * @param x x-position of char (top left)
00191      * @param y y-position
00192      * @param c char to print
00193      *
00194      */
00195     virtual void character(int x, int y, int c);
00196 
00197     /** setup cursor position
00198      *
00199      * @param x x-position (top left)
00200      * @param y y-position
00201      */
00202     virtual void locate(int x, int y);
00203     
00204     /** setup auto update of screen 
00205       *
00206       * @param up 1 = on , 0 = off
00207       * if switched off the program has to call copy_to_lcd() 
00208       * to update screen from framebuffer
00209       */
00210     void set_auto_up(unsigned int up);
00211 
00212     /** get status of the auto update function
00213       *
00214       *  @returns if auto update is on
00215       */
00216     unsigned int get_auto_up(void);
00217 
00218     /** Vars     */
00219     SPI _spi;
00220     DigitalOut _reset;
00221     DigitalOut _A0;
00222     DigitalOut _CS;
00223     unsigned char* font;
00224     unsigned int draw_mode;
00225 
00226 
00227     /** select the font to use
00228       *
00229       * @param f pointer to font array
00230       *
00231       *   font array can created with GLCD Font Creator from http://www.mikroe.com
00232       *   you have to add 4 parameter at the beginning of the font array to use:
00233       *   - the number of byte / char
00234       *   - the vertial size in pixel
00235       *   - the horizontal size in pixel
00236       *   - the number of byte per vertical line
00237       *   you also have to change the array to char[]
00238       *
00239       */
00240     void set_font(unsigned char* f);
00241     
00242     /** print bitmap to buffer
00243       *
00244       * @param bm Bitmap in flash
00245       * @param x  x start
00246       * @param y  y start 
00247       *
00248       */
00249 
00250     void print_bm(Bitmap bm, int x, int y);
00251 
00252 protected:
00253 
00254     /** draw a horizontal line
00255       *
00256       * @param x0 horizontal start
00257       * @param x1 horizontal stop
00258       * @param y vertical position
00259       * @param ,1 set pixel ,0 erase pixel
00260       *
00261       */
00262     void hline(int x0, int x1, int y, int colour);
00263 
00264     /** draw a vertical line
00265      *
00266      * @param x horizontal position
00267      * @param y0 vertical start
00268      * @param y1 vertical stop
00269      * @param ,1 set pixel ,0 erase pixel
00270      */
00271     void vline(int y0, int y1, int x, int colour);
00272 
00273     /** Init the C12832 LCD controller
00274      *
00275      */
00276     void lcd_reset();
00277 
00278     /** Write data to the LCD controller
00279      *
00280      * @param dat data written to LCD controller
00281      *
00282      */
00283     void wr_dat(unsigned char value);
00284 
00285     /** Write a command the LCD controller
00286       *
00287       * @param cmd: command to be written
00288       *
00289       */
00290     void wr_cmd(unsigned char value);
00291 
00292     void wr_cnt(unsigned char cmd);
00293 
00294     unsigned int orientation;
00295     unsigned int char_x;
00296     unsigned int char_y;
00297     unsigned char buffer[512];
00298     unsigned int contrast;
00299     unsigned int auto_up;
00300 
00301 };
00302 
00303 
00304 
00305 
00306 #endif