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

Dependents:   xivelyboard

Committer:
celeritous
Date:
Thu Aug 11 16:00:05 2011 +0000
Revision:
0:59cb20947fd6
Added doxygen tags.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
celeritous 0:59cb20947fd6 1 /*
celeritous 0:59cb20947fd6 2 * mbed ST7565R Display Driver
celeritous 0:59cb20947fd6 3 * Copyright (c)
celeritous 0:59cb20947fd6 4 *
celeritous 0:59cb20947fd6 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
celeritous 0:59cb20947fd6 6 * of this software and associated documentation files (the "Software"), to deal
celeritous 0:59cb20947fd6 7 * in the Software without restriction, including without limitation the rights
celeritous 0:59cb20947fd6 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
celeritous 0:59cb20947fd6 9 * copies of the Software, and to permit persons to whom the Software is
celeritous 0:59cb20947fd6 10 * furnished to do so, subject to the following conditions:
celeritous 0:59cb20947fd6 11 *
celeritous 0:59cb20947fd6 12 * The above copyright notice and this permission notice shall be included in
celeritous 0:59cb20947fd6 13 * all copies or substantial portions of the Software.
celeritous 0:59cb20947fd6 14 *
celeritous 0:59cb20947fd6 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
celeritous 0:59cb20947fd6 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
celeritous 0:59cb20947fd6 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
celeritous 0:59cb20947fd6 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
celeritous 0:59cb20947fd6 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
celeritous 0:59cb20947fd6 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
celeritous 0:59cb20947fd6 21 * THE SOFTWARE.
celeritous 0:59cb20947fd6 22 */
celeritous 0:59cb20947fd6 23
celeritous 0:59cb20947fd6 24 #ifndef ST7565R_H
celeritous 0:59cb20947fd6 25 #define ST7565R_H
celeritous 0:59cb20947fd6 26
celeritous 0:59cb20947fd6 27 #include "Text.h"
celeritous 0:59cb20947fd6 28 #include "mbed.h"
celeritous 0:59cb20947fd6 29
celeritous 0:59cb20947fd6 30 typedef struct
celeritous 0:59cb20947fd6 31 {
celeritous 0:59cb20947fd6 32 char screen1[512];
celeritous 0:59cb20947fd6 33 char screen2[512];
celeritous 0:59cb20947fd6 34 } screen_memory_t;
celeritous 0:59cb20947fd6 35
celeritous 0:59cb20947fd6 36 typedef struct
celeritous 0:59cb20947fd6 37 {
celeritous 0:59cb20947fd6 38 short x;
celeritous 0:59cb20947fd6 39 short y;
celeritous 0:59cb20947fd6 40 } loc_t;
celeritous 0:59cb20947fd6 41 /** ST7565R Display Driver; uses some code taken from the TextLCD driver for displaying text.
celeritous 0:59cb20947fd6 42 *
celeritous 0:59cb20947fd6 43 * Example:
celeritous 0:59cb20947fd6 44 * @code
celeritous 0:59cb20947fd6 45 * #include "ST7565R.h"
celeritous 0:59cb20947fd6 46 * #include "mbed.h"
celeritous 0:59cb20947fd6 47 *
celeritous 0:59cb20947fd6 48 * ST7565R lcd(p12,p29,p7,p5, p30 , false);
celeritous 0:59cb20947fd6 49 *
celeritous 0:59cb20947fd6 50 * int main() {
celeritous 0:59cb20947fd6 51 * lcd.printf("Hello world!");
celeritous 0:59cb20947fd6 52 * }
celeritous 0:59cb20947fd6 53 * @endcode
celeritous 0:59cb20947fd6 54 */
celeritous 0:59cb20947fd6 55 class ST7565R : public Stream
celeritous 0:59cb20947fd6 56 {
celeritous 0:59cb20947fd6 57 public:
celeritous 0:59cb20947fd6 58 enum {
celeritous 0:59cb20947fd6 59 BITBLT_SRCCOPY,
celeritous 0:59cb20947fd6 60 BITBLT_SRCAND,
celeritous 0:59cb20947fd6 61 BITBLT_SRCOR
celeritous 0:59cb20947fd6 62 };
celeritous 0:59cb20947fd6 63 /** Create a ST7565R display object on the pins specified.
celeritous 0:59cb20947fd6 64 *
celeritous 0:59cb20947fd6 65 * @param cs The chip select pin for the display.
celeritous 0:59cb20947fd6 66 * @param a0 The data/read select line for the display; specified as A0 in the datasheet.
celeritous 0:59cb20947fd6 67 * @param scl The clock pin for SPI.
celeritous 0:59cb20947fd6 68 * @param rst The reset pin on the display.
celeritous 0:59cb20947fd6 69 * @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.
celeritous 0:59cb20947fd6 70 */
celeritous 0:59cb20947fd6 71 ST7565R(PinName cs,PinName a0, PinName scl, PinName si, PinName rst, bool BackBuffer);
celeritous 0:59cb20947fd6 72
celeritous 0:59cb20947fd6 73 /** Function to move the text cursor to where specified;
celeritous 0:59cb20947fd6 74 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 75 *
celeritous 0:59cb20947fd6 76 * @param col The column number. With the font in Text.h this number is 21 and can be retrieved from columns()
celeritous 0:59cb20947fd6 77 * @param row The chip select pin for the display.
celeritous 0:59cb20947fd6 78 */
celeritous 0:59cb20947fd6 79 void moveto(int col, int row);
celeritous 0:59cb20947fd6 80
celeritous 0:59cb20947fd6 81 /** Function to send a command byte to the display.
celeritous 0:59cb20947fd6 82 *
celeritous 0:59cb20947fd6 83 * @param value The command byte to send over spi.
celeritous 0:59cb20947fd6 84 */
celeritous 0:59cb20947fd6 85 void command(int value);
celeritous 0:59cb20947fd6 86
celeritous 0:59cb20947fd6 87 /** Function to send display data to the display.
celeritous 0:59cb20947fd6 88 *
celeritous 0:59cb20947fd6 89 * @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.
celeritous 0:59cb20947fd6 90 */
celeritous 0:59cb20947fd6 91 void data(int value);
celeritous 0:59cb20947fd6 92
celeritous 0:59cb20947fd6 93 /** Function that uses the reset line and then reinitializes the display as well as clearing the current buffer.
celeritous 0:59cb20947fd6 94 */
celeritous 0:59cb20947fd6 95 void reset();
celeritous 0:59cb20947fd6 96
celeritous 0:59cb20947fd6 97 /** Function to set a specific pixel to black.
celeritous 0:59cb20947fd6 98 * @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.
celeritous 0:59cb20947fd6 99 * @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.
celeritous 0:59cb20947fd6 100 */
celeritous 0:59cb20947fd6 101 void setpixel(int x, int y);
celeritous 0:59cb20947fd6 102
celeritous 0:59cb20947fd6 103 /** Function to set a specific pixel to white.
celeritous 0:59cb20947fd6 104 * @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.
celeritous 0:59cb20947fd6 105 * @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.
celeritous 0:59cb20947fd6 106 */
celeritous 0:59cb20947fd6 107 void clearpixel(int x, int y);
celeritous 0:59cb20947fd6 108 /** 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.
celeritous 0:59cb20947fd6 109 */
celeritous 0:59cb20947fd6 110 char * getDrawingScreen();
celeritous 0:59cb20947fd6 111 /** 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.
celeritous 0:59cb20947fd6 112 */
celeritous 0:59cb20947fd6 113 char * getCurrentScreen();
celeritous 0:59cb20947fd6 114 /** Function to clear the current drawing buffer. This clears the current screen when not using a backbuffer.
celeritous 0:59cb20947fd6 115 */
celeritous 0:59cb20947fd6 116 void clearBuffer();
celeritous 0:59cb20947fd6 117 /** 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.
celeritous 0:59cb20947fd6 118 */
celeritous 0:59cb20947fd6 119 void swapBuffers();
celeritous 0:59cb20947fd6 120 /** 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.
celeritous 0:59cb20947fd6 121 * @param dstx The x coordinate destination on the screen you want to blit to.
celeritous 0:59cb20947fd6 122 * @param dsty The y coordinate destination on the screen you want to blit to.
celeritous 0:59cb20947fd6 123 * @param blit_width The width of the image copy you want to perform.
celeritous 0:59cb20947fd6 124 * @param blit_height The height of the image copy you want to perform.
celeritous 0:59cb20947fd6 125 * @param img The pointer to the data of the image.
celeritous 0:59cb20947fd6 126 * @param img_width The width of the image. Required for calculating the address to start the next line in the img buffer.
celeritous 0:59cb20947fd6 127 * @param img_height The height of the image.
celeritous 0:59cb20947fd6 128 * @param srcx The x coordinate where to start copying image data from within the source image.
celeritous 0:59cb20947fd6 129 * @param srcy The y coordinate where to start copying image data from within the source image
celeritous 0:59cb20947fd6 130 * @param format What kind of copy to perform. BITBLT_SRCCOPY is a standard image copy.
celeritous 0:59cb20947fd6 131 */
celeritous 0:59cb20947fd6 132 void bitblt(int dstx, int dsty,
celeritous 0:59cb20947fd6 133 int blit_width, int blit_height,
celeritous 0:59cb20947fd6 134 char* img,
celeritous 0:59cb20947fd6 135 int img_width, int img_height,
celeritous 0:59cb20947fd6 136 int srcx, int srcy,
celeritous 0:59cb20947fd6 137 int format);
celeritous 0:59cb20947fd6 138
celeritous 0:59cb20947fd6 139 /** Function to place a character on the screen.
celeritous 0:59cb20947fd6 140 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 141 *
celeritous 0:59cb20947fd6 142 * @param column The column number. With the font in Text.h this number is 21 and can be retrieved from columns()
celeritous 0:59cb20947fd6 143 * @param row The row number. With the font in Text.h this number is 4 and can be retrieved from rows()
celeritous 0:59cb20947fd6 144 */
celeritous 0:59cb20947fd6 145 void character(int column, int row, char c);
celeritous 0:59cb20947fd6 146 /** Function to return the number of columns; for now all it does is returns 21. Reserved for possible later code manipulation with multiple fonts.
celeritous 0:59cb20947fd6 147 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 148 */
celeritous 0:59cb20947fd6 149 int columns();
celeritous 0:59cb20947fd6 150 /** Function to return the number of rows; for now all it does is returns 4. Reserved for possible later code manipulation with multiple fonts.
celeritous 0:59cb20947fd6 151 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 152 */
celeritous 0:59cb20947fd6 153 int rows();
celeritous 0:59cb20947fd6 154 protected:
celeritous 0:59cb20947fd6 155 /** Overwritten function from the Stream object.
celeritous 0:59cb20947fd6 156 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 157 */
celeritous 0:59cb20947fd6 158 virtual int _putc(int value);
celeritous 0:59cb20947fd6 159 /** Overwritten function from the Stream object.
celeritous 0:59cb20947fd6 160 * DISCLAIMER: All text routines are based on code from TextLCD, who's link is in the cookbook.
celeritous 0:59cb20947fd6 161 */
celeritous 0:59cb20947fd6 162 virtual int _getc();
celeritous 0:59cb20947fd6 163 private:
celeritous 0:59cb20947fd6 164 int _column;
celeritous 0:59cb20947fd6 165 int _row;
celeritous 0:59cb20947fd6 166
celeritous 0:59cb20947fd6 167 SPI _spi;
celeritous 0:59cb20947fd6 168 DigitalOut _cs;
celeritous 0:59cb20947fd6 169 DigitalOut _a0;
celeritous 0:59cb20947fd6 170 DigitalOut _rst;
celeritous 0:59cb20947fd6 171
celeritous 0:59cb20947fd6 172 bool scr;
celeritous 0:59cb20947fd6 173
celeritous 0:59cb20947fd6 174 char * current_buffer;
celeritous 0:59cb20947fd6 175 loc_t pos;
celeritous 0:59cb20947fd6 176 screen_memory_t screen;
celeritous 0:59cb20947fd6 177 bool UsingBackBuffer;
celeritous 0:59cb20947fd6 178 };
celeritous 0:59cb20947fd6 179
celeritous 0:59cb20947fd6 180 #endif