epaper

Dependents:   epaper_mbed_test_copy1

Fork of EaEpaper by Peter Drescher

Committer:
fenoth
Date:
Tue Apr 08 10:07:49 2014 +0000
Revision:
3:6e990a69c6cf
Parent:
2:1f3672176ca3
new

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:fedcef5319f5 1 /* mbed library for 264*176 pixel 2.7 INCH E-PAPER DISPLAY from Pervasive Displays
dreschpe 0:fedcef5319f5 2 * Copyright (c) 2013 Peter Drescher - DC2PD
dreschpe 0:fedcef5319f5 3 *
dreschpe 0:fedcef5319f5 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:fedcef5319f5 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:fedcef5319f5 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:fedcef5319f5 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:fedcef5319f5 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:fedcef5319f5 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:fedcef5319f5 10 * THE SOFTWARE.
dreschpe 0:fedcef5319f5 11 */
dreschpe 0:fedcef5319f5 12
dreschpe 0:fedcef5319f5 13
dreschpe 0:fedcef5319f5 14 // 09.11.2013 initial Version
dreschpe 0:fedcef5319f5 15
dreschpe 0:fedcef5319f5 16 #ifndef EAEPAPER_H
dreschpe 0:fedcef5319f5 17 #define EAEPAPER_H
dreschpe 0:fedcef5319f5 18
dreschpe 0:fedcef5319f5 19 /**
dreschpe 0:fedcef5319f5 20 * Includes
dreschpe 0:fedcef5319f5 21 */
dreschpe 0:fedcef5319f5 22 #include "mbed.h"
dreschpe 0:fedcef5319f5 23 #include "EPD.h"
dreschpe 0:fedcef5319f5 24 #include "GraphicsDisplay.h"
dreschpe 0:fedcef5319f5 25
dreschpe 0:fedcef5319f5 26 // we have to double buffer the display
dreschpe 0:fedcef5319f5 27 #define EA_IMG_BUF_SZ (5808) // 264 x 176 / 8 = 5808
dreschpe 0:fedcef5319f5 28
dreschpe 0:fedcef5319f5 29 /** Draw mode
dreschpe 0:fedcef5319f5 30 * NORMAl
dreschpe 0:fedcef5319f5 31 * XOR set pixel by xor of the screen
dreschpe 0:fedcef5319f5 32 */
dreschpe 0:fedcef5319f5 33 enum {NORMAL,XOR};
dreschpe 0:fedcef5319f5 34
dreschpe 0:fedcef5319f5 35 /** Bitmap
dreschpe 0:fedcef5319f5 36 */
dreschpe 0:fedcef5319f5 37 struct Bitmap{
dreschpe 0:fedcef5319f5 38 int xSize;
dreschpe 0:fedcef5319f5 39 int ySize;
dreschpe 0:fedcef5319f5 40 int Byte_in_Line;
dreschpe 0:fedcef5319f5 41 char* data;
dreschpe 0:fedcef5319f5 42 };
dreschpe 0:fedcef5319f5 43
dreschpe 0:fedcef5319f5 44 /* color definitions */
dreschpe 0:fedcef5319f5 45 #define Black 0x0
dreschpe 0:fedcef5319f5 46 #define White 0x1
dreschpe 0:fedcef5319f5 47
dreschpe 0:fedcef5319f5 48 /** Display control class, based on GraphicsDisplay and TextDisplay
dreschpe 0:fedcef5319f5 49 *
dreschpe 1:90d18805a8a4 50 * Example with pinning for KL25Z:
dreschpe 0:fedcef5319f5 51 * @code
dreschpe 0:fedcef5319f5 52 * #include "mbed.h"
dreschpe 0:fedcef5319f5 53 * #include "EaEpaper.h"
dreschpe 0:fedcef5319f5 54 * #include "Arial28x28.h"
dreschpe 0:fedcef5319f5 55 * #include "Arial12x12.h"
dreschpe 0:fedcef5319f5 56 * #include "font_big.h"
dreschpe 0:fedcef5319f5 57 * #include "graphics.h"
dreschpe 0:fedcef5319f5 58
dreschpe 0:fedcef5319f5 59 * // the E-Paper board from embedded artists has a LM75 temp sensor to compensate the temperature effect. If it is cold the display reacts slower.
dreschpe 0:fedcef5319f5 60 * // The LM75 need a I2C -> 2 pins : sda and scl
dreschpe 0:fedcef5319f5 61 * // The display data is written via SPI -> 3 pins : mosi,miso,sck
dreschpe 0:fedcef5319f5 62 * // There are also some control signals
dreschpe 0:fedcef5319f5 63 * // The pwm pin has to be connected to a PWM enabled pin : pwm
dreschpe 0:fedcef5319f5 64 * // The other signals are connected to normal IO`s
dreschpe 0:fedcef5319f5 65 * //
dreschpe 0:fedcef5319f5 66 * EaEpaper epaper(PTD7, // PWR_CTRL
dreschpe 0:fedcef5319f5 67 * PTD6, // BORDER
dreschpe 0:fedcef5319f5 68 * PTE31, // DISCHARGE
dreschpe 0:fedcef5319f5 69 * PTA17, // RESET_DISP
dreschpe 0:fedcef5319f5 70 * PTA16, // BUSY
dreschpe 0:fedcef5319f5 71 * PTC17, // SSEL
dreschpe 0:fedcef5319f5 72 * PTD4, // PWM
dreschpe 0:fedcef5319f5 73 * PTD2,PTD3,PTD1, // MOSI,MISO,SCLK
dreschpe 2:1f3672176ca3 74 * PTE0,PTE1); // SDA,SCL
dreschpe 0:fedcef5319f5 75 *
dreschpe 0:fedcef5319f5 76 * int main() {
dreschpe 0:fedcef5319f5 77 *
dreschpe 0:fedcef5319f5 78 * epaper.cls(); // clear screen
dreschpe 0:fedcef5319f5 79 * epaper.set_font((unsigned char*) Arial28x28); // select the font
dreschpe 0:fedcef5319f5 80 * epaper.locate(5,20); // set cursor
dreschpe 0:fedcef5319f5 81 * epaper.printf("Hello Mbed"); // print text
dreschpe 0:fedcef5319f5 82 * epaper.rect(3,15,150,50,1); // draw frame
dreschpe 0:fedcef5319f5 83 * epaper.write_disp(); // update screen
dreschpe 0:fedcef5319f5 84 *
dreschpe 0:fedcef5319f5 85 * @endcode
dreschpe 0:fedcef5319f5 86 */
dreschpe 0:fedcef5319f5 87
dreschpe 0:fedcef5319f5 88
dreschpe 0:fedcef5319f5 89 class EaEpaper : public GraphicsDisplay {
dreschpe 0:fedcef5319f5 90
dreschpe 0:fedcef5319f5 91 public:
dreschpe 0:fedcef5319f5 92
dreschpe 0:fedcef5319f5 93 /**
dreschpe 0:fedcef5319f5 94 * Constructor.
dreschpe 0:fedcef5319f5 95 */
dreschpe 0:fedcef5319f5 96 EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs, // IO-Pins
dreschpe 0:fedcef5319f5 97 PinName pwm, // PWM Pin
dreschpe 0:fedcef5319f5 98 PinName mosi, PinName miso, PinName sck, // SPI
dreschpe 0:fedcef5319f5 99 PinName sda, PinName scl, // I2C
dreschpe 0:fedcef5319f5 100 const char* name ="E_Paper");
dreschpe 0:fedcef5319f5 101
dreschpe 0:fedcef5319f5 102 /** Get the width of the screen in pixel
dreschpe 0:fedcef5319f5 103 *
dreschpe 0:fedcef5319f5 104 * @param
dreschpe 0:fedcef5319f5 105 * @returns width of screen in pixel
dreschpe 0:fedcef5319f5 106 *
dreschpe 0:fedcef5319f5 107 */
dreschpe 0:fedcef5319f5 108 virtual int width();
dreschpe 0:fedcef5319f5 109
dreschpe 0:fedcef5319f5 110 /** Get the height of the screen in pixel
dreschpe 0:fedcef5319f5 111 *
dreschpe 0:fedcef5319f5 112 * @returns height of screen in pixel
dreschpe 0:fedcef5319f5 113 *
dreschpe 0:fedcef5319f5 114 */
dreschpe 0:fedcef5319f5 115 virtual int height();
dreschpe 0:fedcef5319f5 116
dreschpe 0:fedcef5319f5 117
dreschpe 0:fedcef5319f5 118 /**
dreschpe 0:fedcef5319f5 119 * Clear the display
dreschpe 0:fedcef5319f5 120 */
dreschpe 0:fedcef5319f5 121 void clear();
dreschpe 0:fedcef5319f5 122
dreschpe 0:fedcef5319f5 123 /**
dreschpe 0:fedcef5319f5 124 * Write image buffer to display
dreschpe 0:fedcef5319f5 125 */
dreschpe 0:fedcef5319f5 126 void write_disp(void);
dreschpe 0:fedcef5319f5 127
dreschpe 0:fedcef5319f5 128 /**
dreschpe 0:fedcef5319f5 129 * set or reset a single pixel
dreschpe 0:fedcef5319f5 130 *
dreschpe 0:fedcef5319f5 131 * @param x horizontal position
dreschpe 0:fedcef5319f5 132 * @param y vertical position
dreschpe 0:fedcef5319f5 133 * @param color : 0 white, 1 black
dreschpe 0:fedcef5319f5 134 */
dreschpe 0:fedcef5319f5 135 virtual void pixel(int x, int y, int color);
dreschpe 0:fedcef5319f5 136
dreschpe 0:fedcef5319f5 137 /** Fill the screen with white
dreschpe 0:fedcef5319f5 138 *
dreschpe 0:fedcef5319f5 139 */
dreschpe 0:fedcef5319f5 140 virtual void cls(void);
dreschpe 0:fedcef5319f5 141
dreschpe 0:fedcef5319f5 142 /** draw a 1 pixel line
dreschpe 0:fedcef5319f5 143 *
dreschpe 0:fedcef5319f5 144 * @param x0,y0 start point
dreschpe 0:fedcef5319f5 145 * @param x1,y1 stop point
dreschpe 0:fedcef5319f5 146 * @param color : 0 white, 1 black
dreschpe 0:fedcef5319f5 147 */
dreschpe 0:fedcef5319f5 148 void line(int x0, int y0, int x1, int y1, int color);
dreschpe 0:fedcef5319f5 149
dreschpe 0:fedcef5319f5 150 /** draw a rect
dreschpe 0:fedcef5319f5 151 *
dreschpe 0:fedcef5319f5 152 * @param x0,y0 top left corner
dreschpe 0:fedcef5319f5 153 * @param x1,y1 down right corner
dreschpe 0:fedcef5319f5 154 * @param color : 0 white, 1 black
dreschpe 0:fedcef5319f5 155 */
dreschpe 0:fedcef5319f5 156 void rect(int x0, int y0, int x1, int y1, int color);
dreschpe 0:fedcef5319f5 157
dreschpe 0:fedcef5319f5 158 /** draw a filled rect
dreschpe 0:fedcef5319f5 159 *
dreschpe 0:fedcef5319f5 160 * @param x0,y0 top left corner
dreschpe 0:fedcef5319f5 161 * @param x1,y1 down right corner
dreschpe 0:fedcef5319f5 162 * @param color : 0 white, 1 black
dreschpe 0:fedcef5319f5 163 */
dreschpe 0:fedcef5319f5 164 void fillrect(int x0, int y0, int x1, int y1, int color);
dreschpe 0:fedcef5319f5 165
dreschpe 0:fedcef5319f5 166 /** draw a circle
dreschpe 0:fedcef5319f5 167 *
dreschpe 0:fedcef5319f5 168 * @param x0,y0 center
dreschpe 0:fedcef5319f5 169 * @param r radius
dreschpe 0:fedcef5319f5 170 * @param color : 0 white, 1 black *
dreschpe 0:fedcef5319f5 171 */
dreschpe 0:fedcef5319f5 172 void circle(int x0, int y0, int r, int color);
dreschpe 0:fedcef5319f5 173
dreschpe 0:fedcef5319f5 174 /** draw a filled circle
dreschpe 0:fedcef5319f5 175 *
dreschpe 0:fedcef5319f5 176 * @param x0,y0 center
dreschpe 0:fedcef5319f5 177 * @param r radius
dreschpe 0:fedcef5319f5 178 * @param color : 0 white, 1 black *
dreschpe 0:fedcef5319f5 179 */
dreschpe 0:fedcef5319f5 180 void fillcircle(int x0, int y0, int r, int color);
dreschpe 0:fedcef5319f5 181
dreschpe 0:fedcef5319f5 182 /** set drawing mode
dreschpe 0:fedcef5319f5 183 * @param NORMAL : paint normal color, XOR : paint XOR of current pixels
dreschpe 0:fedcef5319f5 184 */
dreschpe 0:fedcef5319f5 185 void setmode(int mode);
dreschpe 0:fedcef5319f5 186
dreschpe 0:fedcef5319f5 187 /** setup cursor position
dreschpe 0:fedcef5319f5 188 *
dreschpe 0:fedcef5319f5 189 * @param x x-position (top left)
dreschpe 0:fedcef5319f5 190 * @param y y-position
dreschpe 0:fedcef5319f5 191 */
dreschpe 0:fedcef5319f5 192 virtual void locate(int x, int y);
dreschpe 0:fedcef5319f5 193
dreschpe 0:fedcef5319f5 194 /** calculate the max number of char in a line
dreschpe 0:fedcef5319f5 195 *
dreschpe 0:fedcef5319f5 196 * @returns max columns
dreschpe 0:fedcef5319f5 197 * depends on actual font size
dreschpe 0:fedcef5319f5 198 */
dreschpe 0:fedcef5319f5 199 virtual int columns();
dreschpe 0:fedcef5319f5 200
dreschpe 0:fedcef5319f5 201 /** calculate the max number of columns
dreschpe 0:fedcef5319f5 202 *
dreschpe 0:fedcef5319f5 203 * @returns max column
dreschpe 0:fedcef5319f5 204 * depends on actual font size
dreschpe 0:fedcef5319f5 205 */
dreschpe 0:fedcef5319f5 206 virtual int rows();
dreschpe 0:fedcef5319f5 207
dreschpe 0:fedcef5319f5 208 /** put a char on the screen
dreschpe 0:fedcef5319f5 209 *
dreschpe 0:fedcef5319f5 210 * @param value char to print
dreschpe 0:fedcef5319f5 211 * @returns printed char
dreschpe 0:fedcef5319f5 212 */
dreschpe 0:fedcef5319f5 213 virtual int _putc(int value);
dreschpe 0:fedcef5319f5 214
dreschpe 0:fedcef5319f5 215 /** paint a character on given position out of the active font to the screen buffer
dreschpe 0:fedcef5319f5 216 *
dreschpe 0:fedcef5319f5 217 * @param x x-position (top left)
dreschpe 0:fedcef5319f5 218 * @param y y-position
dreschpe 0:fedcef5319f5 219 * @param c char code
dreschpe 0:fedcef5319f5 220 */
dreschpe 0:fedcef5319f5 221 virtual void character(int x, int y, int c);
dreschpe 0:fedcef5319f5 222
dreschpe 0:fedcef5319f5 223 /** select the font to use
dreschpe 0:fedcef5319f5 224 *
dreschpe 0:fedcef5319f5 225 * @param f pointer to font array
dreschpe 0:fedcef5319f5 226 *
dreschpe 0:fedcef5319f5 227 * font array can created with GLCD Font Creator from http://www.mikroe.com
dreschpe 0:fedcef5319f5 228 * you have to add 4 parameter at the beginning of the font array to use:
dreschpe 0:fedcef5319f5 229 * - the number of byte / char
dreschpe 0:fedcef5319f5 230 * - the vertial size in pixel
dreschpe 0:fedcef5319f5 231 * - the horizontal size in pixel
dreschpe 0:fedcef5319f5 232 * - the number of byte per vertical line
dreschpe 0:fedcef5319f5 233 * you also have to change the array to char[]
dreschpe 0:fedcef5319f5 234 */
dreschpe 0:fedcef5319f5 235 void set_font(unsigned char* f);
dreschpe 0:fedcef5319f5 236
dreschpe 0:fedcef5319f5 237 /** print bitmap to buffer
dreschpe 0:fedcef5319f5 238 *
dreschpe 0:fedcef5319f5 239 * @param bm struct Bitmap in flash
dreschpe 0:fedcef5319f5 240 * @param x x start
dreschpe 0:fedcef5319f5 241 * @param y y start
dreschpe 0:fedcef5319f5 242 *
dreschpe 0:fedcef5319f5 243 */
dreschpe 0:fedcef5319f5 244 void print_bm(Bitmap bm, int x, int y);
dreschpe 0:fedcef5319f5 245
dreschpe 0:fedcef5319f5 246
dreschpe 0:fedcef5319f5 247 unsigned char* font;
dreschpe 0:fedcef5319f5 248 unsigned int draw_mode;
dreschpe 0:fedcef5319f5 249
dreschpe 0:fedcef5319f5 250 private:
dreschpe 0:fedcef5319f5 251
dreschpe 0:fedcef5319f5 252 EPD_Class epd_;
dreschpe 0:fedcef5319f5 253 I2C i2c_;
dreschpe 0:fedcef5319f5 254 unsigned int char_x;
dreschpe 0:fedcef5319f5 255 unsigned int char_y;
dreschpe 0:fedcef5319f5 256 int32_t readTemperature();
dreschpe 0:fedcef5319f5 257
dreschpe 0:fedcef5319f5 258 };
dreschpe 0:fedcef5319f5 259
dreschpe 0:fedcef5319f5 260 #endif /* EAEPAPER_H */