Lib for the LCD display on mbed lab Board

Committer:
dreschpe
Date:
Tue Oct 16 14:05:57 2012 +0000
Revision:
0:4bbc531be6e2
Child:
1:66dd8afbfd06
version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:4bbc531be6e2 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
dreschpe 0:4bbc531be6e2 2 * use C12832 controller
dreschpe 0:4bbc531be6e2 3 * Copyright (c) 2012 Peter Drescher - DC2PD
dreschpe 0:4bbc531be6e2 4 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:4bbc531be6e2 5 *
dreschpe 0:4bbc531be6e2 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:4bbc531be6e2 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:4bbc531be6e2 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:4bbc531be6e2 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:4bbc531be6e2 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:4bbc531be6e2 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:4bbc531be6e2 12 * THE SOFTWARE.
dreschpe 0:4bbc531be6e2 13 */
dreschpe 0:4bbc531be6e2 14
dreschpe 0:4bbc531be6e2 15 #ifndef C12832_H
dreschpe 0:4bbc531be6e2 16 #define C12832_H
dreschpe 0:4bbc531be6e2 17
dreschpe 0:4bbc531be6e2 18 #include "mbed.h"
dreschpe 0:4bbc531be6e2 19 #include "GraphicsDisplay.h"
dreschpe 0:4bbc531be6e2 20
dreschpe 0:4bbc531be6e2 21
dreschpe 0:4bbc531be6e2 22 /** optional Defines :
dreschpe 0:4bbc531be6e2 23 * #define debug_lcd 1 enable infos to PC_USB
dreschpe 0:4bbc531be6e2 24 */
dreschpe 0:4bbc531be6e2 25
dreschpe 0:4bbc531be6e2 26 // some defines for the DMA use
dreschpe 0:4bbc531be6e2 27 #define DMA_CHANNEL_ENABLE 1
dreschpe 0:4bbc531be6e2 28 #define DMA_TRANSFER_TYPE_M2P (1UL << 11)
dreschpe 0:4bbc531be6e2 29 #define DMA_CHANNEL_TCIE (1UL << 31)
dreschpe 0:4bbc531be6e2 30 #define DMA_CHANNEL_SRC_INC (1UL << 26)
dreschpe 0:4bbc531be6e2 31 #define DMA_MASK_IE (1UL << 14)
dreschpe 0:4bbc531be6e2 32 #define DMA_MASK_ITC (1UL << 15)
dreschpe 0:4bbc531be6e2 33 #define DMA_SSP1_TX (1UL << 2)
dreschpe 0:4bbc531be6e2 34 #define DMA_SSP0_TX (0)
dreschpe 0:4bbc531be6e2 35 #define DMA_DEST_SSP1_TX (2UL << 6)
dreschpe 0:4bbc531be6e2 36 #define DMA_DEST_SSP0_TX (0UL << 6)
dreschpe 0:4bbc531be6e2 37
dreschpe 0:4bbc531be6e2 38 /** Draw mode
dreschpe 0:4bbc531be6e2 39 * NORMAl
dreschpe 0:4bbc531be6e2 40 * XOR set pixel by xor the screen
dreschpe 0:4bbc531be6e2 41 */
dreschpe 0:4bbc531be6e2 42 enum {NORMAL,XOR};
dreschpe 0:4bbc531be6e2 43
dreschpe 0:4bbc531be6e2 44 class C12832_LCD : public GraphicsDisplay
dreschpe 0:4bbc531be6e2 45 {
dreschpe 0:4bbc531be6e2 46 public:
dreschpe 0:4bbc531be6e2 47 /** Create a C12832_LCD object connected to SPI1
dreschpe 0:4bbc531be6e2 48 *
dreschpe 0:4bbc531be6e2 49 */
dreschpe 0:4bbc531be6e2 50
dreschpe 0:4bbc531be6e2 51 C12832_LCD(const char* name = "LCD");
dreschpe 0:4bbc531be6e2 52
dreschpe 0:4bbc531be6e2 53 /** Get the width of the screen in pixel
dreschpe 0:4bbc531be6e2 54 *
dreschpe 0:4bbc531be6e2 55 * @param
dreschpe 0:4bbc531be6e2 56 * @returns width of screen in pixel
dreschpe 0:4bbc531be6e2 57 *
dreschpe 0:4bbc531be6e2 58 */
dreschpe 0:4bbc531be6e2 59 virtual int width();
dreschpe 0:4bbc531be6e2 60
dreschpe 0:4bbc531be6e2 61 /** Get the height of the screen in pixel
dreschpe 0:4bbc531be6e2 62 *
dreschpe 0:4bbc531be6e2 63 * @returns height of screen in pixel
dreschpe 0:4bbc531be6e2 64 *
dreschpe 0:4bbc531be6e2 65 */
dreschpe 0:4bbc531be6e2 66 virtual int height();
dreschpe 0:4bbc531be6e2 67
dreschpe 0:4bbc531be6e2 68 /** Draw a pixel at x,y black or white
dreschpe 0:4bbc531be6e2 69 *
dreschpe 0:4bbc531be6e2 70 * @param x horizontal position
dreschpe 0:4bbc531be6e2 71 * @param y vertical position
dreschpe 0:4bbc531be6e2 72 * @param colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 73 */
dreschpe 0:4bbc531be6e2 74 virtual void pixel(int x, int y,int colour);
dreschpe 0:4bbc531be6e2 75
dreschpe 0:4bbc531be6e2 76 /** draw a circle
dreschpe 0:4bbc531be6e2 77 *
dreschpe 0:4bbc531be6e2 78 * @param x0,y0 center
dreschpe 0:4bbc531be6e2 79 * @param r radius
dreschpe 0:4bbc531be6e2 80 * @param colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 81 *
dreschpe 0:4bbc531be6e2 82 */
dreschpe 0:4bbc531be6e2 83 void circle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 84
dreschpe 0:4bbc531be6e2 85 /** draw a filled circle
dreschpe 0:4bbc531be6e2 86 *
dreschpe 0:4bbc531be6e2 87 * @param x0,y0 center
dreschpe 0:4bbc531be6e2 88 * @param r radius
dreschpe 0:4bbc531be6e2 89 * @param color ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 90 *
dreschpe 0:4bbc531be6e2 91 * use circle with different radius,
dreschpe 0:4bbc531be6e2 92 * can miss some pixel
dreschpe 0:4bbc531be6e2 93 */
dreschpe 0:4bbc531be6e2 94 void fillcircle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 95
dreschpe 0:4bbc531be6e2 96 /** draw a 1 pixel line
dreschpe 0:4bbc531be6e2 97 *
dreschpe 0:4bbc531be6e2 98 * @param x0,y0 start point
dreschpe 0:4bbc531be6e2 99 * @param x1,y1 stop point
dreschpe 0:4bbc531be6e2 100 * @param color ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 101 *
dreschpe 0:4bbc531be6e2 102 */
dreschpe 0:4bbc531be6e2 103 void line(int x0, int y0, int x1, int y1, int colour);
dreschpe 0:4bbc531be6e2 104
dreschpe 0:4bbc531be6e2 105 /** draw a rect
dreschpe 0:4bbc531be6e2 106 *
dreschpe 0:4bbc531be6e2 107 * @param x0,y0 top left corner
dreschpe 0:4bbc531be6e2 108 * @param x1,y1 down right corner
dreschpe 0:4bbc531be6e2 109 * @param color 1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 110 * *
dreschpe 0:4bbc531be6e2 111 */
dreschpe 0:4bbc531be6e2 112 void rect(int x0, int y0, int x1, int y1, int colour);
dreschpe 0:4bbc531be6e2 113
dreschpe 0:4bbc531be6e2 114 /** draw a filled rect
dreschpe 0:4bbc531be6e2 115 *
dreschpe 0:4bbc531be6e2 116 * @param x0,y0 top left corner
dreschpe 0:4bbc531be6e2 117 * @param x1,y1 down right corner
dreschpe 0:4bbc531be6e2 118 * @param color 1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 119 *
dreschpe 0:4bbc531be6e2 120 */
dreschpe 0:4bbc531be6e2 121 void fillrect(int x0, int y0, int x1, int y1, int colour);
dreschpe 0:4bbc531be6e2 122
dreschpe 0:4bbc531be6e2 123 /** copy display buffer to lcd
dreschpe 0:4bbc531be6e2 124 *
dreschpe 0:4bbc531be6e2 125 */
dreschpe 0:4bbc531be6e2 126
dreschpe 0:4bbc531be6e2 127 void copy_to_lcd(void);
dreschpe 0:4bbc531be6e2 128
dreschpe 0:4bbc531be6e2 129 /** set the orienation of the screen
dreschpe 0:4bbc531be6e2 130 *
dreschpe 0:4bbc531be6e2 131 */
dreschpe 0:4bbc531be6e2 132
dreschpe 0:4bbc531be6e2 133 void set_orientation(unsigned int o);
dreschpe 0:4bbc531be6e2 134
dreschpe 0:4bbc531be6e2 135 /** set the contrast of the screen
dreschpe 0:4bbc531be6e2 136 *
dreschpe 0:4bbc531be6e2 137 */
dreschpe 0:4bbc531be6e2 138
dreschpe 0:4bbc531be6e2 139 void set_contrast(unsigned int o);
dreschpe 0:4bbc531be6e2 140
dreschpe 0:4bbc531be6e2 141 /** invert the screen
dreschpe 0:4bbc531be6e2 142 *
dreschpe 0:4bbc531be6e2 143 * @param o = 0 normal, 1 invert
dreschpe 0:4bbc531be6e2 144 */
dreschpe 0:4bbc531be6e2 145 void invert(unsigned int o);
dreschpe 0:4bbc531be6e2 146
dreschpe 0:4bbc531be6e2 147 /** clear the screen
dreschpe 0:4bbc531be6e2 148 *
dreschpe 0:4bbc531be6e2 149 */
dreschpe 0:4bbc531be6e2 150 virtual void cls(void);
dreschpe 0:4bbc531be6e2 151
dreschpe 0:4bbc531be6e2 152 /** set the drawing mode
dreschpe 0:4bbc531be6e2 153 *
dreschpe 0:4bbc531be6e2 154 * @param mode NORMAl or XOR
dreschpe 0:4bbc531be6e2 155 */
dreschpe 0:4bbc531be6e2 156
dreschpe 0:4bbc531be6e2 157 void setmode(int mode);
dreschpe 0:4bbc531be6e2 158
dreschpe 0:4bbc531be6e2 159 int columns(void);
dreschpe 0:4bbc531be6e2 160
dreschpe 0:4bbc531be6e2 161 /** calculate the max number of columns
dreschpe 0:4bbc531be6e2 162 *
dreschpe 0:4bbc531be6e2 163 * @returns max column
dreschpe 0:4bbc531be6e2 164 * depends on actual font size
dreschpe 0:4bbc531be6e2 165 *
dreschpe 0:4bbc531be6e2 166 */
dreschpe 0:4bbc531be6e2 167 int rows(void);
dreschpe 0:4bbc531be6e2 168
dreschpe 0:4bbc531be6e2 169 /** put a char on the screen
dreschpe 0:4bbc531be6e2 170 *
dreschpe 0:4bbc531be6e2 171 * @param value char to print
dreschpe 0:4bbc531be6e2 172 * @returns printed char
dreschpe 0:4bbc531be6e2 173 *
dreschpe 0:4bbc531be6e2 174 */
dreschpe 0:4bbc531be6e2 175 int _putc(int value);
dreschpe 0:4bbc531be6e2 176
dreschpe 0:4bbc531be6e2 177 /** draw a character on given position out of the active font to the LCD
dreschpe 0:4bbc531be6e2 178 *
dreschpe 0:4bbc531be6e2 179 * @param x x-position of char (top left)
dreschpe 0:4bbc531be6e2 180 * @param y y-position
dreschpe 0:4bbc531be6e2 181 * @param c char to print
dreschpe 0:4bbc531be6e2 182 *
dreschpe 0:4bbc531be6e2 183 */
dreschpe 0:4bbc531be6e2 184 virtual void character(int x, int y, int c);
dreschpe 0:4bbc531be6e2 185
dreschpe 0:4bbc531be6e2 186 /** setup cursor position
dreschpe 0:4bbc531be6e2 187 *
dreschpe 0:4bbc531be6e2 188 * @param x x-position (top left)
dreschpe 0:4bbc531be6e2 189 * @param y y-position
dreschpe 0:4bbc531be6e2 190 */
dreschpe 0:4bbc531be6e2 191 void locate(int x, int y);
dreschpe 0:4bbc531be6e2 192
dreschpe 0:4bbc531be6e2 193
dreschpe 0:4bbc531be6e2 194 /** Vars */
dreschpe 0:4bbc531be6e2 195 SPI _spi;
dreschpe 0:4bbc531be6e2 196 DigitalOut _reset;
dreschpe 0:4bbc531be6e2 197 DigitalOut _A0;
dreschpe 0:4bbc531be6e2 198 DigitalOut _CS;
dreschpe 0:4bbc531be6e2 199 unsigned char* font;
dreschpe 0:4bbc531be6e2 200 unsigned int draw_mode;
dreschpe 0:4bbc531be6e2 201
dreschpe 0:4bbc531be6e2 202
dreschpe 0:4bbc531be6e2 203 /** select the font to use
dreschpe 0:4bbc531be6e2 204 *
dreschpe 0:4bbc531be6e2 205 * @param f pointer to font array
dreschpe 0:4bbc531be6e2 206 *
dreschpe 0:4bbc531be6e2 207 * font array can created with GLCD Font Creator from http://www.mikroe.com
dreschpe 0:4bbc531be6e2 208 * you have to add 4 parameter at the beginning of the font array to use:
dreschpe 0:4bbc531be6e2 209 * - the number of byte / char
dreschpe 0:4bbc531be6e2 210 * - the vertial size in pixel
dreschpe 0:4bbc531be6e2 211 * - the horizontal size in pixel
dreschpe 0:4bbc531be6e2 212 * - the number of byte per vertical line
dreschpe 0:4bbc531be6e2 213 * you also have to change the array to char[]
dreschpe 0:4bbc531be6e2 214 *
dreschpe 0:4bbc531be6e2 215 */
dreschpe 0:4bbc531be6e2 216 void set_font(unsigned char* f);
dreschpe 0:4bbc531be6e2 217
dreschpe 0:4bbc531be6e2 218
dreschpe 0:4bbc531be6e2 219 protected:
dreschpe 0:4bbc531be6e2 220
dreschpe 0:4bbc531be6e2 221 /** draw a horizontal line
dreschpe 0:4bbc531be6e2 222 *
dreschpe 0:4bbc531be6e2 223 * @param x0 horizontal start
dreschpe 0:4bbc531be6e2 224 * @param x1 horizontal stop
dreschpe 0:4bbc531be6e2 225 * @param y vertical position
dreschpe 0:4bbc531be6e2 226 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 227 *
dreschpe 0:4bbc531be6e2 228 */
dreschpe 0:4bbc531be6e2 229 void hline(int x0, int x1, int y, int colour);
dreschpe 0:4bbc531be6e2 230
dreschpe 0:4bbc531be6e2 231 /** draw a vertical line
dreschpe 0:4bbc531be6e2 232 *
dreschpe 0:4bbc531be6e2 233 * @param x horizontal position
dreschpe 0:4bbc531be6e2 234 * @param y0 vertical start
dreschpe 0:4bbc531be6e2 235 * @param y1 vertical stop
dreschpe 0:4bbc531be6e2 236 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 237 */
dreschpe 0:4bbc531be6e2 238 void vline(int y0, int y1, int x, int colour);
dreschpe 0:4bbc531be6e2 239
dreschpe 0:4bbc531be6e2 240 /** Init the C12832 LCD controller
dreschpe 0:4bbc531be6e2 241 *
dreschpe 0:4bbc531be6e2 242 */
dreschpe 0:4bbc531be6e2 243 void lcd_reset();
dreschpe 0:4bbc531be6e2 244
dreschpe 0:4bbc531be6e2 245 /** Write data to the LCD controller
dreschpe 0:4bbc531be6e2 246 *
dreschpe 0:4bbc531be6e2 247 * @param dat data written to LCD controller
dreschpe 0:4bbc531be6e2 248 *
dreschpe 0:4bbc531be6e2 249 */
dreschpe 0:4bbc531be6e2 250 void wr_dat(unsigned char value);
dreschpe 0:4bbc531be6e2 251
dreschpe 0:4bbc531be6e2 252 /** Write a command the LCD controller
dreschpe 0:4bbc531be6e2 253 *
dreschpe 0:4bbc531be6e2 254 * @param cmd: command to be written
dreschpe 0:4bbc531be6e2 255 *
dreschpe 0:4bbc531be6e2 256 */
dreschpe 0:4bbc531be6e2 257 void wr_cmd(unsigned char value);
dreschpe 0:4bbc531be6e2 258
dreschpe 0:4bbc531be6e2 259 void wr_cnt(unsigned char cmd);
dreschpe 0:4bbc531be6e2 260
dreschpe 0:4bbc531be6e2 261 unsigned int orientation;
dreschpe 0:4bbc531be6e2 262 unsigned int char_x;
dreschpe 0:4bbc531be6e2 263 unsigned int char_y;
dreschpe 0:4bbc531be6e2 264 unsigned char buffer[512];
dreschpe 0:4bbc531be6e2 265
dreschpe 0:4bbc531be6e2 266 };
dreschpe 0:4bbc531be6e2 267
dreschpe 0:4bbc531be6e2 268
dreschpe 0:4bbc531be6e2 269
dreschpe 0:4bbc531be6e2 270
dreschpe 0:4bbc531be6e2 271 #endif