LPC General Purpose Shield (OM13082) LCD module library

Dependents:   OM13082-LCD OM13082-test LPCXpresso4337_OM13082_test lpc4337_acc_demo ... more

Fork of KT7567 by Toyomasa Watarai

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ST7567.h Source File

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