A C12832 LCD with generic interface

Dependents:   mbed_blinky HTTPClient_HelloWorld websocketandnode xbeerx ... more

Fork of C12832 by Chris Styles

Committer:
sam_grove
Date:
Fri May 09 23:03:21 2014 +0000
Revision:
18:03069e3deaa4
Parent:
17:1c3011afe95d
Hush compiler warning by changing the order of the constructor initialization list

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