Lib for the LCD display on mbed lab Board

Fork of C12832_lcd by Peter Drescher

Committer:
co838_pld9
Date:
Sat May 07 17:43:42 2016 +0000
Revision:
11:6dd427fccfc6
LCD library;

Who changed what in which revision?

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