Driver to control the EM027BS013 board from Embedded Artists

Dependencies:   EM027BS013

EM027BS013 Simple Driver

This library provides an easy way to write data to the EM027BS013 display, by providing interfaces to common C functions and methods. The library was originally written by Peter Drescher, who created the "EaEpaper" library for the EM027AS012 display (available here, but adapted to use the newer display type and driver (available here), as the existing display is now discontinued.

Big thanks go to the team from Pervasive Displays and Electronic Artists for producing such a nice display, and to Peter for providing the initial interface used in this driver.

Committer:
Leigh_LbR
Date:
Mon May 09 12:29:02 2016 +0000
Revision:
0:e36f1973a674
Child:
1:46dfef41919b
Created initial display driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Leigh_LbR 0:e36f1973a674 1 /* Driver for the 2.7" EM027BS013 E-Paper display produced by Pervasive Displays.
Leigh_LbR 0:e36f1973a674 2 * Based off of the 2.7" EM027AS182 display driver produced by Peter Drescher, but with key differences to use the newer Pervasive Displays driver.
Leigh_LbR 0:e36f1973a674 3 * Copyright notice is below for original driver; this is distributed under the same license.
Leigh_LbR 0:e36f1973a674 4 *
Leigh_LbR 0:e36f1973a674 5 * mbed library for 264*176 pixel 2.7 INCH E-PAPER DISPLAY from Pervasive Displays
Leigh_LbR 0:e36f1973a674 6 * Copyright (c) 2013 Peter Drescher - DC2PD
Leigh_LbR 0:e36f1973a674 7 *
Leigh_LbR 0:e36f1973a674 8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Leigh_LbR 0:e36f1973a674 9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Leigh_LbR 0:e36f1973a674 10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Leigh_LbR 0:e36f1973a674 11 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Leigh_LbR 0:e36f1973a674 12 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Leigh_LbR 0:e36f1973a674 13 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Leigh_LbR 0:e36f1973a674 14 * THE SOFTWARE.
Leigh_LbR 0:e36f1973a674 15 */
Leigh_LbR 0:e36f1973a674 16
Leigh_LbR 0:e36f1973a674 17 #ifndef EAEPAPER_H
Leigh_LbR 0:e36f1973a674 18 #define EAEPAPER_H
Leigh_LbR 0:e36f1973a674 19
Leigh_LbR 0:e36f1973a674 20 /**
Leigh_LbR 0:e36f1973a674 21 * Includes
Leigh_LbR 0:e36f1973a674 22 */
Leigh_LbR 0:e36f1973a674 23 #include "GraphicsDisplay.h"
Leigh_LbR 0:e36f1973a674 24 #include "EM027BS013.h"
Leigh_LbR 0:e36f1973a674 25 #include "mbed.h"
Leigh_LbR 0:e36f1973a674 26
Leigh_LbR 0:e36f1973a674 27 // we have to double buffer the display
Leigh_LbR 0:e36f1973a674 28 #define EA_IMG_BUF_SZ (5808) // 264 x 176 / 8 = 5808
Leigh_LbR 0:e36f1973a674 29
Leigh_LbR 0:e36f1973a674 30 /** Draw mode
Leigh_LbR 0:e36f1973a674 31 * NORMAl
Leigh_LbR 0:e36f1973a674 32 * XOR set pixel by xor of the screen
Leigh_LbR 0:e36f1973a674 33 */
Leigh_LbR 0:e36f1973a674 34 enum {NORMAL,XOR};
Leigh_LbR 0:e36f1973a674 35
Leigh_LbR 0:e36f1973a674 36 /** Bitmap
Leigh_LbR 0:e36f1973a674 37 */
Leigh_LbR 0:e36f1973a674 38 struct Bitmap{
Leigh_LbR 0:e36f1973a674 39 int xSize;
Leigh_LbR 0:e36f1973a674 40 int ySize;
Leigh_LbR 0:e36f1973a674 41 int Byte_in_Line;
Leigh_LbR 0:e36f1973a674 42 char* data;
Leigh_LbR 0:e36f1973a674 43 };
Leigh_LbR 0:e36f1973a674 44
Leigh_LbR 0:e36f1973a674 45
Leigh_LbR 0:e36f1973a674 46 /* color definitions */
Leigh_LbR 0:e36f1973a674 47 #define Black 0x0
Leigh_LbR 0:e36f1973a674 48 #define White 0x1
Leigh_LbR 0:e36f1973a674 49
Leigh_LbR 0:e36f1973a674 50
Leigh_LbR 0:e36f1973a674 51 class EaEpaper : public GraphicsDisplay
Leigh_LbR 0:e36f1973a674 52 {
Leigh_LbR 0:e36f1973a674 53 public:
Leigh_LbR 0:e36f1973a674 54 EaEpaper(PinName sec03_SpiSCK,
Leigh_LbR 0:e36f1973a674 55 PinName sec04_SpiMOSI,
Leigh_LbR 0:e36f1973a674 56 PinName sec05_SpiMISO,
Leigh_LbR 0:e36f1973a674 57 PinName sec06_EpdCS,
Leigh_LbR 0:e36f1973a674 58 PinName sec07_EpdBusy,
Leigh_LbR 0:e36f1973a674 59 PinName sec08_EpdBorder,
Leigh_LbR 0:e36f1973a674 60 PinName sec09_I2cSCL,
Leigh_LbR 0:e36f1973a674 61 PinName sec10_I2cSDA,
Leigh_LbR 0:e36f1973a674 62 PinName sec11_FlashCS,
Leigh_LbR 0:e36f1973a674 63 PinName sec12_EpdReset,
Leigh_LbR 0:e36f1973a674 64 PinName sec13_EpdPanelOn,
Leigh_LbR 0:e36f1973a674 65 PinName sec14_EpdDischarge,
Leigh_LbR 0:e36f1973a674 66 const char* name = "EPD");
Leigh_LbR 0:e36f1973a674 67
Leigh_LbR 0:e36f1973a674 68 /** Get the width of the screen in pixel
Leigh_LbR 0:e36f1973a674 69 *
Leigh_LbR 0:e36f1973a674 70 * @param
Leigh_LbR 0:e36f1973a674 71 * @returns width of screen in pixel
Leigh_LbR 0:e36f1973a674 72 *
Leigh_LbR 0:e36f1973a674 73 */
Leigh_LbR 0:e36f1973a674 74 virtual int width();
Leigh_LbR 0:e36f1973a674 75
Leigh_LbR 0:e36f1973a674 76 /** Get the height of the screen in pixel
Leigh_LbR 0:e36f1973a674 77 *
Leigh_LbR 0:e36f1973a674 78 * @returns height of screen in pixel
Leigh_LbR 0:e36f1973a674 79 *
Leigh_LbR 0:e36f1973a674 80 */
Leigh_LbR 0:e36f1973a674 81 virtual int height();
Leigh_LbR 0:e36f1973a674 82
Leigh_LbR 0:e36f1973a674 83
Leigh_LbR 0:e36f1973a674 84 /**
Leigh_LbR 0:e36f1973a674 85 * Clear the display
Leigh_LbR 0:e36f1973a674 86 */
Leigh_LbR 0:e36f1973a674 87 void clear();
Leigh_LbR 0:e36f1973a674 88
Leigh_LbR 0:e36f1973a674 89 /**
Leigh_LbR 0:e36f1973a674 90 * Write image buffer to display
Leigh_LbR 0:e36f1973a674 91 */
Leigh_LbR 0:e36f1973a674 92 void write_disp(void);
Leigh_LbR 0:e36f1973a674 93
Leigh_LbR 0:e36f1973a674 94 /**
Leigh_LbR 0:e36f1973a674 95 * set or reset a single pixel
Leigh_LbR 0:e36f1973a674 96 *
Leigh_LbR 0:e36f1973a674 97 * @param x horizontal position
Leigh_LbR 0:e36f1973a674 98 * @param y vertical position
Leigh_LbR 0:e36f1973a674 99 * @param color : 0 white, 1 black
Leigh_LbR 0:e36f1973a674 100 */
Leigh_LbR 0:e36f1973a674 101 virtual void pixel(int x, int y, int color);
Leigh_LbR 0:e36f1973a674 102
Leigh_LbR 0:e36f1973a674 103 /** Fill the screen with white
Leigh_LbR 0:e36f1973a674 104 *
Leigh_LbR 0:e36f1973a674 105 */
Leigh_LbR 0:e36f1973a674 106 virtual void cls(void);
Leigh_LbR 0:e36f1973a674 107
Leigh_LbR 0:e36f1973a674 108 /** draw a 1 pixel line
Leigh_LbR 0:e36f1973a674 109 *
Leigh_LbR 0:e36f1973a674 110 * @param x0,y0 start point
Leigh_LbR 0:e36f1973a674 111 * @param x1,y1 stop point
Leigh_LbR 0:e36f1973a674 112 * @param color : 0 white, 1 black
Leigh_LbR 0:e36f1973a674 113 */
Leigh_LbR 0:e36f1973a674 114 void line(int x0, int y0, int x1, int y1, int color);
Leigh_LbR 0:e36f1973a674 115
Leigh_LbR 0:e36f1973a674 116 /** draw a rect
Leigh_LbR 0:e36f1973a674 117 *
Leigh_LbR 0:e36f1973a674 118 * @param x0,y0 top left corner
Leigh_LbR 0:e36f1973a674 119 * @param x1,y1 down right corner
Leigh_LbR 0:e36f1973a674 120 * @param color : 0 white, 1 black
Leigh_LbR 0:e36f1973a674 121 */
Leigh_LbR 0:e36f1973a674 122 void rect(int x0, int y0, int x1, int y1, int color);
Leigh_LbR 0:e36f1973a674 123
Leigh_LbR 0:e36f1973a674 124 /** draw a filled rect
Leigh_LbR 0:e36f1973a674 125 *
Leigh_LbR 0:e36f1973a674 126 * @param x0,y0 top left corner
Leigh_LbR 0:e36f1973a674 127 * @param x1,y1 down right corner
Leigh_LbR 0:e36f1973a674 128 * @param color : 0 white, 1 black
Leigh_LbR 0:e36f1973a674 129 */
Leigh_LbR 0:e36f1973a674 130 void fillrect(int x0, int y0, int x1, int y1, int color);
Leigh_LbR 0:e36f1973a674 131
Leigh_LbR 0:e36f1973a674 132 /** draw a circle
Leigh_LbR 0:e36f1973a674 133 *
Leigh_LbR 0:e36f1973a674 134 * @param x0,y0 center
Leigh_LbR 0:e36f1973a674 135 * @param r radius
Leigh_LbR 0:e36f1973a674 136 * @param color : 0 white, 1 black *
Leigh_LbR 0:e36f1973a674 137 */
Leigh_LbR 0:e36f1973a674 138 void circle(int x0, int y0, int r, int color);
Leigh_LbR 0:e36f1973a674 139
Leigh_LbR 0:e36f1973a674 140 /** draw a filled circle
Leigh_LbR 0:e36f1973a674 141 *
Leigh_LbR 0:e36f1973a674 142 * @param x0,y0 center
Leigh_LbR 0:e36f1973a674 143 * @param r radius
Leigh_LbR 0:e36f1973a674 144 * @param color : 0 white, 1 black *
Leigh_LbR 0:e36f1973a674 145 */
Leigh_LbR 0:e36f1973a674 146 void fillcircle(int x0, int y0, int r, int color);
Leigh_LbR 0:e36f1973a674 147
Leigh_LbR 0:e36f1973a674 148 /** set drawing mode
Leigh_LbR 0:e36f1973a674 149 * @param NORMAL : paint normal color, XOR : paint XOR of current pixels
Leigh_LbR 0:e36f1973a674 150 */
Leigh_LbR 0:e36f1973a674 151 void setmode(int mode);
Leigh_LbR 0:e36f1973a674 152
Leigh_LbR 0:e36f1973a674 153 /** setup cursor position
Leigh_LbR 0:e36f1973a674 154 *
Leigh_LbR 0:e36f1973a674 155 * @param x x-position (top left)
Leigh_LbR 0:e36f1973a674 156 * @param y y-position
Leigh_LbR 0:e36f1973a674 157 */
Leigh_LbR 0:e36f1973a674 158 virtual void locate(int x, int y);
Leigh_LbR 0:e36f1973a674 159
Leigh_LbR 0:e36f1973a674 160 /** calculate the max number of char in a line
Leigh_LbR 0:e36f1973a674 161 *
Leigh_LbR 0:e36f1973a674 162 * @returns max columns
Leigh_LbR 0:e36f1973a674 163 * depends on actual font size
Leigh_LbR 0:e36f1973a674 164 */
Leigh_LbR 0:e36f1973a674 165 virtual int columns();
Leigh_LbR 0:e36f1973a674 166
Leigh_LbR 0:e36f1973a674 167 /** calculate the max number of columns
Leigh_LbR 0:e36f1973a674 168 *
Leigh_LbR 0:e36f1973a674 169 * @returns max column
Leigh_LbR 0:e36f1973a674 170 * depends on actual font size
Leigh_LbR 0:e36f1973a674 171 */
Leigh_LbR 0:e36f1973a674 172 virtual int rows();
Leigh_LbR 0:e36f1973a674 173
Leigh_LbR 0:e36f1973a674 174 /** put a char on the screen
Leigh_LbR 0:e36f1973a674 175 *
Leigh_LbR 0:e36f1973a674 176 * @param value char to print
Leigh_LbR 0:e36f1973a674 177 * @returns printed char
Leigh_LbR 0:e36f1973a674 178 */
Leigh_LbR 0:e36f1973a674 179 virtual int _putc(int value);
Leigh_LbR 0:e36f1973a674 180
Leigh_LbR 0:e36f1973a674 181 /** paint a character on given position out of the active font to the screen buffer
Leigh_LbR 0:e36f1973a674 182 *
Leigh_LbR 0:e36f1973a674 183 * @param x x-position (top left)
Leigh_LbR 0:e36f1973a674 184 * @param y y-position
Leigh_LbR 0:e36f1973a674 185 * @param c char code
Leigh_LbR 0:e36f1973a674 186 */
Leigh_LbR 0:e36f1973a674 187 virtual void character(int x, int y, int c);
Leigh_LbR 0:e36f1973a674 188
Leigh_LbR 0:e36f1973a674 189 /** select the font to use
Leigh_LbR 0:e36f1973a674 190 *
Leigh_LbR 0:e36f1973a674 191 * @param f pointer to font array
Leigh_LbR 0:e36f1973a674 192 *
Leigh_LbR 0:e36f1973a674 193 * font array can created with GLCD Font Creator from http://www.mikroe.com
Leigh_LbR 0:e36f1973a674 194 * you have to add 4 parameter at the beginning of the font array to use:
Leigh_LbR 0:e36f1973a674 195 * - the number of byte / char
Leigh_LbR 0:e36f1973a674 196 * - the vertial size in pixel
Leigh_LbR 0:e36f1973a674 197 * - the horizontal size in pixel
Leigh_LbR 0:e36f1973a674 198 * - the number of byte per vertical line
Leigh_LbR 0:e36f1973a674 199 * you also have to change the array to char[]
Leigh_LbR 0:e36f1973a674 200 */
Leigh_LbR 0:e36f1973a674 201 void set_font(unsigned char* f);
Leigh_LbR 0:e36f1973a674 202
Leigh_LbR 0:e36f1973a674 203 /** print bitmap to buffer
Leigh_LbR 0:e36f1973a674 204 *
Leigh_LbR 0:e36f1973a674 205 * @param bm struct Bitmap in flash
Leigh_LbR 0:e36f1973a674 206 * @param x x start
Leigh_LbR 0:e36f1973a674 207 * @param y y start
Leigh_LbR 0:e36f1973a674 208 *
Leigh_LbR 0:e36f1973a674 209 */
Leigh_LbR 0:e36f1973a674 210 void print_bm(Bitmap bm, int x, int y);
Leigh_LbR 0:e36f1973a674 211
Leigh_LbR 0:e36f1973a674 212 void drawImage(uint8_t* img);
Leigh_LbR 0:e36f1973a674 213
Leigh_LbR 0:e36f1973a674 214 unsigned char* font;
Leigh_LbR 0:e36f1973a674 215 unsigned int draw_mode;
Leigh_LbR 0:e36f1973a674 216
Leigh_LbR 0:e36f1973a674 217 private:
Leigh_LbR 0:e36f1973a674 218
Leigh_LbR 0:e36f1973a674 219 EM027BS013 _epd;
Leigh_LbR 0:e36f1973a674 220 unsigned int char_x;
Leigh_LbR 0:e36f1973a674 221 unsigned int char_y;
Leigh_LbR 0:e36f1973a674 222
Leigh_LbR 0:e36f1973a674 223 };
Leigh_LbR 0:e36f1973a674 224
Leigh_LbR 0:e36f1973a674 225
Leigh_LbR 0:e36f1973a674 226 #endif