A ST7565R display driver written with backbuffering capabilities. Model used and tested: NHD-C12832A1Z-FSW-FBW-3V3

Dependents:   xivelyboard

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ST7565R.h Source File

ST7565R.h

00001 /*
00002  * mbed ST7565R Display Driver
00003  * Copyright (c) 
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 
00024 #ifndef ST7565R_H
00025 #define ST7565R_H
00026 
00027 #include "Text.h"
00028 #include "mbed.h"
00029 
00030 typedef struct
00031 {
00032     char screen1[512];
00033     char screen2[512];
00034 } screen_memory_t;
00035 
00036 typedef struct
00037 {
00038     short x;
00039     short y;
00040 } loc_t;
00041 /** ST7565R Display Driver; uses some code taken from the TextLCD driver for displaying text.
00042   *
00043   * Example:
00044   * @code
00045   * #include "ST7565R.h"
00046   * #include "mbed.h"
00047   *
00048   * ST7565R lcd(p12,p29,p7,p5, p30 , false);
00049   * 
00050   * int main() { 
00051   *   lcd.printf("Hello world!");
00052   * }
00053   * @endcode
00054   */
00055 class ST7565R : public Stream
00056 {
00057 public:
00058     enum {
00059         BITBLT_SRCCOPY,
00060         BITBLT_SRCAND,
00061         BITBLT_SRCOR
00062     };
00063    /** Create a ST7565R display object on the pins specified.
00064     *
00065     * @param cs  The chip select pin for the display.
00066     * @param a0  The data/read select line for the display; specified as A0 in the datasheet.
00067     * @param scl The clock pin for SPI.
00068     * @param rst The reset pin on the display.
00069     * @param BackBuffer The display I have has a memory area thats can be used for backbuffering. This turns this option on. When using this option you must call swapBuffers() in order to display your changes to the screen. This is to help prevent flickering on the display. If not using a backbuffer all writes using bitblt or setpixel are immediate and visible to the screen.
00070     */
00071     ST7565R(PinName cs,PinName a0, PinName scl, PinName si, PinName rst, bool BackBuffer);
00072     
00073    /** Function to move the text cursor to where specified; 
00074     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00075     *
00076     * @param col  The column number. With the font in Text.h this number is 21 and can be retrieved from columns()
00077     * @param row  The chip select pin for the display.
00078     */
00079     void moveto(int col, int row);
00080     
00081    /** Function to send a command byte to the display.
00082     *
00083     * @param value The command byte to send over spi.
00084     */
00085     void command(int value);
00086     
00087    /** Function to send display data to the display.
00088     *
00089     * @param value The data byte to send over spi. Memory is arranged in pages. A data write will cover 8 pixels vertically (the page) and only one column. A data write will increment the column by 1 but will never increment the page.
00090     */
00091     void data(int value);
00092     
00093    /** Function that uses the reset line and then reinitializes the display as well as clearing the current buffer.
00094     */
00095     void reset();
00096     
00097    /** Function to set a specific pixel to black.
00098     * @param x Measured from the top left of the display; If the display is in backbuffering mode the pixel change is completely within the offscreen buffer and won't display until swapBuffer() is called.
00099     * @param y Measured from the top left of the display; If the display is in backbuffering mode the pixel change is completely within the offscreen buffer and won't display until swapBuffer() is called.
00100     */
00101     void setpixel(int x, int y);
00102 
00103    /** Function to set a specific pixel to white.
00104     * @param x Measured from the top left of the display; If the display is in backbuffering mode the pixel change is completely within the offscreen buffer and won't display until swapBuffer() is called.
00105     * @param y Measured from the top left of the display; If the display is in backbuffering mode the pixel change is completely within the offscreen buffer and won't display until swapBuffer() is called.
00106     */    
00107     void clearpixel(int x, int y);
00108    /** Function to get the buffer being used inside the object to do bit writes, required because of the lack of reading screen data back over spi for the ST7565R. The buffer returned is the one that you can draw to without immediately updating the screen.
00109     */        
00110     char * getDrawingScreen();
00111    /** Function to get the buffer being used inside the object to do bit writes, required because of the lack of reading screen data back over spi for the ST7565R. The buffer returned is the one that has the current screen data on it. Without backbuffering mode this returns the current screen.
00112     */         
00113     char * getCurrentScreen();
00114    /** Function to clear the current drawing buffer. This clears the current screen when not using a backbuffer.
00115     */         
00116     void clearBuffer();
00117    /** Function to commit all the data to the drawing buffer, then calls the display command to change buffers so as to not promote a flicker in the display. Not needed if not using a backbuffer.
00118     */         
00119     void swapBuffers();
00120    /** Function to blit an image to the screen. Used internally for copying the font to the screen, but also is powerful for displaying any monochrome image.
00121     * @param dstx The x coordinate destination on the screen you want to blit to.
00122     * @param dsty The y coordinate destination on the screen you want to blit to.
00123     * @param blit_width The width of the image copy you want to perform.
00124     * @param blit_height The height of the image copy you want to perform. 
00125     * @param img The pointer to the data of the image.
00126     * @param img_width The width of the image. Required for calculating the address to start the next line in the img buffer. 
00127     * @param img_height The height of the image. 
00128     * @param srcx The x coordinate where to start copying image data from within the source image.
00129     * @param srcy The y coordinate where to start copying image data from within the source image
00130     * @param format What kind of copy to perform. BITBLT_SRCCOPY is a standard image copy.
00131     */    
00132     void bitblt(int dstx, int dsty, 
00133                 int blit_width, int blit_height, 
00134                 char* img, 
00135                 int img_width, int img_height,
00136                 int srcx, int srcy, 
00137                 int format);
00138 
00139    /** Function to place a character on the screen. 
00140     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00141     *
00142     * @param column  The column number. With the font in Text.h this number is 21 and can be retrieved from columns()
00143     * @param row  The row number. With the font in Text.h this number is 4 and can be retrieved from rows()
00144     */
00145     void character(int column, int row, char c);
00146    /** Function to return the number of columns; for now all it does is returns 21. Reserved for possible later code manipulation with multiple fonts.
00147     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00148     */
00149     int columns();
00150    /** Function to return the number of rows; for now all it does is returns 4. Reserved for possible later code manipulation with multiple fonts.
00151     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00152     */
00153     int rows();
00154 protected:
00155    /** Overwritten function from the Stream object.
00156     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00157     */
00158     virtual int _putc(int value);
00159    /** Overwritten function from the Stream object.
00160     * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
00161     */
00162     virtual int _getc();
00163 private:
00164     int _column;
00165     int _row;
00166 
00167     SPI        _spi;
00168     DigitalOut _cs;
00169     DigitalOut _a0;
00170     DigitalOut _rst;
00171 
00172     bool scr;
00173 
00174     char * current_buffer;
00175     loc_t pos;
00176     screen_memory_t screen;  
00177     bool UsingBackBuffer;  
00178 };
00179 
00180 #endif