LCD

Fork of C12832 by Chris Styles

Committer:
dreschpe
Date:
Fri Dec 21 20:43:59 2012 +0000
Revision:
7:0f5a3b0f3cab
Parent:
6:6b96b16aad47
Child:
12:4affce236743
Add bitmap graphic

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 1:66dd8afbfd06 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 1:66dd8afbfd06 38 /** Draw mode
dreschpe 1:66dd8afbfd06 39 * NORMAl
dreschpe 1:66dd8afbfd06 40 * XOR set pixel by xor the screen
dreschpe 1:66dd8afbfd06 41 */
dreschpe 0:4bbc531be6e2 42 enum {NORMAL,XOR};
dreschpe 0:4bbc531be6e2 43
dreschpe 7:0f5a3b0f3cab 44 /** Bitmap
dreschpe 7:0f5a3b0f3cab 45 */
dreschpe 7:0f5a3b0f3cab 46 struct Bitmap{
dreschpe 7:0f5a3b0f3cab 47 int xSize;
dreschpe 7:0f5a3b0f3cab 48 int ySize;
dreschpe 7:0f5a3b0f3cab 49 int Byte_in_Line;
dreschpe 7:0f5a3b0f3cab 50 char* data;
dreschpe 7:0f5a3b0f3cab 51 };
dreschpe 7:0f5a3b0f3cab 52
dreschpe 0:4bbc531be6e2 53 class C12832_LCD : public GraphicsDisplay
dreschpe 0:4bbc531be6e2 54 {
dreschpe 0:4bbc531be6e2 55 public:
dreschpe 0:4bbc531be6e2 56 /** Create a C12832_LCD object connected to SPI1
dreschpe 0:4bbc531be6e2 57 *
dreschpe 0:4bbc531be6e2 58 */
dreschpe 0:4bbc531be6e2 59
dreschpe 0:4bbc531be6e2 60 C12832_LCD(const char* name = "LCD");
dreschpe 0:4bbc531be6e2 61
dreschpe 0:4bbc531be6e2 62 /** Get the width of the screen in pixel
dreschpe 0:4bbc531be6e2 63 *
dreschpe 0:4bbc531be6e2 64 * @param
dreschpe 0:4bbc531be6e2 65 * @returns width of screen in pixel
dreschpe 0:4bbc531be6e2 66 *
dreschpe 0:4bbc531be6e2 67 */
dreschpe 0:4bbc531be6e2 68 virtual int width();
dreschpe 0:4bbc531be6e2 69
dreschpe 0:4bbc531be6e2 70 /** Get the height of the screen in pixel
dreschpe 0:4bbc531be6e2 71 *
dreschpe 0:4bbc531be6e2 72 * @returns height of screen in pixel
dreschpe 0:4bbc531be6e2 73 *
dreschpe 0:4bbc531be6e2 74 */
dreschpe 0:4bbc531be6e2 75 virtual int height();
dreschpe 0:4bbc531be6e2 76
dreschpe 0:4bbc531be6e2 77 /** Draw a pixel at x,y black or white
dreschpe 0:4bbc531be6e2 78 *
dreschpe 0:4bbc531be6e2 79 * @param x horizontal position
dreschpe 0:4bbc531be6e2 80 * @param y vertical position
dreschpe 0:4bbc531be6e2 81 * @param colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 82 */
dreschpe 0:4bbc531be6e2 83 virtual void pixel(int x, int y,int colour);
dreschpe 0:4bbc531be6e2 84
dreschpe 0:4bbc531be6e2 85 /** draw a 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 colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 90 *
dreschpe 0:4bbc531be6e2 91 */
dreschpe 0:4bbc531be6e2 92 void circle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 93
dreschpe 0:4bbc531be6e2 94 /** draw a filled circle
dreschpe 0:4bbc531be6e2 95 *
dreschpe 0:4bbc531be6e2 96 * @param x0,y0 center
dreschpe 0:4bbc531be6e2 97 * @param r radius
dreschpe 0:4bbc531be6e2 98 * @param color ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 99 *
dreschpe 0:4bbc531be6e2 100 * use circle with different radius,
dreschpe 0:4bbc531be6e2 101 * can miss some pixel
dreschpe 0:4bbc531be6e2 102 */
dreschpe 0:4bbc531be6e2 103 void fillcircle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 104
dreschpe 0:4bbc531be6e2 105 /** draw a 1 pixel line
dreschpe 0:4bbc531be6e2 106 *
dreschpe 0:4bbc531be6e2 107 * @param x0,y0 start point
dreschpe 0:4bbc531be6e2 108 * @param x1,y1 stop point
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 line(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 113
dreschpe 0:4bbc531be6e2 114 /** draw a rect
dreschpe 1:66dd8afbfd06 115 *
dreschpe 1:66dd8afbfd06 116 * @param x0,y0 top left corner
dreschpe 1:66dd8afbfd06 117 * @param x1,y1 down right corner
dreschpe 1:66dd8afbfd06 118 * @param color 1 set pixel ,0 erase pixel
dreschpe 1:66dd8afbfd06 119 * *
dreschpe 1:66dd8afbfd06 120 */
dreschpe 1:66dd8afbfd06 121 void rect(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 122
dreschpe 1:66dd8afbfd06 123 /** draw a filled rect
dreschpe 1:66dd8afbfd06 124 *
dreschpe 1:66dd8afbfd06 125 * @param x0,y0 top left corner
dreschpe 1:66dd8afbfd06 126 * @param x1,y1 down right corner
dreschpe 1:66dd8afbfd06 127 * @param color 1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 128 *
dreschpe 0:4bbc531be6e2 129 */
dreschpe 1:66dd8afbfd06 130 void fillrect(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 131
dreschpe 1:66dd8afbfd06 132 /** copy display buffer to lcd
dreschpe 1:66dd8afbfd06 133 *
dreschpe 1:66dd8afbfd06 134 */
dreschpe 1:66dd8afbfd06 135
dreschpe 0:4bbc531be6e2 136 void copy_to_lcd(void);
dreschpe 0:4bbc531be6e2 137
dreschpe 0:4bbc531be6e2 138 /** set the orienation of the screen
dreschpe 1:66dd8afbfd06 139 *
dreschpe 1:66dd8afbfd06 140 */
dreschpe 1:66dd8afbfd06 141
dreschpe 1:66dd8afbfd06 142 //void set_orientation(unsigned int o);
dreschpe 0:4bbc531be6e2 143
dreschpe 1:66dd8afbfd06 144 /** set the contrast of the screen
dreschpe 1:66dd8afbfd06 145 *
dreschpe 1:66dd8afbfd06 146 * @param o contrast 0-63
dreschpe 1:66dd8afbfd06 147 */
dreschpe 0:4bbc531be6e2 148
dreschpe 0:4bbc531be6e2 149 void set_contrast(unsigned int o);
dreschpe 1:66dd8afbfd06 150
dreschpe 1:66dd8afbfd06 151 /** read the contrast level
dreschpe 1:66dd8afbfd06 152 *
dreschpe 1:66dd8afbfd06 153 */
dreschpe 1:66dd8afbfd06 154 unsigned int get_contrast(void);
dreschpe 1:66dd8afbfd06 155
dreschpe 1:66dd8afbfd06 156
dreschpe 1:66dd8afbfd06 157
dreschpe 1:66dd8afbfd06 158 /** invert the screen
dreschpe 1:66dd8afbfd06 159 *
dreschpe 1:66dd8afbfd06 160 * @param o = 0 normal, 1 invert
dreschpe 1:66dd8afbfd06 161 */
dreschpe 0:4bbc531be6e2 162 void invert(unsigned int o);
dreschpe 1:66dd8afbfd06 163
dreschpe 1:66dd8afbfd06 164 /** clear the screen
dreschpe 1:66dd8afbfd06 165 *
dreschpe 1:66dd8afbfd06 166 */
dreschpe 1:66dd8afbfd06 167 virtual void cls(void);
dreschpe 1:66dd8afbfd06 168
dreschpe 1:66dd8afbfd06 169 /** set the drawing mode
dreschpe 1:66dd8afbfd06 170 *
dreschpe 1:66dd8afbfd06 171 * @param mode NORMAl or XOR
dreschpe 1:66dd8afbfd06 172 */
dreschpe 1:66dd8afbfd06 173
dreschpe 1:66dd8afbfd06 174 void setmode(int mode);
dreschpe 1:66dd8afbfd06 175
dreschpe 6:6b96b16aad47 176 virtual int columns(void);
dreschpe 1:66dd8afbfd06 177
dreschpe 1:66dd8afbfd06 178 /** calculate the max number of columns
dreschpe 1:66dd8afbfd06 179 *
dreschpe 1:66dd8afbfd06 180 * @returns max column
dreschpe 1:66dd8afbfd06 181 * depends on actual font size
dreschpe 1:66dd8afbfd06 182 *
dreschpe 1:66dd8afbfd06 183 */
dreschpe 6:6b96b16aad47 184 virtual int rows(void);
dreschpe 1:66dd8afbfd06 185
dreschpe 1:66dd8afbfd06 186 /** put a char on the screen
dreschpe 1:66dd8afbfd06 187 *
dreschpe 1:66dd8afbfd06 188 * @param value char to print
dreschpe 1:66dd8afbfd06 189 * @returns printed char
dreschpe 1:66dd8afbfd06 190 *
dreschpe 1:66dd8afbfd06 191 */
dreschpe 6:6b96b16aad47 192 virtual int _putc(int value);
dreschpe 1:66dd8afbfd06 193
dreschpe 1:66dd8afbfd06 194 /** draw a character on given position out of the active font to the LCD
dreschpe 1:66dd8afbfd06 195 *
dreschpe 1:66dd8afbfd06 196 * @param x x-position of char (top left)
dreschpe 1:66dd8afbfd06 197 * @param y y-position
dreschpe 1:66dd8afbfd06 198 * @param c char to print
dreschpe 1:66dd8afbfd06 199 *
dreschpe 1:66dd8afbfd06 200 */
dreschpe 1:66dd8afbfd06 201 virtual void character(int x, int y, int c);
dreschpe 1:66dd8afbfd06 202
dreschpe 1:66dd8afbfd06 203 /** setup cursor position
dreschpe 1:66dd8afbfd06 204 *
dreschpe 1:66dd8afbfd06 205 * @param x x-position (top left)
dreschpe 1:66dd8afbfd06 206 * @param y y-position
dreschpe 1:66dd8afbfd06 207 */
dreschpe 6:6b96b16aad47 208 virtual void locate(int x, int y);
dreschpe 3:468cdccff7af 209
dreschpe 3:468cdccff7af 210 /** setup auto update of screen
dreschpe 3:468cdccff7af 211 *
dreschpe 3:468cdccff7af 212 * @param up 1 = on , 0 = off
dreschpe 3:468cdccff7af 213 * if switched off the program has to call copy_to_lcd()
dreschpe 3:468cdccff7af 214 * to update screen from framebuffer
dreschpe 3:468cdccff7af 215 */
dreschpe 5:0f53e522a2bf 216 void set_auto_up(unsigned int up);
dreschpe 1:66dd8afbfd06 217
dreschpe 3:468cdccff7af 218 /** get status of the auto update function
dreschpe 3:468cdccff7af 219 *
dreschpe 3:468cdccff7af 220 * @returns if auto update is on
dreschpe 3:468cdccff7af 221 */
dreschpe 5:0f53e522a2bf 222 unsigned int get_auto_up(void);
dreschpe 0:4bbc531be6e2 223
dreschpe 0:4bbc531be6e2 224 /** Vars */
dreschpe 0:4bbc531be6e2 225 SPI _spi;
dreschpe 0:4bbc531be6e2 226 DigitalOut _reset;
dreschpe 0:4bbc531be6e2 227 DigitalOut _A0;
dreschpe 0:4bbc531be6e2 228 DigitalOut _CS;
dreschpe 0:4bbc531be6e2 229 unsigned char* font;
dreschpe 0:4bbc531be6e2 230 unsigned int draw_mode;
dreschpe 0:4bbc531be6e2 231
dreschpe 0:4bbc531be6e2 232
dreschpe 1:66dd8afbfd06 233 /** select the font to use
dreschpe 1:66dd8afbfd06 234 *
dreschpe 1:66dd8afbfd06 235 * @param f pointer to font array
dreschpe 1:66dd8afbfd06 236 *
dreschpe 1:66dd8afbfd06 237 * font array can created with GLCD Font Creator from http://www.mikroe.com
dreschpe 1:66dd8afbfd06 238 * you have to add 4 parameter at the beginning of the font array to use:
dreschpe 1:66dd8afbfd06 239 * - the number of byte / char
dreschpe 1:66dd8afbfd06 240 * - the vertial size in pixel
dreschpe 1:66dd8afbfd06 241 * - the horizontal size in pixel
dreschpe 1:66dd8afbfd06 242 * - the number of byte per vertical line
dreschpe 1:66dd8afbfd06 243 * you also have to change the array to char[]
dreschpe 1:66dd8afbfd06 244 *
dreschpe 1:66dd8afbfd06 245 */
dreschpe 1:66dd8afbfd06 246 void set_font(unsigned char* f);
dreschpe 7:0f5a3b0f3cab 247
dreschpe 7:0f5a3b0f3cab 248 /** print bitmap to buffer
dreschpe 7:0f5a3b0f3cab 249 *
dreschpe 7:0f5a3b0f3cab 250 * @param bm Bitmap in flash
dreschpe 7:0f5a3b0f3cab 251 * @param x x start
dreschpe 7:0f5a3b0f3cab 252 * @param y y start
dreschpe 7:0f5a3b0f3cab 253 *
dreschpe 7:0f5a3b0f3cab 254 */
dreschpe 0:4bbc531be6e2 255
dreschpe 7:0f5a3b0f3cab 256 void print_bm(Bitmap bm, int x, int y);
dreschpe 0:4bbc531be6e2 257
dreschpe 0:4bbc531be6e2 258 protected:
dreschpe 0:4bbc531be6e2 259
dreschpe 0:4bbc531be6e2 260 /** draw a horizontal line
dreschpe 0:4bbc531be6e2 261 *
dreschpe 0:4bbc531be6e2 262 * @param x0 horizontal start
dreschpe 0:4bbc531be6e2 263 * @param x1 horizontal stop
dreschpe 0:4bbc531be6e2 264 * @param y vertical position
dreschpe 0:4bbc531be6e2 265 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 266 *
dreschpe 0:4bbc531be6e2 267 */
dreschpe 0:4bbc531be6e2 268 void hline(int x0, int x1, int y, int colour);
dreschpe 0:4bbc531be6e2 269
dreschpe 0:4bbc531be6e2 270 /** draw a vertical line
dreschpe 0:4bbc531be6e2 271 *
dreschpe 0:4bbc531be6e2 272 * @param x horizontal position
dreschpe 0:4bbc531be6e2 273 * @param y0 vertical start
dreschpe 0:4bbc531be6e2 274 * @param y1 vertical stop
dreschpe 0:4bbc531be6e2 275 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 276 */
dreschpe 0:4bbc531be6e2 277 void vline(int y0, int y1, int x, int colour);
dreschpe 0:4bbc531be6e2 278
dreschpe 0:4bbc531be6e2 279 /** Init the C12832 LCD controller
dreschpe 0:4bbc531be6e2 280 *
dreschpe 0:4bbc531be6e2 281 */
dreschpe 0:4bbc531be6e2 282 void lcd_reset();
dreschpe 0:4bbc531be6e2 283
dreschpe 0:4bbc531be6e2 284 /** Write data to the LCD controller
dreschpe 0:4bbc531be6e2 285 *
dreschpe 0:4bbc531be6e2 286 * @param dat data written to LCD controller
dreschpe 0:4bbc531be6e2 287 *
dreschpe 0:4bbc531be6e2 288 */
dreschpe 0:4bbc531be6e2 289 void wr_dat(unsigned char value);
dreschpe 0:4bbc531be6e2 290
dreschpe 0:4bbc531be6e2 291 /** Write a command the LCD controller
dreschpe 0:4bbc531be6e2 292 *
dreschpe 0:4bbc531be6e2 293 * @param cmd: command to be written
dreschpe 0:4bbc531be6e2 294 *
dreschpe 0:4bbc531be6e2 295 */
dreschpe 0:4bbc531be6e2 296 void wr_cmd(unsigned char value);
dreschpe 1:66dd8afbfd06 297
dreschpe 0:4bbc531be6e2 298 void wr_cnt(unsigned char cmd);
dreschpe 0:4bbc531be6e2 299
dreschpe 0:4bbc531be6e2 300 unsigned int orientation;
dreschpe 0:4bbc531be6e2 301 unsigned int char_x;
dreschpe 0:4bbc531be6e2 302 unsigned int char_y;
dreschpe 0:4bbc531be6e2 303 unsigned char buffer[512];
dreschpe 1:66dd8afbfd06 304 unsigned int contrast;
dreschpe 3:468cdccff7af 305 unsigned int auto_up;
dreschpe 0:4bbc531be6e2 306
dreschpe 0:4bbc531be6e2 307 };
dreschpe 0:4bbc531be6e2 308
dreschpe 0:4bbc531be6e2 309
dreschpe 0:4bbc531be6e2 310
dreschpe 0:4bbc531be6e2 311
dreschpe 0:4bbc531be6e2 312 #endif