Ken Todotani
/
eDISP
eDisp library and sample code
eDisp.h@0:e86010984e9a, 2010-03-07 (annotated)
- Committer:
- todotani
- Date:
- Sun Mar 07 00:45:31 2010 +0000
- Revision:
- 0:e86010984e9a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
todotani | 0:e86010984e9a | 1 | /* mbed eDISP Library |
todotani | 0:e86010984e9a | 2 | * Copyright (c) 2010 todotani |
todotani | 0:e86010984e9a | 3 | * Version 0.1 (March 6, 2010) |
todotani | 0:e86010984e9a | 4 | * Released under the MIT License: http://mbed.org/license/mit |
todotani | 0:e86010984e9a | 5 | */ |
todotani | 0:e86010984e9a | 6 | |
todotani | 0:e86010984e9a | 7 | #ifndef MBED_EDISP_H |
todotani | 0:e86010984e9a | 8 | #define MBED_EDISP_H |
todotani | 0:e86010984e9a | 9 | |
todotani | 0:e86010984e9a | 10 | #include "mbed.h" |
todotani | 0:e86010984e9a | 11 | #include "Stream.h" |
todotani | 0:e86010984e9a | 12 | |
todotani | 0:e86010984e9a | 13 | // Text Color code |
todotani | 0:e86010984e9a | 14 | #define BLACK 30 |
todotani | 0:e86010984e9a | 15 | #define RED 31 |
todotani | 0:e86010984e9a | 16 | #define GREEN 32 |
todotani | 0:e86010984e9a | 17 | #define YELLOW 33 |
todotani | 0:e86010984e9a | 18 | #define BLUE 34 |
todotani | 0:e86010984e9a | 19 | #define PURPLE 35 |
todotani | 0:e86010984e9a | 20 | #define AQUA 36 |
todotani | 0:e86010984e9a | 21 | #define WHITE 37 |
todotani | 0:e86010984e9a | 22 | #define TRANSPARENT 49 // default background color |
todotani | 0:e86010984e9a | 23 | |
todotani | 0:e86010984e9a | 24 | // RGB555 color code (converted from 32bit color code) |
todotani | 0:e86010984e9a | 25 | #define RGB_Black (0 << 10) + (0 << 5) + 0 |
todotani | 0:e86010984e9a | 26 | #define RGB_Navy (0 << 10) + (0 << 5) + 0x80/8 |
todotani | 0:e86010984e9a | 27 | #define RGB_Silver (0xc0/8 << 10) + (0xc0/8 << 5) + 0xc0/8 |
todotani | 0:e86010984e9a | 28 | #define RGB_Blue (0 << 10) + (0 << 5) + 0xff/8 |
todotani | 0:e86010984e9a | 29 | #define RGB_Maroon (0x80/8 << 10) + (0 << 5) + 0 |
todotani | 0:e86010984e9a | 30 | #define RGB_Purple (0x80/8 << 10) + (0 << 5) + 0x80/8 |
todotani | 0:e86010984e9a | 31 | #define RGB_Red (0xff/8 << 10) + (0 << 5) + 0 |
todotani | 0:e86010984e9a | 32 | #define RGB_Fuchsia (0xff/8 << 10) + (0 << 5) + 0xff/8 |
todotani | 0:e86010984e9a | 33 | #define RGB_Green (0 << 10) + (0x80/8 << 5) + 0 |
todotani | 0:e86010984e9a | 34 | #define RGB_Teal (0 << 10) + (0x80/8 << 5) + 0x80/8 |
todotani | 0:e86010984e9a | 35 | #define RGB_Lime (0 << 10) + (0xff/8 << 5) + 0 |
todotani | 0:e86010984e9a | 36 | #define RGB_Aqua (0 << 10) + (0xff/8 << 5) + 0xff/8 |
todotani | 0:e86010984e9a | 37 | #define RGB_Olive (0x80/8 << 10) + (0x80/8 << 5) + 0 |
todotani | 0:e86010984e9a | 38 | #define RGB_Gray (0x80/8 << 10) + (0x80/8 << 5) + 0x80/8 |
todotani | 0:e86010984e9a | 39 | #define RGB_Yellow (0xff/8 << 10) + (0xff/8 << 5) + 0 |
todotani | 0:e86010984e9a | 40 | #define RGB_White (0xff/8 << 10) + (0xff/8 << 5) + 0xff/8 |
todotani | 0:e86010984e9a | 41 | |
todotani | 0:e86010984e9a | 42 | |
todotani | 0:e86010984e9a | 43 | namespace mbed { |
todotani | 0:e86010984e9a | 44 | |
todotani | 0:e86010984e9a | 45 | /* Class: eDisp |
todotani | 0:e86010984e9a | 46 | * Driver for eDISP (http://www.ddlab.jp/shop/edisp/syouhin.cgi) |
todotani | 0:e86010984e9a | 47 | * |
todotani | 0:e86010984e9a | 48 | * Allows you to print to a Text LCD screen, set color and locate/cls. |
todotani | 0:e86010984e9a | 49 | * Also support graphics functions fillRect, drawLine |
todotani | 0:e86010984e9a | 50 | * |
todotani | 0:e86010984e9a | 51 | */ |
todotani | 0:e86010984e9a | 52 | class eDisp : public Stream { |
todotani | 0:e86010984e9a | 53 | public: |
todotani | 0:e86010984e9a | 54 | /* Constructor: eDisp |
todotani | 0:e86010984e9a | 55 | * Create a eDisp object, connected to the specified pins |
todotani | 0:e86010984e9a | 56 | * |
todotani | 0:e86010984e9a | 57 | * All signals must be connected to pair of Serial Tx/Rx pin |
todotani | 0:e86010984e9a | 58 | * (p9/p10, p13/p14 or p28/p27) |
todotani | 0:e86010984e9a | 59 | * |
todotani | 0:e86010984e9a | 60 | * Variables: |
todotani | 0:e86010984e9a | 61 | * tx - Used to specify tx of Serial port |
todotani | 0:e86010984e9a | 62 | * rx - Used to specify rx of Serial port (acturally not used) |
todotani | 0:e86010984e9a | 63 | * baud - baudrate of serial port |
todotani | 0:e86010984e9a | 64 | */ |
todotani | 0:e86010984e9a | 65 | eDisp(PinName tx, PinName rx, int baud = 19200, |
todotani | 0:e86010984e9a | 66 | int columns = 40, int rows = 15); |
todotani | 0:e86010984e9a | 67 | |
todotani | 0:e86010984e9a | 68 | #if 0 // Inhereted from Stream, for documentation only |
todotani | 0:e86010984e9a | 69 | /* Function: putc |
todotani | 0:e86010984e9a | 70 | * Write a character |
todotani | 0:e86010984e9a | 71 | * |
todotani | 0:e86010984e9a | 72 | * Variables: |
todotani | 0:e86010984e9a | 73 | * c - The character to write to the serial port |
todotani | 0:e86010984e9a | 74 | */ |
todotani | 0:e86010984e9a | 75 | int putc(int c); |
todotani | 0:e86010984e9a | 76 | |
todotani | 0:e86010984e9a | 77 | /* Function: printf |
todotani | 0:e86010984e9a | 78 | * Write a formated string |
todotani | 0:e86010984e9a | 79 | * |
todotani | 0:e86010984e9a | 80 | * Variables: |
todotani | 0:e86010984e9a | 81 | * format - A printf-style format string, followed by the |
todotani | 0:e86010984e9a | 82 | * variables to use in formating the string. |
todotani | 0:e86010984e9a | 83 | */ |
todotani | 0:e86010984e9a | 84 | int printf(const char* format, ...); |
todotani | 0:e86010984e9a | 85 | #endif |
todotani | 0:e86010984e9a | 86 | |
todotani | 0:e86010984e9a | 87 | /* Function: locate |
todotani | 0:e86010984e9a | 88 | * set cursor position |
todotani | 0:e86010984e9a | 89 | * Variables: |
todotani | 0:e86010984e9a | 90 | * colum - x position (0 - 39) |
todotani | 0:e86010984e9a | 91 | * row - y position (0 - 14) |
todotani | 0:e86010984e9a | 92 | */ |
todotani | 0:e86010984e9a | 93 | void locate(int column, int row); |
todotani | 0:e86010984e9a | 94 | |
todotani | 0:e86010984e9a | 95 | /* Function: textColor |
todotani | 0:e86010984e9a | 96 | * Set text color |
todotani | 0:e86010984e9a | 97 | * Variables: |
todotani | 0:e86010984e9a | 98 | * color - Text color code |
todotani | 0:e86010984e9a | 99 | */ |
todotani | 0:e86010984e9a | 100 | void textColor(int color); |
todotani | 0:e86010984e9a | 101 | |
todotani | 0:e86010984e9a | 102 | /* Function: backgroundColor |
todotani | 0:e86010984e9a | 103 | * Set backgound color |
todotani | 0:e86010984e9a | 104 | * Variables: |
todotani | 0:e86010984e9a | 105 | * color - Text color code |
todotani | 0:e86010984e9a | 106 | */ |
todotani | 0:e86010984e9a | 107 | void backgroundColor(int color); |
todotani | 0:e86010984e9a | 108 | |
todotani | 0:e86010984e9a | 109 | /* Function: cls |
todotani | 0:e86010984e9a | 110 | * Clear the screen, and locate to 0,0 |
todotani | 0:e86010984e9a | 111 | */ |
todotani | 0:e86010984e9a | 112 | void cls(); |
todotani | 0:e86010984e9a | 113 | |
todotani | 0:e86010984e9a | 114 | /* Function: reset |
todotani | 0:e86010984e9a | 115 | * Set default text/backgroudn color, clear the screen, and locate to 0,0 |
todotani | 0:e86010984e9a | 116 | */ |
todotani | 0:e86010984e9a | 117 | void reset(); |
todotani | 0:e86010984e9a | 118 | |
todotani | 0:e86010984e9a | 119 | /* Function: fillRect |
todotani | 0:e86010984e9a | 120 | * Fill secreen with specified color |
todotani | 0:e86010984e9a | 121 | * Variables: |
todotani | 0:e86010984e9a | 122 | * buffer - number of screen buffer (0 - 3) |
todotani | 0:e86010984e9a | 123 | * width - width of rectangle (1 - 320) |
todotani | 0:e86010984e9a | 124 | * hight - hight of rectangle (1 - 240) |
todotani | 0:e86010984e9a | 125 | * x - x coordinate (0 - 319) of upper left point |
todotani | 0:e86010984e9a | 126 | * y - y coordinate (0 - 239) of upper left point |
todotani | 0:e86010984e9a | 127 | * color - RGB555 color code 0rrrrrgggggbbbbb |
todotani | 0:e86010984e9a | 128 | */ |
todotani | 0:e86010984e9a | 129 | void fillRect(int buffer, int width, int hight, int x, int y, int color ); |
todotani | 0:e86010984e9a | 130 | |
todotani | 0:e86010984e9a | 131 | /* Function: drawLine |
todotani | 0:e86010984e9a | 132 | * draw line from (x0, y0) to (x1, y1) |
todotani | 0:e86010984e9a | 133 | * Variables: |
todotani | 0:e86010984e9a | 134 | * buffer - number of screen buffer (0 - 3) |
todotani | 0:e86010984e9a | 135 | * x0 - coordinate x (0 - 319) of start point |
todotani | 0:e86010984e9a | 136 | * y0 - coordinate y (0 - 319) of start point |
todotani | 0:e86010984e9a | 137 | * x1 - coordinate x (0 - 319) of end point |
todotani | 0:e86010984e9a | 138 | * y1 - coordinate y (0 - 319) of end point |
todotani | 0:e86010984e9a | 139 | * color - RGB555 color code 0rrrrrgggggbbbbb |
todotani | 0:e86010984e9a | 140 | */ |
todotani | 0:e86010984e9a | 141 | void drawLine(int buffer, int x0, int y0, int x1, int y1, int color); |
todotani | 0:e86010984e9a | 142 | |
todotani | 0:e86010984e9a | 143 | protected: |
todotani | 0:e86010984e9a | 144 | virtual int _putc(int c); |
todotani | 0:e86010984e9a | 145 | virtual int _getc(); |
todotani | 0:e86010984e9a | 146 | void newline(); |
todotani | 0:e86010984e9a | 147 | |
todotani | 0:e86010984e9a | 148 | Serial _serial; |
todotani | 0:e86010984e9a | 149 | int _baud; |
todotani | 0:e86010984e9a | 150 | int _row; |
todotani | 0:e86010984e9a | 151 | int _column; |
todotani | 0:e86010984e9a | 152 | int _columns; // Number of max columns |
todotani | 0:e86010984e9a | 153 | int _rows; // Number of max rows |
todotani | 0:e86010984e9a | 154 | }; |
todotani | 0:e86010984e9a | 155 | |
todotani | 0:e86010984e9a | 156 | #endif |
todotani | 0:e86010984e9a | 157 | } |